fix: pass -Scope correctly when Target=CurrentUser for PowerShellGet package#167
Open
DearingDev wants to merge 7 commits into
Open
fix: pass -Scope correctly when Target=CurrentUser for PowerShellGet package#167DearingDev wants to merge 7 commits into
DearingDev wants to merge 7 commits into
Conversation
…packages Resolves PowerShellOrg#130. Resolves PowerShellOrg#156. The elseif condition checked \$Scope (undefined at that point) instead of \$Dependency.Target, so -Scope was never added to Install-Package parameters, causing an elevation error. Restructured to match the same Target->Scope pattern used in PSGalleryModule.ps1.
## Summary - **Test files**: Fully migrated `PSDepend.Tests.ps1` and `PSModuleGallery.Type.Tests.ps1` to Pester 5 — all setup code moved into `BeforeAll` blocks with `$script:` scoped variables, assertion syntax updated (`Should be` → `Should -Be`), `Assert-MockCalled` replaced with `Should -Invoke`, `-ExclusiveFilter` replaced with a two-assertion pattern, `-Scope It` removed, stub function definitions moved into `BeforeAll` so they survive the discovery→run phase boundary - **`Get-ClonedObject.ps1`**: Replaced `BinaryFormatter` (removed in .NET 7) with a recursive hashtable deep-clone — fixes 2 test failures on PS7 - **`Test-PlatformSupport.ps1`**: Added a PS Core on Windows exemption so dependency types that declare `Supports = 'windows'` (FileDownload, FileSystem, Chocolatey) are no longer incorrectly skipped under PS7 Core on Windows — fixes 12 test failures **Result: 92 passed, 0 failed, 1 skipped** (the 1 skip is a pre-existing `PendingSkip` tag, not a regression) ## Test plan - [x] Run `Invoke-Pester ./Tests -Output Detailed` locally — 92 passed, 0 failed - [x] Verify CI passes on Windows, macOS, and Ubuntu runners (GitHub Actions matrix) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes misleading error message when dependency file has been saved erroneously as *.depend.ps1 instead of *.depend.psd1
…rentuser-giving-error-asking-for-elevation fix: pass -Scope correctly when Target=CurrentUser for PowerShellGet packages
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.
What this changes
Fixes a variable reference bug in PSDepend/PSDependScripts/Package.ps1 where the elseif condition checked $Scope (undefined at that point) instead of $Dependency.Target. As a result, -Scope was never passed to Install-Package when Target = 'CurrentUser', causing an elevation prompt. The Target→Scope logic has been restructured to match the pattern used in PSGalleryModule.ps1.
Why
When invoking PSDepend with -Target CurrentUser for PowerShellGet packages, users were unexpectedly prompted for elevation because the scope was never set.
Closes #130
Type of change
Checklist
Invoke-psake Analyzepasses locally with no new warningsInvoke-psake Testpasses locally on at least one platformCHANGELOG.mdupdated (required for any user-facing change)Additional notes
The fix mirrors the existing logic in PSGalleryModule.ps1 which handles the same Target→Scope mapping correctly.