fix(tests): move Pester pin to 6.0.1 and allow empty -ForEach collections - #49
Conversation
…ions The GitHub-hosted runner images now ship Pester 6.0.1. PSDepend imports the pinned Pester, then PowerShellBuild's Test-PSBuildPester runs `Import-Module Pester -MinimumVersion 5.0.0`, which resolves to the highest installed version and collides with the already-loaded 5.7.1 DLL. Bumping the pin exposes a second, quieter problem. Pester 6 throws on a null/empty -ForEach by default (Run.FailOnNullOrEmptyForEach); Pester 5 quietly generated zero tests. The throw happens during discovery, so Pester fails the entire container (the whole file). A failed container does not increment FailedCount, and Test-PSBuildPester only throws on FailedCount -- so the build passes while that file's tests never run. The affected collections are legitimately empty in a default module: - $helpLinks -- a command declares no http(s) .LINK - $commandParameters -- a command declares only common parameters - $helpParameterNames -- likewise - $dependencies -- RequiredModules is commented out (template default) $commands is deliberately left strict: an empty command list means the module failed to import and should fail loudly. Verified by rendering the template with Initialize-Template.ps1 and running ./build.ps1 -Task Test under Pester 6.0.1: before Tests Passed: 27, containers failed: 2 (Help.tests.ps1, Manifest.tests.ps1) after Tests Passed: 30, containers failed: 0 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015fsEPNYeL5LKdWLDNdv3T6
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe build dependency changes from Pester 5.7.1 to 6.0.1. Help and manifest tests now allow null or empty collections during ChangesPester compatibility
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the template’s test toolchain to align with GitHub-hosted runner images that now ship Pester 6.0.1, and adjusts a few Pester -ForEach blocks so that legitimate empty collections no longer abort test discovery (silently skipping entire files).
Changes:
- Bump the build-time Pester dependency pin from 5.7.1 to 6.0.1.
- Add
-AllowNullOrEmptyForEachto specificIt/Contextblocks inHelp.tests.ps1where empty collections are valid in a default template. - Add
-AllowNullOrEmptyForEachto the manifest dependencyContextinManifest.tests.ps1whereRequiredModulesmay be empty by default.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
build.depend.psd1 |
Pins Pester to 6.0.1 to avoid runner-provided Pester 6 colliding with a pinned Pester 5 in-session. |
tests/Help.tests.ps1 |
Prevents discovery-time failures when .LINK entries or filtered parameter lists are empty by allowing empty -ForEach. |
tests/Manifest.tests.ps1 |
Prevents discovery-time failure when RequiredModules is empty by allowing empty -ForEach for dependency checks. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Why
Two problems, found and fixed first in
PlexAutomationToolkit. Both were triggered by a GitHub-hosted runner image change, not by any commit — the images now ship Pester 6.0.1.Problem A — Pester 5 pin collides with Pester 6 on the runner
PSDepend imports the pinned Pester 5.7.1, then PowerShellBuild's
Test-PSBuildPesterrunsImport-Module Pester -MinimumVersion 5.0.0, which resolves to the highest installed version (6.0.1 from the runner image) and collides with the already-loaded 5.7.1 DLL:Problem B — empty
-ForEachkills whole test files, silentlyApplying the fix for A is what exposes B, so they ship together.
Pester 6 throws on a null/empty
-ForEachby default (Run.FailOnNullOrEmptyForEach); Pester 5 quietly generated zero tests. The throw happens during discovery, so Pester fails the entire container (the whole file). A failed container does not incrementFailedCount, andTest-PSBuildPesteronly throws onFailedCount— so the build passes while that file's tests never run.What changed
build.depend.psd1— Pester pin5.7.1→6.0.1tests/Help.tests.ps1—-AllowNullOrEmptyForEachon$helpLinks,$commandParameters,$helpParameterNamestests/Manifest.tests.ps1—-AllowNullOrEmptyForEachon$dependenciesEach of these is legitimately empty in a default module: no command declares an
http(s).LINK, a command may declare only common parameters, andRequiredModulesis commented out by default.Describe "Test help for <_.Name>" -ForEach $commandsis deliberately left strict — an empty command list means the module failed to import and should fail loudly.Verification
This repo's own CI never exercises these tests —
CI.yamlgatesBuild and Testbehindtemplate_guard, which trips on the presence ofCHANGELOG.template.md. So it was verified by rendering the template and running the real task:Help.tests.ps1,Manifest.tests.ps1Before the fix, discovery aborted at
Help.tests.ps1:164andManifest.tests.ps1:211— the exact lines changed here.No
CHANGELOG.mdentry: this is not user-facing.🤖 Generated with Claude Code
https://claude.ai/code/session_015fsEPNYeL5LKdWLDNdv3T6
Summary by CodeRabbit
Bug Fixes
Tests