refactor(tests): bootstrap remaining standalone tests via build.ps1#39
Conversation
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>
|
Warning Review limit reached
More reviews will be available in 50 minutes and 59 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR standardizes standalone test bootstrap logic across multiple test scripts by replacing ChangesStandalone Test Bootstrap Standardization
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly Related Issues
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 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 standardizes the “standalone Invoke-Pester” bootstrap path across the remaining test scaffolds by delegating to build.ps1 -Task 'Build' -Bootstrap whenever BHBuildOutput is unset, aligning with the approach introduced in #38.
Changes:
- Updated
tests/Manifest.tests.ps1(BeforeDiscovery/BeforeAll) to callbuild.ps1instead of invokingbuild.psake.ps1directly when bootstrapping. - Updated the
tests/Unit/public/private template tests to use the samebuild.ps1bootstrap guard. - Documented the change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/Manifest.tests.ps1 | Switches standalone bootstrap guard from direct Invoke-psake to delegating through build.ps1. |
| tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1 | Uses the build.ps1 bootstrap guard for standalone runs (consistent with #38). |
| tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1 | Uses the build.ps1 bootstrap guard for standalone runs (consistent with #38). |
| CHANGELOG.md | Notes that Manifest + Unit test templates now share the build.ps1 bootstrap approach. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1 (1)
18-26: 💤 Low valueOptional: compute
$projectRootonce and reuse it.The 3-level
Split-Path -Parentwalk is duplicated at Line 18 (to locatebuild.ps1) and Line 23 ($projectRoot). Hoisting$projectRootabove the guard removes the duplication and keeps the path depth a single source of truth.♻️ Proposed refactor
BeforeDiscovery { + # PowerShellBuild outputs to Output/<ModuleName>/<Version>/ + $projectRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -Parent + # Build module if not running in psake build if ($null -eq $Env:BHBuildOutput) { # ...comment... - $buildScript = Join-Path -Path (Split-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -Parent) -ChildPath 'build.ps1' + $buildScript = Join-Path -Path $projectRoot -ChildPath 'build.ps1' & $buildScript -Task 'Build' -Bootstrap } - # PowerShellBuild outputs to Output/<ModuleName>/<Version>/ - $projectRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -Parent $sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"🤖 Prompt for 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. In `@tests/Unit/Private/Invoke-`{{Prefix}}Helper.tests.ps1 around lines 18 - 26, The duplicated 3-level Split-Path -Parent traversal should be computed once into a $projectRoot variable above the guard so it can be reused; compute $projectRoot from $PSScriptRoot first, then build $buildScript using $projectRoot (for the build.ps1 invocation) and reuse the same $projectRoot to form $sourceManifest and $Env:BHBuildOutput, ensuring $buildScript, $sourceManifest and $Env:BHBuildOutput all reference this single $projectRoot variable instead of repeating Split-Path logic.
🤖 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.
Nitpick comments:
In `@tests/Unit/Private/Invoke-`{{Prefix}}Helper.tests.ps1:
- Around line 18-26: The duplicated 3-level Split-Path -Parent traversal should
be computed once into a $projectRoot variable above the guard so it can be
reused; compute $projectRoot from $PSScriptRoot first, then build $buildScript
using $projectRoot (for the build.ps1 invocation) and reuse the same
$projectRoot to form $sourceManifest and $Env:BHBuildOutput, ensuring
$buildScript, $sourceManifest and $Env:BHBuildOutput all reference this single
$projectRoot variable instead of repeating Split-Path logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 85704801-d1b9-4ef2-ae9d-b366342c94f9
📒 Files selected for processing (4)
CHANGELOG.mdtests/Manifest.tests.ps1tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1
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>
Summary
Follow-up to #38. Applies the same delegate-to-
build.ps1standalone bootstrap to the remaining test scaffolds so every test file uses one consistent, maintainable bootstrap path:tests/Manifest.tests.ps1(bothBeforeDiscoveryandBeforeAll)tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1Problem
These files bootstrapped the module by calling
Invoke-psakeagainstbuild.psake.ps1directly, but never populated the BuildHelpers env vars (BHProjectName,BHPSModuleManifest) that psake'spropertiesblock needs — so a standaloneInvoke-Pesteron any of them hit the same empty-env failure #38 fixed forHelp.tests.ps1. (Unlike the pre-#38Help.tests.ps1, these didn't even callSet-BuildEnvironment.)Fix
Each
if ($null -eq $Env:BHBuildOutput)guard now delegates to the canonical build entry point:build.ps1— dependency bootstrap,Set-BuildEnvironment, and module staging all run through the real build path instead of a partial reimplementation.exit-safe — invoked with the call operator (&), not dot-sourced, sobuild.ps1's terminatingexitis contained to the script boundary and doesn't end the Pester run.Join-PathoverSplit-Path -Parent. Thetests/Unit/files resolve the project root three levels up (Split-Path -Parentx3), matching each file's existing$projectRootcomputation;Manifest.tests.ps1uses one level, likeHelp.tests.ps1../build.ps1— the guard only fires whenBHBuildOutputis unset.tests/Meta.tests.ps1is intentionally untouched — it has no build-bootstrap block (it's repo-meta checks).Test plan
0x2014em-dashes inManifest.tests.ps1comments are untouched and outside CI's lint scope, which only scans./{{ModuleName}})&-exitcontainment already verified end-to-end in feat: make Help tests runnable standalone via build.ps1 #38 (identical approach)🤖 Generated with Claude Code
Summary by CodeRabbit