Skip to content

fix(build): target staged output for code coverage#47

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

fix(build): target staged output for code coverage#47
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

Pester reports 0% coverage on this module because the coverage globs in build.psake.ps1 point at the source tree (PlexAutomationToolkit/{Public,Private}/*.ps1) while the test files Import-Module from the staged build output (Output/<Name>/<Version>/). Pester treats the two paths as different files, so every executed line counts as "missed."

This fix points coverage at the staged output, derived from the manifest version and BuildHelpers env vars.

Why this matters

Same root cause and same fix as upstream tablackburn/PowerShellModuleTemplate#19 — the template this module was scaffolded from. Verified there at 0% → 100% coverage on identical test infrastructure.

This module's tests use Import-Module -Name (Join-Path -Path $Env:BHBuildOutput -ChildPath "$Env:BHProjectName.psd1") (template default), so the bug applies and the fix lands cleanly.

Why not just use $Env:BHBuildOutput?

That was the first attempt — it doesn't work. PowerShellBuild only rewrites BHBuildOutput to the staged version path later, inside its own tasks. At psake properties-evaluation time, it's still BuildHelpers' default <root>/BuildOutput, which doesn't exist and causes Pester to bail with Could not resolve coverage path.

So the path has to be computed explicitly from the manifest ($Env:BHPSModuleManifest is populated by Set-BuildEnvironment before psake runs).

Test plan

  • CI runs ./build.ps1 -Task Build,Test on three OSes (plus Windows PowerShell 5.1) — all jobs green
  • Codecov unittests flag continues to report non-zero coverage; codecov/patch passes

🤖 Generated with Claude Code

Pester reports 0% coverage because the coverage globs in build.psake.ps1
point at the source tree (PlexAutomationToolkit/{Public,Private}/*.ps1)
while the test files Import-Module from the staged build output
(Output/<Name>/<Version>/). Pester treats the two paths as different
files, so every executed line counts as "missed."

Compute the staged path explicitly from the manifest version (read via
$Env:BHPSModuleManifest, which BuildHelpers populates before psake
runs), and guard against missing env vars so direct Invoke-psake
invocations fail fast with an actionable message.

Same fix as upstream tablackburn/PowerShellModuleTemplate#19, the
template this module was scaffolded from.

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

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@tablackburn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 23 minutes and 24 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee5c67ac-6ad1-4c31-a25b-28bba4be629e

📥 Commits

Reviewing files that changed from the base of the PR and between 67c7347 and 6666c1a.

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

Walkthrough

The build script's code coverage configuration was updated to reference staged build output instead of source files. The script now requires BHPSModuleManifest and BHProjectName environment variables, reads the module version from the manifest, computes the staged output directory path, and configures coverage file globs to target built .ps1 files.

Changes

Build Coverage Configuration

Layer / File(s) Summary
Build Configuration
build.psake.ps1
Code coverage file globs updated to target staged output at Output/<BHProjectName>/<ModuleVersion> instead of source tree. Script now validates required environment variables (BHPSModuleManifest, BHProjectName), reads ModuleVersion from manifest, computes staged path, and updates coverage includes for Public/*.ps1 and Private/*.ps1 from staged directory.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hopping build that's staged so neat,
Coverage files in output's beat,
Version-versed, the manifest's read,
Test the built code, not source instead! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: targeting staged build output for code coverage configuration, which directly addresses the core issue of fixing Pester's 0% coverage reporting.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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
Contributor

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 updates the build/test configuration so Pester code coverage is collected against the staged module output under Output/<Name>/<Version> instead of the source tree, aligning coverage paths with how this repository’s tests import the module.

Changes:

  • Repoints Pester coverage globs from PlexAutomationToolkit/{Public,Private} to the staged Output/<Project>/<Version> directory.
  • Derives the staged coverage path from BuildHelpers environment variables and the module manifest version.
  • Adds an early guard/error when required BuildHelpers variables are not available during psake property evaluation.

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

Comment thread build.psake.ps1
Rename $_moduleVersion → $moduleVersion and $_stagedOutput → $stagedOutput
to match the upstream template change in
tablackburn/PowerShellModuleTemplate. Pure rename, no behavior change.

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