Skip to main content

Module coverage

Module coverage 

Source
Expand description

Coverage rule (Python — issue #26; TypeScript — issue #31; Rust — issue #37; exemptions — issue #32).

Enforces the README’s Coverage rule: a library’s unit suite must meet the configured floor, with test files excluded from the denominator. This module is the deterministic core — given a parsed coverage report and the thresholds from config, an evaluate function decides pass/fail. Producing the report (shelling out to the language’s coverage tool) is a thin layer on top, kept separate so the guarantee is testable without that toolchain installed.

Python (#26) uses coverage.py: a single total, branch coverage on. Given a CoverageReport and Thresholds, evaluate decides pass/fail, and measure shells out to coverage. TypeScript (#31) is the twin: vitest reports four independent metrics (lines / branches / functions / statements), so it carries its own TypeScriptThresholds, VitestReport, and evaluate_typescript / measure_typescript pair — sharing only the Outcome type. Its subprocess layer shells out to vitest. Rust (#37) is the third twin: cargo llvm-cov reports regions/lines (branch coverage is experimental), so it carries RustThresholds, LlvmCovReport, and evaluate_rust / measure_rust; its subprocess layer shells out to cargo llvm-cov.

Files exempted from coverage in config (issue #32) are omitted from the denominator alongside the test files; the caller resolves them (crate::config::resolve_exempt) and passes their paths to measure / measure_typescript / measure_rust.

Structs§

CoverageReport
A coverage.py JSON report (coverage json), pared to what the checks need: the totals (the floor) and the per-file files block (patch coverage, #132). Unmodeled fields (metadata, per-function/class data) are ignored.
FileCoverage
Per-file coverage detail from a coverage.py report (one files entry) — what patch coverage (#132) reads to decide whether a changed line is covered. Unmodeled fields (the summary, per-function/class data) are ignored.
LlvmCovData
One export entry — only its totals are needed (--summary-only omits the per-file and per-function detail).
LlvmCovMetric
One metric’s totals from an llvm-cov export, pared to what the check needs: the denominator size and the covered percent.
LlvmCovReport
A cargo llvm-cov --json export (LLVM’s llvm.coverage.json.export), pared to the totals the check needs. A single run produces one data entry; unmodeled fields (per-file/per-function detail, type, version) are ignored.
LlvmCovTotals
The totals block of an llvm-cov export — the two metrics this rule enforces. llvm-cov also reports functions, instantiations, and (experimental) branches, which the check ignores.
RustPatchCoverage
Per-file region detail from a cargo llvm-cov --json export — the per-region counts the diff-scoped floor (#162) needs. Each entry carries one (start_line, end_line, covered) tuple per code region, so the pure [crate::patch_coverage::evaluate_patch_rust] can restrict both the regions and lines metrics to the changed lines.
RustThresholds
The two cargo llvm-cov coverage floors, from a [rust].coverage table. Branch coverage is still experimental, so only regions and lines are enforced.
Thresholds
The coverage floor to enforce, from a [<language>].coverage table.
Totals
The totals block of a coverage.py report.
TsPatchCoverage
Per-file coverage detail from a vitest v8 coverage-final.json (Istanbul) report — the counts the diff-scoped floor (#162) needs. Each entry carries the Istanbul maps reduced to (line, …, covered) tuples, so the pure [crate::patch_coverage::evaluate_patch_typescript] can restrict each of the four metrics to the changed lines.
TypeScriptThresholds
The four vitest coverage floors, from a [typescript].coverage table. Each is an independent percent the unit suite must meet — vitest measures all four.
VitestMetric
One metric’s totals from a vitest json-summary block, pared to what the check needs: the covered percent and the denominator size.
VitestReport
A vitest coverage-summary.json report, pared to the total block the check needs. Per-file entries and unmodeled fields are ignored.
VitestTotals
The total block of a vitest json-summary report — the four metrics this rule enforces. vitest also emits branchesTrue, which the check ignores.

Enums§

Outcome
The result of checking a report against the thresholds.

Functions§

evaluate
Decide whether report meets thresholds.
evaluate_rust
Decide whether report meets both thresholds.
evaluate_typescript
Decide whether report meets every threshold in thresholds.
measure
Run the unit suite under coverage.py in root and check it against thresholds.
measure_patch_report
Run the Python unit suite under coverage.py in root with every source under root measured (coverage run --source=.) and return the parsed report — so an untested source shows in the files block as wholly uncovered rather than vanishing. The per-file detail is what patch coverage (#132) reads; omit is as in measure (an exempt file stays out of the run, so its changed lines are lifted).
measure_patch_rust_detail
Run the Rust unit suite under cargo llvm-cov in root and return the per-file region detail — keyed by the absolute path llvm-cov reports, the caller re-keying to root-relative to match the diff. Reads the full --json export for the diff-scoped floor (#162): the per-region (line, covered) detail the floor’s regions metric needs. ignore is the coverage-rule exemptions, dropped from the run so an exempt file’s changed lines are lifted. cargo-llvm-cov must be installed.
measure_patch_typescript_detail
Run the TypeScript unit suite under vitest in root and return the per-file coverage detail for the four metrics — keyed by the absolute path vitest reports, the caller re-keying to root-relative to match the diff. Reads the Istanbul report for the diff-scoped floor (#162): the per-statement / per-branch-arm / per-function (line, covered) detail the floor’s ratio needs. exclude is the coverage-rule exemptions, dropped from the run so an exempt file’s changed lines are lifted. npx resolves the project-local vitest, so it and @vitest/coverage-v8 must be installed under root.
measure_rust
Run the unit suite under cargo llvm-cov in root and check it against thresholds.
measure_typescript
Run the unit suite under vitest coverage in root and check it against thresholds.
parse_llvm_cov_report
Parse a cargo llvm-cov --json export.
parse_report
Parse a coverage.py JSON report (the output of coverage json).
parse_vitest_report
Parse a vitest json-summary report (coverage-summary.json).