Skip to content

Commit a683b64

Browse files
Marius StorhaugCopilot
authored andcommitted
Correct the reason given for shim teardown by name
Copilot review flagged the comments as factually wrong, and it was half right. Set-Item does accept 'function:global:X' - it creates X in the global scope. The real problem is asymmetry: Remove-Item and Get-Item do not resolve that same path back to the function, and fail silently instead of erroring, so the teardown was a no-op. Verified no 'global:' path form removes the function (function:global:X, Function:global:X, Function:\global:X all leave it in place), so removing by name is required. Behaviour is unchanged; only the explanation is corrected. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent c8d1ade commit a683b64

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ AfterAll {
2929
foreach ($name in $script:environmentVariableNames) {
3030
[System.Environment]::SetEnvironmentVariable($name, $script:originalEnvironment[$name])
3131
}
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.
32+
# Set-Item accepts 'function:global:X' and creates a function named 'X' in the global scope, but
33+
# Remove-Item and Get-Item do not resolve that same path back to it, and fail silently rather than
34+
# erroring. Removing by name is what actually deletes the shims; leaving them behind would shadow the
35+
# real cmdlets for every test file that runs later in the session.
3436
Remove-Item -Path 'Function:\Find-PSResource' -ErrorAction SilentlyContinue
3537
Remove-Item -Path 'Function:\Publish-PSResource' -ErrorAction SilentlyContinue
3638
Remove-Item -Path 'Function:\Resolve-PSModuleDependency' -ErrorAction SilentlyContinue

.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-
# 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.
38+
# Set-Item accepts 'function:global:X' and creates a function named 'X' in the global scope, but
39+
# Remove-Item and Get-Item do not resolve that same path back to it, and fail silently rather than
40+
# erroring. Removing by name is what actually deletes the shims; leaving them behind would shadow the
41+
# real commands for every test file that runs later in the session.
4042
Remove-Item -Path 'Function:\gh' -ErrorAction SilentlyContinue
4143
Remove-Item -Path 'Function:\git' -ErrorAction SilentlyContinue
4244
}

0 commit comments

Comments
 (0)