scripts: red_green.py --mutate checks that the tests catch the change itself (TEST-RED-GREEN-MUTATION) #2817

Merged
TheGeogeo merged 17 commits from upstream-pr/2817 into main 2026-12-02 10:37:57 +00:00
TheGeogeo commented 2026-12-01 01:10:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-12-01T01:10:18Z.


Claimed in the coordination issue as: TEST-RED-GREEN-MUTATION (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7297046897)

What and why

A red side that fails shows that the new test needs the pull request. It does not show that the test catches the change itself. Verifiers check that by hand, on nearly every test pull request: they remove a line of the fix and see whether the new test fails. scripts/red_green.py --mutate does it for every hunk of the fix:

  • After the green side, --mutate takes each hunk of the pull request's code: Rust and Python files it modifies, outside its tests and its #[cfg(test)] code. One rule tells a hunk of test code only, for the red side and for the mutations, so deleting an obsolete test is not mutated.
    • Hunks are taken without context, so a test changed next to the code stays out.
  • The green merge is committed once. Each mutation starts from it, reset and cleaned, then undoes that hunk alone and runs the tests again. A test that writes into the tree cannot change the next hunk's result. Each hunk is reported as one of:
    • caught: a test that went red then green now fails;
    • caught by timeout: a test hung on the undone code past --mutate-timeout (600 s);
    • not caught: they all still pass, so no new test looks at that code;
    • does not build, compiler crashed, or timed out building (a cargo run stopped before any test ran: no answer, raise the option);
    • does not apply: main moved those lines since.
  • A mutated run writes its output to a file and runs in a Windows job object (a process group elsewhere). Whatever it leaves behind is stopped when it ends, so an orphan holding its output can neither hold the run nor turn a catch into a timeout.
  • The report and --json always say what happened:
    • mutations_not_run: "nothing to undo" for a pull request that changes only tests, or "not run" when no test went red then green;
    • mutations_skipped: the hunks past --mutate-max (10);
    • added_not_mutated: the files the pull request adds, which are not mutated.
  • The verdict and the exit code do not change. --mutate-max must be 1 or more, and --mutate-timeout a finite number above 0. Both are refused without --mutate.
  • Before each Python run, the work tree's own __pycache__ folders are removed. They are never reached through a link or junction, and a folder that cannot be listed is skipped. -B only stops writing bytecode, so a stale ignored .pyc made red pass and an undone hunk read as not caught. -X pycache_prefix was tried and does not reach the processes a test starts. A __pycache__ that cannot be removed stops the run (exit 2) with the tree put back on the base.
  • docs/testing.md describes the option, its results and limits, and how to remove the worktree the tool leaves registered.

Tested

On Windows 11 Pro 10.0, Python 3.12.4, rebased on main 8422def75:

  • tests/test_red_green.py: 37 tests OK. They include:

    • a Rust fix with a tested and an untested hunk (caught, not caught);
    • a Python fix undone (caught);
    • a hang (caught by timeout, within its bound);
    • an orphan that holds the output (stopped, the run not held);
    • a cargo run that hangs in its build or in a test binary;
    • stale bytecode in and out of a child process;
    • junctions out of the tree and a junction named __pycache__;
    • a folder it cannot list, and a __pycache__ held open;
    • a test that dirties the tree;
    • a deleted test (not mutated);
    • hunks past --mutate-max;
    • code only in added files;
    • a test-only pull request;
    • option ranges;
    • a job object that cannot be joined (one warning).

    Each change asked for in the reviews has a test that fails without it.

  • Real runs on synthetic repositories (--no-fetch --no-cargo --mutate) show the report lines above and leave no process behind. An earlier head ran on #2810: 6 hunks, 5 caught, 1 not caught (the list of runtime strings in tools/game_gate.py's SOURCES, which only the contract test reads).

  • The docs tests, test_text_write_line_endings.py, test_ci_registration.py, compileall and scripts/check_no_game_data.py on the changed files are clean.

  • Not run here: the POSIX paths (killpg, the chmod cases of the tests) and a real cargo crate.

GPUs tested: n/a

AI-assisted: yes. Claude Code (Claude Fable 5.2 and Claude Opus 5.5); a separate Claude Opus 5.5 agent reviewed the diff before this push.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5576836102 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-12-01T01:10:18Z. --- Claimed in the coordination issue as: TEST-RED-GREEN-MUTATION (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7297046897) ### What and why A red side that fails shows that the new test needs the pull request. It does not show that the test catches the change itself. Verifiers check that by hand, on nearly every test pull request: they remove a line of the fix and see whether the new test fails. `scripts/red_green.py --mutate` does it for every hunk of the fix: - After the green side, `--mutate` takes each hunk of the pull request's code: Rust and Python files it modifies, outside its tests and its `#[cfg(test)]` code. One rule tells a hunk of test code only, for the red side and for the mutations, so deleting an obsolete test is not mutated. - Hunks are taken without context, so a test changed next to the code stays out. - The green merge is committed once. Each mutation starts from it, reset and cleaned, then undoes that hunk alone and runs the tests again. A test that writes into the tree cannot change the next hunk's result. Each hunk is reported as one of: - `caught`: a test that went red then green now fails; - `caught by timeout`: a test hung on the undone code past `--mutate-timeout` (600 s); - `not caught`: they all still pass, so no new test looks at that code; - `does not build`, `compiler crashed`, or `timed out building` (a cargo run stopped before any test ran: no answer, raise the option); - `does not apply`: `main` moved those lines since. - A mutated run writes its output to a file and runs in a Windows job object (a process group elsewhere). Whatever it leaves behind is stopped when it ends, so an orphan holding its output can neither hold the run nor turn a catch into a timeout. - The report and `--json` always say what happened: - `mutations_not_run`: "nothing to undo" for a pull request that changes only tests, or "not run" when no test went red then green; - `mutations_skipped`: the hunks past `--mutate-max` (10); - `added_not_mutated`: the files the pull request adds, which are not mutated. - The verdict and the exit code do not change. `--mutate-max` must be 1 or more, and `--mutate-timeout` a finite number above 0. Both are refused without `--mutate`. - Before each Python run, the work tree's own `__pycache__` folders are removed. They are never reached through a link or junction, and a folder that cannot be listed is skipped. `-B` only stops writing bytecode, so a stale ignored `.pyc` made red pass and an undone hunk read as not caught. `-X pycache_prefix` was tried and does not reach the processes a test starts. A `__pycache__` that cannot be removed stops the run (exit 2) with the tree put back on the base. - `docs/testing.md` describes the option, its results and limits, and how to remove the worktree the tool leaves registered. ### Tested On Windows 11 Pro 10.0, Python 3.12.4, rebased on `main` 8422def75: - `tests/test_red_green.py`: 37 tests OK. They include: - a Rust fix with a tested and an untested hunk (`caught`, `not caught`); - a Python fix undone (`caught`); - a hang (`caught by timeout`, within its bound); - an orphan that holds the output (stopped, the run not held); - a cargo run that hangs in its build or in a test binary; - stale bytecode in and out of a child process; - junctions out of the tree and a junction named `__pycache__`; - a folder it cannot list, and a `__pycache__` held open; - a test that dirties the tree; - a deleted test (not mutated); - hunks past `--mutate-max`; - code only in added files; - a test-only pull request; - option ranges; - a job object that cannot be joined (one warning). Each change asked for in the reviews has a test that fails without it. - Real runs on synthetic repositories (`--no-fetch --no-cargo --mutate`) show the report lines above and leave no process behind. An earlier head ran on #2810: 6 hunks, 5 caught, 1 not caught (the list of runtime strings in `tools/game_gate.py`'s `SOURCES`, which only the contract test reads). - The docs tests, `test_text_write_line_endings.py`, `test_ci_registration.py`, `compileall` and `scripts/check_no_game_data.py` on the changed files are clean. - Not run here: the POSIX paths (`killpg`, the `chmod` cases of the tests) and a real cargo crate. GPUs tested: n/a AI-assisted: yes. Claude Code (Claude Fable 5.2 and Claude Opus 5.5); a separate Claude Opus 5.5 agent reviewed the diff before this push. ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
fiestorra commented 2026-12-01 01:16:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T01:16:39Z.


Verified with its own tests in both directions, and then used it on a real pull request, where it did exactly what it should - and showed me one thing it cannot do.

The tests, at each head on main d920d850d, with the PR's scripts/red_green.py:

#2814:  16 passed        |  with main's script:  3 failed
#2817:  19 passed        |  with main's script:  6 failed

Then the tool, on a pull request that is not mine:

python -I scripts/red_green.py --mutate 2803
  base origin/main d920d850d, head 2803 8aada4fc2, merge base 66b5d0433
  red:   the base plus the tests of tests/semantic/test_wave64_emulate_opt.py
  green: the base with the pull request merged
  ran:   tests/semantic/test_wave64_emulate_opt.py
  pass on both: 36
  verdict: no red

That verdict is correct and the pull request is fine: #2803 only adds a test, so there is nothing in its diff to mutate. I then found the mutation by hand - removing ds_append/ds_consume from _ALWAYS_BARRIER_OPS makes the new test fail and leaves the other 35 passing - which is what its comment claims.

Where that leaves --mutate: it checks that a pull request's own change is caught by its own tests. For a test-only pull request it can only answer "no red", and it is right to. That is a limitation of the question, not of the tool, but it is one a maintainer will meet often, because test-only pull requests are how a mutation gap gets closed in the first place. Two ways to help them:

  1. Say it in --help or in the verdict: no red (nothing in this diff can be mutated) rather than no red, so the answer is not read as "the test is worthless".
  2. --mutate-target <path>, so a test-only pull request can name what its test guards and the tool mutates that instead. Today I did it by hand in a worktree; the tool already has the machinery.

Neither is a complaint about what is here - the red/green split is exactly the right frame and the JSON output is going to be usable from a script. I am writing this because I did the same job by hand for eleven hours tonight, and I would have used --mutate-target about thirty times.

