-
Notifications
You must be signed in to change notification settings - Fork 125
Description
Summary
Test-ActionVersionConsistency.ps1 validates SHA-pinned action version comment consistency across GitHub Actions workflows, but its CI integration is minimal: Write-CIAnnotation fires only in the catch block (line 425) for fatal errors, and Write-CIStepSummary is never called. Contributors see per-violation Write-Host output in the console log but get no inline PR annotations and no job summary tab content.
Current Behavior
- Console output: Per-violation
Write-Hostvia a log helper function (line 96) with color coding. ✅ - CI annotations:
Write-CIAnnotationonly incatchblock (line 425) — fires on fatal script errors, not per-violation. ❌ - Step summary: No
Write-CIStepSummarycall anywhere in the script. ❌ - Workflow: No dedicated workflow file exists — the script runs via
npm run lint:version-consistencyonly.
Expected Behavior
- Each version mismatch or missing comment should produce a
Write-CIAnnotation(levelWarning) with the workflow file path, action reference, and description of the inconsistency — so GitHub renders inline annotations on PR diffs. - A
Write-CIStepSummaryshould produce a markdown table in the job summary tab showing all scanned workflows, the actions checked, and their consistency status.
Root Cause
The script's CI output integration was not extended beyond the catch-block pattern. The validation loop writes to console via Write-Host but never calls Write-CIAnnotation per violation. Write-CIStepSummary is absent entirely.
Files Requiring Changes
| File | Change |
|---|---|
scripts/security/Test-ActionVersionConsistency.ps1 |
Add Write-CIAnnotation per violation in the validation results loop. Add Write-CIStepSummary with a markdown summary table after all validations complete. |
scripts/tests/security/Test-ActionVersionConsistency.Tests.ps1 |
Add mocks and assertions for Write-CIAnnotation (per violation) and Write-CIStepSummary. |
Additional Context
- The script imports
SecurityClasses.psm1fromscripts/security/Modules/SecurityClasses.psm1. - The
CIHelpersmodule is already available — no new imports needed. Write-Hostis safe —PSAvoidUsingWriteHostis explicitly excluded inscripts/linting/PSScriptAnalyzer.psd1.- No workflow file changes needed since the script has no dedicated workflow.
Fix Guidance
Per-Violation Annotations
In the validation results processing section, after each Write-Host violation line:
Write-CIAnnotation -Message "Action version mismatch: $($violation.Action) in $($violation.File) — SHA comment says $($violation.CommentVersion) but latest is $($violation.ActualVersion)" `
-Level Warning `
-File $violation.FileStep Summary
After all validations complete and before the exit decision:
$summaryLines = @(
"## Action Version Consistency Results"
""
"| Workflow File | Action | Comment Version | Status |"
"|-------------|--------|----------------|--------|"
)
foreach ($result in $allResults) {
$status = if ($result.IsConsistent) { "✅ Consistent" } else { "❌ Mismatch" }
$summaryLines += "| $($result.File) | $($result.Action) | $($result.CommentVersion) | $status |"
}
$summaryLines += ""
$summaryLines += "**Total**: $($allResults.Count) actions checked, $($inconsistentCount) inconsistent"
Write-CIStepSummary -Summary ($summaryLines -join "`n")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 must meet the patch coverage gate.
Pester Coverage
- Config:
scripts/tests/pester.config.ps1— JaCoCo format,CoveragePercentTarget = 80 - Coverage path:
scripts/security/is already in the coverage scan scope - Run:
npm run test:ps
Current Test Gap
The existing test file scripts/tests/security/Test-ActionVersionConsistency.Tests.ps1 has no mocks for Write-CIAnnotation, Write-CIStepSummary, or Write-Host. All CI helper mock infrastructure must be built from scratch:
- Mock
Write-CIAnnotation— add mock with-ParameterFilterto assert correct-File,-Level Warning, and-Messagecontent per violation. Currently only called in catch block. - Mock
Write-CIStepSummary— add mock andShould -Invokeassertion verifying the markdown summary includes workflow file names, action references, and consistency status. - Mock
Write-Host— add content verification for per-violation console output lines.
RPI Phase Testing Guidance
- Research: Audit
Test-ActionVersionConsistency.Tests.ps1for CI helper coverage gaps; document the validation loop structure and catch-block-only annotation pattern. - Plan: Design test cases for per-violation
Write-CIAnnotation,Write-CIStepSummarymarkdown content, andWrite-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.
RPI Framework Starter Prompts
Research Phase
Research CI output coverage in
scripts/security/Test-ActionVersionConsistency.ps1. Document: (1) the log helper function (line 96) providing per-violationWrite-Hostoutput, (2) the catch-onlyWrite-CIAnnotationpattern (line 425), (3) the absence ofWrite-CIStepSummary, (4) that no dedicated workflow file exists — script runs vianpm run lint:version-consistency, (5) theSecurityClasses.psm1module dependency, (6) existing Pester test coverage and the complete absence of CI helper mocks, and (7)codecov.ymlandscripts/tests/pester.config.ps1coverage requirements (80% patch target). Compare withInvoke-PSScriptAnalyzer.ps1as the per-violation annotation reference andTest-DependencyPinning.ps1as the step summary reference.
Plan Phase
Plan CI output improvements for
Test-ActionVersionConsistency.ps1. The plan should cover: (1) insertingWrite-CIAnnotationcalls with Warning level per version mismatch — determine the correct insertion point in the validation results loop, (2) building a markdown summary table from validation results and callingWrite-CIStepSummaryafter all validations complete, (3) adding Pester tests with mocks forWrite-CIAnnotation(per-violation) andWrite-CIStepSummaryto verify call count, arguments, and markdown content, and (4) ensuring patch coverage meets the 80% codecov gate.
Implement Phase
Implement CI output improvements for
Test-ActionVersionConsistency.ps1. Steps: (1) In the validation results loop, after eachWrite-Hostmismatch line, addWrite-CIAnnotation -Message "..." -Level Warning -File $filewith the action name, expected version, and actual version. (2) After all validations, build a markdown table from results (columns: Workflow File, Action, Comment Version, Status) and callWrite-CIStepSummary -Summary $markdown. (3) InTest-ActionVersionConsistency.Tests.ps1, add mocks forWrite-CIAnnotationandWrite-CIStepSummarywith-ParameterFilterassertions; ensure patch coverage ≥ 80%. Runnpm run lint:psandnpm run test:psto validate.
Review Phase
Review CI output changes to
Test-ActionVersionConsistency.ps1. Verify: (1)Write-CIAnnotationis called once per version mismatch with Warning level and correct file path, (2)Write-CIStepSummaryproduces a well-formed markdown table with all scanned actions, (3) existing catch-blockWrite-CIAnnotationis unmodified, (4) Pester tests mock and assert both CI helpers, (5)npm run lint:pspasses, (6) no regressions in existing tests, (7) patch coverage meets the 80% codecov gate, and (8) output formats align with other scripts for consistency.
References
- Affected script:
scripts/security/Test-ActionVersionConsistency.ps1 - Module dependency:
scripts/security/Modules/SecurityClasses.psm1 - Tests:
scripts/tests/security/Test-ActionVersionConsistency.Tests.ps1 - No dedicated workflow — runs via
npm run lint:version-consistency - Reference implementations:
scripts/linting/Invoke-PSScriptAnalyzer.ps1(per-violation annotations),scripts/security/Test-DependencyPinning.ps1(step summary) - CI helpers module:
scripts/lib/Modules/CIHelpers.psm1 - Codecov config:
codecov.yml(80% patch target, auto +1% project threshold) - Pester config:
scripts/tests/pester.config.ps1(JaCoCo format, 80% coverage target)