Skip to content

mutate: run each importer's tests once before any edit, and stop on a failure - #133

Merged
aledbf merged 2 commits into
mainfrom
mutate-importers-pass
Nov 22, 2026
Merged

aledbf merged 2 commits into
mainfrom
mutate-importers-pass

Conversation

@aledbf

@aledbf aledbf commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Why

Every repository's mutate gate should mean the same thing locally and in CI, and a 0 survived should mean the tests held every edit. Today an importer's test that fails regardless makes it mean nothing. mutate checks that the mutated package's own tests pass with nothing broken (Cover). It doesn't check the importers whose tests it also asks. An importer test that always fails refuses every edit put to it, and the run reports 0 survived with no warning. In spin-stack/machine#418, a test applied to an older commit failed on every run, and every mutate run over it said 0 survived.

What changes

  • Before the first edit, RunAll builds each distinct importer of the packages being broken and runs its tests once, on the code as it is, in a copy of the module (brokenImporters). It reuses runPackage, the path an edit built alone already takes.
  • A failure stops the run with exit 2, naming <importer>: <test> (the top-level --- FAIL: lines) and printing the tail of the output to stderr. Tally.Broken carries the names, as it does for the package's own broken tests.
  • An importer that doesn't build is left alone. It asks nothing either way, and spin has packages that embed a build output a fresh checkout lacks.
  • The site's mutate page says so, under "A test that fails with nothing broken".
  • byPackage is extracted from RunAll to keep it under the linter's complexity limit.

Evidence

TestAnImporterTestThatAlwaysFailsStopsTheRunBeforeAnyEdit: lib's own test calls Double and checks nothing. Its importer use has TestBroken, which always fails.

Before the fix (commit 1c5a31f, the test alone):

--- FAIL: TestAnImporterTestThatAlwaysFailsStopsTheRunBeforeAnyEdit (0.55s)
    Error: An error is expected but got nil.
    Messages: a run whose importer has a test that fails with nothing broken started:
      lib: 2 edit(s) in one binary, 0 built alone
      refused   lib/lib.go:4 (Double): the result is its left side alone
      refused   lib/lib.go:4 (Double): + becomes -

After:

--- PASS: TestAnImporterTestThatAlwaysFailsStopsTheRunBeforeAnyEdit (0.28s)

The existing importer tests (TestAPackageWithNoTestsIsAskedThroughItsImporters, TestAnEditItsOwnTestsLetThroughIsAskedOfEachImporterInTurn) still pass, so an importer that passes doesn't stop a run. task lint test mutate passes locally: 29 refused, 0 survived, 7 did not build.

Cost

One build and one run per distinct importer, side by side within -j, before the first edit. Measured on a laptop on spin-stack/machine at 6889fe4, -base HEAD~4 -max 20 (10 files, 5 importers), runs interleaved:

mutate run 1 run 2 verdict
main 6s 5s 20 refused, 0 survived
this change 11s 10s 20 refused, 0 survived

So about 5 s per run there, for 5 importers. It doesn't grow with the number of edits. Two runs a side is enough to size the cost, not to measure it precisely. Over machine's last commit alone (-base HEAD~1, no importers), the check costs nothing.

Closes #130

🤖 Generated with Claude Code

aledbf and others added 2 commits November 22, 2026 10:08
Fails today: use's TestBroken refuses both of Double's edits, and the
run reports 0 survived with no error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… failure

mutate checked that the package under mutation passes with nothing
broken, but not the importers whose tests it also asks. An importer's
test that fails regardless refused every edit asked of it, and the run
reported 0 survived with no warning. In spin-stack/machine#418 a test
applied to an older commit failed on every run, and every mutate run
over it showed 0 survived.

Before the first edit, each importer of the packages being broken is
built once and its tests run in a copy of the module, on the code as it
is. A failure stops the run with exit 2, naming "<importer>: <test>".
An importer that doesn't build is left alone, as it asks nothing either
way. The cost is one build and one run per distinct importer.

Closes #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf
aledbf merged commit 0352cf7 into main Nov 22, 2026
3 checks passed
@aledbf
aledbf deleted the mutate-importers-pass branch November 22, 2026 13:21
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.

mutate: an importer test that always fails reports 0 survived

1 participant