Skip to content

Verify a single loaded module version in the version-pinning actions (unload error handling) #382

Description

Context

The version-pinning actions — Invoke-ScriptAnalyzer, Invoke-Pester (Install-PSResourceWithRetry), and GitHub-Script (init.ps1) — now ensure the selected module version is the only one loaded by removing already-loaded instances (Get-Module -Name <Name> -All | Remove-Module -Force) and importing the resolved version with -RequiredVersion -Force -Global.

Copilot review on PSModule/Invoke-Pester#74 and PSModule/GitHub-Script#100 flagged that removal currently uses -ErrorAction SilentlyContinue. If unloading a previously-imported instance fails (for example the module is in use), the run can silently proceed with multiple versions loaded, undermining the determinism guarantee, with no signal.

Trade-off

Naively switching removal to -ErrorAction Stop is risky: Get-Module -All can return nested/duplicate entries whose removal legitimately errors, causing spurious failures. So a blanket stop-on-remove is not the right fix.

Proposal

Adopt a consistent, low-risk verification across all three actions:

  • Keep removal resilient, but after import verify determinism, e.g. assert Get-Module -Name <Name> resolves to exactly the selected version and throw with context if multiple versions remain loaded.
  • Apply the same approach in all three actions so behavior is uniform.

Acceptance criteria

  • After provisioning, exactly one version of the target module is loaded, or the action fails with a clear message naming the versions found.
  • No spurious failures from benign Remove-Module conditions.
  • Consistent implementation across Invoke-ScriptAnalyzer, Invoke-Pester, and GitHub-Script.

Raised from Copilot review feedback on PSModule/Invoke-Pester#74 and PSModule/GitHub-Script#100.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions