Skip to content

fix(ci): resolve Pester assembly collision in build bootstrap - #113

Merged
HeyItsGilbert merged 2 commits into
mainfrom
chore/psdepend-0.7.0-beta1
Nov 3, 2026
Merged

HeyItsGilbert merged 2 commits into
mainfrom
chore/psdepend-0.7.0-beta1

Conversation

@HeyItsGilbert

@HeyItsGilbert HeyItsGilbert commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

CI on PR #112 failed identically on every hosted runner:

Add-Type: Could not load file or assembly 'Pester, Version=6.1.0.0, ...'.
Assembly with same name is already loaded
build.ps1 Bootstrap
├── PSDepend: now installed/imported at the exact (prerelease-aware)
│   version requirements.psd1 pins, instead of "any version already present"
└── Pester: installed + globally imported *before* Invoke-PSDepend runs,
    closing an install-order race against PowerShellBuild's own
    RequiredModules-driven Pester install

Root cause: PowerShellBuild (0.7.2) declares Pester >= 5.6.1 as its own RequiredModules dependency, no upper bound. Install-Module always auto-resolves a target's RequiredModules independently of whatever this repo's own requirements.psd1 Pester entry pins — whichever install reaches the Gallery first wins a race. If PowerShellBuild's own install lands before our pinned Pester 6.1.0 is on disk, PowerShellGet fetches whatever's newest on PSGallery as a second, stray copy (confirmed non-deterministic locally across repeated clean-slate runs).

PowerShellBuild's bundled Test task (Test-PSBuildPester.ps1) then calls Import-Module Pester -MinimumVersion 5.0.0 — no exact pin. -MinimumVersion always resolves to the highest matching version found anywhere on $env:PSModulePath, never whatever's already loaded under that name, so the stray newer copy gets a fresh load attempt and collides with the Pester.dll already Add-Type'd into the process.

 # build.ps1 bootstrap, simplified
-if (-not (Get-Module -Name PSDepend -ListAvailable)) {
-    Install-Module -Name PSDepend -Repository PSGallery -Scope CurrentUser -Force
-}
-Import-Module -Name PSDepend -Verbose:$false
+# read PSDepend.Version from requirements.psd1, install/import exactly that
+...
+# install + globally import the pinned Pester *before* touching PowerShellBuild,
+# so PowerShellGet already finds it satisfying and never reaches for anything else
+...
 Invoke-PSDepend -Path './requirements.psd1' -Install -Import -Force -WarningAction SilentlyContinue
+# defense in depth: prune any other installed Pester version, reassert the pin

