Repository navigation
Conversation
|
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 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 Where that leaves
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 AI-assisted: yes - DeepSeek v4.1 (flash), which also ran it. Written with an AI assistant. |
|
Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head MEASURED
Small note: AI-assisted: Claude Code |
KelboLive
left a comment
There was a problem hiding this comment.
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:
- Added files are silently never mutated.
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. - The
-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, 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.
|
Thanks @KelboLive. Confirmed: when a hunk cannot be restored, 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. |
VERIFY-2817 — Linux, Python 3.15, no GPU device, no game filesVerdict: PASS — the change does what it says, and the part that is new (the mutation check) reports a known answer correctly. Head 1. Its own suite, and the three rows
Row B's failures are assertions, not load errors — the test file runs on The other failure and the four errors are the same cause: 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:
3.
|
| 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 (
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. - The cargo path (
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.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.
6. The whole standalone suite, against the same runner on a clean treeTo 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
The two failures are the same two files on both trees, and neither is this change's:
So the pull request adds its 19 tests and changes nothing else in the suite. AI-assisted: MiniMax M3.1 Flash. |
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:
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. |
A note on this machine's graphics, so "no GPU device" is not misreadI 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 There is no Vulkan hardware device here. mesa's svga driver has no Vulkan backend, so the loader enumerates nothing by default; with 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
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. AI-assisted: MiniMax M3.1 Flash. |
Correction to my note above: the frame-rate comparison was not controlledMy 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 With the window size and the swap interval fixed,
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:
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. |
… itself (TEST-RED-GREEN-MUTATION) Verifiers remove a line of the fix by hand on nearly every test pull request to see the new test fail. --mutate does it for each hunk of the pull request's code outside its tests (Rust and Python files it changes; hunks taken without context, so a test changed next to the code stays out): after the green side, it undoes that hunk alone, runs the tests again and reports it as caught (a test that went red then green fails), not caught, does not build or does not apply, up to --mutate-max hunks (10); the hunk is put back after each run. Python tests now run with -B: an undone change of the same size within the same second would otherwise run the stale bytecode.
… Python run, so no test runs stale bytecode (review) -B only stops writing bytecode. An ignored .pyc left in the work tree (git clean keeps it) ran instead of the reverted source: red passed and an undone hunk was not caught. -X pycache_prefix would cover the unittest process only, not the processes its tests start; removing the folders covers both.
… and reports it as caught by timeout (review) Each command of a mutated run (cargo test, one Python test file) is stopped after --mutate-timeout seconds (600) together with the processes it started (taskkill /T on Windows, the process group elsewhere): a test binary or a process a test starts would otherwise keep the output pipe open. The hunk is then 'caught by timeout', apart from 'caught'. The red and green sides have no timeout, as before.
…undone, and which added files it does not mutate (review) A hunk that cannot be put back no longer drops the whole mutations section: the report and --json (mutations_stopped) name the hunk, the reason and how many hunks were not tried. With --mutate, mutations is always a list and mutations_not_run says why none was undone: nothing to undo (a test-only pull request), or no test went red then green. Files the pull request adds stay unmutated, and the report and --json (added_not_mutated) now list them. Verdicts and exit codes are unchanged.
…ed; git worktree remove <dir>/tree removes it (review)
…lders, never through a link or junction (review) Path.rglob follows directory junctions on Windows, so a junction in the tree to an outside folder had that folder's __pycache__ deleted, and a link itself named __pycache__ made shutil.rmtree raise. The walk now skips symbolic links and every reparse point (junctions included).
…rphan holding its output does not hold the run (review) taskkill /T on a command that has already ended finds no tree: a child it left behind kept the output pipe open, the run waited for the timeout and a real caught read caught by timeout. A mutated run now writes its output to a temporary file and, on Windows, runs in a job object (kill on close) that its children join; once the command ends or times out, the job (the process group elsewhere) is stopped.
… merge, reset and cleaned (review) A put-back that applies did not prove the tree green again: a test that wrote into a tracked file changed the result of the next hunk. The green merge is now committed with the tool's identity before its tests run, and each mutation resets the tree to it and cleans it before undoing its hunk. A hunk can no longer fail to go back, so mutations_stopped and its test are gone; a test that dirties the tree now has its own.
…or the red side and for the mutations (review) code_hunks looked only at the lines a hunk adds, so a hunk that deletes an obsolete test inside a #[cfg(test)] module was mutated and read as not caught, while the red side took it as a test hunk. Both now use test_hunk_flags: every removed or added line is test code, blank or a comment, and one at least is test code.
With more code hunks than --mutate-max, the report read as if every hunk was tried. The hunks left out are now in --json (mutations_skipped, file and line) and in the text (not tried, past --mutate-max).
… as timed out building, not caught (review) A mutated cargo run that times out before its first Running line was still a build: it says nothing about the tests, so it is no longer counted as caught by timeout. A stub cargo that hangs in its build or in a test binary now covers the cargo timeout path, which no test reached before.
…t that is not above 0, and both without --mutate (review)
…s nothing to undo in the files it modifies (review)
…ed; one way to remove the worktree, default folder or --work-dir (review)
…nd is stopped, not only that it does not hold the run (review) With the output in a file the run no longer waits for such a process, so only a mark it would write later shows that the job (the process group elsewhere) stopped it. drop_bytecode reads a folder's attributes only for folders.
…ree put back on a __pycache__ it cannot remove, and four smaller fixes (review) drop_bytecode skips a folder it may not list (Python cannot import from it either). A __pycache__ it cannot remove is now a usage error naming it (exit 2), and any such error during a run puts the tree back on the base, where before the undone hunk stayed. --mutate-timeout must also be finite. In a mutated run, a Python test stopped while running outweighs a cargo build that was stopped. job_of says once on stderr when it has no job object. docs/testing.md: one line rewrapped.
5193b25 to
bf65aa4
Compare
|
Rebased on
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). |
Claimed in the coordination issue as: TEST-RED-GREEN-MUTATION (#2570 (comment))
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
main8422def: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 gate: summary.json gets the run's memory peaks (D3D12-GATE-MEMORY-PEAKS) #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)