Skip to content

feat(coverage): --coverage-diff to report only lines changed since a ref - #1044

Merged
Chemaclass merged 1 commit into
mainfrom
feat/1032-diff-coverage
Aug 10, 2026
Merged

feat(coverage): --coverage-diff to report only lines changed since a ref#1044
Chemaclass merged 1 commit into
mainfrom
feat/1032-diff-coverage

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 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 sources git_changed_files already merges (commit range, working tree, untracked counted in full)
  • Pure deletions contribute 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 — a change that fully covers itself passes inside a poorly covered file. A change with no executable lines scores 100%, not 0%
  • LCOV and HTML stay whole-file; genhtml/Codecov do their own diffing and expect complete records

Decisions 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.

⚠️ Pre-existing failure on main, not from this PR

test_built_binary_stays_below_500_kib is already red on main: 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 when shfmt/jq are unavailable there, so it went unnoticed through the recent merges. Worth its own issue.

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
Chemaclass force-pushed the feat/1032-diff-coverage branch from 0dd3780 to 9787718 Compare August 10, 2026 19:12
@Chemaclass
Chemaclass merged commit 104704f into main Aug 10, 2026
60 of 62 checks passed
@Chemaclass
Chemaclass deleted the feat/1032-diff-coverage branch August 10, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant