Skip to content

fix(cargo-coverage-gate): eliminate unkillable format_delta mutant - #197

Merged
martin-kolinek merged 1 commit into
mainfrom
fix/coverage-gate-format-delta-equivalent-mutant
Sep 23, 2026
Merged

martin-kolinek merged 1 commit into
mainfrom
fix/coverage-gate-format-delta-equivalent-mutant

Conversation

@martin-kolinek

Copy link
Copy Markdown
Collaborator

🤖 Fixes the scheduled anvil-scheduled workflow failure: both scheduled-exhaustive (linux) and scheduled-exhaustive (windows) legs failed anvil-mutants-full with exit code 2 because of a single MISSED mutant:

crates/cargo-coverage-gate/src/render/mod.rs:89:23: replace < with <= in format_delta

Root cause

format_delta rounds a delta to one decimal place and then chooses the sign text via:

if rounded > 0.0 {
    format!("+{rounded:.1}pp")
} else if rounded < 0.0 {
    format!("{rounded:.1}pp")
} else {
    "0.0pp".to_owned()
}

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 exactly 0.0 (verified numerically at and around the boundary). That means the rounded < 0.0 branch is unreachable in practice, so mutating it to rounded <= 0.0 is an equivalent mutant — no test can ever observe the difference, which is exactly why cargo-mutants reported it as MISSED on every scheduled run.

Fix

Restructured the branch so the unreachable comparison no longer exists:

let rounded = (delta * 10.0).round() / 10.0;
if rounded == 0.0 {
    return "0.0pp".to_owned();
}
if rounded.is_sign_positive() {
    format!("+{rounded:.1}pp")
} else {
    format!("{rounded:.1}pp")
}

Checking rounded == 0.0 first (which is caught by the existing format_delta_renders_exact_match_as_zero test either way it's mutated) and then dispatching on is_sign_positive() removes the redundant </<= comparison entirely, since is_sign_positive isn't a target for cargo-mutants' operator-swap mutations and its true/false stub 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 or cargo anvil regeneration was required for this change. I confirmed just anvil-fmt --fix, just anvil-readme --fix, and just anvil-spellcheck produce 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.

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>
Copilot AI lite review requested due to automatic review settings September 22, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-commenter

Codecov Comments Bot (codecov-commenter) commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (9248a3b) to head (7be6624).
⚠️ Report is 2 commits behind head on main.

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     
Flag Coverage Δ
linux 100.0% <100.0%> (+1.8%) ⬆️
linux-arm 100.0% <100.0%> (+1.8%) ⬆️
scheduled ?
windows 100.0% <100.0%> (+1.5%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martin-kolinek
martin-kolinek merged commit 17946d7 into main Sep 23, 2026
29 checks passed
@martin-kolinek
martin-kolinek deleted the fix/coverage-gate-format-delta-equivalent-mutant branch September 23, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants