fix(cargo-coverage-gate): eliminate unkillable format_delta mutant - #197
Merged
martin-kolinek merged 1 commit intoSep 23, 2026
Merged
Conversation
format_delta rounded a non-zero delta and then branched on rounded > 0.0 / rounded < 0.0 / else. Once the sub-precision guard above rules out |delta| < ~0.1, the rounded tenth can never land back on exactly 0.0, so the rounded < 0.0 branch was unreachable and mutating it to rounded <= 0.0 produced an equivalent mutant that no test could kill. cargo-mutants flagged this as MISSED on both the Linux and Windows legs of the scheduled-exhaustive workflow, failing anvil-mutants-full with exit code 2. Restructure the branch to check rounded == 0.0 first, then dispatch on rounded.is_sign_positive() for the sign. This keeps every observable case covered by the existing unit tests while removing the redundant comparison that could never be exercised. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The only finding is a non-blocking documentation nit, and validation reports zero missed mutants.
Review effort: Lite
Findings: None
What changed in this PR
This pull request refactors format_delta to eliminate an equivalent mutation while preserving coverage-delta rendering.
Changes:
- Handles rounded zero explicitly.
- Uses
is_sign_positive()for nonzero values. - Retains existing sign and boundary test coverage.
| File | Summary |
|---|---|
crates/cargo-coverage-gate/src/render/mod.rs |
Refactors delta formatting; a minor documentation nit requests clarifying that only the zero case is unreachable. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #197 +/- ##
=========================================
+ Coverage 98.1% 100.0% +1.8%
=========================================
Files 309 16 -293
Lines 85048 1553 -83495
=========================================
- Hits 83505 1553 -81952
+ Misses 1543 0 -1543
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Evgenii (Vaiz)
approved these changes
Sep 23, 2026
martinhavelka (wukchung)
approved these changes
Sep 23, 2026
martin-kolinek
deleted the
fix/coverage-gate-format-delta-equivalent-mutant
branch
September 23, 2026 14:16
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.
🤖 Fixes the scheduled
anvil-scheduledworkflow failure: bothscheduled-exhaustive (linux)andscheduled-exhaustive (windows)legs failedanvil-mutants-fullwith exit code 2 because of a single MISSED mutant:crates/cargo-coverage-gate/src/render/mod.rs:89:23: replace < with <= in format_deltaRoot cause
format_deltarounds a delta to one decimal place and then chooses the sign text via:By the time this code runs, the sub-precision guard earlier in the function has already ruled out
|delta| < DELTA_DISPLAY_PRECISION - DELTA_BOUNDARY_TOLERANCE(~0.0999999999999). Rounding any delta whose magnitude already clears that bound to one decimal place can never produce exactly0.0(verified numerically at and around the boundary). That means therounded < 0.0branch is unreachable in practice, so mutating it torounded <= 0.0is an equivalent mutant — no test can ever observe the difference, which is exactly why cargo-mutants reported it asMISSEDon every scheduled run.Fix
Restructured the branch so the unreachable comparison no longer exists:
Checking
rounded == 0.0first (which is caught by the existingformat_delta_renders_exact_match_as_zerotest either way it's mutated) and then dispatching onis_sign_positive()removes the redundant</<=comparison entirely, sinceis_sign_positiveisn't a target for cargo-mutants' operator-swap mutations and itstrue/falsestub mutations are already caught by the existing positive/negative sign tests.This file (
crates/cargo-coverage-gate/src/render/mod.rs) is hand-written crate source, not a cargo-anvil generated file, so no template edit orcargo anvilregeneration was required for this change. I confirmedjust anvil-fmt --fix,just anvil-readme --fix, andjust anvil-spellcheckproduce no diffs.Verification
cargo test -p cargo-coverage-gate— all 47 unit tests + 3 ignored + 1 doctest pass.cargo mutants -p cargo-coverage-gate --test-workspace false --file crates/cargo-coverage-gate/src/render/mod.rs --no-shuffle— 334 mutants tested: 294 caught, 40 unviable, 0 missed (previously 1 missed).just anvil-clippy— clean, no warnings.just anvil-spellcheck— clean.just anvil-fmt --fix/just anvil-readme --fix— no changes.Not related to the currently open PRs #177/#178 — this is a standalone fix scoped to the scheduled mutation-testing failure.