Skip to content

fix(tests): move Pester pin to 6.0.1 and allow empty -ForEach collections - #49

Merged
tablackburn merged 1 commit into
mainfrom
fix/pester-6-empty-foreach
Aug 10, 2026
Merged

fix(tests): move Pester pin to 6.0.1 and allow empty -ForEach collections#49
tablackburn merged 1 commit into
mainfrom
fix/pester-6-empty-foreach

Conversation

@tablackburn

@tablackburn tablackburn commented Aug 10, 2026

Copy link
Copy Markdown
Owner

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-PSBuildPester runs Import-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:

Exception: An incompatible version of the Pester.dll assembly is already loaded.
The loaded dll version is 5.7.1.0, but at least version 6.0.1 is required

Problem B — empty -ForEach kills whole test files, silently

Applying the fix for A is what exposes B, so they ship together.

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 FailedCountso the build passes while that file's tests never run.

What changed

  • build.depend.psd1 — Pester pin 5.7.16.0.1
  • tests/Help.tests.ps1-AllowNullOrEmptyForEach on $helpLinks, $commandParameters, $helpParameterNames
  • tests/Manifest.tests.ps1-AllowNullOrEmptyForEach on $dependencies

Each of these is legitimately empty in a default module: no command declares an http(s) .LINK, a command may declare only common parameters, and RequiredModules is commented out by default.

Describe "Test help for <_.Name>" -ForEach $commands is 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.yaml gates Build and Test behind template_guard, which trips on the presence of CHANGELOG.template.md. So it was verified by rendering the template and running the real task:

./Initialize-Template.ps1 -ModuleName AuditProbe -Prefix Ap ... -NoGitInit -NoBootstrap
./build.ps1 -Task Test
Tests Passed Containers failed
before (Pester 6.0.1) 27 2Help.tests.ps1, Manifest.tests.ps1
after (Pester 6.0.1) 30 0

Before the fix, discovery aborted at Help.tests.ps1:164 and Manifest.tests.ps1:211 — the exact lines changed here.

No CHANGELOG.md entry: this is not user-facing.

🤖 Generated with Claude Code

https://claude.ai/code/session_015fsEPNYeL5LKdWLDNdv3T6

Summary by CodeRabbit

  • Bug Fixes

    • Improved automated validation for modules with empty or missing help links, parameters, and dependency collections.
    • Prevented test discovery failures caused by empty test inputs.
  • Tests

    • Updated test compatibility with the latest testing framework version.

…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
Copilot AI lite review requested due to automatic review settings August 10, 2026 16:07
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b10d0118-a38f-4768-9daf-7d1c4c1aa380

📥 Commits

Reviewing files that changed from the base of the PR and between d0f1ad8 and e9796f9.

📒 Files selected for processing (3)
  • build.depend.psd1
  • tests/Help.tests.ps1
  • tests/Manifest.tests.ps1

📝 Walkthrough

Walkthrough

The build dependency changes from Pester 5.7.1 to 6.0.1. Help and manifest tests now allow null or empty collections during -ForEach expansion.

Changes

Pester compatibility

Layer / File(s) Summary
Pester dependency and test iteration updates
build.depend.psd1, tests/Help.tests.ps1, tests/Manifest.tests.ps1
The build uses Pester 6.0.1. Test contexts permit null or empty collections during iteration. Test bodies and validation logic remain unchanged.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the Pester version update and the test changes for empty -ForEach collections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pester-6-empty-foreach

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -AllowNullOrEmptyForEach to specific It/Context blocks in Help.tests.ps1 where empty collections are valid in a default template.
  • Add -AllowNullOrEmptyForEach to the manifest dependency Context in Manifest.tests.ps1 where RequiredModules may 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.

@tablackburn
tablackburn merged commit 458b666 into main Aug 10, 2026
12 checks passed
@tablackburn
tablackburn deleted the fix/pester-6-empty-foreach branch August 10, 2026 17:17
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