From b38e8a19314e48765d2718b9aaa2b69f2f0fe48a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 24 Nov 2026 02:57:18 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20no=20outcom?= =?UTF-8?q?es=20file=20means=20no=20mutant,=20two=20tests=20use=20subTest,?= =?UTF-8?q?=20and=20a=20test's=20name=20fits=20its=20assertion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/mutate_changes/in_diff_tools.py | 3 ++- bin/task_bench/figures.py | 4 +++- bin/task_bench/main.py | 15 ++++++++------- bin/task_bench/planted_mutant.py | 3 +-- bin/task_bench/rust_bugs.py | 12 +++++++----- bin/task_bench/test_figures.py | 5 +++++ bin/task_bench/test_rust_bugs.py | 26 ++++++++++++++++---------- bin/task_bench/test_task_bench.py | 2 +- todo.md | 14 +++++++++++++- 9 files changed, 56 insertions(+), 28 deletions(-) diff --git a/bin/mutate_changes/in_diff_tools.py b/bin/mutate_changes/in_diff_tools.py index f3bd6765..e8d198f6 100644 --- a/bin/mutate_changes/in_diff_tools.py +++ b/bin/mutate_changes/in_diff_tools.py @@ -45,7 +45,8 @@ def run_cargo_mutants(top: str, base: str, paths: list[str], run: Run, git: Git, def cargo_mutants_out(top: str, scratch: str, arguments: list[str], run: Run, jobs: int) -> pathlib.Path | Failure: - """The `mutants.out` folder that `cargo mutants `, which runs in top, writes in scratch, a folder in top.""" + """Run `cargo mutants ` in top, and return the `mutants.out` folder it writes. That folder is in scratch, which is a + folder in top.""" ran = run(["cargo", "mutants", *arguments, "--output", os.path.relpath(scratch, top), "--jobs", str(jobs)], top) if isinstance(ran, Failure) or ran.code not in CARGO_FINISHED: return ran if isinstance(ran, Failure) else failed("cargo mutants", ran) diff --git a/bin/task_bench/figures.py b/bin/task_bench/figures.py index 53300c1a..04a01ccb 100644 --- a/bin/task_bench/figures.py +++ b/bin/task_bench/figures.py @@ -108,8 +108,10 @@ def median(column: Column, results: list[Result]) -> float | None: def row(task: str, side: str, results: list[Result]) -> str: + """A task's row for one side. A `|` in the task's name is escaped, since cargo-mutants names a mutant by its operator, as in + `replace || with &&`, and a bare one would end the cell.""" passed = f"{sum(result.passed for result in results)}/{len(results)}" - return cells([task, side, passed, *("-" if (found := median(column, results)) is None else number(found) for column in COLUMNS)]) + return cells([task.replace("|", "\\|"), side, passed, *("-" if (found := median(column, results)) is None else number(found) for column in COLUMNS)]) def change(bugs: list[tuple[list[Result], list[Result]]]) -> str: diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 13112455..17579781 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -15,13 +15,13 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. - Plant. It copies the tree at the base and runs a mutation tool there, over the files that hold the places `larv-review places` prints, the ones the comprehension seats found hardest: Gremlins over the Go files, as `gremlins unleash`, mutmut 3 over - the Python files, as `mutmut run`, and cargo-mutants over the Rust files, as `cargo mutants`. It takes the mutants the tests kill in the order --seed sets, 1 by default, until --bugs of + the Python files, as `mutmut run`, and cargo-mutants over the Rust files, as `cargo mutants`. No other language is planted + in so far. It takes the mutants the tests kill in the order --seed sets, 1 by default, until --bugs of them, 5 by default, have become bugs. A mutant becomes a bug where the lines it changes stand unchanged at the head, and where, planted at each side, a test fails and prints a message that says more than the test's name. The bench reads that message from `go test`'s output for a Go file, from pytest's for a Python file and from `cargo test`'s for a Rust file, so --test must - run the tests of each language the places name, with that runner: pytest as it prints by default, or with --tb=short. Any - other mutant is passed over, so a change to the very lines of a bug is not benched. Go, Python and Rust are the languages so - far. + run the tests of each language the places name, with that runner: pytest as it prints by default, or with --tb=short, and + `cargo test` without --nocapture. Any other mutant is passed over, so a change to the very lines of a bug is not benched. - Run. Haiku fixes each bug --runs times at each side, 5 by default, the sides in turn. A fix starts from a copy of that side's tree with the bug in it, committed once, so git doesn't show which line the bug is on. In the copy, in a container, `claude -p --strict-mcp-config --disable-slash-commands --no-session-persistence --model claude-haiku-5-5 --effort low` works with every @@ -29,7 +29,8 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. Claude home is new and empty, so the project's own CLAUDE.md, or AGENTS.md, in the copy is all the setup that loads. Its network reaches api.anthropic.com and nothing else. A fix ends after 30 minutes. - Check. The test command runs over the planted tree with each file that is no test as Haiku left it; a fix passes where it exits 0. - A test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder. + A test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder. A Rust test that + stands in the file of the code it tests is the exception: the bench takes that file whole, so a change to such a test counts. --image is the project's development image, such as golang:1.27.4. The bench adds Claude Code to it, as its installer installs it, so the image needs curl and bash; the result names the version. Haiku works in that image. So does --test: sh runs that text at @@ -48,8 +49,8 @@ for Go, for Python and then for Rust: docker run --rm --memory 16g --memory-swap 16g --user "$(id -u):$(id -g)" -e CARGO_HOME=/tmp/cargo -v "$PWD:$PWD" -w "$PWD" \ rust:1.100.0 sh -c 'cargo install --quiet --locked cargo-mutants@27.1.0 && exec "$@"' sh -Where the places name files in more than one language, the one prefix gets each tool's command, in the order above, and a tool -it cannot run fails the bench. Such a prefix picks the tool by "$1", which is `gremlins`, `mutmut` or `cargo`, as here for Go +Where the places name files in more than one language, the one prefix gets each tool's command, Gremlins' first and +cargo-mutants' last, and a tool it cannot run fails the bench. Such a prefix picks the tool by "$1", which is `gremlins`, `mutmut` or `cargo`, as here for Go and Python: sh -c 'case "$1" in diff --git a/bin/task_bench/planted_mutant.py b/bin/task_bench/planted_mutant.py index 85a4c6c2..ba6f31f8 100644 --- a/bin/task_bench/planted_mutant.py +++ b/bin/task_bench/planted_mutant.py @@ -11,8 +11,7 @@ class Mutant(typing.NamedTuple): """A mutant the project's tests killed, as the lines it changes in the tree its tool ran in: the number of the first, from 1, those lines as the tree has them, and what the mutant has in their place. Where it only adds lines, the number is that of the line they go in before. name is what the report calls the bug it becomes: the path and line, then what the tool tells the - mutant by, which is Gremlins' column and mutator, or mutmut's name. A Rust mutant's name is the one cargo-mutants gives it, which holds - the path and line.""" + mutant by, which is Gremlins' column and mutator, or mutmut's name. cargo-mutants' own name for a mutant holds all of it.""" path: str line: int diff --git a/bin/task_bench/rust_bugs.py b/bin/task_bench/rust_bugs.py index ba79a414..6a1a6cd1 100644 --- a/bin/task_bench/rust_bugs.py +++ b/bin/task_bench/rust_bugs.py @@ -19,13 +19,13 @@ SECTION = re.compile(r"^---- (\S+) std(?:out|err) ----$") PANICKED = re.compile(r"^thread '.*' (?:\(\d+\) )?panicked at .*:$") # What follows a panic's message: a hint to ask for a backtrace, or the backtrace. AFTER_MESSAGE = ("note: run with `RUST_BACKTRACE", "stack backtrace:") -# The heading of the list that names the failed tests, after the last test's section. +# The heading cargo test prints twice: before the first failed test's section, and before the list of the failed tests' names. FAILED_TESTS = "failures:" def killed_mutants(top: str, files: list[str], run: Run, jobs: int) -> list[Mutant] | Failure: """The mutants in `files` that the tests of the tree at top kill, as cargo-mutants finds them there, each under the name - cargo-mutants gives it. One whose diff is not one run of changed lines is left out.""" + cargo-mutants gives it. One whose diff holds no change, or more than one hunk, is left out.""" scratch = scratch_folder(top) if isinstance(scratch, Failure): return scratch @@ -33,8 +33,10 @@ def killed_mutants(top: str, files: list[str], run: Run, jobs: int) -> list[Muta out = in_diff_tools.cargo_mutants_out(top, scratch, [argument for path in files for argument in ("--file", path)], run, jobs) if isinstance(out, Failure): return out - outcomes = json.loads((out / "outcomes.json").read_bytes())["outcomes"] - # The run of the unmutated tree is an outcome too, whose scenario is no mutant. + # cargo-mutants writes no outcomes where it finds no mutant, as in a file that holds only types. + outcomes = json.loads(listed.read_bytes())["outcomes"] if (listed := out / "outcomes.json").is_file() else [] + # The run of the unmutated tree is an outcome too. Its scenario is the text `Baseline`, which holds no mutant, so the summary is + # checked first. caught = [(mutant, outcome["diff_path"]) for outcome in outcomes if outcome["summary"] == "CaughtMutant" and (mutant := outcome["scenario"]["Mutant"])["file"] in files] lines = [(mutant, changed((out / diff).read_bytes())) for mutant, diff in caught] return [Mutant(mutant["file"], found[0], mutant["name"], found[1], found[2]) for mutant, found in lines if found] @@ -86,7 +88,7 @@ def task_text(output: str) -> str | None: within = False elif within: message.append(line.strip()) - # A test in a module is named after it, as `tests::adds`; a message may name the whole or the test alone. A Rust test's own + # A test in a module has the module's name before its own, as `tests::adds`; a message may name the whole or the test alone. A Rust test's own # name is often a plain word, such as `big`, so a longer identifier that holds it, such as `is_big`, doesn't name the test. names = [re.compile(rf"(? i32 { sum } """ -# A mutant that swaps an operator, and one that replaces a function's body. OPERATOR_DIFF = b"""--- src/pick.rs +++ replace += with -= in total @@ -3,12 +3,12 @@ @@ -135,10 +135,11 @@ class ChangedTest(unittest.TestCase): def test_the_tree_with_the_mutant_applied_is_the_code_cargo_mutants_tested_without_its_mark(self): for diff, line in ((OPERATOR_DIFF, b" sum -= item;"), (BODY_DIFF, b" None")): - line_number, was, now = changed(diff) - planted = mutated(PICK, Mutant("src/pick.rs", line_number, "a name", was, now)) - self.assertIn(line, planted.split(b"\n")) - self.assertNotIn(b"cargo-mutants", planted) + with self.subTest(line=line): + line_number, was, now = changed(diff) + planted = mutated(PICK, Mutant("src/pick.rs", line_number, "a name", was, now)) + self.assertIn(line, planted.split(b"\n")) + self.assertNotIn(b"cargo-mutants", planted) def test_keeps_an_unchanged_line_between_two_changed_ones_on_both_sides(self): diff = b"--- a.rs\n+++ a name\n@@ -4,5 +4,4 @@\n fn f() {\n- a\n b\n- c\n+ d /* ~ changed by cargo-mutants ~ */\n }\n" @@ -253,10 +254,15 @@ class KilledMutantsTest(unittest.TestCase): self.assertIn("cargo-mutants said so", found.reason) def test_outcomes_or_a_diff_that_cannot_be_read_are_a_failure_that_names_the_folder(self): - for outcomes, diffs in ((None, self.DIFFS), ({"outcomes": [{"summary": "CaughtMutant"}]}, self.DIFFS), ("no outcomes", self.DIFFS), (self.OUTCOMES, {})): - found = killed_mutants(self.top, ["src/pick.rs"], self.cargo_mutants(outcomes, diffs=diffs), 3) - self.assertIsInstance(found, Failure) - self.assertIn(f"could not read cargo-mutants' outcomes in {self.top}", found.reason) + for outcomes, diffs in (({"outcomes": [{"summary": "CaughtMutant"}]}, self.DIFFS), ("no outcomes", self.DIFFS), (self.OUTCOMES, {})): + with self.subTest(outcomes=outcomes, diffs=diffs): + found = killed_mutants(self.top, ["src/pick.rs"], self.cargo_mutants(outcomes, diffs=diffs), 3) + self.assertIsInstance(found, Failure) + self.assertIn(f"could not read cargo-mutants' outcomes in {self.top}", found.reason) + + def test_finds_no_mutant_where_cargo_mutants_wrote_no_outcomes_as_it_does_where_it_finds_none(self): + self.assertEqual(killed_mutants(self.top, ["src/pick.rs"], self.cargo_mutants(None), 3), []) + self.assertEqual(list(pathlib.Path(self.top).iterdir()), []) if __name__ == "__main__": diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 5e5aa67f..c40d6ee7 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -306,7 +306,7 @@ class BenchTest(unittest.TestCase): self.assertEqual(report[0], f"task-bench: base {self.head[:12]}, head {self.head[:12]}. 1 bug, each run 1 time at each side by claude-haiku-5-5 in Claude Code 2.1.330.") self.assertEqual(report[4:6], ["| 1: calc.go:5:11 ARITHMETIC_BASE | base | 1/1 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | 1 |", "| 1: calc.go:5:11 ARITHMETIC_BASE | head | 1/1 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | 1 |"]) - def test_fails_where_the_places_name_no_go_or_python_file_of_the_base(self): + def test_fails_where_the_places_name_no_file_of_the_base_in_a_language_the_bench_plants_in(self): with contextlib.redirect_stderr(io.StringIO()): found = main.bench({**self.given, "--base": "main"}, self.env, lambda home: "- `gone.go:1` `Gone`: removed\n- `README.md:1` `Calc`: thin\n", self.home) self.assertEqual(found, Failure("The places the seats found hard don't name any Go, Python or Rust file that the base holds, so there is nowhere to plant a bug.")) diff --git a/todo.md b/todo.md index 5819ddde..ace2558f 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 532` +`Next ID = 533` ## Renamed @@ -18,6 +18,7 @@ |---|---|---|---|---|---|---|---|---|---|---|---| | 531 | 0.16.0 | | | **Bench the shipped features of a branch that landed by fast-forward: take as the feature the commits from the one after the item finished before it, up to the commit that took its item out of the plan.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 | 1.1 | | 524 | 0.16.0 | | owner | **Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names.** | 3 | 2 | 1 | 4 | 6 | 1.1 by 3 | 0.5 | +| 532 | 0.16.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a Rust test that stands in the file of the code it tests.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | | 526 | 0.16.0 | | owner | **Plant bugs for `task-bench` in Rust, from the mutants cargo-mutants kills.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 1 | 0.3 | | 527 | 0.16.0 | | owner | **Plant bugs for `task-bench` in TypeScript, from the mutants Stryker kills.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 1 | 0.3 | | 528 | 0.16.0 | | owner | **Plant bugs for `task-bench` in PHP, from the mutants Infection kills.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 1 | 0.3 | @@ -138,6 +139,17 @@ The second part of item 504, which says what a bench feature is and when a run c Done when `task-bench` counts a run of each: its acceptance tests fail at fejkdata's base and head and pass with its reference patch. The six land in fejkdata's checkout or its config folder, wherever its `bench-tasks` setting points, so the item changes no file of this repo and carries no `Touches:` list. About 1,000 lines of Go and specs. +### 532. Leave out of a `task-bench` fix a change Haiku makes to a Rust test that stands in the file of the code it tests. + +Today the check takes each file that is no test as Haiku left it, and `is_test` tells a test by its file's path. Rust keeps unit tests in the source file, in a `#[cfg(test)]` module, so a fix that edits or deletes the failing test there passes. The help's Check paragraph says so. It holds at the base and at the head alike, so the head's change against the base still compares like with like; the Passed column of a Rust bench counts such a run as a fix. + +Recommended: keep each `#[cfg(test)]` module of a Rust file as the planted tree has it, and take the rest of the file from Haiku's copy; where the module cannot be told apart, pass the mutant over. Passing over every mutant that a test in a source file kills would leave most Rust bugs out, since unit tests are where most Rust tests stand. A product-owner finding on item 526's chunk raised this. + +Touches: +- `bin/task_bench/runs.py`: `checked_tree`, `of_tests` (small) +- `bin/task_bench/test_task_bench.py` +- `bin/task_bench/main.py`: lines 30-33 + ### 526. Plant bugs for `task-bench` in Rust, from the mutants cargo-mutants kills. cargo-mutants runs over the changed lines only today. Run it over the files that hold the seats' places, at the tree's top without git, and turn each killed mutant into the lines it changes, read from the diffs it writes under `mutants.out`. Tell Haiku the failure `cargo test` prints, without the test's name or file. Check the module against the tool's real output on a small project in a container, since this repo holds no Rust.