Skip to content

refactor(build): align coverage config with template pattern#11

Merged
tablackburn merged 4 commits into
mainfrom
fix/coverage-paths-target-staged-output
May 5, 2026
Merged

refactor(build): align coverage config with template pattern#11
tablackburn merged 4 commits into
mainfrom
fix/coverage-paths-target-staged-output

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

@tablackburn tablackburn commented May 4, 2026

Summary

Cosmetic alignment to the env-var-driven coverage-path pattern from upstream tablackburn/PowerShellModuleTemplate#19, the template this module was scaffolded from.

This is not a bug fix — coverage already works on `main` (verified at 78.95% / 77.91% / 98.51% / 100% by computing percentages from the JaCoCo XML directly; the console summary reporting 0% is a known PowerShellBuild 0.7.3 integer-truncation display bug, unrelated to this PR). It's purely a style convergence so this repo's `build.psake.ps1` matches the rest of the user's PowerShell modules.

Changes

  • Use `$Env:BHPSModuleManifest` / `$Env:BHProjectName` (populated by `Set-BuildEnvironment` before psake runs) instead of a hardcoded `$moduleName = 'ReScenePS'` + manual manifest-path computation.
  • Add an env-var guard so direct `Invoke-psake` invocations (bypassing `build.ps1`) fail fast with an actionable message.
  • Use `[IO.Path]::Combine` for the staged path, matching the rest of the `properties` block.
  • Preserves the existing third coverage path (`Classes/`) — this module has a `Classes/` subdirectory not present in the upstream template.

Verification

Local `./build.ps1 -Task Test` produces an identical coverage XML before and after this change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Improved code coverage to target the staged build output for more accurate coverage measurement and reporting.
  • Tests

    • Test setup now ensures required build environment is populated for isolated test runs, improving reliability of test execution.

Switch the staged-output path computation from a hardcoded module name
to the env-var-driven pattern from
tablackburn/PowerShellModuleTemplate#19:

- Use $Env:BHPSModuleManifest / $Env:BHProjectName (populated by
  Set-BuildEnvironment before psake runs) instead of a hardcoded
  $moduleName = 'ReScenePS' and a manual manifest-path computation.

- Add an env-var guard so direct Invoke-psake invocations (bypassing
  build.ps1) fail fast with an actionable message instead of an
  obscure Import-PowerShellDataFile null-binding error.

- Use [IO.Path]::Combine for the staged path to avoid mixed
  separators on Windows, matching the rest of the properties block.

Preserves the existing third coverage path (Classes/) — this module
has a Classes/ subdirectory.

Functionally equivalent to the prior config (same staged Output path,
same coverage targets); this is a cosmetic alignment to the template
pattern across the rest of the user's PowerShell modules.

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

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 83a3bf2e-1d32-4a6b-8607-add0b6f50681

📥 Commits

Reviewing files that changed from the base of the PR and between f362c8f and f57b725.

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

📝 Walkthrough

Walkthrough

