Repository navigation
fix(ci): resolve Pester assembly collision in build bootstrap - #113
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 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.1to0.7.0-beta1with prerelease support. - Reads the bootstrap version from
requirements.psd1and 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
Test Results 4 files 448 suites 12s ⏱️ 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
force-pushed
the
chore/psdepend-0.7.0-beta1
branch
from
November 3, 2026 17:38
8b9a90b to
6369933
Compare
- 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.
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.

Summary
CI on PR #112 failed identically on every hosted runner:
Root cause:
PowerShellBuild(0.7.2) declaresPester >= 5.6.1as its ownRequiredModulesdependency, no upper bound.Install-Modulealways auto-resolves a target'sRequiredModulesindependently of whatever this repo's ownrequirements.psd1Pesterentry pins — whichever install reaches the Gallery first wins a race. IfPowerShellBuild'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 callsImport-Module Pester -MinimumVersion 5.0.0— no exact pin.-MinimumVersionalways 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 thePester.dllalreadyAdd-Type'd into the process.Investigation note: the first fix attempt (bumping
PSDependto0.7.0-beta1alone, 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 somethingPSDepend's own dependency graph controls (PowerShellGet's nativeRequiredModulesauto-install, invoked inside a singleInstall-Modulecall, happens beneathPSDependentirely). ThePSDependbump is kept — it's a legitimate improvement and narrows this class of collision for dependenciesPSDependitself resolves — but the actual fix is the install-order change inbuild.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/5macOS-latest: pass, 368/0/5windows-latest: Pester task passes cleanly, 368/0/5 — confirming the collision itself is resolved on every platform. That job currently fails afterward, in the unrelatedANALYZEtask (PSScriptAnalyzerNullReferenceExceptioninTest-PSBuildScriptAnalysis.ps1) — a separate, pre-existing issue this change doesn't touch and didn't introduce (nothing here touchesPSScriptAnalyzerconfig, and the local LinuxAnalyzetask runs clean on every local run below).PowerShell 5.1job: 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):
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-beta1is a prerelease, flagged explicitly viaAllowPrereleaseso the intent is visible inrequirements.psd1. The windows-latestANALYZEfailure is called out above as a known, separate, pre-existing gap — not claimed as fixed by this PR.