Skip to content

Commit 7019cd9

Browse files
Marius StorhaugCopilot
authored andcommitted
Stop test command shims leaking into the global scope
Remove-Item does not accept a 'global:' scope qualifier in a provider path, so the AfterAll cleanup silently failed and left the Find-PSResource, Publish-PSResource, Resolve-PSModuleDependency, gh, and git shims in the global scope. Later test files then resolved the shims instead of the real commands, which failed Get-NextPrereleaseNumber with 'A parameter cannot be found that matches parameter name Prerelease'. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 41f022c commit 7019cd9

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

.github/actions/Publish-PSModule/tests/Publish-PSModule.Recovery.Tests.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ AfterAll {
2929
foreach ($name in $script:environmentVariableNames) {
3030
[System.Environment]::SetEnvironmentVariable($name, $script:originalEnvironment[$name])
3131
}
32-
Remove-Item -Path function:global:Find-PSResource -ErrorAction SilentlyContinue
33-
Remove-Item -Path function:global:Publish-PSResource -ErrorAction SilentlyContinue
34-
Remove-Item -Path function:global:Resolve-PSModuleDependency -ErrorAction SilentlyContinue
32+
# The 'global:' scope qualifier is not a valid provider path, so it must be omitted here.
33+
# Otherwise the shims leak into the global scope and shadow the real cmdlets in later test files.
34+
Remove-Item -Path 'Function:\Find-PSResource' -ErrorAction SilentlyContinue
35+
Remove-Item -Path 'Function:\Publish-PSResource' -ErrorAction SilentlyContinue
36+
Remove-Item -Path 'Function:\Resolve-PSModuleDependency' -ErrorAction SilentlyContinue
3537
}
3638

3739
Describe 'Publish-PSModule recovery' {

.github/actions/Release-PSModule/tests/Release-PSModule.WhatIf.Tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ AfterAll {
3535
foreach ($name in $script:environmentVariableNames) {
3636
[System.Environment]::SetEnvironmentVariable($name, $script:originalEnvironment[$name])
3737
}
38-
Remove-Item -Path function:global:gh -ErrorAction SilentlyContinue
39-
Remove-Item -Path function:global:git -ErrorAction SilentlyContinue
38+
# The 'global:' scope qualifier is not a valid provider path, so it must be omitted here.
39+
# Otherwise the shims leak into the global scope and shadow the real commands in later test files.
40+
Remove-Item -Path 'Function:\gh' -ErrorAction SilentlyContinue
41+
Remove-Item -Path 'Function:\git' -ErrorAction SilentlyContinue
4042
}
4143

4244
Describe 'Release-PSModule WhatIf' {

0 commit comments

Comments
 (0)