-
Notifications
You must be signed in to change notification settings - Fork 125
Description
Bug Description
Test-CopyrightHeaders.ps1 produces good per-file console output via Write-Host (✅/❌ indicators with file paths), but it is missing two CI integration features that the gold-standard Invoke-PSScriptAnalyzer.ps1 already uses:
-
No
Write-CIAnnotationper failing file — The onlyWrite-CIAnnotationcall fires inside thecatchblock (line 214) for fatal script errors, not for individual header violations. GitHub Actions users see no inline annotations on PRs indicating which files are missing headers. -
No
Write-CIStepSummary— After the summary block (📋 Summary:on line 196), the script never callsWrite-CIStepSummary. The GitHub Actions job summary panel remains empty — users must expand the log or download artifacts to see results.
Current Behavior
- Per-file
Write-Hostoutput shows ✅/❌ with file paths (this works correctly). Write-CIAnnotationonly fires on fatal errors (catch block), not per failing file.- No
Write-CIStepSummarycall, so the Actions summary tab is empty for this job. - Users must manually download
copyright-header-results.jsonfrom artifacts to see details.
Expected Behavior
- Each file missing headers produces a
Write-CIAnnotation(levelWarning) so GitHub renders inline PR annotations showing the exact files. - A
Write-CIStepSummarygenerates a markdown table in the Actions summary tab with file paths, missing header type (copyright/SPDX/both), and overall compliance percentage.
Reference Implementation
Invoke-PSScriptAnalyzer.ps1 (lines 91–127) demonstrates the pattern:
- Per-file headers (
📄 Analyzing: $filePath) - Per-issue detail lines with color-coded severity (
⚠️ [Severity] Rule: Message) Write-CIAnnotationper violationWrite-CIStepSummarywith a formatted results table
Affected Files
| File | What to Change |
|---|---|
scripts/linting/Test-CopyrightHeaders.ps1 |
Add Write-CIAnnotation per failing file inside the foreach loop (after the Write-Host "❌" line ~177). Add Write-CIStepSummary after the summary block (~line 203). |
scripts/tests/linting/Test-CopyrightHeaders.Tests.ps1 |
Add tests verifying Write-CIAnnotation is called per failing file and Write-CIStepSummary is called with expected content. |
Additional Notes
Write-Hostis safe to use —PSAvoidUsingWriteHostis explicitly excluded inscripts/linting/PSScriptAnalyzer.psd1.- The
CIHelpersmodule (scripts/lib/Modules/CIHelpers.psm1) is already imported by the script — no new imports needed. - The workflow file (
.github/workflows/copyright-headers.yml) does not need changes. - Validate changes with
npm run lint:ps(PSScriptAnalyzer) andnpm run test:ps(Pester tests).
Unit Testing and Code Coverage Requirements
Codecov Configuration
The repository enforces an auto-incrementing project coverage threshold (+1% over base) and an 80% patch target (codecov.yml). All new or modified lines in scripts/linting/Test-CopyrightHeaders.ps1 must meet the patch coverage gate.
Pester Coverage
- Config:
scripts/tests/pester.config.ps1— JaCoCo format,CoveragePercentTarget = 80 - Coverage path:
scripts/linting/is already in the coverage scan scope - Run:
npm run test:ps
Current Test Gap
The existing test file scripts/tests/linting/Test-CopyrightHeaders.Tests.ps1 has no mocks for Write-CIAnnotation or Write-CIStepSummary. When adding per-file Write-CIAnnotation calls and a Write-CIStepSummary block, entirely new mock infrastructure is needed:
- Mock
Write-CIAnnotation— currently only called in catch blocks. New per-file annotation calls require mocks with-ParameterFilterto assert correct-File,-Level, and-Messagefor each missing/invalid header. - Mock
Write-CIStepSummary— does not exist in the script today. Add mock andShould -Invokeassertion verifying the markdown summary includes file counts, pass/fail status per file, and overall compliance score. - Verify
Write-Hostcall content — the script already emits per-file ✅/❌ output viaWrite-Host. Existing tests should verify message content matches expected patterns, not just thatWrite-Hostwas called.
RPI Phase Testing Guidance
- Research: Audit existing test coverage for CI output paths in
Test-CopyrightHeaders.Tests.ps1; confirm no existing mocks for CI helpers. - Plan: Design test cases for per-file
Write-CIAnnotation,Write-CIStepSummarymarkdown output, and enhancedWrite-Hostcontent verification. - Implement: Add mock infrastructure for all CI helper functions; verify
npm run test:pspasses with patch coverage ≥ 80%. - Review: Confirm no coverage regressions in the
pesterflag on Codecov; verify the reference implementation pattern fromInvoke-PSScriptAnalyzer.ps1is followed.
RPI Starter Prompts
Research Phase
Research the CI output gap in
Test-CopyrightHeaders.ps1. Compare itsInvoke-CopyrightHeaderCheckfunction with the per-issue output loop inInvoke-PSScriptAnalyzer.ps1(lines 91–127). Document: (1) where per-fileWrite-CIAnnotationcalls should be inserted inside theforeachloop after theWrite-Host "❌"block (~line 177), (2) what aWrite-CIStepSummarymarkdown table should contain (file path, missing header types, compliance percentage), (3) which Pester tests inTest-CopyrightHeaders.Tests.ps1need updating, and (4) the current test gap — no mocks exist forWrite-CIAnnotationorWrite-CIStepSummary— and what mock infrastructure is needed to maintain codecov patch coverage ≥ 80%. Reference theCIHelpersmodule exports inscripts/lib/Modules/CIHelpers.psm1for exact function signatures. Reviewcodecov.ymlandscripts/tests/pester.config.ps1for coverage configuration.
Plan Phase
Plan the changes to add CI annotations and step summary to
Test-CopyrightHeaders.ps1. The plan should cover: (1) insertingWrite-CIAnnotation -Message "..." -Level Warning -File $fileinside theforeachfailing-file branch after theWrite-Host "❌"line, (2) building a markdown summary table from$resultsand passing it toWrite-CIStepSummaryafter the summary block, and (3) adding Pester tests that mockWrite-CIAnnotationandWrite-CIStepSummaryto verify call count and arguments, with sufficient coverage to meet the 80% codecov patch target. Follow the pattern established inInvoke-PSScriptAnalyzer.ps1.
Implement Phase
Implement the CI output improvements for
Test-CopyrightHeaders.ps1. InInvoke-CopyrightHeaderCheck: (1) after theWrite-Host " ❌ ..."line inside theforeachloop, add aWrite-CIAnnotationcall with level Warning, the file path, and a message stating which headers are missing, (2) after the summary block ending atWrite-Host " Compliance: ...", build a markdown table from$results(columns: File, Copyright, SPDX, Status) and callWrite-CIStepSummary. InTest-CopyrightHeaders.Tests.ps1: add tests that mockWrite-CIAnnotationandWrite-CIStepSummaryto verify they are called with correct arguments when files are missing headers. Ensure all new code paths have test coverage to meet the 80% codecov patch target. Runnpm run lint:psandnpm run test:psto validate.
Review Phase
Review the changes to
Test-CopyrightHeaders.ps1andTest-CopyrightHeaders.Tests.ps1. Verify: (1)Write-CIAnnotationis called exactly once per failing file with appropriate message and Warning level, (2)Write-CIStepSummaryproduces a well-formed markdown table, (3) no regressions in existing Pester tests, (4)npm run lint:pspasses without PSScriptAnalyzer violations, (5) the CI workflow file is unchanged, (6) the output pattern aligns withInvoke-PSScriptAnalyzer.ps1for user consistency, (7) patch coverage meets the 80% codecov gate for modified files, and (8) no coverage regressions in thepesterflag on Codecov.