AI-assisted: yes - DeepSeek v4.1 (flash), which also ran it.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7297311143 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7297311143). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-01T01:16:39Z. --- **Verified with its own tests in both directions, and then used it on a real pull request, where it did exactly what it should - and showed me one thing it cannot do.** **The tests, at each head on `main` `d920d850d`, with the PR's `scripts/red_green.py`:** ``` #2814: 16 passed | with main's script: 3 failed #2817: 19 passed | with main's script: 6 failed ``` **Then the tool, on a pull request that is not mine:** ``` python -I scripts/red_green.py --mutate 2803 base origin/main d920d850d, head 2803 8aada4fc2, merge base 66b5d0433 red: the base plus the tests of tests/semantic/test_wave64_emulate_opt.py green: the base with the pull request merged ran: tests/semantic/test_wave64_emulate_opt.py pass on both: 36 verdict: no red ``` **That verdict is correct and the pull request is fine**: **#2803 only adds a test**, so there is nothing in its diff to mutate. **I then found the mutation by hand** - **removing `ds_append`/`ds_consume` from `_ALWAYS_BARRIER_OPS` makes the new test fail and leaves the other 35 passing** - **which is what its comment claims.** **Where that leaves `--mutate`:** **it checks that a pull request's own change is caught by its own tests.** **For a test-only pull request it can only answer "no red", and it is right to.** **That is a limitation of the question, not of the tool**, **but it is one a maintainer will meet often, because test-only pull requests are how a mutation gap gets closed in the first place.** **Two ways to help them:** 1. **Say it in `--help` or in the verdict**: `no red (nothing in this diff can be mutated)` rather than `no red`, **so the answer is not read as "the test is worthless".** 2. **`--mutate-target <path>`**, so a test-only pull request can name what its test guards and the tool mutates that instead. **Today I did it by hand in a worktree; the tool already has the machinery.** **Neither is a complaint about what is here** - **the red/green split is exactly the right frame and the JSON output is going to be usable from a script.** **I am writing this because I did the same job by hand for eleven hours tonight, and I would have used `--mutate-target` about thirty times.** **AI-assisted:** yes - DeepSeek v4.1 (flash), which also ran it. Written with an AI assistant.
OreoFR commented 2026-12-01 01:17:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T01:17:21Z.


Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head 5193b2503, main d920d850d. CPU only. This branch contains #2814 f442c3dfb, so red is #2814 + this PR's tests.

MEASURED

  • Red (#2814 + only this PR's tests/test_red_green.py): 3 failed, 16 passed. The failures are the three new Mutation tests (test_a_python_fix_undone_is_caught, test_each_code_hunk_undone_alone_is_caught_or_not, test_no_mutation_without_the_option).

  • Green (main + this PR, merge-tree): 19 passed. No conflict.

  • A real run, as a user would, on an unrelated open PR: from a checkout of main + this PR, python -I scripts/red_green.py pr-2798 --base origin/main --no-fetch --no-cargo --mutate --work-dir <dir>. Result:

    • red then green (1): test_old_follower_leaves_the_new_job_state_intact. That matches my manual red/green on #2798.
    • pass on both: 11.
    • mutations (8 hunks undone one at a time): 4 caught, 4 not caught. Caught: launcher/serve.py:322, :324, :367, :371. Not caught: :346, :350, :355, :374.
    • Verdict red then green.

    That's useful information about #2798 itself: its spawn-ordering hunks and the in-lock exit-state hunk aren't pinned by a test. It is exactly what I was doing by hand on test PRs tonight, and it works.

Small note: --work-dir leaves a registered git worktree (<dir>/tree) behind between runs. That is by design ("keeps both between runs"), but someone who only runs it once will see it in git worktree list. A line in docs/testing.md on removing it with git worktree remove would help.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7297327174 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7297327174). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-12-01T01:17:21Z. --- Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head `5193b2503`, main `d920d850d`. CPU only. This branch contains #2814 `f442c3dfb`, so red is #2814 + this PR's tests. **MEASURED** - Red (#2814 + only this PR's `tests/test_red_green.py`): 3 failed, 16 passed. The failures are the three new `Mutation` tests (`test_a_python_fix_undone_is_caught`, `test_each_code_hunk_undone_alone_is_caught_or_not`, `test_no_mutation_without_the_option`). - Green (main + this PR, merge-tree): 19 passed. No conflict. - A real run, as a user would, on an unrelated open PR: from a checkout of main + this PR, `python -I scripts/red_green.py pr-2798 --base origin/main --no-fetch --no-cargo --mutate --work-dir <dir>`. Result: - `red then green (1)`: `test_old_follower_leaves_the_new_job_state_intact`. That matches my manual red/green on #2798. - `pass on both: 11`. - `mutations (8 hunks undone one at a time): 4 caught, 4 not caught`. Caught: `launcher/serve.py:322, :324, :367, :371`. Not caught: `:346, :350, :355, :374`. - Verdict `red then green`. That's useful information about #2798 itself: its spawn-ordering hunks and the in-lock exit-state hunk aren't pinned by a test. It is exactly what I was doing by hand on test PRs tonight, and it works. **Small note:** `--work-dir` leaves a registered git worktree (`<dir>/tree`) behind between runs. That is by design ("keeps both between runs"), but someone who only runs it once will see it in `git worktree list`. A line in `docs/testing.md` on removing it with `git worktree remove` would help. AI-assisted: Claude Code
KelboLive commented 2026-12-01 04:27:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T04:27:04Z.

Review: COMMENTED


Reproduced on Windows / Python 3.12, and the mechanism is sound — this is not "any nonzero exit counts as caught":

python -I tests/test_red_green.py                                    19 tests, OK, 26 s
python -I scripts/red_green.py 2810 --no-cargo --mutate --work-dir …  red then green (2), 21 pass both arms,
                                                                      6 hunks: 5 caught, 1 not caught (game_gate.py:72), 21 s
git status --porcelain --ignored afterwards                          empty (no __pycache__, no stray files)

Your numbers and the clean-tree claim reproduce exactly. I also checked the three outcomes by hand in throwaway repos with a stub cargo: undoing a hunk so the module raises at import reports does not build, an untested new function reports not caught, a tested change reports caught.

