scripts: red_green.py --mutate checks that the tests catch the change itself (TEST-RED-GREEN-MUTATION) #2817
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2817"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 --mutatedoes it for every hunk of the fix:--mutatetakes 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.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, ortimed out building(a cargo run stopped before any test ran: no answer, raise the option);does not apply:mainmoved those lines since.--jsonalways 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.--mutate-maxmust be 1 or more, and--mutate-timeouta finite number above 0. Both are refused without--mutate.__pycache__folders are removed. They are never reached through a link or junction, and a folder that cannot be listed is skipped.-Bonly stops writing bytecode, so a stale ignored.pycmade red pass and an undone hunk read as not caught.-X pycache_prefixwas 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.mddescribes 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
main8422def75:tests/test_red_green.py: 37 tests OK. They include:caught,not caught);caught);caught by timeout, within its bound);__pycache__;__pycache__held open;--mutate-max;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 intools/game_gate.py'sSOURCES, which only the contract test reads).The docs tests,
test_text_write_line_endings.py,test_ci_registration.py,compileallandscripts/check_no_game_data.pyon the changed files are clean.Not run here: the POSIX paths (
killpg, thechmodcases 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)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
maind920d850d, with the PR'sscripts/red_green.py:Then the tool, on a pull request that is not mine:
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_consumefrom_ALWAYS_BARRIER_OPSmakes 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:--helpor in the verdict:no red (nothing in this diff can be mutated)rather thanno red, so the answer is not read as "the test is worthless".--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-targetabout thirty times.AI-assisted: yes - DeepSeek v4.1 (flash), which also ran it.
Written with an AI assistant.
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, maind920d850d. CPU only. This branch contains #2814f442c3dfb, 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 newMutationtests (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.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-dirleaves 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 ingit worktree list. A line indocs/testing.mdon removing it withgit worktree removewould help.AI-assisted: Claude Code
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":
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 reportsnot caught, a tested change reportscaught.Two things need fixing:
scripts/red_green.py:541uses--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 addstools/helper.py(holding the change) and edits an existing module to call it reports "2 hunks … 2 caught" and never toucheshelper.py. Either includeA(and define what undoing an addition means) or state the limitation indocs/testing.mdand in the report itself.-Bcomment atscripts/red_green.py:329is wrong.-Bstops writing bytecode, not reading it. With a stale__pycache__/*.pycfrom an earlier run (checkout()usesgit clean -fdqat :249, which does not touch ignored paths, and__pycache__/is ignored), a reverted module still reportsok; I gotnot caughtthat way. Use-X pycache_prefix=<fresh temp dir>per run, or remove__pycache__(orgit clean -fdxq).Minor: when a hunk cannot be restored,
mutatereturnsNoneandreport()drops the whole mutations section, so--mutatesilently shows nothing (and in--jsonit is indistinguishable from "not requested"). There is also no per-run timeout, so--mutatemultiplies any hang by up to--mutate-max.Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-12-01T05:36:34Z.
Thanks @KelboLive. Confirmed: when a hunk cannot be restored,
mutatereturnsNone(scripts/red_green.py:595) andreport()then prints no mutations section, and--jsoncannot 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.
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, based920d850(the merge-base with the currentmain), 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 ontomainonce #2814 lands; both are in this head, and both were measured.1. Its own suite, and the three rows
tests/test_red_green.pymain0259473b+ this PRmain+ only this PR's test change (patched)Row B's failures are assertions, not load errors — the test file runs on
mainand the new tests fail because the behaviour is missing:The other failure and the four errors are the same cause:
main'sscripts/red_green.pyhas noCOMPILER_CRASH, so a compiler that dies with0xC0000005is reported asgreen failsinstead ofcompiler 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:
scripts/red_green.pyreverted tomain's3.
--mutateon a repository whose answer is known in advanceThis 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:
return 1→return 2), the test asserts the new valuecaughttools/bar.pyline 2caughtcaught+not caughttools/bar.pyline 2caught, line 16not caughtnot caughthunkred then green, exit 0The
not caughtrow 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 stillred then green.One note on reading the output, in case it catches someone else:
--mutatecounts hunks, andgit diff -U0merges 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
#[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.0xC0000005and the rest) are matched by the tool's own tests with the text cargo prints; I did not see a real Windows rustc crash.cargo_once,cargo_tests) is exercised only through the stub cargo the tests use; I did not run a realcargo teston a D3D12 crate.5. Neighbours
tests/test_red_green.pyis 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.
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
maintree and compared the lists:5193b250main86c30fceThe 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 onmaintoo.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.
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:
mutatereturnsNoneandreport()prints no mutations section, and--jsoncannot tell that run from one without--mutate;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.
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 byvmwgfx, 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.jsonit 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: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 -Balso reportsVideo memory: 2048MB,direct rendering: Yes, OpenGL core profile 4.3 (Mesa 26.2.7), andvmwgfx's kernel capabilities include3D; GNOME logsCreated 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'sAccelerated: nois not evidence that 3D acceleration is off — that field comes from mesa'sGLX_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 inglxgears), 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.
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,
glxgearson this host gives: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:
GL_VENDOR/GL_RENDERER(VMware, Inc./SVGA3DversusMesa/llvmpipe), never by the frame rate.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.
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-12-02T04:27:07Z.
Rebased on
main8422def75(#2814 is inmain, 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 (headbf65aa450):added_not_mutatedin the report and--json, and indocs/testing.md.-Bcomment was wrong. Before each Python run, the work tree's own__pycache__folders are removed, never through a link or junction.-X pycache_prefixalone was tried and does not reach the processes a test starts.--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 readcaught by timeout, ortimed out buildingwhen cargo had not started a test.mutations_not_run), with the verdict unchanged.--mutate-maxare listed (mutations_skipped); one rule tells test-only hunks for the red side and the mutations; the options are range-checked;docs/testing.mdlists every result and how to remove the worktree.--mutate-targetstays 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).
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T10:13:09Z.
RUN (independent run on Windows, #2817 head
bf65aa450, merged locally intomaina917c54d6withgit 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 -Ias the CI's standalone loop runs them:python -I tests/test_red_green.py -v: main 16 OK; merge 37 OK in 138 s.main'sscripts/red_green.pywith this pull request's test file: 37 run, 1 failure and 19 errors. 20 of the 21 new tests fail for the missing feature (--mutateunknown, nodrop_bytecode, no job object, nomutationskey;test_bytecode_it_cannot_remove_stops_the_run_with_the_tree_put_backgets exit 1 and a result instead of exit 2). The 21st,test_mutate_options_are_checked, passes onmaintoo:mainrefuses 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.scripts/run_standalone_tests.py -j 4(the 13tests/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:not caughtinstead ofcaught by timeout: killed (3 tests, among themtest_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-maxignored: killed (test_hunks_past_mutate_max_are_listed_as_not_tried).test_hunk_flagsbypassed incode_hunks): killed (4 tests, among themtest_a_hunk_that_only_deletes_a_test_is_not_mutated).test_a_link_named_pycache_is_left_alone,test_a_link_out_of_the_tree_is_not_followed).git clean -fdqbetween hunks: survives (37 OK).test_a_test_that_dirties_the_tree_does_not_change_the_next_hunkwrites into a tracked file, whichgit reset --hardalready restores; an untracked file left by a test is not pinned. Minor.Real use, this head's
red_green.pyon two other pull requests (--no-fetch --no-cargo --mutate):main: red then green, 4 tests; 26 pass on both; 8 hunks, 8 caught; 111 s.--base: red then green, 6 tests; 29 pass on both; 10 hunks, 9 caught, 1 not caught (twoSOURCESkeys that only the contract test reads, detailed on #2813).docs/testing.mdsays, and was removed afterwards withgit worktree remove --force.Not covered here: a real cargo crate (no cargo here), the POSIX paths (
killpg, thechmodcases), 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.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:25:36Z.
Merging. Head
bf65aa450merges cleanly withmain80910637fand does not force a rebase of #2566. Independent check on headbf65aa450: 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).
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 filesVerdict: PASS. The change does what it says:
--mutateundoes each hunk of the pull request's code (not its tests) alone on the green tree and re-runs the tests, reportingcaughtwhen a test that went red then green now fails,not caughtwhen they all still pass,does not buildwhen the undone code no longer builds so the test cannot run,caught by timeout/timed out buildingwhen a command hangs, andcompiler crashed/does not applyfor the two exceptional cases. It does not change the verdict or the exit code (verdict()takes nomutationsargument, confirmed empirically on agreen failsPR and on ared then greenPR). The strongest evidence is the tool run on its own pull request: 31 code hunks inscripts/red_green.py, 7 of the first 8caught, 1not caught(the docstring usage line — a documentation line no test looks at, correctly reported as not caught), and the verdictred 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 onlyscripts/red_green.pyto the merge base gives 17 errors + 2 failures + 1 "ok" that passes for the wrong reason, below). Clean-room check, docs tests,compilealland 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 currentorigin/main8422def7(31 commits behindmain). 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.pygains three options —--mutate,--mutate-max(default 10),--mutate-timeout(default 600 s) — and the machinery behind them:code_files()(line 714) andcode_hunks()(line 722): the hunks a mutation undoes, taken with-U0, from the Rust and Python files the pull request modifies (statusM) outside the tests and#[cfg(test)]code. Files the PR adds are not mutated and are listed asadded_not_mutated.mutate()(line 750): for each hunk,reset --hardto 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 runside()again.does not applyon a failed reverse-apply.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-Bcomment at line 463 is the corrected one (the old comment was wrong;-Bstops 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.--json:mutations,mutations_not_run,mutations_skipped,added_not_mutated.--mutate-maxmust be ≥ 1,--mutate-timeouta finite number > 0, and both are refused without--mutate.tests/test_red_green.pyadds 22 test methods (aMutationclass of 14, aDropBytecodeclass of 3, a Windows-onlyJobclass of 1, and 2 more inPython), plus aCHILD_TESTand helpers.docs/testing.mddocuments 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()filtersis_test_file()and.pyundertests/;code_hunks()skips#[cfg(test)]-only hunks viatest_hunk_flags(the same rule the red side uses). On the tool's own PR it found 31 hunks, all inscripts/red_green.py, none intests/test_red_green.py. The mutation is applied to the source, not the test: undoing a hunk ofscripts/red_green.pyis what changes behaviour.test_a_hunk_that_only_deletes_a_test_is_not_mutatedconfirms a test-only hunk is left alone."The green merge is committed once. Each mutation starts from it, reset and cleaned." — Confirmed:
git commit-treeof the merge (line 683–685) before the green side runs, andmutate()resets to it per hunk (line 758).test_a_test_that_dirties_the_tree_does_not_change_the_next_hunkpasses; 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 sotwo()returns the old value makestest_twofail →caught.not caught— they all still pass. Confirmed on #2798 (4 not caught atlauncher/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 leavesTWO = helper()at module level withhelperundefined: the test module no longer imports, the test never runs, the hunk is reporteddoes not build(notcaught).caught by timeout/timed out building— the tool's owntest_a_cargo_run_that_hangs_is_stopped_and_said_whereandtest_a_mutated_run_that_hangs_is_caught_by_timeoutpass on this host.compiler crashed— theCompilerCrashtests (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) andtest_a_cargo_run_that_hangs_is_stopped_and_said_where. The Windows job-object path is read in code only (theJobtest 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-maxtruncates 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_mutatedcovers 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 nomutations) and empirically: on a genuinegreen failsPR (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.--mutateon ared not constructible(no test), ano red, and agreen not constructiblePR all leave the verdict untouched.The
__pycache__/-Bfix. — The old-Bcomment was indeed wrong (a review point); the new code removes the tree's own__pycache__folders before each Python run and keeps-Bto stop writing.test_stale_bytecode_in_the_work_tree_is_never_runandtest_bytecode_it_cannot_remove_stops_the_run_with_the_tree_put_backpass. 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_flagsis the single implementation and bothtest_hunksandcode_hunkscall it. Good deduplication, and it fixes the review point that a deleted test must not be mutated.Docs. —
docs/testing.mdmatches the code: the option, the result list,--mutate-max/--mutate-timeout, the added-files limitation, andgit worktree remove --force <folder>/treefor 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
caughtiff one of the tests that went red→green fails after the hunk is undone; it isdoes not buildiff none of those tests can run at all. That is the right discrimination, and I confirmed both halves:does not build, notcaught. Undoing a hunk that leavesTWO = helper()at module level withhelperundefined makes the test module fail to import; the target test never appears in the run, and the tool reportsdoes not build. This is the honest answer: a test that cannot run proves nothing about whether it catches the change.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 recordedfailedand the hunk iscaught. 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 thatcaughtdoes not require the specific assertion to fail; acaughthunk 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").mutate()consults onlytargets(the red→green tests). A mutation that breaks an unrelated pre-existing test is reportednot caught(if the targets still pass). That is correct for the tool's question ("does the new test catch this hunk") but meansnot caughtmeans "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 onlyscripts/red_green.pyto the merge base (in a/tmpcopy 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 andAttributeError: module 'red_green' has no attribute 'drop_bytecode', i.e. the new tests genuinely fail without the source change. The one "ok" istest_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-diron disk,--no-cargo):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 atlauncher/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.scripts/red_green.py; with--mutate-max 8, 7 caught, 1 not caught (line 6, the docstring usage line), 23 listed asnot tried, past --mutate-max, 19 red→green, 17 pass on both, verdictred then green, exit 0. The onenot caughtis a documentation line — a correct, honest result.green not constructible(conflicts with the base indocs/game_gate.md);--mutatecorrectly reportsnot run: there is no green side.Repo/stub-cargo helpers) confirmed: thedoes not builddiscrimination; 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); agreen failsPR unchanged by--mutate; added files listed and not undone;--mutate-maxskipping; the option-range checks.Clean-room and hygiene on the three changed files:
python3 -I scripts/check_no_game_data.pyclean;python3 -I -m unittest discover -s tests -p "test_docs_*.py" -v= 57 OK;python3 -m compileall -qOK;test_text_write_line_endings.pyOK.5. Anything wrong (with file and line)
No defect that changes the verdict. Four honest observations:
tests/test_red_green.py:599test_mutate_options_are_checkeddoes not discriminate. On the merge base it passes too, because--mutateis an unknown argument there, so argparse exits 2 and the message happens to contain--mutate-max/--mutateas 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.)does not applyis nearly unreachable.git apply -R --unidiff-zerois tolerant of line shifts, so whenmainmoves the lines above a hunk the reverse apply still succeeds (my "main adds a line above" probe reportedcaught, notdoes 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.D) are neither mutated nor listed.code_files()uses--diff-filter=Mfor mutation and--diff-filter=Aforadded_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.caughtis counted beforedoes not buildinmutate()(line 768 vs 774). They are mutually exclusive in practice (a build that fails yields no recorded test, so thecaughtbranch 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
job_of,stop_all), the junction detection indrop_bytecode, theicaclsdeny case, andJob.test_a_job_object_that_cannot_be_joined_is_said_once— all Windows; theJobtest 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.cargo teston a real crate, so the Rust--mutatepath is verified through the stub and theCompilerCrash/mutation tests, not a real build.does not applyand thecompiler crashed/rerun_afterpaths against real toolchains. I read thedoes not applycode and could not trigger it (caveat 2).compiler crashedis exercised by the tests' crash stub, not a real rustc crash.test_red_green.py,test_docs_*.py,test_text_write_line_endings.py,check_no_game_data.pyandcompileall. The change is confined toscripts/red_green.pyand 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.TEST-RED-GREEN-MUTATIONclaim.7. Neighbours
The change touches only
scripts/red_green.py,tests/test_red_green.pyanddocs/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.