Skip to content

fix(mutation): fail the gate when tests fail without any mutation - #15

Merged
kamuikatsurgi merged 4 commits into
mainfrom
kamuikatsurgi/surface-failing-baseline
Nov 27, 2026
Merged

kamuikatsurgi merged 4 commits into
mainfrom
kamuikatsurgi/surface-failing-baseline

Conversation

@kamuikatsurgi

Copy link
Copy Markdown
Member

Problem

If a package's tests fail before any mutation is applied, diffguard dropped every mutant of that package, reported them as NOT RUN (budget or cancelled) and still exited 0. The only trace was a line on stderr. Seen running locally on bor, where one miner test fails on the machine:

mutation: .../bor/miner: its instrumented tests do not pass; testing its 29 mutants one build at a time
mutation: tests fail without any mutation in .../bor/miner; its mutants were not run
Score: 97.9% (595/608 killed, 13 survived) | ... | 29 NOT RUN (budget or cancelled)  [WARN]

A local exit 0 could hide a whole package, and any package with a flaky or environment-dependent test would get the same treatment in CI. The fallback also ran the full suite once more only to fail again.

Changes

  • New outcome baseline_failed for mutants whose tests fail without any mutation. It is excluded from the score, shown in the summary as N NOT TESTED (their tests fail without any mutation), and listed as one finding per file.
  • A Tier 1 or Tier 2 mutant in that state makes the section FAIL, so the run exits non-zero.
  • One failing test no longer costs the package its other tests. Each test is traced on its own and retried once if it fails. If the whole suite does not pass either, the failing tests are left out and named on stderr, and the rest are used. A mutant is baseline_failed only if no passing test reaches it and a left-out test does.
  • The one-build-at-a-time fallback, with its extra full suite run, now happens only when no test in the package passes on its own.

Behaviour to be aware of

  • Stricter in CI: a test that fails twice unmutated can now fail the gate where it used to pass with a warning.
  • A mutant that only a left-out test would have killed is reported as survived if other tests reach it.

Testing

  • make build, make test pass.
  • ./diffguard . exits 0: complexity max 8, T1 90.5% (19/21), T2 100% (8/8).
  • New tests: TestSession_FailingTestIsLeftOut, TestBuildSection_BaselineFailedFailsTheGate; TestSession_FailingBaselineRunsNothing and TestSession_TestsThatDoNotCompileRunNothing now expect baseline_failed.
  • Not yet run against bor itself.

A package whose tests failed unmutated had all its mutants reported as
"not run (budget or cancelled)" and the run still exited 0.

Such mutants now get their own outcome, baseline_failed, which is named
in the summary and findings and fails a gating tier. A single failing
test no longer costs the package its other tests: it is retried once,
then left out and named, and only the mutants no passing test reaches
are reported as untested.
A test is already retried on its own, so the second whole-suite attempt
only repeated a failing run. Dropping it also removes the conditions no
test could tell apart.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Discarded failure traces can misclassify mutants as uncovered and let the gate pass incorrectly, while overlay runs still reject mutants covered by healthy tests due to unrelated test failures.

3 open issues
What changed in this PR

This PR makes baseline test failures visible to diffguard’s mutation gate, failing the run when they prevent Tier 1 or Tier 2 mutants from being tested.

Changes:

  • Adds a baseline_failed outcome, excluded from scores but reflected in summaries, findings, and gate severity.
  • Retries individually failing tests and retains passing tests when the full suite also fails.
  • Adds regression coverage and documents the updated behavior.
File Description
README.md Documents untestable mutants and baseline-failure handling.
internal/​mutation/​tiers.go Counts baseline failures separately per tier.
internal/​mutation/​section.go Adds baseline-failure reporting and gate severity rules.
internal/​mutation/​run_test.go Tests scoring, findings, and gating for baseline failures.
internal/​mutation/​cache_test.go Verifies baseline failures are not cached.
internal/​lang/​lang.go Defines the new outcome and its serialized name.
internal/​lang/​lang_test.go Adds outcome-name round-trip coverage.
internal/​lang/​goanalyzer/​session.go Classifies mutants affected by failing baseline tests.
internal/​lang/​goanalyzer/​session_test.go Tests mixed passing/failing tests and updates baseline expectations.
internal/​lang/​goanalyzer/​session_prepare.go Retries individual tests and records reachability for excluded tests.

Review effort: Balanced

Comment thread internal/lang/goanalyzer/session.go Resolved
… on the overlay path

A mutant only failing runs reach was reported as not covered when the
evidence was in the whole-suite run or in a first attempt the retry did
not repeat. Both now count.

Mutants that need a build of their own were all rejected when one test
failed, because their baseline ran the full suite. The baseline and the
mutant runs now skip the left-out tests.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical baseline and test-filtering defects discard healthy tests and misclassify overlay-only mutants, producing unreliable mutation scores and potentially allowing the gate to pass incorrectly.

3 open issues
3 resolved since last review

Review effort: Balanced

Comment thread internal/lang/goanalyzer/session.go Resolved
…s all fail

A dependent package with no passing test made preparation give up on
every binary, and the fallback then rejected all of the package's
mutants. Such a binary is now kept with all of its tests left out.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A shared baseline is incorrectly rejected when the mutated package’s tests all fail but dependent tests pass, causing mutants covered by healthy tests to be marked baseline_failed instead of tested.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Preserve healthy dependent tests when the mutated package baseline fails

internal/​lang/​goanalyzer/​session_prepare.go:349

When all tests in the mutated package fail but a dependent subpackage has passing tests, this rejects the entire shared baseline. Mutants covered by those healthy tests are then reported as baseline_failed instead of being tested. Retain the own binary's failed-test traces and exclusions too, and decide whether any passing baseline remains across all binaries in baselineAll before falling back.

3 resolved since last review

Review effort: Balanced

@kamuikatsurgi
kamuikatsurgi merged commit 835413b into main Nov 27, 2026
7 checks passed
@kamuikatsurgi
kamuikatsurgi deleted the kamuikatsurgi/surface-failing-baseline branch November 27, 2026 10:59
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.

2 participants