fix: InputObject hashtable no longer mutated by Get-Dependency (#35)#192
Open
HeyItsGilbert wants to merge 2 commits into
Open
fix: InputObject hashtable no longer mutated by Get-Dependency (#35)#192HeyItsGilbert wants to merge 2 commits into
HeyItsGilbert wants to merge 2 commits into
Conversation
Parse-Dependency called $Dependencies.Remove('PSDependOptions') on the
original hashtable because $Dependencies was assigned by reference.
Clone each element before Parse-Dependency runs so the caller's object
is left intact and a second Invoke-PSDepend / Get-Dependency call still
honours PSDependOptions (e.g. Target).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a side effect where Get-Dependency -InputObject mutated the caller-provided hashtable by removing PSDependOptions, which broke subsequent invocations that relied on those global options.
Changes:
- Clone each
-InputObjecthashtable before parsing to preventPSDependOptionsremoval from mutating the caller’s object. - Add regression tests ensuring the caller’s
PSDependOptionssurvivesGet-Dependencycalls. - Document the fix in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
PSDepend/Public/Get-Dependency.ps1 |
Clones each input hashtable before Parse-Dependency removes PSDependOptions, avoiding caller mutation. |
Tests/PSDepend.Tests.ps1 |
Adds regression tests for non-mutation across single/double invocation scenarios. |
CHANGELOG.md |
Notes the behavioral fix under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test Results 3 files 66 suites 1m 24s ⏱️ Results for commit cd1fcb4. ♻️ This comment has been updated with latest results. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Gilbert Sanchez <me@gilbertsanchez.com>
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.
Summary
Get-Dependency -InputObjectnow clones each element before passing it toParse-Dependency, soPSDependOptionsis no longer stripped from the caller's hashtableInvoke-PSDepend/Get-Dependencycall with the same object now correctly honours global options (e.g.Target)Root cause
Get-Dependency.ps1:440assigned$Dependencies = $InputDependency(a reference copy).Parse-Dependencythen called$Dependencies.Remove('PSDependOptions'), mutating the original hashtable in the caller's scope.Fix:
$Dependencies = $InputDependency.Clone()— one-line shallow clone, sufficient becauseRemoveonly touches the top-level key and no other mutation sites exist.Test plan
.\build.ps1 StageFilesthenInvoke-Pester Tests\PSDepend.Tests.ps1 -Tag Unit— all 22 tests passCloses #35
Generated with Claude Code