feat: make Help tests runnable standalone via build.ps1#38
Conversation
tests/Help.tests.ps1 bootstraps the build via Invoke-psake when $Env:BHBuildOutput is unset, but build.psake.ps1's properties block needs BuildHelpers vars (BHProjectName, BHPSModuleManifest) that are only populated by ./build.ps1 before psake runs. Running the Help tests in isolation (e.g. Invoke-Pester tests/Help.tests.ps1 from an editor) bypasses that, leaving the vars empty and the standalone build broken. Call Set-BuildEnvironment inside the existing bootstrap guard in both BeforeDiscovery and BeforeAll so the vars are populated before psake is invoked. The guard only fires when BHBuildOutput is unset, so there is no effect when tests run via ./build.ps1 or in CI; Set-BuildEnvironment -Force is idempotent. Surfaced by a cross-repo audit against a consumer module (tablackburn/PlexAutomationToolkit) that already carried this fix locally. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Help test file now explicitly initializes BuildHelpers environment variables using ChangesHelp Test Standalone Execution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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
Makes tests/Help.tests.ps1 runnable standalone by calling Set-BuildEnvironment inside the existing bootstrap guard, so BuildHelpers vars required by build.psake.ps1's properties block are populated when tests are invoked without first running ./build.ps1.
Changes:
- Add
Set-BuildEnvironment -Path ... -Forceinside the$Env:BHBuildOutputnull guard in bothBeforeDiscoveryandBeforeAll. - Document the change in
CHANGELOG.mdunder Added.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/Help.tests.ps1 | Populates BuildHelpers env vars before invoking psake in the standalone-bootstrap path. |
| CHANGELOG.md | Notes the new standalone-runnable Help tests behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/Help.tests.ps1`:
- Around line 51-56: The tests/Help.tests.ps1 calls Set-BuildEnvironment without
ensuring the BuildHelpers module is available; before the Set-BuildEnvironment
invocation (both occurrences) bootstrap dependencies or import BuildHelpers: run
the existing ./build.ps1 dependency bootstrap (e.g. invoke the script or its
bootstrap function) or explicitly ensure BuildHelpers is installed and
Import-Module BuildHelpers (matching the version pinned by build.depend.psd1) so
Set-BuildEnvironment is defined when the test runs standalone.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1242274b-5c92-4c3b-9a0c-0471a8a0d036
📒 Files selected for processing (2)
CHANGELOG.mdtests/Help.tests.ps1
Replace the inline Set-BuildEnvironment + Invoke-psake bootstrap in Help.tests.ps1 (both BeforeDiscovery and BeforeAll) with a single call to build.ps1 -- the canonical entry point -- so dependency bootstrap, BuildHelpers environment setup, and module staging all run through the real build path instead of a partial reimplementation that could drift. build.ps1 is invoked with the call operator (&), not dot-sourced, so its terminating exit is contained to the script boundary and does not end the Pester run (verified on Windows PowerShell 5.1 and PowerShell 7). Path is built with a single two-argument Join-Path over Split-Path -Parent so it stays valid on PowerShell 5.1 (which lacks Join-Path -AdditionalChildPath). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
) * refactor(tests): bootstrap remaining standalone tests via build.ps1 Apply the delegate-to-build.ps1 bootstrap from #38 to the rest of the test scaffolds: tests/Manifest.tests.ps1 (both BeforeDiscovery and BeforeAll) and the tests/Unit/ Private and Public templates. These previously called Invoke-psake against build.psake.ps1 directly without populating the BuildHelpers env vars its properties block needs, so the standalone path was broken the same way Help.tests.ps1 was. Each guard now calls build.ps1 -Task 'Build' -Bootstrap via the call operator (&), so dependency bootstrap and BuildHelpers environment setup run through the canonical entry point and the script's terminating exit is contained to the script boundary instead of ending the Pester run. Project root is resolved with Split-Path -Parent (one level for Manifest.tests.ps1, three for the tests/Unit/ files, matching each file's existing root computation) and a single two-argument Join-Path, keeping it valid on PowerShell 5.1. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(tests): compute project root once in bootstrap Address review feedback (Copilot) on the standalone bootstrap: the project root was computed twice -- once inline for $buildScript and again a few lines later for $projectRoot -- which is exactly the kind of duplication that can drift. Hoist the single $projectRoot assignment above the BHBuildOutput guard and derive $buildScript from it via Join-Path, in Manifest.tests.ps1 (both blocks) and the tests/Unit/ Private and Public templates. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Makes
tests/Help.tests.ps1runnable standalone (e.g.Invoke-Pester tests/Help.tests.ps1straight from an editor, or an agent running a single test) by having its build-bootstrap guard delegate tobuild.ps1— the canonical build entry point — instead of partially re-implementing the build.Problem
When
$Env:BHBuildOutputis unset,Help.tests.ps1bootstraps the module itself. The original bootstrap calledInvoke-psakeagainstbuild.psake.ps1directly, but psake'spropertiesblock needs BuildHelpers vars (BHProjectName,BHPSModuleManifest) that are normally populated by./build.ps1before psake runs. Running the Help tests in isolation skippedbuild.ps1, so those vars were empty and the standalone build path was broken.Fix
Replace the inline
Set-BuildEnvironment+Invoke-psakeblock in bothBeforeDiscoveryandBeforeAllwith a single call tobuild.ps1:Set-BuildEnvironment), and module staging all run throughbuild.ps1itself, rather than a partial copy of its preamble that can drift. This also closes the dependency-bootstrap gap CodeRabbit flagged on the earlier revision (the standalone path no longer assumesBuildHelpersis already imported —-Bootstrapinstalls/imports deps).exit-safe —build.ps1ends inexit ([int](-not $psake.build_success)). It's invoked with the call operator (&), not dot-sourced, so theexitis contained to the script boundary and does not terminate the Pester run. Verified on Windows PowerShell 5.1 and PowerShell 7.Join-PathoverSplit-Path -Parent; avoids-AdditionalChildPath(PS 6+ only) and platform-specific..\child paths.BHBuildOutputis unset, which is never the case under./build.ps1.PSUseBOMForUnicodeEncodedFilesurface.Provenance
Surfaced by a cross-repo audit against a consumer module (tablackburn/PlexAutomationToolkit) whose inherited
Help.tests.ps1needed to run standalone. This contributes the capability back so new modules get standalone-runnable Help tests by default — using the more maintainable delegate-to-build.ps1approach rather than re-implementing the build preamble in the test file.Scope note
Only
tests/Help.tests.ps1is touched here.tests/Manifest.tests.ps1and thetests/Unit/templates use the same bootstrap pattern and could get the same treatment in a follow-up; left out to keep this PR focused.Test plan
tests/Help.tests.ps1parses with no syntax errorsInvoke-Pesterinvokesbuild.ps1via&, deps bootstrap, psake Build runs, andexitdoes not terminate Pesterexit-containment of&-invoked scripts confirmed on Windows PowerShell 5.1 and PowerShell 7🤖 Generated with Claude Code