Skip to content

Warn when -GroupProvider outputs more than one value in a call - #105

Merged
HalRiveria merged 2 commits into
mainfrom
fix/group-provider-warning
Dec 2, 2026
Merged

HalRiveria merged 2 commits into
mainfrom
fix/group-provider-warning

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

-GroupProvider is meant to output one value per call: the group, or $null to end. When a call output more than one value, they were silently taken together as one group. That covers a stray value next to the group (the index ArrayList.Add returns, say) and a list returned without the leading comma. Nothing said so.

The dispatcher now warns, once per run, when a call outputs more than one value. The warning names -GroupProvider, says how many values arrived, and suggests $null = ... for a stray value or return ,$list for a list group. The group itself is unchanged: return @('a', 'b', 'c') is still one three-item group, and a stray index is still part of the group it came with. Output ending in $null keeps its existing warning and isn't warned about twice.

To tell the two apart, the provider's output is now collected with @(...), which keeps one element per value output, instead of by plain assignment, which turns one list and several separate values into the same array. The call keeps the continue/break guard every callback has, inlined, and the harness's static guard check now recognizes that @(do { } while ($false)) form. Each value comes through exactly as before, PSObject wrapper and note properties included. A .NET list's Add() would have dropped them.

Testing

New tests in harness section AT: one value, $null, no output, a list with the comma (two items and one), a stray value plus the group, and a list returned without the comma. The last two warn once per run, with the count; the rest don't. A further test checks a group value keeps a note property.

Against the code before this change, on Windows PowerShell 5.1, the two warning cases failed and the rest passed (2 failed, 13 passed in that section). With it:

Windows PowerShell 5.1 PowerShell 7
Full harness all passed (731 assertions) all passed (731 assertions)
-AsModule -Section MODULE passed (289 assertions) passed (289 assertions)

Cost, 5,000 groups with no jobs (median of 5): 5.1 went from 437 to 394 µs per group, and 7 from 129 to 102. The provider is no longer called through a separate function.

🤖 Generated with Claude Code

HalRiveria and others added 2 commits December 2, 2026 00:59
Several values in one call (a stray ArrayList.Add index next to the group, or a list returned without the leading comma) are taken together as one group, as before, but now with a warning once per run that says how many values arrived. The provider's output is counted as it comes down the pipeline, since collecting it by assignment can't tell one list from several values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Count -GroupProvider's values with @() instead of passing each through a .NET list, whose Add() unwrapped a value's PSObject and lost any note property on it. The harness's static guard check accepts the @(do { } while ($false)) form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria
HalRiveria merged commit 5a21356 into main Dec 2, 2026
2 checks passed
@HalRiveria
HalRiveria deleted the fix/group-provider-warning branch December 2, 2026 06:33
@HalRiveria-Bot HalRiveria-Bot mentioned this pull request Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants