feat(coverage): --coverage-diff to report only lines changed since a ref - #1044
Merged
Conversation
A whole-file percentage cannot answer the question a pull request asks — are the lines I touched covered — and it moves for reasons unrelated to the change: adding a well-covered file raises the total while saying nothing about the new code. --coverage-diff <ref> restricts the console report to lines added or modified since the ref, merging the three sources git_changed_files already merges (commit range, working tree, untracked-in-full). A pure deletion contributes nothing, and changed lines that are not executable are ignored, so a comment-only commit is not penalised. With --coverage-min the gate follows the report, so a change that fully covers itself passes inside a poorly covered file. A change with no executable lines scores 100%, not 0%. The base ref is required rather than defaulted: an optional value would make `--coverage-diff tests/` swallow the path as a ref. A missing repository, missing git, or unresolvable ref is a hard error — on a shallow clone the base is simply absent, which would otherwise report "no changed lines" and pass a threshold while measuring nothing. LCOV and HTML stay whole-file; their consumers do their own diffing. Closes #1032
Chemaclass
force-pushed
the
feat/1032-diff-coverage
branch
from
August 10, 2026 19:12
0dd3780 to
9787718
Compare
This was referenced Aug 10, 2026
Closed
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.
🤔 Background
Related #1032
The coverage report was whole-file. For a pull request the useful question is are the lines I touched covered — and a whole-file percentage moves for reasons unrelated to the change: adding a well-covered file raises the total while saying nothing about the new code, and the reverse hides untested additions behind a healthy number.
💡 Changes
--coverage-diff <ref>restricts the console report to lines added or modified since the ref, reusing the three sourcesgit_changed_filesalready merges (commit range, working tree, untracked counted in full)--coverage-minthe gate follows the report — a change that fully covers itself passes inside a poorly covered file. A change with no executable lines scores 100%, not 0%genhtml/Codecov do their own diffing and expect complete recordsDecisions worth flagging
The base ref is required, not defaulted. An optional value would make
--coverage-diff tests/silently swallow the path as a ref.A missing repo, missing git, or unresolvable ref is a hard error. On a shallow CI clone the base is simply absent — left unchecked that reports "no changed lines" and passes a diff threshold while measuring nothing, which is a silent false pass rather than a missing feature.
Verification
Mutation-tested: counting non-executable lines fails 2 tests, treating every changed line as hit fails 3, including deletion-only hunks fails 4. 26 tests green on the Bash 3.0 floor.
test_built_binary_stays_below_500_kibis already red onmain: 513,422 bytes vs a 512,000 budget, before any change of mine (this PR adds ~5 KiB on top). It passes in CI only because the test skips whenshfmt/jqare unavailable there, so it went unnoticed through the recent merges. Worth its own issue.