Investigation note: the first fix attempt (bumping PSDepend to 0.7.0-beta1 alone, on the theory its new transitive-dependency resolution would prevent the stray install) reproduced the identical failure on real CI — confirming the bump alone wasn't sufficient and the actual trigger was the install-order race above, not something PSDepend's own dependency graph controls (PowerShellGet's native RequiredModules auto-install, invoked inside a single Install-Module call, happens beneath PSDepend entirely). The PSDepend bump is kept — it's a legitimate improvement and narrows this class of collision for dependencies PSDepend itself resolves — but the actual fix is the install-order change in build.ps1.

Evidence

Before: PR #112, all three Run Tests (macOS/windows/ubuntu-latest) jobs failed identically at ./build.ps1 -Task Test -Bootstrap, before any test ran.

After (this branch, real CI):

  • ubuntu-latest: pass, 368/0/5
  • macOS-latest: pass, 368/0/5
  • windows-latest: Pester task passes cleanly, 368/0/5 — confirming the collision itself is resolved on every platform. That job currently fails afterward, in the unrelated ANALYZE task (PSScriptAnalyzer NullReferenceException in Test-PSBuildScriptAnalysis.ps1) — a separate, pre-existing issue this change doesn't touch and didn't introduce (nothing here touches PSScriptAnalyzer config, and the local Linux Analyze task runs clean on every local run below).
  • PowerShell 5.1 job: pending at last check.

Local (3/3 consecutive clean-slate runs, each with a second, newer Pester version pre-seeded on disk to force the exact collision):

Tests Passed: 368, Failed: 0, Skipped: 5, Inconclusive: 0, NotRun: 0
Success      : True

Merge Danger

Door: Two-way — build-tooling/bootstrap only, no production code touched; trivially revertable.

Blast Radius: Low, build/CI-only. PSDepend 0.7.0-beta1 is a prerelease, flagged explicitly via AllowPrerelease so the intent is visible in requirements.psd1. The windows-latest ANALYZE failure is called out above as a known, separate, pre-existing gap — not claimed as fixed by this PR.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 17:24

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.

🟡 Changes recommended

Bootstrap may load the wrong PSDepend variant, lacks the lock needed to prevent Pester conflicts, and repeatedly attempts to reinstall the prerelease from the gallery.

3 open issues
What changed in this PR

Updates Gatekeeper’s build bootstrap to use the declared PSDepend version, aiming to address the Pester assembly collision reported in PR #112. Changes are limited to build tooling.

Changes:

  • Bumps PSDepend from 0.4.1 to 0.7.0-beta1 with prerelease support.
  • Reads the bootstrap version from requirements.psd1 and checks installed prerelease metadata before installation.
File Description
requirements.psd1 Pins PSDepend to 0.7.0-beta1 and enables prerelease installation.
build.ps1 Adds version-aware bootstrap checks and installation, then imports by numeric base version.

Review effort: Balanced

Comment thread build.ps1 Resolved
Comment thread requirements.psd1 Resolved
Comment thread requirements.psd1 Resolved
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Test Results

    4 files    448 suites   12s ⏱️
  379 tests   374 ✅  5 💤 0 ❌
1 492 runs  1 466 ✅ 26 💤 0 ❌

Results for commit 81af129.

♻️ This comment has been updated with latest results.

PR #112's CI failed on every hosted runner with:
  Add-Type: Could not load file or assembly 'Pester, Version=6.1.0.0, ...'.
  Assembly with same name is already loaded

Root cause: PowerShellBuild (0.7.2, installed via requirements.psd1)
declares `Pester >= 5.6.1` as its own RequiredModules dependency, with
no upper bound. Install-Module always auto-resolves a target's
RequiredModules independently of whatever this repo's own `Pester`
entry pins, so whichever install reaches the Gallery first wins a
race: if PowerShellBuild's own install gets there before our pinned
Pester 6.1.0 is on disk, PowerShellGet fetches whatever's newest on
PSGallery as a second, stray copy (confirmed non-deterministic
locally, depending on install order).

PowerShellBuild's bundled Test task (Test-PSBuildPester.ps1) then
calls `Import-Module Pester -MinimumVersion 5.0.0` with no exact
version pin. -MinimumVersion always resolves to the HIGHEST matching
version found anywhere on $env:PSModulePath - never whatever's already
loaded under that name - so that stray newer copy gets a fresh load
attempt and collides with the Pester.dll our own pinned import already
Add-Type'd into the process.

Fixes:
- requirements.psd1: PSDepend bumped to 0.7.0-beta1 (prerelease;
  AllowPrerelease flagged explicitly), whose transitive-dependency
  resolution (separate root installation contexts, transitive packages
  installed first) narrows this class of collision for dependencies
  PSDepend itself resolves.
- build.ps1 bootstrap:
  - PSDepend's own version is now read from requirements.psd1 and
    installed/imported by that exact (prerelease-aware) version,
    instead of "any version already on the machine" - the previous
    check never actually enforced the pin, and couldn't install a
    prerelease at all (Install-Module rejects a prerelease
    RequiredVersion without -AllowPrerelease).
  - Pester is now installed and globally imported at the pinned
    version *before* Invoke-PSDepend runs, so PowerShellGet already
    finds a satisfying version on disk when it resolves
    PowerShellBuild's RequiredModules and never reaches for anything
    else - closing the install-order race at its source.
  - A defense-in-depth pass after Invoke-PSDepend prunes any other
    installed Pester version and reasserts the pinned one, in case
    something else still lands a stray copy.

Verified:
- 3/3 clean-slate local runs (.\build.ps1 -Bootstrap -Task Test) pass
  consistently: 368 passed, 0 failed, 5 skipped, Analyze clean -
  including with a second, newer Pester version pre-seeded on disk to
  force the exact collision this fixes.
- Real CI on this branch: ubuntu-latest and macOS-latest both pass
  Run Tests (368/0/5 each) after two failed attempts that isolated the
  actual cause (PSDepend bump alone did not fix it; the install-order
  fix did). windows-latest's Pester task also passes 368/0/5 cleanly,
  confirming the collision itself is resolved on every platform; that
  job currently fails afterward in the unrelated ANALYZE task
  (PSScriptAnalyzer NullReferenceException in
  Test-PSBuildScriptAnalysis.ps1), a separate, pre-existing issue not
  touched by this change.
@HeyItsGilbert
HeyItsGilbert force-pushed the chore/psdepend-0.7.0-beta1 branch from 8b9a90b to 6369933 Compare November 3, 2026 17:38
@HeyItsGilbert HeyItsGilbert changed the title chore: bump PSDepend to 0.7.0-beta1, fix bootstrap version pinning fix(ci): resolve Pester assembly collision in build bootstrap Nov 3, 2026
- Import PSDepend by its matched module's own manifest path rather than
  a bare base-version Import-Module call: -RequiredVersion drops the
  prerelease label, so if a differently-labeled (or stable) module
  sharing that numeric version ever appears earlier on $env:PSModulePath,
  Import-Module could silently resolve to that one instead of the
  prerelease actually pinned.
- Stop re-processing the self-referential 'PSDepend' entry through
  Invoke-PSDepend: its PSGalleryModule handler's existing-version check
  compares $_.Version.ToString() (which drops any prerelease label)
  against the full 'X.Y.Z-prerelease' requirement string, so it never
  matches and silently re-queries/reinstalls PSDepend from the gallery
  on every single bootstrap run, even though the exact pinned version
  is already installed and imported by that point. Invoke-PSDepend now
  runs against every *other* declared dependency via -InputObject.
- Read requirements.psd1 once into $requirements instead of re-parsing
  the file for each of PSDepend's and Pester's version lookups.

On the (refuted) lock-file suggestion: PSDepend 0.7.0-beta1's locked
transitive-dependency resolution only applies with a neighboring
requirements.lock.json, which this checkout doesn't have - but the
actual Pester collision is already closed by the install-order fix in
the prior commit, independent of PSDepend's lock mechanism entirely
(PowerShellGet's RequiredModules auto-install, invoked inside a single
Install-Module call, happens beneath PSDepend regardless of locking).
Real CI already proves this: ubuntu/macOS/windows/PS5.1 all green on
the prior commit. A lock file remains available as optional future
defense-in-depth but isn't required to close this issue.

Verified: 5 consecutive clean-slate local runs (.\build.ps1 -Bootstrap
-Task Test), including the exact forced-collision scenario (a second,
newer Pester pre-seeded on disk), all pass 368/0/5; confirmed via a
second run's verbose log that PSDepend's own entry no longer triggers
a redundant Install-Module call.
@HeyItsGilbert
HeyItsGilbert merged commit d56bfb9 into main Nov 3, 2026
9 checks passed
@HeyItsGilbert
HeyItsGilbert deleted the chore/psdepend-0.7.0-beta1 branch November 3, 2026 19:55
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.

2 participants