Skip to content

refactor(tests): bootstrap remaining standalone tests via build.ps1#39

Merged
tablackburn merged 2 commits into
mainfrom
refactor/standalone-test-bootstrap
May 29, 2026
Merged

refactor(tests): bootstrap remaining standalone tests via build.ps1#39
tablackburn merged 2 commits into
mainfrom
refactor/standalone-test-bootstrap

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

@tablackburn tablackburn commented May 29, 2026

Summary

Follow-up to #38. Applies the same delegate-to-build.ps1 standalone bootstrap to the remaining test scaffolds so every test file uses one consistent, maintainable bootstrap path:

  • tests/Manifest.tests.ps1 (both BeforeDiscovery and BeforeAll)
  • tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1
  • tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1

Problem

These files bootstrapped the module by calling Invoke-psake against build.psake.ps1 directly, but never populated the BuildHelpers env vars (BHProjectName, BHPSModuleManifest) that psake's properties block needs — so a standalone Invoke-Pester on any of them hit the same empty-env failure #38 fixed for Help.tests.ps1. (Unlike the pre-#38 Help.tests.ps1, these didn't even call Set-BuildEnvironment.)

Fix

Each if ($null -eq $Env:BHBuildOutput) guard now delegates to the canonical build entry point:

$buildScript = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'build.ps1'
& $buildScript -Task 'Build' -Bootstrap
  • Delegates to 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, so build.ps1's terminating exit is contained to the script boundary and doesn't end the Pester run.
  • PowerShell 5.1-safe path — single two-argument Join-Path over Split-Path -Parent. The tests/Unit/ files resolve the project root three levels up (Split-Path -Parent x3), matching each file's existing $projectRoot computation; Manifest.tests.ps1 uses one level, like Help.tests.ps1.
  • No effect on CI / ./build.ps1 — the guard only fires when BHBuildOutput is unset.

tests/Meta.tests.ps1 is intentionally untouched — it has no build-bootstrap block (it's repo-meta checks).

Test plan

  • All three files parse with no syntax errors
  • PSScriptAnalyzer: no new findings; added lines are pure ASCII (the two pre-existing 0x2014 em-dashes in Manifest.tests.ps1 comments are untouched and outside CI's lint scope, which only scans ./{{ModuleName}})
  • Bootstrap mechanism and &-exit containment already verified end-to-end in feat: make Help tests runnable standalone via build.ps1 #38 (identical approach)
  • CI green (build pipeline path unaffected)

Same caveat as #38: the tests can't reach green against the un-initialized template repo (placeholder {{GUID}} / {{Prefix}}), which is the pre-existing limitation CI guards with its is_template check. Green is reachable in an initialized module.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Updated test bootstrap process to support standalone test execution. Tests now use a unified build initialization approach for consistent behavior across all test suites, with no impact on CI or standard build workflows.

Review Change Stack

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>
Copilot AI review requested due to automatic review settings May 29, 2026 02:28
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Warning

Review limit reached

@tablackburn, we couldn't start this review because you've reached your PR review rate limit.

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 @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 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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40f89d57-be11-4702-8b93-c6435c6b7ab6

📥 Commits

Reviewing files that changed from the base of the PR and between 49a6dd6 and 409bbda.

📒 Files selected for processing (3)
  • tests/Manifest.tests.ps1
  • tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1
  • tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1
📝 Walkthrough

Walkthrough

This PR standardizes standalone test bootstrap logic across multiple test scripts by replacing Invoke-psake with build.psake.ps1 calls with direct invocations of build.ps1 -Task 'Build' -Bootstrap. The pattern is applied consistently to Manifest.tests.ps1 and unit test templates.

Changes

Standalone Test Bootstrap Standardization

Layer / File(s) Summary
Manifest test bootstrap updates
tests/Manifest.tests.ps1
BeforeDiscovery and BeforeAll hooks now call build.ps1 -Task 'Build' -Bootstrap directly (via &) instead of invoking Invoke-psake with build.psake.ps1, standardizing the standalone execution path for non-CI test runs.
Unit test template bootstrap updates
tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1, tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1
Both test template scripts' BeforeDiscovery hooks updated to use the same build.ps1 direct invocation pattern in place of Invoke-psake, ensuring consistent bootstrap behavior across all test files.
Changelog documentation
CHANGELOG.md
Added entry documenting that Manifest.tests.ps1 and Unit test templates now support standalone execution through the BHBuildOutput-missing guard delegating to the canonical build path.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly Related Issues

Possibly Related PRs

  • tablackburn/PowerShellModuleTemplate#38: Introduced the build.ps1 -Task 'Build' -Bootstrap standalone bootstrap approach in Help.tests.ps1; this PR extends that established pattern to Manifest.tests.ps1 and unit test templates for consistency.

Poem

🐰 A hop, a skip, a bootstrap call,
From psake to build.ps1, once and for all,
Test scripts align in harmonious grace,
Standalone execution finds its true place.

🚥 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 accurately describes the primary change: refactoring test bootstrapping to use build.ps1 for remaining standalone tests, which is the core focus of the changeset.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/standalone-test-bootstrap

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 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 call build.ps1 instead of invoking build.psake.ps1 directly when bootstrapping.
  • Updated the tests/Unit/ public/private template tests to use the same build.ps1 bootstrap 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.

Comment thread tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1 Outdated
Comment thread tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1 Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1 (1)

18-26: 💤 Low value

Optional: compute $projectRoot once and reuse it.

The 3-level Split-Path -Parent walk is duplicated at Line 18 (to locate build.ps1) and Line 23 ($projectRoot). Hoisting $projectRoot above 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

📥 Commits

Reviewing files that changed from the base of the PR and between fc04e67 and 49a6dd6.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • tests/Manifest.tests.ps1
  • tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1
  • tests/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>
@tablackburn tablackburn merged commit 6a07a67 into main May 29, 2026
11 checks passed
@tablackburn tablackburn deleted the refactor/standalone-test-bootstrap branch May 29, 2026 05:36
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