Respect CommandType during fuzzy Get-Command lookup#27516
Open
KirtiRamchandani wants to merge 2 commits into
Open
Respect CommandType during fuzzy Get-Command lookup#27516KirtiRamchandani wants to merge 2 commits into
KirtiRamchandani wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds regression coverage and adjusts Get-Command fuzzy matching accumulation so that command filtering (e.g., -CommandType) is respected consistently during fuzzy matches.
Changes:
- Added a Pester test validating
-CommandType Functionexcludes alias results during fuzzy matching. - Updated
GetCommandCommand.AccumulateMatchingCommandsto apply matching/parameter filters while iterating fuzzy matches, accumulating results and scores in one pass.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Command.Tests.ps1 | Adds regression test ensuring -CommandType is honored with -UseFuzzyMatching. |
| src/System.Management.Automation/engine/GetCommandCommand.cs | Refactors fuzzy matching accumulation to filter commands before adding to results/scores. |
Comment on lines
+34
to
+47
| function Invoke-ZzqFuzzyCommandTypeThing { } | ||
| Set-Alias -Name Invoke-ZzqFuzzyCommandTypeThang -Value Invoke-ZzqFuzzyCommandTypeThing | ||
|
|
||
| try { | ||
| $cmds = Get-Command Invoke-ZzqFuzzyCommandTypeThng -UseFuzzyMatching -CommandType Function | ||
|
|
||
| $cmds.Name | Should -Contain 'Invoke-ZzqFuzzyCommandTypeThing' | ||
| $cmds.Name | Should -Not -Contain 'Invoke-ZzqFuzzyCommandTypeThang' | ||
| $cmds.CommandType | Should -Not -Contain ([System.Management.Automation.CommandTypes]::Alias) | ||
| } | ||
| finally { | ||
| Remove-Item -Path Function:\Invoke-ZzqFuzzyCommandTypeThing -ErrorAction SilentlyContinue | ||
| Remove-Item -Path Alias:\Invoke-ZzqFuzzyCommandTypeThang -ErrorAction SilentlyContinue | ||
| } |
Comment on lines
+899
to
+913
| CommandInfo current = commandScore.Command; | ||
|
|
||
| if (IsCommandMatch(ref current, out isDuplicate) && (!IsCommandInResult(current)) && IsParameterMatch(current)) | ||
| { | ||
| _accumulatedResults.Add(current); | ||
| _commandScores.Add(new CommandScore(current, commandScore.Score)); | ||
|
|
||
| commands = _commandScores.Select(static x => x.Command); | ||
| // Make sure we don't exceed the TotalCount parameter | ||
| ++count; | ||
|
|
||
| if (TotalCount >= 0 && count >= TotalCount) | ||
| { | ||
| break; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Fixes #26592.
When Get-Command discovers fuzzy matches from available modules, it currently records fuzzy scores before applying the normal CommandType and parameter filters. OutputResultsHelper later emits from the score list, so commands filtered out of the accumulated result set can still appear in output.
This change keeps fuzzy scores only for commands that pass the same matching path used for accumulated results. The non-fuzzy module lookup path is unchanged.
PR Context
Get-Command -UseFuzzyMatching -CommandType should return only commands of the requested type.
PR Checklist
Validation
Result: Get-Command.Tests.ps1 passed: 23 passed, 0 failed.