feat(coverage): render coverage summaries as a Markdown table - #14
Open
dchaudhari7177 wants to merge 1 commit into
Open
dchaudhari7177 wants to merge 1 commit into
dchaudhari7177 wants to merge 1 commit into
Conversation
Add `npm run coverage:summary`, converting the two Vitest coverage-summary JSON files into a deterministic Markdown table: statements, branches, functions and lines with covered/total counts and percentages, for both the all-source and critical safety/privacy suites. Split the way the other scripts here are: pure functions in scripts/lib/saferide-coverage-summary.mjs, a thin CLI in scripts/saferide-coverage-summary.mjs that only handles stdout and the exit code. buildCoverageReport takes rootDir and sources, so the tests never need a real coverage run. Deterministic on purpose -- fixed metric order and two-decimal percentages -- so re-rendering the same input produces a byte-identical file and evidence diffs stay readable. Read-only. It asserts no threshold, so the 15% global and 80% critical gates in coverage-policy.v1.json are untouched; the only change outside new files is one added npm script. Bad input fails with the offending path rather than a stack trace: a missing summary names the file and the command that produces it, and malformed JSON, a non-object, a missing total block, a missing metric or a non-numeric field all raise CoverageSummaryError. 15 node --test cases cover those paths plus table formatting, percentage rounding, byte-identical repeat runs, and both suites being required. Documented under Coverage gates in docs/open-source/build-and-test.md. Closes esherialabs#5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5.
npm run coverage:summaryturns the two Vitestcoverage-summary.jsonfiles into a deterministic Markdown table.Acceptance criteria
docs/open-source/build-and-test.md— new "Human-readable summary" subsection under Coverage gatesIt cannot weaken the gates
The generator is read-only and asserts no threshold — it reports numbers the existing gates already produced.
config/release/coverage-policy.v1.jsonand all three vitest configs are untouched.The only change outside new files is one added npm script:
Structure
Split the way the other scripts here are — pure functions in
scripts/lib/saferide-coverage-summary.mjs, a thin CLI inscripts/saferide-coverage-summary.mjsthat only owns stdout and the exit code, mirroringsaferide-claim-register-check.mjs.buildCoverageReport({ rootDir, sources })is injectable, so the tests never need a real coverage run.Deterministic on purpose: fixed metric order and two-decimal percentages, so re-rendering the same input is byte-identical and evidence diffs stay readable. One test asserts exactly that by building twice and comparing.
Failure modes name the file
A stack trace is not useful in CI, so every bad input raises
CoverageSummaryErrorwith the offending path:exit code
1.Covered: missing file, malformed JSON, a JSON array, a missing
totalblock, each of the four metrics missing individually, and a non-numericpct.Verification
node --test scripts/__tests__/saferide-coverage-summary.test.mjs— 15 pass, 0 failnpm run coverage:summaryend-to-end against fixture summaries (output above) and confirmed the missing-file path exits1with the message shown.