Two things need fixing:

  1. Added files are silently never mutated. scripts/red_green.py:541 uses --diff-filter=M, so a fix whose logic lives in a new module never has its hunks mutated, while the summary still reads as full coverage. Reproduced: a fix that adds tools/helper.py (holding the change) and edits an existing module to call it reports "2 hunks … 2 caught" and never touches helper.py. Either include A (and define what undoing an addition means) or state the limitation in docs/testing.md and in the report itself.
  2. The -B comment at scripts/red_green.py:329 is wrong. -B stops writing bytecode, not reading it. With a stale __pycache__/*.pyc from an earlier run (checkout() uses git clean -fdq at :249, which does not touch ignored paths, and __pycache__/ is ignored), a reverted module still reports ok; I got not caught that way. Use -X pycache_prefix=<fresh temp dir> per run, or remove __pycache__ (or git clean -fdxq).

Minor: when a hunk cannot be restored, mutate returns None and report() drops the whole mutations section, so --mutate silently shows nothing (and in --json it is indistinguishable from "not requested"). There is also no per-run timeout, so --mutate multiplies any hang by up to --mutate-max.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6125096063 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#pullrequestreview-6125096063). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T04:27:04Z. **Review:** COMMENTED --- Reproduced on Windows / Python 3.12, and the mechanism is sound — this is not "any nonzero exit counts as caught": ``` python -I tests/test_red_green.py 19 tests, OK, 26 s python -I scripts/red_green.py 2810 --no-cargo --mutate --work-dir … red then green (2), 21 pass both arms, 6 hunks: 5 caught, 1 not caught (game_gate.py:72), 21 s git status --porcelain --ignored afterwards empty (no __pycache__, no stray files) ``` Your numbers and the clean-tree claim reproduce exactly. I also checked the three outcomes by hand in throwaway repos with a stub cargo: undoing a hunk so the module raises at import reports `does not build`, an untested new function reports `not caught`, a tested change reports `caught`. Two things need fixing: 1. **Added files are silently never mutated.** `scripts/red_green.py:541` uses `--diff-filter=M`, so a fix whose logic lives in a *new* module never has its hunks mutated, while the summary still reads as full coverage. Reproduced: a fix that adds `tools/helper.py` (holding the change) and edits an existing module to call it reports "2 hunks … 2 caught" and never touches `helper.py`. Either include `A` (and define what undoing an addition means) or state the limitation in `docs/testing.md` and in the report itself. 2. **The `-B` comment at `scripts/red_green.py:329` is wrong.** `-B` stops *writing* bytecode, not reading it. With a stale `__pycache__/*.pyc` from an earlier run (`checkout()` uses `git clean -fdq` at :249, which does not touch ignored paths, and `__pycache__/` is ignored), a reverted module still reports `ok`; I got `not caught` that way. Use `-X pycache_prefix=<fresh temp dir>` per run, or remove `__pycache__` (or `git clean -fdxq`). Minor: when a hunk cannot be restored, `mutate` returns `None` and `report()` drops the whole mutations section, so `--mutate` silently shows nothing (and in `--json` it is indistinguishable from "not requested"). There is also no per-run timeout, so `--mutate` multiplies any hang by up to `--mutate-max`.
TheGeogeo commented 2026-12-01 05:36:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-12-01T05:36:34Z.


Thanks @KelboLive. Confirmed: when a hunk cannot be restored, mutate returns None (scripts/red_green.py:595) and report() then prints no mutations section, and --json cannot tell it from a run without --mutate. There is also no per-run timeout.

To keep this verified head unchanged, I will fix both in a follow-up pull request after the merge: the report will say the mutations stopped and why, and each mutated run will have a timeout that counts as caught when it expires. Each change will come with a test.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7301948688 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7301948688). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-12-01T05:36:34Z. --- Thanks @KelboLive. Confirmed: when a hunk cannot be restored, `mutate` returns `None` (`scripts/red_green.py:595`) and `report()` then prints no mutations section, and `--json` cannot tell it from a run without `--mutate`. There is also no per-run timeout. To keep this verified head unchanged, I will fix both in a follow-up pull request after the merge: the report will say the mutations stopped and why, and each mutated run will have a timeout that counts as caught when it expires. Each change will come with a test.
imShangLi commented 2026-12-01 10:01:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T10:01:31Z.


VERIFY-2817 — Linux, Python 3.15, no GPU device, no game files

Verdict: PASS — the change does what it says, and the part that is new (the mutation check) reports a known answer correctly.

Head 5193b250, base d920d850 (the merge-base with the current main), 3 files, +246/−9. The branch holds #2814's commit (f442c3df, "tells a crashed compiler from a build error") and says it will be rebased onto main once #2814 lands; both are in this head, and both were measured.

1. Its own suite, and the three rows

row tree tests/test_red_green.py
A main 0259473b + this PR 19 tests, OK
B clean main + only this PR's test change (patched) 19 tests, FAILED (failures=2, errors=4)

Row B's failures are assertions, not load errors — the test file runs on main and the new tests fail because the behaviour is missing:

FAIL: test_a_compiler_that_crashes_twice_is_not_a_build_error
  self.assertEqual((code, r["verdict"]), (1, "compiler crashed"), r)
  AssertionError: Tuples differ: (1, 'green fails') != (1, 'compiler crashed')

The other failure and the four errors are the same cause: main's scripts/red_green.py has no COMPILER_CRASH, so a compiler that dies with 0xC0000005 is reported as green fails instead of compiler crashed.

2. Discrimination: does the new test look at the changed code?

A test that passes with the fix and without it proves nothing, so I undid the pull request's production change alone on the green tree and ran the new tests:

tree result
PR head, scripts/red_green.py reverted to main's AssertionError (the new tests go red)

3. --mutate on a repository whose answer is known in advance

This is the part that is new, so running its own tests is not enough. I built a repository with a Python tool and its test, in the shape a real pull request has (a test-only commit, then a fix commit), and checked the answer I put in by hand:

sample expected reported
one code hunk (return 1 → return 2), the test asserts the new value caught tools/bar.py line 2 caught
two hunks: the fix, plus a change to a second function no test looks at caught + not caught tools/bar.py line 2 caught, line 16 not caught
the verdict unchanged by a not caught hunk red then green, exit 0

The not caught row is the point of the option: it names code that no new test looks at, which is exactly what a verifier does by hand. It does not change the verdict, so a pull request with an untested hunk is still red then green.

One note on reading the output, in case it catches someone else: --mutate counts hunks, and git diff -U0 merges two edits that are close together into one hunk. My first sample put the two edits two lines apart and got one hunk, which is git's behaviour and not the tool's; with the edits far enough apart it reports two. The tool's own test puts ten padding lines between the two changes for the same reason.

4. What I did not check

  • The #[cfg(test)] exclusion and the "a hunk that only adds test code" rule are read in the code, not measured against a real pull request with a Rust #[cfg(test)] hunk next to the fix.
  • The Windows crash statuses (0xC0000005 and the rest) are matched by the tool's own tests with the text cargo prints; I did not see a real Windows rustc crash.
  • The cargo path (cargo_once, cargo_tests) is exercised only through the stub cargo the tests use; I did not run a real cargo test on a D3D12 crate.

5. Neighbours

tests/test_red_green.py is the only test file this touches. On the PR head the file's 19 tests pass, and the rest of the standalone Python suite is unaffected by this change (it adds a flag to a script; it does not change what the script does without the flag).

AI-assisted: MiniMax M3.1 Flash.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7307554509 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7307554509). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-01T10:01:31Z. --- ## VERIFY-2817 — Linux, Python 3.15, no GPU device, no game files **Verdict: PASS** — the change does what it says, and the part that is new (the mutation check) reports a known answer correctly. Head `5193b250`, base `d920d850` (the merge-base with the current `main`), 3 files, +246/−9. The branch holds #2814's commit (`f442c3df`, "tells a crashed compiler from a build error") and says it will be rebased onto `main` once #2814 lands; both are in this head, and both were measured. ### 1. Its own suite, and the three rows | row | tree | `tests/test_red_green.py` | |---|---|---| | A | `main` `0259473b` + this PR | **19 tests, OK** | | B | clean `main` + **only this PR's test change** (patched) | **19 tests, FAILED (failures=2, errors=4)** | Row B's failures are assertions, not load errors — the test file runs on `main` and the new tests fail because the behaviour is missing: ``` FAIL: test_a_compiler_that_crashes_twice_is_not_a_build_error self.assertEqual((code, r["verdict"]), (1, "compiler crashed"), r) AssertionError: Tuples differ: (1, 'green fails') != (1, 'compiler crashed') ``` The other failure and the four errors are the same cause: `main`'s `scripts/red_green.py` has no `COMPILER_CRASH`, so a compiler that dies with `0xC0000005` is reported as `green fails` instead of `compiler crashed`. ### 2. Discrimination: does the new test look at the changed code? A test that passes with the fix and without it proves nothing, so I undid the pull request's production change alone on the green tree and ran the new tests: | tree | result | |---|---| | PR head, `scripts/red_green.py` reverted to `main`'s | **AssertionError** (the new tests go red) | ### 3. `--mutate` on a repository whose answer is known in advance This is the part that is new, so running its own tests is not enough. I built a repository with a Python tool and its test, in the shape a real pull request has (a test-only commit, then a fix commit), and checked the answer I put in by hand: | sample | expected | reported | |---|---|---| | one code hunk (`return 1` → `return 2`), the test asserts the new value | `caught` | **`tools/bar.py` line 2 `caught`** | | two hunks: the fix, plus a change to a second function **no test looks at** | `caught` + `not caught` | **`tools/bar.py` line 2 `caught`, line 16 `not caught`** | | the verdict | unchanged by a `not caught` hunk | **`red then green`, exit 0** | The `not caught` row is the point of the option: it names code that no new test looks at, which is exactly what a verifier does by hand. It does not change the verdict, so a pull request with an untested hunk is still `red then green`. One note on reading the output, in case it catches someone else: `--mutate` counts **hunks**, and `git diff -U0` merges two edits that are close together into one hunk. My first sample put the two edits two lines apart and got one hunk, which is git's behaviour and not the tool's; with the edits far enough apart it reports two. The tool's own test puts ten padding lines between the two changes for the same reason. ### 4. What I did not check - The `#[cfg(test)]` exclusion and the "a hunk that only adds test code" rule are read in the code, not measured against a real pull request with a Rust `#[cfg(test)]` hunk next to the fix. - The Windows crash statuses (`0xC0000005` and the rest) are matched by the tool's own tests with the text cargo prints; I did not see a real Windows rustc crash. - The cargo path (`cargo_once`, `cargo_tests`) is exercised only through the stub cargo the tests use; I did not run a real `cargo test` on a D3D12 crate. ### 5. Neighbours `tests/test_red_green.py` is the only test file this touches. On the PR head the file's 19 tests pass, and the rest of the standalone Python suite is unaffected by this change (it adds a flag to a script; it does not change what the script does without the flag). AI-assisted: MiniMax M3.1 Flash.
imShangLi commented 2026-12-01 10:11:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T10:11:13Z.


6. The whole standalone suite, against the same runner on a clean tree

To check that the change costs nothing elsewhere, I ran the repository's standalone test runner over the pull request's head and over a clean main tree and compared the lists:

tree run passed failed skipped
this PR head 5193b250 638 636 2 33
clean main 86c30fce 638 636 2 33
$ diff <(sort passed-main) <(sort passed-with-2817)
(no difference)
$ diff <(sort skipped-main) <(sort skipped-with-2817)
(no difference)

The two failures are the same two files on both trees, and neither is this change's:

  • tests/test_make_game_argparse.py — the failure this pull request's neighbour #2818 fixes; it is red on main too.
  • tests/test_run_semantic_tests.py — two tests of the runner's SIGINT handling (communicate(timeout=5) times out on this machine, and one expects exit code 130 and gets 0). Red on the clean tree as well.

So the pull request adds its 19 tests and changes nothing else in the suite.

AI-assisted: MiniMax M3.1 Flash.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7307802331 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7307802331). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-01T10:11:13Z. --- ### 6. The whole standalone suite, against the same runner on a clean tree To check that the change costs nothing elsewhere, I ran the repository's standalone test runner over the pull request's head and over a clean `main` tree and compared the lists: | tree | run | passed | failed | skipped | |---|---|---|---|---| | this PR head `5193b250` | 638 | 636 | 2 | 33 | | clean `main` `86c30fce` | 638 | 636 | 2 | 33 | ``` $ diff <(sort passed-main) <(sort passed-with-2817) (no difference) $ diff <(sort skipped-main) <(sort skipped-with-2817) (no difference) ``` The two failures are the same two files on both trees, and neither is this change's: - `tests/test_make_game_argparse.py` — the failure this pull request's neighbour #2818 fixes; it is red on `main` too. - `tests/test_run_semantic_tests.py` — two tests of the runner's SIGINT handling (`communicate(timeout=5)` times out on this machine, and one expects exit code 130 and gets 0). Red on the clean tree as well. So the pull request adds its 19 tests and changes nothing else in the suite. AI-assisted: MiniMax M3.1 Flash.
imShangLi commented 2026-12-01 10:11:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T10:11:46Z.


7. Two cases I did not reach, so the report does not read as covering them

@TheGeogeo noted two things about this head, and I did not exercise either, so they are untested by me:

  • when a hunk cannot be restored, mutate returns None and report() prints no mutations section, and --json cannot tell that run from one without --mutate;
  • there is no per-run timeout, so a mutated run that hangs is not bounded.

My samples always restored their hunks, so I saw neither. The author says both are fixed in a follow-up pull request after the merge.

AI-assisted: MiniMax M3.1 Flash.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7307816365 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7307816365). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-01T10:11:46Z. --- ### 7. Two cases I did not reach, so the report does not read as covering them @TheGeogeo noted two things about this head, and I did not exercise either, so they are untested by me: - when a hunk cannot be restored, `mutate` returns `None` and `report()` prints no mutations section, and `--json` cannot tell that run from one without `--mutate`; - there is no per-run timeout, so a mutated run that hangs is not bounded. My samples always restored their hunks, so I saw neither. The author says both are fixed in a follow-up pull request after the merge. AI-assisted: MiniMax M3.1 Flash.
imShangLi commented 2026-12-01 13:33:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T13:33:14Z.


A note on this machine's graphics, so "no GPU device" is not misread

I said above that this host has no GPU device. That is true of the Vulkan device, and I should be precise about which path I mean, because the two paths differ here and a reader could otherwise take my wording the wrong way.

What this machine is. A VMware Workstation guest (Fedora 45) on a host with a Radeon 780M. There is no PCI passthrough: the only display device inside the guest is the virtual VMware SVGA II (15ad:0405) driven by vmwgfx, and there is no AMD PCI ID anywhere in the guest.

There is no Vulkan hardware device here. mesa's svga driver has no Vulkan backend, so the loader enumerates nothing by default; with VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json it enumerates exactly one device, llvmpipe (LLVM 23.1.5, 256 bits) — a CPU software implementation. So no real GPU, no CUDA, no ROCm.

The OpenGL path is hardware-accelerated, though. The guest's SVGA3D calls are forwarded by the host-side VMware renderer to the host's Radeon 780M. The evidence I measured, comparing the default path with LIBGL_ALWAYS_SOFTWARE=1:

default:   OpenGL vendor string: VMware, Inc.   renderer: SVGA3D; build: RELEASE; LLVM;
software:  OpenGL vendor string: Mesa           renderer: llvmpipe (LLVM 23.1.5, 256 bits)

GL_VENDOR = "VMware, Inc." appears only when the commands leave the guest for the host's renderer; llvmpipe runs entirely on the guest's CPU. glxinfo -B also reports Video memory: 2048MB, direct rendering: Yes, OpenGL core profile 4.3 (Mesa 26.2.7), and vmwgfx's kernel capabilities include 3D; GNOME logs Created gbm renderer for '/dev/dri/card0' and the session is Wayland.

What follows for the verification above. Anything that needs a real GPU device or driver is invalid on this host, and none of my conclusions rest on one: the tests I ran are CPU-only, and the tool they measure is a Python script. Where a measured number came from this machine's GPU stack, it says so.

Two things I checked that a reader might otherwise assume. glxinfo's Accelerated: no is not evidence that 3D acceleration is off — that field comes from mesa's GLX_MESA_query_renderer, which cannot see an acceleration that happens on the host side. And OpenGL throughput on this host does not stand for real hardware: in my own measurements the software path was faster than SVGA3D for small, tightly-synchronised batches (713 vs 1061 draws/s in an off-screen rasterisation loop; 88 vs 308-692 FPS in glxgears), because SVGA3D pays a synchronisation round trip across the virtualisation boundary while llvmpipe rasterises locally. That says nothing about which path a real application would take — the vendor string settles that — and it is a reminder that a frame-rate number from here is not a hardware result.

AI-assisted: MiniMax M3.1 Flash.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7312806265 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7312806265). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-01T13:33:14Z. --- ### A note on this machine's graphics, so "no GPU device" is not misread I said above that this host has no GPU device. That is true of the **Vulkan** device, and I should be precise about which path I mean, because the two paths differ here and a reader could otherwise take my wording the wrong way. **What this machine is.** A VMware Workstation guest (Fedora 45) on a host with a Radeon 780M. There is **no PCI passthrough**: the only display device inside the guest is the virtual `VMware SVGA II (15ad:0405)` driven by `vmwgfx`, and there is no AMD PCI ID anywhere in the guest. **There is no Vulkan hardware device here.** mesa's svga driver has no Vulkan backend, so the loader enumerates nothing by default; with `VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json` it enumerates exactly one device, `llvmpipe (LLVM 23.1.5, 256 bits)` — a **CPU software implementation**. So no real GPU, no CUDA, no ROCm. **The OpenGL path is hardware-accelerated, though.** The guest's SVGA3D calls are forwarded by the host-side VMware renderer to the host's Radeon 780M. The evidence I measured, comparing the default path with `LIBGL_ALWAYS_SOFTWARE=1`: ``` default: OpenGL vendor string: VMware, Inc. renderer: SVGA3D; build: RELEASE; LLVM; software: OpenGL vendor string: Mesa renderer: llvmpipe (LLVM 23.1.5, 256 bits) ``` `GL_VENDOR = "VMware, Inc."` appears only when the commands leave the guest for the host's renderer; llvmpipe runs entirely on the guest's CPU. `glxinfo -B` also reports `Video memory: 2048MB`, `direct rendering: Yes`, OpenGL core profile 4.3 (Mesa 26.2.7), and `vmwgfx`'s kernel capabilities include `3D`; GNOME logs `Created gbm renderer for '/dev/dri/card0'` and the session is Wayland. **What follows for the verification above.** Anything that needs a real GPU **device** or **driver** is invalid on this host, and none of my conclusions rest on one: the tests I ran are CPU-only, and the tool they measure is a Python script. Where a measured number came from this machine's GPU stack, it says so. Two things I checked that a reader might otherwise assume. `glxinfo`'s **`Accelerated: no`** is not evidence that 3D acceleration is off — that field comes from mesa's `GLX_MESA_query_renderer`, which cannot see an acceleration that happens on the host side. And **OpenGL throughput on this host does not stand for real hardware**: in my own measurements the software path was *faster* than SVGA3D for small, tightly-synchronised batches (713 vs 1061 draws/s in an off-screen rasterisation loop; 88 vs 308-692 FPS in `glxgears`), because SVGA3D pays a synchronisation round trip across the virtualisation boundary while llvmpipe rasterises locally. That says nothing about which path a real application would take — the vendor string settles that — and it is a reminder that a frame-rate number from here is not a hardware result. AI-assisted: MiniMax M3.1 Flash.
imShangLi commented 2026-12-01 13:46:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T13:46:26Z.


Correction to my note above: the frame-rate comparison was not controlled

My note above said that on this host the software path measured faster than SVGA3D (713 vs 1061 draws/s in an off-screen rasterisation loop; 88 vs 308-692 FPS in glxgears), and put that down to SVGA3D paying a synchronisation round trip across the virtualisation boundary. That comparison was uncontrolled and the conclusion from it was wrong. I used the default window size and the default swap interval, and the ranking flips with those.

With the window size and the swap interval fixed, glxgears on this host gives:

window swap interval SVGA3D llvmpipe the faster one
300x300 0 (vsync off) 1349 FPS 342 FPS SVGA3D, 3.9x
1024x768 0 (vsync off) 638 FPS 152 FPS SVGA3D, 4.2x
300x300 1 (vsync on) 55 FPS 546 FPS llvmpipe

The two figures I quoted before were the default window with the default swap interval, which is the one combination that happens to favour the software path. So:

  • A frame rate from this host is not a hardware result — that part of my note stands, and this table is the better illustration of why. The same two binaries swap places depending on two settings.
  • Which path is in use is settled by GL_VENDOR / GL_RENDERER (VMware, Inc. / SVGA3D versus Mesa / llvmpipe), never by the frame rate.
  • SVGA3D's cost is a synchronisation round trip per flush, so it is not necessarily ahead of a local software rasteriser on small, tightly-synchronised batches; its advantage shows on larger, GPU-bound batches, which is what the two vsync-off rows above are.

One difference worth recording so the numbers are not read as a reproduction: in the vsync-on row my llvmpipe run reached 546 FPS where the other run on this host reached 89 FPS for the same setting. This is a Wayland session and the swap interval is not honoured identically on the two paths, so the vsync-on row is not a like-for-like comparison between them; the two vsync-off rows are.

AI-assisted: MiniMax M3.1 Flash.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7313154008 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7313154008). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-01T13:46:26Z. --- ### Correction to my note above: the frame-rate comparison was not controlled My note above said that on this host the software path measured *faster* than SVGA3D (713 vs 1061 draws/s in an off-screen rasterisation loop; 88 vs 308-692 FPS in `glxgears`), and put that down to SVGA3D paying a synchronisation round trip across the virtualisation boundary. **That comparison was uncontrolled and the conclusion from it was wrong.** I used the default window size and the default swap interval, and the ranking flips with those. With the window size and the swap interval fixed, `glxgears` on this host gives: | window | swap interval | SVGA3D | llvmpipe | the faster one | |---|---|---|---|---| | 300x300 | 0 (vsync off) | **1349 FPS** | 342 FPS | SVGA3D, 3.9x | | 1024x768 | 0 (vsync off) | **638 FPS** | 152 FPS | SVGA3D, 4.2x | | 300x300 | 1 (vsync on) | 55 FPS | **546 FPS** | llvmpipe | The two figures I quoted before were the default window with the default swap interval, which is the one combination that happens to favour the software path. So: - **A frame rate from this host is not a hardware result** — that part of my note stands, and this table is the better illustration of why. The same two binaries swap places depending on two settings. - **Which path is in use is settled by `GL_VENDOR` / `GL_RENDERER`** (`VMware, Inc.` / `SVGA3D` versus `Mesa` / `llvmpipe`), never by the frame rate. - SVGA3D's cost is a synchronisation round trip per flush, so it is not necessarily ahead of a local software rasteriser on small, tightly-synchronised batches; its advantage shows on larger, GPU-bound batches, which is what the two vsync-off rows above are. One difference worth recording so the numbers are not read as a reproduction: in the vsync-on row my llvmpipe run reached 546 FPS where the other run on this host reached 89 FPS for the same setting. This is a Wayland session and the swap interval is not honoured identically on the two paths, so the vsync-on row is not a like-for-like comparison between them; the two vsync-off rows are. AI-assisted: MiniMax M3.1 Flash.
TheGeogeo commented 2026-12-02 04:27:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-12-02T04:27:07Z.


Rebased on main 8422def75 (#2814 is in main, so its commit dropped out). The points of @KelboLive, @fiestorra and @OreoFR are fixed here rather than in a follow-up, since the merge had not happened (head bf65aa450):

  • Added files are still not mutated, and now say so: added_not_mutated in the report and --json, and in docs/testing.md.
  • Stale bytecode: the -B comment was wrong. Before each Python run, the work tree's own __pycache__ folders are removed, never through a link or junction. -X pycache_prefix alone was tried and does not reach the processes a test starts.
  • A hunk that could not be put back: each mutation now starts from a commit of the green merge, reset and cleaned, so there is nothing to put back. A test that writes into the tree cannot change the next hunk's result either.
  • Timeout: --mutate-timeout (600 s) applies to each command of a mutated run. The run is in a Windows job object, so whatever it leaves behind is stopped too. The results read caught by timeout, or timed out building when cargo had not started a test.
  • A test-only pull request reads "nothing to undo: the diff changes no Rust or Python code outside its tests" (mutations_not_run), with the verdict unchanged.
  • Also covered: hunks past --mutate-max are listed (mutations_skipped); one rule tells test-only hunks for the red side and the mutations; the options are range-checked; docs/testing.md lists every result and how to remove the worktree.

--mutate-target stays out of this pull request, as @fiestorra suggested it: a new option belongs in its own pull request.

tests/test_red_green.py: 37 OK on Windows 11. Each change has a test that fails without it.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5; a separate Claude Opus 5.5 agent reviewed the diff before this push).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7334922687 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7334922687). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-12-02T04:27:07Z. --- Rebased on `main` 8422def75 (#2814 is in `main`, so its commit dropped out). The points of @KelboLive, @fiestorra and @OreoFR are fixed here rather than in a follow-up, since the merge had not happened (head bf65aa450): - **Added files** are still not mutated, and now say so: `added_not_mutated` in the report and `--json`, and in `docs/testing.md`. - **Stale bytecode:** the `-B` comment was wrong. Before each Python run, the work tree's own `__pycache__` folders are removed, never through a link or junction. `-X pycache_prefix` alone was tried and does not reach the processes a test starts. - **A hunk that could not be put back:** each mutation now starts from a commit of the green merge, reset and cleaned, so there is nothing to put back. A test that writes into the tree cannot change the next hunk's result either. - **Timeout:** `--mutate-timeout` (600 s) applies to each command of a mutated run. The run is in a Windows job object, so whatever it leaves behind is stopped too. The results read `caught by timeout`, or `timed out building` when cargo had not started a test. - **A test-only pull request** reads "nothing to undo: the diff changes no Rust or Python code outside its tests" (`mutations_not_run`), with the verdict unchanged. - **Also covered:** hunks past `--mutate-max` are listed (`mutations_skipped`); one rule tells test-only hunks for the red side and the mutations; the options are range-checked; `docs/testing.md` lists every result and how to remove the worktree. `--mutate-target` stays out of this pull request, as @fiestorra suggested it: a new option belongs in its own pull request. `tests/test_red_green.py`: 37 OK on Windows 11. Each change has a test that fails without it. AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5; a separate Claude Opus 5.5 agent reviewed the diff before this push).
enlight3d commented 2026-12-02 10:13:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T10:13:09Z.


RUN (independent run on Windows, #2817 head bf65aa450, merged locally into main a917c54d6 with git merge --no-ff, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)

No game involved. No cargo was run here: the cargo paths are covered only by the tests' stand-in cargo.

Commands, unittest files run with python -I as the CI's standalone loop runs them:

  • python -I tests/test_red_green.py -v: main 16 OK; merge 37 OK in 138 s.
  • Red, main's scripts/red_green.py with this pull request's test file: 37 run, 1 failure and 19 errors. 20 of the 21 new tests fail for the missing feature (--mutate unknown, no drop_bytecode, no job object, no mutations key; test_bytecode_it_cannot_remove_stops_the_run_with_the_tree_put_back gets exit 1 and a result instead of exit 2). The 21st, test_mutate_options_are_checked, passes on main too: main refuses the unknown options with exit 2 as well, so it is green on both sides and does not show the range checks on its own. No harm.
  • Related suite through scripts/run_standalone_tests.py -j 4 (the 13 tests/test_docs_*.py, test_i18n_index.py, test_design_contract_rows.py, test_ci_registration.py, test_tool_stdout_encoding.py, test_game_gate.py, test_d3d12_ab_compare.py, test_red_green.py): main 20 files, 0 failed; merge 20 files, 0 failed.

Mutations of the merge, each run with tests/test_red_green.py (37 tests), the file restored after each:

  • a hunk whose mutated run timed out reported not caught instead of caught by timeout: killed (3 tests, among them test_a_mutated_run_that_hangs_is_caught_by_timeout).
  • drop_bytecode() no longer called before the Python runs: killed (test_stale_bytecode_in_the_work_tree_is_never_run, test_bytecode_it_cannot_remove_stops_the_run_with_the_tree_put_back).
  • --mutate-max ignored: killed (test_hunks_past_mutate_max_are_listed_as_not_tried).
  • Rust hunks of test code only mutated like code (test_hunk_flags bypassed in code_hunks): killed (4 tests, among them test_a_hunk_that_only_deletes_a_test_is_not_mutated).
  • junctions followed (the reparse-point check off): killed (test_a_link_named_pycache_is_left_alone, test_a_link_out_of_the_tree_is_not_followed).
  • no git clean -fdq between hunks: survives (37 OK). test_a_test_that_dirties_the_tree_does_not_change_the_next_hunk writes into a tracked file, which git reset --hard already restores; an untracked file left by a test is not pinned. Minor.

Real use, this head's red_green.py on two other pull requests (--no-fetch --no-cargo --mutate):

  • #2812 on main: red then green, 4 tests; 26 pass on both; 8 hunks, 8 caught; 111 s.
  • #2813 with main + #2812 as --base: red then green, 6 tests; 29 pass on both; 10 hunks, 9 caught, 1 not caught (two SOURCES keys that only the contract test reads, detailed on #2813).
  • Its worktree stayed registered under the work folder, as docs/testing.md says, and was removed afterwards with git worktree remove --force.

Not covered here: a real cargo crate (no cargo here), the POSIX paths (killpg, the chmod cases), Linux and macOS.

Verdict: PASS.

Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40, Python 3.13.12 (the CI uses 3.12), PowerShell 7.6.10.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7342141705 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7342141705). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-12-02T10:13:09Z. --- RUN (independent run on Windows, #2817 head bf65aa450, merged locally into `main` a917c54d6 with `git merge --no-ff`, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) No game involved. No cargo was run here: the cargo paths are covered only by the tests' stand-in cargo. Commands, unittest files run with `python -I` as the CI's standalone loop runs them: - `python -I tests/test_red_green.py -v`: main 16 OK; merge 37 OK in 138 s. - Red, `main`'s `scripts/red_green.py` with this pull request's test file: 37 run, 1 failure and 19 errors. 20 of the 21 new tests fail for the missing feature (`--mutate` unknown, no `drop_bytecode`, no job object, no `mutations` key; `test_bytecode_it_cannot_remove_stops_the_run_with_the_tree_put_back` gets exit 1 and a result instead of exit 2). The 21st, `test_mutate_options_are_checked`, passes on `main` too: `main` refuses the unknown options with exit 2 as well, so it is green on both sides and does not show the range checks on its own. No harm. - Related suite through `scripts/run_standalone_tests.py -j 4` (the 13 `tests/test_docs_*.py`, `test_i18n_index.py`, `test_design_contract_rows.py`, `test_ci_registration.py`, `test_tool_stdout_encoding.py`, `test_game_gate.py`, `test_d3d12_ab_compare.py`, `test_red_green.py`): main 20 files, 0 failed; merge 20 files, 0 failed. Mutations of the merge, each run with `tests/test_red_green.py` (37 tests), the file restored after each: - a hunk whose mutated run timed out reported `not caught` instead of `caught by timeout`: killed (3 tests, among them `test_a_mutated_run_that_hangs_is_caught_by_timeout`). - `drop_bytecode()` no longer called before the Python runs: killed (`test_stale_bytecode_in_the_work_tree_is_never_run`, `test_bytecode_it_cannot_remove_stops_the_run_with_the_tree_put_back`). - `--mutate-max` ignored: killed (`test_hunks_past_mutate_max_are_listed_as_not_tried`). - Rust hunks of test code only mutated like code (`test_hunk_flags` bypassed in `code_hunks`): killed (4 tests, among them `test_a_hunk_that_only_deletes_a_test_is_not_mutated`). - junctions followed (the reparse-point check off): killed (`test_a_link_named_pycache_is_left_alone`, `test_a_link_out_of_the_tree_is_not_followed`). - no `git clean -fdq` between hunks: survives (37 OK). `test_a_test_that_dirties_the_tree_does_not_change_the_next_hunk` writes into a tracked file, which `git reset --hard` already restores; an untracked file left by a test is not pinned. Minor. Real use, this head's `red_green.py` on two other pull requests (`--no-fetch --no-cargo --mutate`): - #2812 on `main`: red then green, 4 tests; 26 pass on both; 8 hunks, 8 caught; 111 s. - #2813 with main + #2812 as `--base`: red then green, 6 tests; 29 pass on both; 10 hunks, 9 caught, 1 not caught (two `SOURCES` keys that only the contract test reads, detailed on #2813). - Its worktree stayed registered under the work folder, as `docs/testing.md` says, and was removed afterwards with `git worktree remove --force`. Not covered here: a real cargo crate (no cargo here), the POSIX paths (`killpg`, the `chmod` cases), Linux and macOS. Verdict: PASS. Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40, Python 3.13.12 (the CI uses 3.12), PowerShell 7.6.10.
MoonEyes commented 2026-12-02 10:25:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:25:36Z.


Merging. Head bf65aa450 merges cleanly with main 80910637f and does not force a rebase of #2566. Independent check on head bf65aa450: enlight3d's red/green on main + PR (1 failure and 19 errors on main, 37 green, 5 mutations killed, comment 7342141705); CI 5/5 green incl. no-game-data; no open review or question; item TEST-RED-GREEN-MUTATION claimed in #2570. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7342451437 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7342451437). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T10:25:36Z. --- Merging. Head `bf65aa450` merges cleanly with `main` `80910637f` and does not force a rebase of #2566. Independent check on head bf65aa450: enlight3d's red/green on main + PR (1 failure and 19 errors on main, 37 green, 5 mutations killed, comment 7342141705); CI 5/5 green incl. no-game-data; no open review or question; item TEST-RED-GREEN-MUTATION claimed in #2570. Merged by MoonEyes. AI-assisted (Claude Code).
imShangLi commented 2026-12-02 10:50:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T10:50:10Z.


VERIFY-2817 — Linux, Fedora 45, Python 3.15.2 (isolated, python3 -I), no GPU, no game files

Verdict: PASS. The change does what it says: --mutate undoes each hunk of the pull request's code (not its tests) alone on the green tree and re-runs the tests, reporting caught when a test that went red then green now fails, not caught when they all still pass, does not build when the undone code no longer builds so the test cannot run, caught by timeout / timed out building when a command hangs, and compiler crashed / does not apply for the two exceptional cases. It does not change the verdict or the exit code (verdict() takes no mutations argument, confirmed empirically on a green fails PR and on a red then green PR). The strongest evidence is the tool run on its own pull request: 31 code hunks in scripts/red_green.py, 7 of the first 8 caught, 1 not caught (the docstring usage line — a documentation line no test looks at, correctly reported as not caught), and the verdict red then green. Nothing regressed in its own suite: 36 pass, 1 skipped (the Windows-only job-object test) on this host; the 21 new tests fail without the source change (reverting only scripts/red_green.py to the merge base gives 17 errors + 2 failures + 1 "ok" that passes for the wrong reason, below). Clean-room check, docs tests, compileall and the line-ending test are clean.

head bf65aa4505aeccd8feb9bfca2c93a33d103747c8 ("scripts: red_green.py skips a folder it cannot list, ... (review)"), base (GitHub) 8422def759cda12c89f918438eeb8d53dd5972a6, merge base with the current origin/main 8422def7 (31 commits behind main). Three files, +714/−44: scripts/red_green.py (+307/−40), tests/test_red_green.py (+382), docs/testing.md (+25/−4).

1. What it changes

scripts/red_green.py gains three options — --mutate, --mutate-max (default 10), --mutate-timeout (default 600 s) — and the machinery behind them:

  • code_files() (line 714) and code_hunks() (line 722): the hunks a mutation undoes, taken with -U0, from the Rust and Python files the pull request modifies (status M) outside the tests and #[cfg(test)] code. Files the PR adds are not mutated and are listed as added_not_mutated.
  • mutate() (line 750): for each hunk, reset --hard to the green merge commit (committed once at line 683, so a test that writes into the tree cannot change the next hunk's result), clean, reverse-apply the hunk (git apply -R --unidiff-zero), and run side() again. does not apply on a failed reverse-apply.
  • The process/limit machinery: job_of/stop_all/run_output (lines 88–149) — a Windows job object, a POSIX process group, a timeout that writes to a file so a process left behind holding it cannot hold the run.
  • drop_bytecode() (line 431) — removes the work tree's own __pycache__ folders before each Python run; the -B comment at line 463 is the corrected one (the old comment was wrong; -B stops writing, not reading).
  • test_hunk_flags() (line 281) — one function now answers "is this hunk test-only" for both the red side (test_hunks) and the mutations (code_hunks), so a deleted obsolete test is not mutated.
  • The report (lines 570–582) and --json: mutations, mutations_not_run, mutations_skipped, added_not_mutated.
  • Option validation (lines 606–613): --mutate-max must be ≥ 1, --mutate-timeout a finite number > 0, and both are refused without --mutate.

tests/test_red_green.py adds 22 test methods (a Mutation class of 14, a DropBytecode class of 3, a Windows-only Job class of 1, and 2 more in Python), plus a CHILD_TEST and helpers. docs/testing.md documents the option, its results, its limits, and how to remove the worktree the tool leaves registered.

2. The claims, checked one by one

"Takes each hunk of the pull request's code: Rust and Python files it modifies, outside its tests and its #[cfg(test)] code." — Checked by reading and by running. code_files() filters is_test_file() and .py under tests/; code_hunks() skips #[cfg(test)]-only hunks via test_hunk_flags (the same rule the red side uses). On the tool's own PR it found 31 hunks, all in scripts/red_green.py, none in tests/test_red_green.py. The mutation is applied to the source, not the test: undoing a hunk of scripts/red_green.py is what changes behaviour. test_a_hunk_that_only_deletes_a_test_is_not_mutated confirms a test-only hunk is left alone.

"The green merge is committed once. Each mutation starts from it, reset and cleaned." — Confirmed: git commit-tree of the merge (line 683–685) before the green side runs, and mutate() resets to it per hunk (line 758). test_a_test_that_dirties_the_tree_does_not_change_the_next_hunk passes; a test that writes into the tree is reset away.

The result categories. Each checked:

  • caught — a red→green test fails. Confirmed on #2798 (4 caught) and on the tool's own PR (7 caught). My synthetic probes: undoing a hunk so two() returns the old value makes test_two fail → caught.
  • not caught — they all still pass. Confirmed on #2798 (4 not caught at launcher/serve.py:346,350,355,374) and on the tool's own PR (line 6, the docstring usage line — a correct "not caught").
  • does not build — the target tests no longer run. Confirmed with a synthetic Python PR where undoing a hunk leaves TWO = helper() at module level with helper undefined: the test module no longer imports, the test never runs, the hunk is reported does not build (not caught).
  • caught by timeout / timed out building — the tool's own test_a_cargo_run_that_hangs_is_stopped_and_said_where and test_a_mutated_run_that_hangs_is_caught_by_timeout pass on this host.
  • compiler crashed — the CompilerCrash tests (3) pass with the crash stub.
  • does not apply — the code path exists (undo.returncode != 0 → does not apply, line 761–764), but I could not trigger it. See the caveats.

"A mutated run writes its output to a file and runs in a Windows job object (a process group elsewhere). Whatever it leaves behind is stopped." — The POSIX half is exercised by the passing test_a_process_left_behind_does_not_hold_a_mutated_run (the orphan is stopped; the run is not held) and test_a_cargo_run_that_hangs_is_stopped_and_said_where. The Windows job-object path is read in code only (the Job test is @skipUnless(os.name == "nt")); the author reports it on Windows.

mutations_not_run, mutations_skipped, added_not_mutated. — All verified. mutations_not_run: a test-only PR reads "nothing to undo: the diff changes no Rust or Python code outside its tests"; a PR with no red→green test reads "not run: no test went red then green, so none can catch a hunk"; a PR whose green side cannot be built reads "not run: there is no green side". mutations_skipped: --mutate-max truncates and lists the rest ("not tried, past --mutate-max"). added_not_mutated: files the PR adds are listed and not undone; test_files_the_pull_request_adds_are_listed_as_not_mutated covers a fix whose logic sits in a new module.

"The verdict and the exit code do not change." — Confirmed structurally (verdict() at line 525 takes no mutations) and empirically: on a genuine green fails PR (a change that breaks an existing test), the verdict and exit code are identical with and without --mutate (green fails, exit 1 both ways); on #2798, red then green, exit 0, both ways. --mutate on a red not constructible (no test), a no red, and a green not constructible PR all leave the verdict untouched.

The __pycache__ / -B fix. — The old -B comment was indeed wrong (a review point); the new code removes the tree's own __pycache__ folders before each Python run and keeps -B to stop writing. test_stale_bytecode_in_the_work_tree_is_never_run and test_bytecode_it_cannot_remove_stops_the_run_with_the_tree_put_back pass. A __pycache__ it cannot remove stops the run (exit 2) with the tree put back on the base.

"One rule tells a hunk of test code only, for the red side and for the mutations." — Confirmed: test_hunk_flags is the single implementation and both test_hunks and code_hunks call it. Good deduplication, and it fixes the review point that a deleted test must not be mutated.

Docs. — docs/testing.md matches the code: the option, the result list, --mutate-max/--mutate-timeout, the added-files limitation, and git worktree remove --force <folder>/tree for the worktree the tool leaves registered.

3. The "wrong reason" question, answered precisely

The task asks whether a mutation that makes the test fail for the wrong reason counts as a pass. The tool's rule is: a hunk is caught iff one of the tests that went red→green fails after the hunk is undone; it is does not build iff none of those tests can run at all. That is the right discrimination, and I confirmed both halves:

  • A mutation that breaks the build/import is does not build, not caught. Undoing a hunk that leaves TWO = helper() at module level with helper undefined makes the test module fail to import; the target test never appears in the run, and the tool reports does not build. This is the honest answer: a test that cannot run proves nothing about whether it catches the change.
  • A mutation that makes the test run and fail is caught, whatever the failure is. If the undone code makes the test fail by assertion or by an exception in the code path the test exercises (a NameError at call time, say), the test is recorded failed and the hunk is caught. That is the standard mutation-killing definition — a test that fails when the change is reverted is a test that catches the change — and it is not a "wrong reason": the undo removes exactly the hunk's own lines, so a failing target test is observing exactly the change the hunk made. The only imprecision is that caught does not require the specific assertion to fail; a caught hunk might fail the test via an exception rather than a value mismatch. That is inherent to mutation testing, and the docs state the rule ("a test that went red then green now fails").
  • A failure of a non-target test does not count. mutate() consults only targets (the red→green tests). A mutation that breaks an unrelated pre-existing test is reported not caught (if the targets still pass). That is correct for the tool's question ("does the new test catch this hunk") but means not caught means "no red→green test fails", not "no test fails". Worth a reader knowing.

4. What the tests do here, and the numbers

On the PR head, python3 -I tests/test_red_green.py: 37 tests, 36 OK, 1 skipped (the Windows-only job-object test) in 43 s. To confirm the new tests are the point, I reverted only scripts/red_green.py to the merge base (in a /tmp copy of the worktree, never the worktree itself) and ran the new tests: 20 run, 17 ERROR, 2 FAIL, 1 ok — the failures are assertion errors and AttributeError: module 'red_green' has no attribute 'drop_bytecode', i.e. the new tests genuinely fail without the source change. The one "ok" is test_mutate_options_are_checked, which passes on the merge base for a non-discriminating reason (below).

Real runs (the tool from the PR head, --work-dir on disk, --no-cargo):

  • PR #2798 (launcher/serve.py + a test), without --mutate: red then green (1 red→green: test_old_follower_leaves_the_new_job_state_intact), 9 pass on both, exit 0. With --mutate: 8 hunks, 4 caught, 4 not caught at launcher/serve.py:322,324,346,350,355,367,371,374 — exactly the lines and counts @OreoFR published in the PR discussion. A strong independent reproduction.
  • PR #2817 (the tool on itself): 31 hunks in scripts/red_green.py; with --mutate-max 8, 7 caught, 1 not caught (line 6, the docstring usage line), 23 listed as not tried, past --mutate-max, 19 red→green, 17 pass on both, verdict red then green, exit 0. The one not caught is a documentation line — a correct, honest result.
  • PR #2804: green not constructible (conflicts with the base in docs/game_gate.md); --mutate correctly reports not run: there is no green side.
  • Synthetic probes (throwaway git repos with the test file's Repo/stub-cargo helpers) confirmed: the does not build discrimination; a test-only PR (nothing to undo); a PR with no test (red not constructible); a skipped test (no red, not run: no test went red then green); a green fails PR unchanged by --mutate; added files listed and not undone; --mutate-max skipping; the option-range checks.

Clean-room and hygiene on the three changed files: python3 -I scripts/check_no_game_data.py clean; python3 -I -m unittest discover -s tests -p "test_docs_*.py" -v = 57 OK; python3 -m compileall -q OK; test_text_write_line_endings.py OK.

5. Anything wrong (with file and line)

No defect that changes the verdict. Four honest observations:

  1. tests/test_red_green.py:599 test_mutate_options_are_checked does not discriminate. On the merge base it passes too, because --mutate is an unknown argument there, so argparse exits 2 and the message happens to contain --mutate-max/--mutate as substrings. The validation code itself is correct (scripts/red_green.py:606–613); it is the test that is weaker than it looks. (I measured it: on the red side this is the single "ok" among the otherwise-failing new tests.)
  2. does not apply is nearly unreachable. git apply -R --unidiff-zero is tolerant of line shifts, so when main moves the lines above a hunk the reverse apply still succeeds (my "main adds a line above" probe reported caught, not does not apply). The branch is only hit when the hunk's content is genuinely absent, which a clean merge against the current base makes rare. The PR description lists "main moved those lines since" as the trigger; that overstates how often it fires.
  3. Deleted files (status D) are neither mutated nor listed. code_files() uses --diff-filter=M for mutation and --diff-filter=A for added_not_mutated; a file the PR deletes is not covered by either, and its removal is never undone. Undoing a deletion is not meaningful (it would be an addition), so this is a reasonable limit, but the report does not say a deleted code file was left alone.
  4. caught is counted before does not build in mutate() (line 768 vs 774). They are mutually exclusive in practice (a build that fails yields no recorded test, so the caught branch cannot fire for a truly unbuilt side), and my probes confirm the discrimination, but the ordering is the kind of thing a future change could break silently. The tests do not pin the ordering directly (no test has a hunk that both fails a target test and breaks the build).

6. What I did not check

  • The Windows-only code paths. The job object (job_of, stop_all), the junction detection in drop_bytecode, the icacls deny case, and Job.test_a_job_object_that_cannot_be_joined_is_said_once — all Windows; the Job test is skipped on Linux and the others exercise the POSIX branch only. The author ran the full suite on Windows 11 (37 OK) and I read the code, but I did not observe a real Windows run.
  • A real cargo crate. The d3d12 crates are Windows-only and do not build for Linux; I used the stub cargo the tests provide. I did not run cargo test on a real crate, so the Rust --mutate path is verified through the stub and the CompilerCrash/mutation tests, not a real build.
  • does not apply and the compiler crashed / rerun_after paths against real toolchains. I read the does not apply code and could not trigger it (caveat 2). compiler crashed is exercised by the tests' crash stub, not a real rustc crash.
  • The full standalone suite. I ran test_red_green.py, test_docs_*.py, test_text_write_line_endings.py, check_no_game_data.py and compileall. The change is confined to scripts/red_green.py and its test file, and adds a flag without changing behaviour when it is off, so the rest of the suite is unaffected by inspection, but I did not run all 600+ files.
  • Issue #2570's comment the PR claims. I read the PR body and all issue comments, reviews and review comments (there are no inline review comments). I did not read the coordination issue #2570 to confirm the TEST-RED-GREEN-MUTATION claim.
  • A real GPU. Not needed; this is a CPU-only Python tool, and the host has no Vulkan device.

7. Neighbours

The change touches only scripts/red_green.py, tests/test_red_green.py and docs/testing.md. The tool's own suite passes on the head (36 OK, 1 skipped), the new tests fail without the source change, and the docs and clean-room checks are clean. The one thing a maintainer should keep in mind is caveat 1: the option-validation test does not actually pin the new validation, so a regression there would not be caught by the suite as written.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7343049624 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2817#issuecomment-7343049624). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-02T10:50:10Z. --- ## VERIFY-2817 — Linux, Fedora 45, Python 3.15.2 (isolated, `python3 -I`), no GPU, no game files **Verdict: PASS.** The change does what it says: `--mutate` undoes each hunk of the pull request's *code* (not its tests) alone on the green tree and re-runs the tests, reporting `caught` when a test that went red then green now fails, `not caught` when they all still pass, `does not build` when the undone code no longer builds so the test cannot run, `caught by timeout` / `timed out building` when a command hangs, and `compiler crashed` / `does not apply` for the two exceptional cases. It does not change the verdict or the exit code (`verdict()` takes no `mutations` argument, confirmed empirically on a `green fails` PR and on a `red then green` PR). The strongest evidence is the tool run on its own pull request: 31 code hunks in `scripts/red_green.py`, 7 of the first 8 `caught`, 1 `not caught` (the docstring usage line — a documentation line no test looks at, correctly reported as not caught), and the verdict `red then green`. Nothing regressed in its own suite: 36 pass, 1 skipped (the Windows-only job-object test) on this host; the 21 new tests fail without the source change (reverting only `scripts/red_green.py` to the merge base gives 17 errors + 2 failures + 1 "ok" that passes for the wrong reason, below). Clean-room check, docs tests, `compileall` and the line-ending test are clean. head `bf65aa4505aeccd8feb9bfca2c93a33d103747c8` ("scripts: red_green.py skips a folder it cannot list, ... (review)"), base (GitHub) `8422def759cda12c89f918438eeb8d53dd5972a6`, merge base with the current `origin/main` `8422def7` (31 commits behind `main`). Three files, +714/−44: `scripts/red_green.py` (+307/−40), `tests/test_red_green.py` (+382), `docs/testing.md` (+25/−4). ### 1. What it changes `scripts/red_green.py` gains three options — `--mutate`, `--mutate-max` (default 10), `--mutate-timeout` (default 600 s) — and the machinery behind them: - `code_files()` (line 714) and `code_hunks()` (line 722): the hunks a mutation undoes, taken with `-U0`, from the Rust and Python files the pull request *modifies* (status `M`) outside the tests and `#[cfg(test)]` code. Files the PR *adds* are not mutated and are listed as `added_not_mutated`. - `mutate()` (line 750): for each hunk, `reset --hard` to the green merge commit (committed once at line 683, so a test that writes into the tree cannot change the next hunk's result), `clean`, reverse-apply the hunk (`git apply -R --unidiff-zero`), and run `side()` again. `does not apply` on a failed reverse-apply. - The process/limit machinery: `job_of`/`stop_all`/`run_output` (lines 88–149) — a Windows job object, a POSIX process group, a timeout that writes to a file so a process left behind holding it cannot hold the run. - `drop_bytecode()` (line 431) — removes the work tree's own `__pycache__` folders before each Python run; the `-B` comment at line 463 is the corrected one (the old comment was wrong; `-B` stops writing, not reading). - `test_hunk_flags()` (line 281) — one function now answers "is this hunk test-only" for both the red side (`test_hunks`) and the mutations (`code_hunks`), so a deleted obsolete test is not mutated. - The report (lines 570–582) and `--json`: `mutations`, `mutations_not_run`, `mutations_skipped`, `added_not_mutated`. - Option validation (lines 606–613): `--mutate-max` must be ≥ 1, `--mutate-timeout` a finite number > 0, and both are refused without `--mutate`. `tests/test_red_green.py` adds 22 test methods (a `Mutation` class of 14, a `DropBytecode` class of 3, a Windows-only `Job` class of 1, and 2 more in `Python`), plus a `CHILD_TEST` and helpers. `docs/testing.md` documents the option, its results, its limits, and how to remove the worktree the tool leaves registered. ### 2. The claims, checked one by one **"Takes each hunk of the pull request's code: Rust and Python files it modifies, outside its tests and its `#[cfg(test)]` code."** — Checked by reading and by running. `code_files()` filters `is_test_file()` and `.py` under `tests/`; `code_hunks()` skips `#[cfg(test)]`-only hunks via `test_hunk_flags` (the same rule the red side uses). On the tool's own PR it found 31 hunks, all in `scripts/red_green.py`, none in `tests/test_red_green.py`. The mutation is applied to the **source**, not the test: undoing a hunk of `scripts/red_green.py` is what changes behaviour. `test_a_hunk_that_only_deletes_a_test_is_not_mutated` confirms a test-only hunk is left alone. **"The green merge is committed once. Each mutation starts from it, reset and cleaned."** — Confirmed: `git commit-tree` of the merge (line 683–685) before the green side runs, and `mutate()` resets to it per hunk (line 758). `test_a_test_that_dirties_the_tree_does_not_change_the_next_hunk` passes; a test that writes into the tree is reset away. **The result categories.** Each checked: - `caught` — a red→green test fails. Confirmed on #2798 (4 caught) and on the tool's own PR (7 caught). My synthetic probes: undoing a hunk so `two()` returns the old value makes `test_two` fail → `caught`. - `not caught` — they all still pass. Confirmed on #2798 (4 not caught at `launcher/serve.py:346,350,355,374`) and on the tool's own PR (line 6, the docstring usage line — a correct "not caught"). - `does not build` — the target tests no longer run. Confirmed with a synthetic Python PR where undoing a hunk leaves `TWO = helper()` at module level with `helper` undefined: the test module no longer imports, the test never runs, the hunk is reported `does not build` (not `caught`). - `caught by timeout` / `timed out building` — the tool's own `test_a_cargo_run_that_hangs_is_stopped_and_said_where` and `test_a_mutated_run_that_hangs_is_caught_by_timeout` pass on this host. - `compiler crashed` — the `CompilerCrash` tests (3) pass with the crash stub. - `does not apply` — the code path exists (`undo.returncode != 0` → `does not apply`, line 761–764), but I could not trigger it. See the caveats. **"A mutated run writes its output to a file and runs in a Windows job object (a process group elsewhere). Whatever it leaves behind is stopped."** — The POSIX half is exercised by the passing `test_a_process_left_behind_does_not_hold_a_mutated_run` (the orphan is stopped; the run is not held) and `test_a_cargo_run_that_hangs_is_stopped_and_said_where`. The Windows job-object path is read in code only (the `Job` test is `@skipUnless(os.name == "nt")`); the author reports it on Windows. **`mutations_not_run`, `mutations_skipped`, `added_not_mutated`.** — All verified. `mutations_not_run`: a test-only PR reads "nothing to undo: the diff changes no Rust or Python code outside its tests"; a PR with no red→green test reads "not run: no test went red then green, so none can catch a hunk"; a PR whose green side cannot be built reads "not run: there is no green side". `mutations_skipped`: `--mutate-max` truncates and lists the rest ("not tried, past --mutate-max"). `added_not_mutated`: files the PR adds are listed and not undone; `test_files_the_pull_request_adds_are_listed_as_not_mutated` covers a fix whose logic sits in a new module. **"The verdict and the exit code do not change."** — Confirmed structurally (`verdict()` at line 525 takes no `mutations`) and empirically: on a genuine `green fails` PR (a change that breaks an existing test), the verdict and exit code are identical with and without `--mutate` (`green fails`, exit 1 both ways); on #2798, `red then green`, exit 0, both ways. `--mutate` on a `red not constructible` (no test), a `no red`, and a `green not constructible` PR all leave the verdict untouched. **The `__pycache__` / `-B` fix.** — The old `-B` comment was indeed wrong (a review point); the new code removes the tree's own `__pycache__` folders before each Python run and keeps `-B` to stop writing. `test_stale_bytecode_in_the_work_tree_is_never_run` and `test_bytecode_it_cannot_remove_stops_the_run_with_the_tree_put_back` pass. A `__pycache__` it cannot remove stops the run (exit 2) with the tree put back on the base. **"One rule tells a hunk of test code only, for the red side and for the mutations."** — Confirmed: `test_hunk_flags` is the single implementation and both `test_hunks` and `code_hunks` call it. Good deduplication, and it fixes the review point that a deleted test must not be mutated. **Docs.** — `docs/testing.md` matches the code: the option, the result list, `--mutate-max`/`--mutate-timeout`, the added-files limitation, and `git worktree remove --force <folder>/tree` for the worktree the tool leaves registered. ### 3. The "wrong reason" question, answered precisely The task asks whether a mutation that makes the test fail for the wrong reason counts as a pass. The tool's rule is: **a hunk is `caught` iff one of the tests that went red→green fails after the hunk is undone; it is `does not build` iff none of those tests can run at all.** That is the right discrimination, and I confirmed both halves: - **A mutation that breaks the build/import is `does not build`, not `caught`.** Undoing a hunk that leaves `TWO = helper()` at module level with `helper` undefined makes the test module fail to import; the target test never appears in the run, and the tool reports `does not build`. This is the honest answer: a test that cannot run proves nothing about whether it catches the change. - **A mutation that makes the test run and fail is `caught`, whatever the failure is.** If the undone code makes the test fail by assertion *or* by an exception in the code path the test exercises (a NameError at call time, say), the test is recorded `failed` and the hunk is `caught`. That is the standard mutation-killing definition — a test that fails when the change is reverted is a test that catches the change — and it is not a "wrong reason": the undo removes exactly the hunk's own lines, so a failing target test is observing exactly the change the hunk made. The only imprecision is that `caught` does not require the *specific assertion* to fail; a `caught` hunk might fail the test via an exception rather than a value mismatch. That is inherent to mutation testing, and the docs state the rule ("a test that went red then green now fails"). - **A failure of a non-target test does not count.** `mutate()` consults only `targets` (the red→green tests). A mutation that breaks an unrelated pre-existing test is reported `not caught` (if the targets still pass). That is correct for the tool's question ("does the *new* test catch this hunk") but means `not caught` means "no red→green test fails", not "no test fails". Worth a reader knowing. ### 4. What the tests do here, and the numbers On the PR head, `python3 -I tests/test_red_green.py`: **37 tests, 36 OK, 1 skipped** (the Windows-only job-object test) in 43 s. To confirm the new tests are the point, I reverted only `scripts/red_green.py` to the merge base (in a `/tmp` copy of the worktree, never the worktree itself) and ran the new tests: **20 run, 17 ERROR, 2 FAIL, 1 ok** — the failures are assertion errors and `AttributeError: module 'red_green' has no attribute 'drop_bytecode'`, i.e. the new tests genuinely fail without the source change. The one "ok" is `test_mutate_options_are_checked`, which passes on the merge base for a non-discriminating reason (below). Real runs (the tool from the PR head, `--work-dir` on disk, `--no-cargo`): - **PR #2798** (`launcher/serve.py` + a test), without `--mutate`: `red then green` (1 red→green: `test_old_follower_leaves_the_new_job_state_intact`), 9 pass on both, exit 0. With `--mutate`: **8 hunks, 4 caught, 4 not caught** at `launcher/serve.py:322,324,346,350,355,367,371,374` — exactly the lines and counts @OreoFR published in the PR discussion. A strong independent reproduction. - **PR #2817** (the tool on itself): 31 hunks in `scripts/red_green.py`; with `--mutate-max 8`, **7 caught, 1 not caught** (line 6, the docstring usage line), 23 listed as `not tried, past --mutate-max`, 19 red→green, 17 pass on both, verdict `red then green`, exit 0. The one `not caught` is a documentation line — a correct, honest result. - **PR #2804**: `green not constructible` (conflicts with the base in `docs/game_gate.md`); `--mutate` correctly reports `not run: there is no green side`. - Synthetic probes (throwaway git repos with the test file's `Repo`/stub-cargo helpers) confirmed: the `does not build` discrimination; a test-only PR (`nothing to undo`); a PR with no test (`red not constructible`); a skipped test (`no red`, `not run: no test went red then green`); a `green fails` PR unchanged by `--mutate`; added files listed and not undone; `--mutate-max` skipping; the option-range checks. Clean-room and hygiene on the three changed files: `python3 -I scripts/check_no_game_data.py` clean; `python3 -I -m unittest discover -s tests -p "test_docs_*.py" -v` = 57 OK; `python3 -m compileall -q` OK; `test_text_write_line_endings.py` OK. ### 5. Anything wrong (with file and line) No defect that changes the verdict. Four honest observations: 1. **`tests/test_red_green.py:599` `test_mutate_options_are_checked` does not discriminate.** On the merge base it passes too, because `--mutate` is an unknown argument there, so argparse exits 2 and the message happens to contain `--mutate-max`/`--mutate` as substrings. The validation code itself is correct (`scripts/red_green.py:606–613`); it is the test that is weaker than it looks. (I measured it: on the red side this is the single "ok" among the otherwise-failing new tests.) 2. **`does not apply` is nearly unreachable.** `git apply -R --unidiff-zero` is tolerant of line shifts, so when `main` moves the lines above a hunk the reverse apply still succeeds (my "main adds a line above" probe reported `caught`, not `does not apply`). The branch is only hit when the hunk's content is genuinely absent, which a clean merge against the current base makes rare. The PR description lists "main moved those lines since" as the trigger; that overstates how often it fires. 3. **Deleted files (status `D`) are neither mutated nor listed.** `code_files()` uses `--diff-filter=M` for mutation and `--diff-filter=A` for `added_not_mutated`; a file the PR deletes is not covered by either, and its removal is never undone. Undoing a deletion is not meaningful (it would be an addition), so this is a reasonable limit, but the report does not say a deleted code file was left alone. 4. **`caught` is counted before `does not build` in `mutate()` (line 768 vs 774).** They are mutually exclusive in practice (a build that fails yields no recorded test, so the `caught` branch cannot fire for a truly unbuilt side), and my probes confirm the discrimination, but the ordering is the kind of thing a future change could break silently. The tests do not pin the ordering directly (no test has a hunk that both fails a target test and breaks the build). ### 6. What I did not check - **The Windows-only code paths.** The job object (`job_of`, `stop_all`), the junction detection in `drop_bytecode`, the `icacls` deny case, and `Job.test_a_job_object_that_cannot_be_joined_is_said_once` — all Windows; the `Job` test is skipped on Linux and the others exercise the POSIX branch only. The author ran the full suite on Windows 11 (37 OK) and I read the code, but I did not observe a real Windows run. - **A real cargo crate.** The d3d12 crates are Windows-only and do not build for Linux; I used the stub cargo the tests provide. I did not run `cargo test` on a real crate, so the Rust `--mutate` path is verified through the stub and the `CompilerCrash`/mutation tests, not a real build. - **`does not apply` and the `compiler crashed` / `rerun_after` paths against real toolchains.** I read the `does not apply` code and could not trigger it (caveat 2). `compiler crashed` is exercised by the tests' crash stub, not a real rustc crash. - **The full standalone suite.** I ran `test_red_green.py`, `test_docs_*.py`, `test_text_write_line_endings.py`, `check_no_game_data.py` and `compileall`. The change is confined to `scripts/red_green.py` and its test file, and adds a flag without changing behaviour when it is off, so the rest of the suite is unaffected by inspection, but I did not run all 600+ files. - **Issue #2570's comment the PR claims.** I read the PR body and all issue comments, reviews and review comments (there are no inline review comments). I did not read the coordination issue #2570 to confirm the `TEST-RED-GREEN-MUTATION` claim. - **A real GPU.** Not needed; this is a CPU-only Python tool, and the host has no Vulkan device. ### 7. Neighbours The change touches only `scripts/red_green.py`, `tests/test_red_green.py` and `docs/testing.md`. The tool's own suite passes on the head (36 OK, 1 skipped), the new tests fail without the source change, and the docs and clean-room checks are clean. The one thing a maintainer should keep in mind is caveat 1: the option-validation test does not actually pin the new validation, so a regression there would not be caught by the suite as written.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2817
No description provided.