build.psake.ps1 now computes code coverage target files from the staged build output (Output//) using environment-provided manifest values; related test scripts set the build environment when BHBuildOutput is unset to populate those env vars before invoking the build.

Changes

Build & Test Environment

Layer / File(s) Summary
Data / Environment
build.psake.ps1, tests/*
Coverage target now depends on $Env:BHPSModuleManifest and $Env:BHProjectName; ModuleVersion is read from the manifest to locate staged output under Output/<BHProjectName>/<ModuleVersion>.
Core Implementation
build.psake.ps1
Replaced prior source-manifest-based coverage path computation with staged-output logic and set Test.CodeCoverage.Files to Public/*.ps1, Private/*.ps1, Classes/*.ps1 within that staged directory.
Wiring / Test Setup
tests/Help.tests.ps1, tests/Manifest.tests.ps1
When BHBuildOutput is null, tests now call Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force in BeforeDiscovery and BeforeAll to populate required BuildHelpers env vars before invoking psake/build.
Tests / Verification
tests/Help.tests.ps1, tests/Manifest.tests.ps1
Test setup changes ensure isolated test runs provide the same build-env prerequisites that build.ps1 normally establishes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble paths where modules grow,
Env vars whisper which way to go,
Output folders gleam with version light,
Tests wake the build before the night,
A cheerful hop — coverage takes flight! 🐇

🚥 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 main change: refactoring the build coverage configuration to align with the template pattern by replacing hardcoded values with environment variables.
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 fix/coverage-paths-target-staged-output

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Aligns the psake build’s Pester coverage-path configuration with the upstream template’s env-var-driven pattern, so coverage targets the staged Output/<Name>/<Version> paths consistently across modules.

Changes:

  • Replace hardcoded module name + manifest path computation with BHPSModuleManifest / BHProjectName environment variables.
  • Add a guard that throws if those BuildHelpers env vars aren’t present.
  • Use [IO.Path]::Combine() to build the staged output path used for coverage globs.

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

Comment thread build.psake.ps1 Outdated
Comment thread build.psake.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)
build.psake.ps1 (1)

29-31: 💤 Low value

Mixed separators in coverage paths contradict the stated [IO.Path]::Combine goal.

$_stagedOutput is built with [IO.Path]::Combine (backslashes on Windows), but the array entries append subdirectory segments with a hard-coded forward slash, producing paths like C:\...\Output\ReScenePS\1.0.0/Public/*.ps1 on Windows. PowerShell normalises these transparently, so coverage collection still works — but the change doesn't fully achieve the stated goal of using [IO.Path]::Combine to avoid mixed separators.

♻️ Consistent use of [IO.Path]::Combine for subdirectory paths
 $PSBPreference.Test.CodeCoverage.Files = @(
-    "$_stagedOutput/Public/*.ps1"
-    "$_stagedOutput/Private/*.ps1"
-    "$_stagedOutput/Classes/*.ps1"
+    [IO.Path]::Combine($_stagedOutput, 'Public', '*.ps1')
+    [IO.Path]::Combine($_stagedOutput, 'Private', '*.ps1')
+    [IO.Path]::Combine($_stagedOutput, 'Classes', '*.ps1')
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@build.psake.ps1` around lines 29 - 31, The coverage path entries mix
separators by concatenating "$_stagedOutput" with forward-slash subpaths; update
the three array items to construct paths with [IO.Path]::Combine instead of
string concatenation so they inherit the platform-native separators (use
[IO.Path]::Combine($_stagedOutput, 'Public', '*.ps1'),
[IO.Path]::Combine($_stagedOutput, 'Private', '*.ps1'), and
[IO.Path]::Combine($_stagedOutput, 'Classes', '*.ps1') to replace the current
"$_stagedOutput/.../*.ps1" entries referencing $_stagedOutput).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@build.psake.ps1`:
- Around line 29-31: The coverage path entries mix separators by concatenating
"$_stagedOutput" with forward-slash subpaths; update the three array items to
construct paths with [IO.Path]::Combine instead of string concatenation so they
inherit the platform-native separators (use [IO.Path]::Combine($_stagedOutput,
'Public', '*.ps1'), [IO.Path]::Combine($_stagedOutput, 'Private', '*.ps1'), and
[IO.Path]::Combine($_stagedOutput, 'Classes', '*.ps1') to replace the current
"$_stagedOutput/.../*.ps1" entries referencing $_stagedOutput).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a07bb5d9-c148-44bc-9dbe-0da3ca746003

📥 Commits

Reviewing files that changed from the base of the PR and between f229287 and f362c8f.

📒 Files selected for processing (1)
  • build.psake.ps1

tablackburn and others added 2 commits May 3, 2026 23:12
Help.tests.ps1 and Manifest.tests.ps1 each have a "running outside
./build.ps1" escape hatch that calls Invoke-psake -TaskList Build
directly. Until now the bootstrap only set BHBuildOutput later in the
file; it relied on PowerShellBuild's Init task to populate the rest of
the BHE env vars as a side effect.

The new env-var guard in build.psake.ps1's properties block (added in
the previous commit on this branch) runs *before* the Build task can
do anything, so the isolated-test invocation path now fails fast with
a guard error instead of bootstrapping. Add Set-BuildEnvironment to
the bootstrap so BHPSModuleManifest and BHProjectName are populated
before psake evaluates properties.

Verified locally: with BH* env vars cleared, Invoke-Pester
./tests/Help.tests.ps1 now bootstraps cleanly (psake builds, 145 tests
pass).

Addresses Copilot review feedback on PR #11.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Rename $_moduleVersion → $moduleVersion and $_stagedOutput → $stagedOutput
per Copilot review feedback on PR #11. Pure rename, no behavior change.

Same rename applied across PowerShellModuleTemplate, JsmOperations,
and PlexAutomationToolkit so the user's modules stay in sync.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tablackburn tablackburn merged commit 3646768 into main May 5, 2026
12 checks passed
@tablackburn tablackburn deleted the fix/coverage-paths-target-staged-output branch May 5, 2026 00:30
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