Expand description
Diff-scoped coverage floor (Python — #132; TypeScript — #135; Rust — #136;
folded into unit coverage --base — #162; parent #46).
Enforces the README Coverage rule over the lines a diff touches: where
crate::coverage measures the whole suite against the configured floor
(#26), the measure* functions here measure that same floor over only the
lines <base>...HEAD added or modified — covered ÷ total-changed-executable,
against the thresholds unit coverage enforces whole-tree. unit coverage --base routes here, so a diff that clears the configured floor passes even with
an uncovered changed line, and one below it fails no matter how small (#162).
Two inputs are combined:
- the diff —
changed_linesrunsgit diff --unified=0 <base>...HEADand returns the new-side line numbers each file gained. This diff machinery is language-agnostic, shared by all three arms. - the coverage — per the language. Python (
measure) reads coverage.py’s per-file lines and branch arcs (crate::coverage::measure_patch_report), restricting thepercent_coveredratio to the changed lines ([evaluate_patch]). TypeScript (measure_typescript) reduces vitest’s v8 export to the four per-metric counts (crate::coverage::measure_patch_typescript_detail) and Rust (measure_rust) reducescargo llvm-cov’s export to the per-region counts (crate::coverage::measure_patch_rust_detail); each metric’s ratio is then restricted to the changed lines ([evaluate_patch_typescript] / [evaluate_patch_rust]). Either way, non-executable changed lines (comments, blanks) andcoverage-exempt files have nothing to cover and drop out of the ratio.
Relationship to the commit-scoped co-change rule (crate::co_change, #33):
co-change enforces that a changed source and its colocated test move
together; the diff-scoped floor enforces that the changed lines are actually
exercised. They are complementary, not overlapping — co-change can pass (the
test file changed) while the floor fails (the change isn’t covered), and
vice versa.
Functions§
- changed_
lines - The new-side lines each file gained in
repo’s<base>...HEADdiff, keyed byrepo-relative path. The diff machinery shared by the TS / Rust twins. - measure
- Diff-scoped Python coverage floor (#162): measure
thresholdsover the<base>...HEADchanged.pylines instead of the whole tree.omitis thecoverage-rule exemptions, as incrate::coverage::measure— an exempt file is omitted from the run, so its changed lines drop out of the ratio. - measure_
rust - Diff-scoped Rust coverage floor (#162): the
cargo llvm-covregions/lines metrics measured over the<base>...HEADchanged.rslines instead of the whole tree.ignoreis thecoverage-rule exemptions, as incrate::coverage::measure_rust— an exempt file is dropped from the run, so its changed lines drop out of the ratios. - measure_
typescript - Diff-scoped TypeScript coverage floor (#162): the four vitest metrics measured
over the
<base>...HEADchanged.ts/.tsx/.mts/.ctslines instead of the whole tree.excludeis thecoverage-rule exemptions, as incrate::coverage::measure_typescript— an excluded file is left out of the run, so its changed lines drop out of the ratios.