Skip to main content

Module patch_coverage

Module patch_coverage 

Source
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 diffchanged_lines runs git diff --unified=0 <base>...HEAD and 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 the percent_covered ratio 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) reduces cargo 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) and coverage-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>...HEAD diff, keyed by repo-relative path. The diff machinery shared by the TS / Rust twins.
measure
Diff-scoped Python coverage floor (#162): measure thresholds over the <base>...HEAD changed .py lines instead of the whole tree. omit is the coverage-rule exemptions, as in crate::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-cov regions/lines metrics measured over the <base>...HEAD changed .rs lines instead of the whole tree. ignore is the coverage-rule exemptions, as in crate::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>...HEAD changed .ts/.tsx/.mts/.cts lines instead of the whole tree. exclude is the coverage-rule exemptions, as in crate::coverage::measure_typescript — an excluded file is left out of the run, so its changed lines drop out of the ratios.