Skip to content

fix: InputObject hashtable no longer mutated by Get-Dependency (#35)#192

Open
HeyItsGilbert wants to merge 2 commits into
mainfrom
worktree-dazzling-whistling-ullman
Open

fix: InputObject hashtable no longer mutated by Get-Dependency (#35)#192
HeyItsGilbert wants to merge 2 commits into
mainfrom
worktree-dazzling-whistling-ullman

Conversation

@HeyItsGilbert

Copy link
Copy Markdown
Member

Summary

  • Get-Dependency -InputObject now clones each element before passing it to Parse-Dependency, so PSDependOptions is no longer stripped from the caller's hashtable
  • A second Invoke-PSDepend / Get-Dependency call with the same object now correctly honours global options (e.g. Target)
  • Two regression tests added covering single and double invocation

Root cause

Get-Dependency.ps1:440 assigned $Dependencies = $InputDependency (a reference copy). Parse-Dependency then called $Dependencies.Remove('PSDependOptions'), mutating the original hashtable in the caller's scope.

Fix: $Dependencies = $InputDependency.Clone() — one-line shallow clone, sufficient because Remove only touches the top-level key and no other mutation sites exist.

Test plan

  • .\build.ps1 StageFiles then Invoke-Pester Tests\PSDepend.Tests.ps1 -Tag Unit — all 22 tests pass
  • New tests: "Does not mutate the caller's InputObject — PSDependOptions key survives after Get-Dependency" and "...honored on a second Get-Dependency call"

Closes #35

Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 13, 2026 00:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -InputObject hashtable before parsing to prevent PSDependOptions removal from mutating the caller’s object.
  • Add regression tests ensuring the caller’s PSDependOptions survives Get-Dependency calls.
  • 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.

Comment thread Tests/PSDepend.Tests.ps1
@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

Test Results

    3 files     66 suites   1m 24s ⏱️
  969 tests   911 ✅ 58 💤 0 ❌
1 296 runs  1 228 ✅ 68 💤 0 ❌

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>
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.

Object passed to InputObject parameter is modified by module

2 participants