Skip to content

fix(tests): populate help-parameter vars in BeforeDiscovery so the param-help check runs#35

Merged
tablackburn merged 2 commits into
mainfrom
fix/help-tests-discovery-phase
May 22, 2026
Merged

fix(tests): populate help-parameter vars in BeforeDiscovery so the param-help check runs#35
tablackburn merged 2 commits into
mainfrom
fix/help-tests-discovery-phase

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

Problem

Help.tests.ps1 has a Pester v5 discovery/run-phase bug. The Context

Context 'Test <_> help parameter help for <commandName>' -Foreach $helpParameterNames {
    It 'finds help parameter in code: <_>' { $_ -in $commandParameterNames | Should -Be $true }
}

uses -Foreach $helpParameterNames, but $helpParameterNames was populated only in BeforeAll (run phase). Pester evaluates -Foreach during discovery, so the collection is $null then and the Context expands to zero tests. The 'no stale/extra parameters documented in help' check has therefore been a silent no-op — in this template and every module scaffolded from it.

(The sibling Context 'Parameter <_.Name>' -Foreach $commandParameters works precisely because $commandParameters is set in BeforeDiscovery.)

Fix

Populate $helpParameters/$helpParameterNames in BeforeDiscovery too (mirroring $commandParameters), so the Context generates one test per documented parameter.

Verification

Local Pester 5.7.1 run of a minimal mirror: a -Foreach collection set in BeforeDiscovery generated 3 tests; the same collection set only in BeforeAll generated 0.

Follow-up

This is the canonical fix; it needs propagating to the consumers' Help.tests.ps1 (the stalled style/align-test-scaffolding-with-template PRs ReScenePS #18 / Plex #55 should carry the fixed version).

🤖 Generated with Claude Code

…ram-help check runs

The 'help parameter help' Context in Help.tests.ps1 uses -Foreach $helpParameterNames,
but $helpParameterNames was assigned only in BeforeAll (run phase). Pester evaluates
-Foreach during DISCOVERY, so the collection was $null then and the Context expanded
to ZERO tests -- the 'no stale/extra parameters documented in help' check has been a
silent no-op in this template and every module scaffolded from it.

Fix: also populate $helpParameters/$helpParameterNames in BeforeDiscovery (mirroring
$commandParameters, which already works in that same block), so the Context generates
one test per documented parameter.

Verified locally with Pester 5.7.1: a -Foreach collection set in BeforeDiscovery
generates tests; the same collection set only in BeforeAll generates zero.

Flagged by Copilot on the ReScenePS test-scaffolding-alignment PR (#18).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 22, 2026 22:59
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Warning

Review limit reached

@tablackburn, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 44 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 52c4ef7b-c73d-4e60-be99-51253a19cb04

📥 Commits

Reviewing files that changed from the base of the PR and between 090de78 and c7ea458.

📒 Files selected for processing (1)
  • tests/Help.tests.ps1
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/help-tests-discovery-phase

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 and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

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 fixes a Pester v5 discovery/run-phase issue in the help tests so that the “no stale/extra parameters documented in help” checks actually generate and run test cases during discovery.

Changes:

  • Populate $helpParameters / $helpParameterNames inside the per-command BeforeDiscovery block so Context ... -ForEach $helpParameterNames expands into tests at discovery time.
  • Add clarifying comments explaining why the values are duplicated between BeforeDiscovery and BeforeAll.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/Help.tests.ps1
…d Context name

The 'Test <_> help parameter help for <commandName>' Context name expands
<commandName> at discovery, but $commandName was only set in BeforeAll. Now that
the prior fix makes this Context actually get discovered, populate $commandName in
BeforeDiscovery too so the generated test names render correctly.

Flagged by Copilot on #35.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tablackburn tablackburn merged commit 350bdea into main May 22, 2026
11 checks passed
@tablackburn tablackburn deleted the fix/help-tests-discovery-phase branch May 22, 2026 23:58
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