From 86edf81d288c509750e09c108546400b4fbab00f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:05:56 +0100 Subject: [PATCH 01/13] Keep a Rust test in a file of its own as planted in a task-bench fix --- bin/task_bench/main.py | 15 ++++- bin/task_bench/runs.py | 36 +++++++++-- bin/task_bench/rust_test_modules.py | 64 +++++++++++++++---- bin/task_bench/test_rust_test_modules.py | 24 +++++++ bin/task_bench/test_task_bench.py | 79 +++++++++++++++++++++++- 5 files changed, 195 insertions(+), 23 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index e7d9971b..826997c2 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -42,8 +42,10 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. Where the planted file has such modules and Haiku's file lacks one of them, or its modules cannot be told apart, the planted file stands whole; where the planted file has none, or its modules cannot be told apart, Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment - is never closed, is passed over. A Rust test in a file of its own, as `#[cfg(test)] mod tests;` names, counts, since the bench - tells no such file from code. + is never closed, is passed over. A Rust file that a `#[cfg(test)] mod name;` in another file of the planted tree names, as + `src/name.rs` or `src/name/mod.rs` beside a `lib.rs`, `main.rs` or `mod.rs`, or in the folder of any other file's name, is a + test: it stands as the planted tree has it, and no mutant is planted in it. A Rust mutant in a tree where such a declaration + names no file there, as one that `#[path]` moves does, is passed over. --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 @@ -200,7 +202,7 @@ from task_bench.tasks import Asked, Bench, BUG, check_made, committed, DATA_SOUR from task_bench.bugs.planted_mutant import bug_at_sides, Mutant from claude_code.reply import Claude from task_bench.bench_folder import clear_left, held -from task_bench.runs import closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, TimedOut, TOKEN, WORK +from task_bench.runs import closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, rust_test_files, TimedOut, TOKEN, WORK from task_bench.figures.digest import counted, digest, Run, TaskRuns from machine_load.slots import CPUS_PER_SLOT from git_cli.git_repo import default_ref, Git, top @@ -588,6 +590,13 @@ def planted(bench: Bench, number: int, mutant: Mutant) -> Task | Failure | None: # The check keeps a Rust file's test modules as planted, which it can only do where it tells them apart. if bugs is None or not all(tells_apart(mutant.path, source) for source in bugs.values()): return None + # ... and a Rust test in a file of its own, which it can only keep where it finds each such file. + if mutant.path.endswith(".rs"): + standing = on_disk(f"find the Rust test files beside {mutant.path}", lambda: [rust_test_files(tree) for tree in bench.trees.values()]) + if isinstance(standing, Failure): + return standing + if any(tests is None or mutant.path in tests for tests in standing): + return None trees: dict[Side, str] = {} messages: dict[Side, str] = {} for side, changed in bugs.items(): diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index 28337af8..ed327f16 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -12,7 +12,7 @@ from mutate_changes.tool_process import failed, Ran from failure import Failure from mutate_changes.changed_lines import is_test from task_bench.api_proxy import PORT -from task_bench.rust_test_modules import with_tests_of +from task_bench.rust_test_modules import declared, homes, with_tests_of MODEL = "claude-haiku-5-5" # Where each run's container mounts its copy of the code, and its home folder: the paths in a run's stream start there. @@ -168,19 +168,21 @@ def checked_tree(planted: str, copy: str, into: str, rust_tests_planted: bool = """Makes at `into` the tree the tests check a fix in: `planted`, the code with the bug as Haiku got it, with each file that is no test as `copy` holds it after the fix. So a test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder, where Go's tests keep the output they expect. Where rust_tests_planted, a Rust file's inline `#[cfg(test)]` - modules stand as the planted file has them too, as `with_tests_of` says. + modules stand as the planted file has them too, as `with_tests_of` says, and so does each Rust file that `rust_test_files` finds. Raises OSError where a file cannot be copied.""" shutil.copytree(planted, into, symlinks=True) + # `rust_test_files` is None for a tree whose declarations it cannot resolve, which the bench passes over where it plants the bug. + rust_tests = (rust_test_files(planted) or set()) if rust_tests_planted else set() before, after = set(entries(planted)), set(entries(copy)) for path in before - after: - if not of_tests(path): + if not of_tests(path, rust_tests): with contextlib.suppress(FileNotFoundError): os.unlink(os.path.join(into, path)) for path in sorted(after): target = os.path.join(into, path) # A link is copied as a link, never followed; and one that would stand in for a folder of the planted tree is left out. - if of_tests(path) or (os.path.isdir(target) and not os.path.islink(target)): + if of_tests(path, rust_tests) or (os.path.isdir(target) and not os.path.islink(target)): continue os.makedirs(os.path.dirname(target), exist_ok=True) with contextlib.suppress(FileNotFoundError): @@ -201,8 +203,30 @@ def keep_rust_tests(planted_file: str, target: str) -> None: pathlib.Path(target).write_bytes(with_tests_of(planted, pathlib.Path(target).read_bytes())) -def of_tests(path: str) -> bool: - return is_test(path) or "testdata" in pathlib.PurePath(path).parts +def of_tests(path: str, rust_tests: typing.AbstractSet[str] = frozenset()) -> bool: + """Whether path is a test by its path alone, or one of rust_tests.""" + return is_test(path) or "testdata" in pathlib.PurePath(path).parts or path in rust_tests + + +def rust_test_files(tree: str) -> set[str] | None: + """The Rust files under tree that a `#[cfg(test)] mod name;` declaration names, by their paths from tree. None where a + declaration names no file there, or `declared` cannot tell a file's declarations. + + Raises OSError where a file cannot be read.""" + files = set(entries(tree)) + found = set() + for path in sorted(files): + if not path.endswith(".rs") or os.path.islink(os.path.join(tree, path)): + continue + names = declared(pathlib.Path(tree, path).read_bytes()) + if names is None: + return None + for name in names: + standing = [home for home in homes(path, name) if home in files] + if not standing: + return None + found.add(standing[0]) + return found def entries(top: str) -> list[str]: diff --git a/bin/task_bench/rust_test_modules.py b/bin/task_bench/rust_test_modules.py index aa2b13d2..2ebed22c 100644 --- a/bin/task_bench/rust_test_modules.py +++ b/bin/task_bench/rust_test_modules.py @@ -1,5 +1,7 @@ -"""The `#[cfg(test)]` modules of a Rust file, which stand in the file of the code they test. Here are where each is, and a file with -the modules of another file put in place of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone.""" +"""The `#[cfg(test)]` modules of a Rust file, which stand in the file of the code they test or, as `mod name;` declares, in a file of +their own. Here are where each inline one is, which files hold the others, and a file with the modules of another file put in place +of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone.""" +import pathlib import re # What the scan steps over or stops at. A string, a char and a comment may hold a brace. @@ -17,6 +19,10 @@ STRING_BODY = re.compile(rb'(?:[^"\\]|\\.)*"', re.DOTALL) COMMENT_EDGE = re.compile(rb"/\*|\*/") # What follows the attribute that starts an inline module: any other attributes, an optional visibility, then `mod name {`. MODULE = re.compile(rb"\s*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*\{") +# What follows the attribute that starts a module kept in a file of its own: any other attributes, an optional visibility, then `mod name;`. +DECLARATION = re.compile(rb"\s*(?P(?:#\[[^\]]*\]\s*)*)(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*;") +PATH_ATTRIBUTE = re.compile(rb"#\[\s*path\b") +KEEP_BESIDE = ("lib.rs", "main.rs", "mod.rs") def tells_apart(path: str, source: bytes) -> bool: @@ -32,16 +38,13 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: depth = 0 # The module being read: its name, the offset of its attribute and the depth outside it. inside: tuple[bytes, int, int] | None = None - position: int | None = 0 - while position is not None and (match := SCAN.search(source, position)): - token, position = match.group(), match.end() - if token == b"/*": - position = after_comment(source, position) - elif token == b'"': - position = after_string(source, position) - elif match.group("hashes") is not None: - position = after_raw_string(source, position, match.group("hashes")) - elif token == b"{": + position = 0 + while match := SCAN.search(source, position): + token = match.group() + if (after := after_token(source, match)) is None: + return None + position = after + if token == b"{": depth += 1 elif token == b"}": depth -= 1 @@ -52,7 +55,42 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: elif token.startswith(b"#[") and inside is None and (module := MODULE.match(source, position)): inside, position = (module.group("name"), match.start(), depth), module.end() depth += 1 - return found if position is not None and depth == 0 and inside is None else None + return found if depth == 0 and inside is None else None + + +def declared(source: bytes) -> list[str] | None: + """The name of each `#[cfg(test)] mod name;` of source, a test module kept in a file of its own, in the order they stand. + None where a `#[path]` attribute moves such a file, or a string or comment is never closed.""" + names = [] + position = 0 + while match := SCAN.search(source, position): + if (after := after_token(source, match)) is None: + return None + position = after + if match.group() == b"#[cfg(test)]" and (declaration := DECLARATION.match(source, position)): + if PATH_ATTRIBUTE.search(declaration.group("attributes")): + return None + names.append(declaration.group("name").decode()) + return names + + +def homes(path: str, name: str) -> list[str]: + """Where the file of the module `name`, declared in the Rust file at path, may stand, by its path from the same top. A crate root + (`lib.rs`, `main.rs`) and a `mod.rs` keep their modules beside them; any other file keeps them in a folder of its own name.""" + declaring = pathlib.PurePosixPath(path) + folder = declaring.parent if declaring.name in KEEP_BESIDE else declaring.parent / declaring.stem + return [str(folder / f"{name}.rs"), str(folder / name / "mod.rs")] + + +def after_token(source: bytes, match: re.Match[bytes]) -> int | None: + """The offset after match, or after the comment, string or raw string that match opens; None where that is never closed.""" + if match.group() == b"/*": + return after_comment(source, match.end()) + if match.group() == b'"': + return after_string(source, match.end()) + if match.group("hashes") is not None: + return after_raw_string(source, match.end(), match.group("hashes")) + return match.end() def after_comment(source: bytes, position: int) -> int | None: diff --git a/bin/task_bench/test_rust_test_modules.py b/bin/task_bench/test_rust_test_modules.py index 6db68697..cfd977c5 100644 --- a/bin/task_bench/test_rust_test_modules.py +++ b/bin/task_bench/test_rust_test_modules.py @@ -103,6 +103,30 @@ class ModulesTest(unittest.TestCase): self.assertIsNone(modules(source)) +def declared(source: str) -> list[str] | None: + return rust_test_modules.declared(source.encode()) + + +class DeclaredTest(unittest.TestCase): + def test_lists_each_test_module_the_file_declares_without_a_body(self): + self.assertEqual(declared("#[cfg(test)]\nmod tests;\n#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks;\n"), ["tests", "checks"]) + + def test_leaves_out_an_inline_module_and_a_declaration_that_is_no_test_module(self): + self.assertEqual(declared(LIB + "mod util;\n#[cfg(feature = \"x\")]\nmod extra;\n"), []) + + def test_leaves_out_a_declaration_in_a_comment_or_a_string(self): + source = '// #[cfg(test)]\n// mod a;\n/* #[cfg(test)] mod b; */\nconst C: &str = "#[cfg(test)] mod c;";\nconst D: &str = r#"#[cfg(test)] mod d;"#;\n' + self.assertEqual(declared(source), []) + + def test_cannot_tell_where_a_declaration_moves_its_file_with_a_path_attribute(self): + self.assertIsNone(declared('#[cfg(test)]\n#[path = "elsewhere.rs"]\nmod tests;\n')) + + def test_cannot_tell_where_a_string_or_comment_is_never_closed(self): + for source in ("#[cfg(test)]\nmod tests;\nconst A: &str = \"\n", "/* open\n#[cfg(test)]\nmod tests;\n"): + with self.subTest(source=source): + self.assertIsNone(declared(source)) + + class TellsApartTest(unittest.TestCase): def test_tells_the_modules_of_a_rust_file_apart_where_they_can_be(self): self.assertEqual([tells_apart("lib.rs", b"fn a() {}"), tells_apart("lib.rs", b"fn a() {")], [True, False]) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 9d0c1d1c..b9252306 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -17,7 +17,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from task_bench import api_proxy, bench_folder, main, runs from test_env import assert_not_root, isolated_env -from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, opened, ran_tests, TimedOut +from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, opened, ran_tests, rust_test_files, TimedOut from task_bench.bugs.plant import drawn from claude_code.entries import Entry, entry_from from failure import Failure @@ -613,6 +613,34 @@ class RunOutcomesTest(unittest.TestCase): mutant = Mutant("lib.rs", 2, "lib.rs:2:7 replace + with -", (b" a + b",), (b" a - b",)) self.assertIsNone(main.planted(self.bench(), 1, mutant)) + def rust_bench(self, files: dict[str, str], *runs: Ran | Failure) -> main.Bench: + for path, text in files.items(): + (self.tree / path).parent.mkdir(parents=True, exist_ok=True) + (self.tree / path).write_text(text) + return self.bench(*runs) + + ADD = "pub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n#[cfg(test)]\nmod tests;\n" + ADDING = Mutant("src/lib.rs", 2, "src/lib.rs:2:7 replace + with -", (b" a + b",), (b" a - b",)) + + def test_a_rust_mutant_in_a_test_file_of_its_own_is_passed_over(self): + bench = self.rust_bench({"src/lib.rs": self.ADD, "src/tests.rs": "fn t() { assert!(1 + 1 == 2); }\n"}) + mutant = Mutant("src/tests.rs", 1, "src/tests.rs:1:20 replace + with -", (b"fn t() { assert!(1 + 1 == 2); }",), (b"fn t() { assert!(1 - 1 == 2); }",)) + self.assertIsNone(main.planted(bench, 1, mutant)) + + def test_a_rust_mutant_in_a_tree_whose_declared_test_file_is_not_found_is_passed_over(self): + self.assertIsNone(main.planted(self.rust_bench({"src/lib.rs": self.ADD}), 1, self.ADDING)) + + def test_a_rust_mutant_in_code_beside_a_test_file_goes_on_to_the_tests(self): + broke = Failure("docker could not start: No such file or directory") + self.assertEqual(main.planted(self.rust_bench({"src/lib.rs": self.ADD, "src/tests.rs": ""}, broke), 1, self.ADDING), broke) + + def test_a_rust_mutant_in_a_tree_whose_rust_file_cannot_be_read_fails_the_bench_naming_the_file(self): + assert_not_root(self) + bench = self.rust_bench({"src/lib.rs": self.ADD, "src/tests.rs": "", "src/other.rs": ""}) + (self.tree / "src/other.rs").chmod(0) + self.addCleanup((self.tree / "src/other.rs").chmod, 0o644) + self.assertFailsWith(main.planted(bench, 1, self.ADDING), "could not find the Rust test files beside src/lib.rs: ") + class ContainersTest(unittest.TestCase): IN_TREE = ["--memory", "512m", "--memory-swap", "512m", "--user", "1000:1000", "--env", "HOME=/tmp", "--volume", "/tree:/work", "--workdir", "/work"] @@ -772,6 +800,55 @@ class CheckedTreeTest(unittest.TestCase): checked_tree(planted, copy, str(self.root / "check")) self.assertEqual(self.held("check")["src/new.rs"], added) + DECLARING = "fn a() { 1 }\n#[cfg(test)]\nmod tests;\n" + + def test_takes_a_rust_test_in_a_file_of_its_own_as_planted_and_the_rest_as_fixed(self): + planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests", "src/other.rs": "bug"}) + copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n", "src/tests.rs": "rewritten", "src/other.rs": "fixed"}) + checked_tree(planted, copy, str(self.root / "check")) + self.assertEqual(self.held("check"), {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n", "src/tests.rs": "old tests", "src/other.rs": "fixed"}) + + def test_takes_a_rust_test_file_the_fix_deleted_as_planted(self): + planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) + copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n"}) + checked_tree(planted, copy, str(self.root / "check")) + self.assertEqual(self.held("check")["src/tests.rs"], "old tests") + + def test_takes_a_rust_test_file_the_fix_added_as_fixed_since_the_planted_tree_declares_none(self): + planted = self.tree("planted", {"src/lib.rs": "fn a() { 1 }\n"}) + copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n", "src/tests.rs": "mine"}) + checked_tree(planted, copy, str(self.root / "check")) + self.assertEqual(self.held("check")["src/tests.rs"], "mine") + + def test_a_task_with_acceptance_tests_takes_a_rust_test_file_as_fixed(self): + planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) + copy = self.tree("copy", {"src/lib.rs": self.DECLARING, "src/tests.rs": "new tests"}) + checked_tree(planted, copy, str(self.root / "check"), rust_tests_planted=False) + self.assertEqual(self.held("check")["src/tests.rs"], "new tests") + + def test_finds_a_rust_test_file_where_the_module_system_puts_it(self): + cases = { + "beside a crate root": ({"src/lib.rs": self.DECLARING, "src/tests.rs": ""}, {"src/tests.rs"}), + "as a folder with a mod.rs": ({"src/main.rs": self.DECLARING, "src/tests/mod.rs": ""}, {"src/tests/mod.rs"}), + "in the folder of a module file": ({"src/pick.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), + "beside a mod.rs": ({"src/pick/mod.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), + "declared by no file": ({"src/lib.rs": "fn a() {}\n", "src/tests.rs": ""}, set()), + } + for name, (files, found) in cases.items(): + with self.subTest(name): + self.assertEqual(rust_test_files(self.tree(name.replace(" ", "-"), files)), found) + + def test_cannot_find_a_rust_test_file_that_is_not_where_its_declaration_puts_it_or_cannot_be_read_from_it(self): + cases = { + "missing": {"src/lib.rs": self.DECLARING}, + "beside a module file, where only a crate root has its modules": {"src/pick.rs": self.DECLARING, "src/tests.rs": ""}, + "moved by a path attribute": {"src/lib.rs": '#[cfg(test)]\n#[path = "t.rs"]\nmod tests;\n', "src/t.rs": ""}, + "in a declaring file whose string is never closed": {"src/lib.rs": '#[cfg(test)]\nmod tests;\nconst A: &str = "\n', "src/tests.rs": ""}, + } + for name, files in cases.items(): + with self.subTest(name): + self.assertIsNone(rust_test_files(self.tree(name.replace(" ", "-"), files))) + def test_leaves_a_rust_link_as_a_link_whatever_it_points_at(self): planted = self.tree("planted", {"z.rs": "fn a() {}\n#[cfg(test)]\nmod tests {}\n", "a.txt": "text"}) copy = self.tree("copy", {"a.txt": "text"}) -- 2.52.0 From b1becdc866fac31bc8ab19fa17f75d12574cacd4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:06:06 +0100 Subject: [PATCH 02/13] Record the reading cost of the chunks since the last figures --- docs/reading-cost.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/reading-cost.md b/docs/reading-cost.md index eb2266a4..aadcccc3 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -3711,3 +3711,33 @@ Read most (opens and searches): - `bin/release_plan/release_standing.py` 3 - `CHANGELOG.md` 1 - `bin/deploy_release/cut.py` 1 + +## Reading cost, chunk 7361c9bb3e9a, finished 2026-11-27T14:31:28Z + +48295 new input tokens before the first commit. + +Read most (opens and searches): + +- `agents/stability-reviewer.md` 3 +- `README.md` 1 +- `agents/systems-architect.md` 1 +- `skills/larv-review/SKILL.md` 1 + +## Reading cost, chunk 73ef8355db51, finished 2026-11-27T14:52:23Z + +61386 new input tokens before the first commit. + +Read most (opens and searches): + +- `agents/stability-reviewer.md` 3 +- `skills/larv-review/SKILL.md` 2 + +## Reading cost, chunk bca62e26ca73, finished 2026-11-27T15:01:02Z + +56538 new input tokens before the first commit. + +Read most (opens and searches): + +- `skills/larv-review/SKILL.md` 2 +- `agents/product-owner-reviewer.md` 1 +- `agents/prose-reviewer.md` 1 -- 2.52.0 From eb2c54ec948300e09769f2f19b19e3e73fc8bffd Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:10:58 +0100 Subject: [PATCH 03/13] Sort the imports of runs.py by their first binding --- bin/task_bench/runs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index ed327f16..e6316e06 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -8,11 +8,11 @@ import shutil import subprocess import typing +from task_bench.rust_test_modules import declared, homes, with_tests_of from mutate_changes.tool_process import failed, Ran from failure import Failure from mutate_changes.changed_lines import is_test from task_bench.api_proxy import PORT -from task_bench.rust_test_modules import declared, homes, with_tests_of MODEL = "claude-haiku-5-5" # Where each run's container mounts its copy of the code, and its home folder: the paths in a run's stream start there. -- 2.52.0 From 001dfcfc85a33130835f4fb63fa7981630221939 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:33:58 +0100 Subject: [PATCH 04/13] Test that the search for Rust test files leaves a link unread --- bin/task_bench/test_task_bench.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index b9252306..5e36a5aa 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -838,6 +838,11 @@ class CheckedTreeTest(unittest.TestCase): with self.subTest(name): self.assertEqual(rust_test_files(self.tree(name.replace(" ", "-"), files)), found) + def test_leaves_a_rust_link_unread_whatever_it_points_at_when_it_looks_for_test_files(self): + tree = self.tree("linked", {"src/lib.rs": self.DECLARING, "src/tests.rs": ""}) + os.symlink("missing.rs", os.path.join(tree, "src/ghost.rs")) + self.assertEqual(rust_test_files(tree), {"src/tests.rs"}) + def test_cannot_find_a_rust_test_file_that_is_not_where_its_declaration_puts_it_or_cannot_be_read_from_it(self): cases = { "missing": {"src/lib.rs": self.DECLARING}, -- 2.52.0 From fb9ca7757b5669580b726e89348ad28389e783df Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:36:18 +0100 Subject: [PATCH 05/13] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20no=20findin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 71842a6a85559fd34a11614b751ae4bd051e492f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:05:37 +0100 Subject: [PATCH 06/13] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20a=20fix=20t?= =?UTF-8?q?hat=20drops=20a=20test=20file's=20declaration=20gets=20the=20pl?= =?UTF-8?q?anted=20file,=20and=20any=20file=20may=20stand=20beside=20or=20?= =?UTF-8?q?under=20its=20declarer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/runs.py | 13 ++++++------ bin/task_bench/rust_test_modules.py | 27 ++++++++++++------------ bin/task_bench/test_rust_test_modules.py | 23 ++++++++++++++++---- bin/task_bench/test_task_bench.py | 15 +++++++++---- 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index e6316e06..3d94c29a 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -168,11 +168,12 @@ def checked_tree(planted: str, copy: str, into: str, rust_tests_planted: bool = """Makes at `into` the tree the tests check a fix in: `planted`, the code with the bug as Haiku got it, with each file that is no test as `copy` holds it after the fix. So a test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder, where Go's tests keep the output they expect. Where rust_tests_planted, a Rust file's inline `#[cfg(test)]` - modules stand as the planted file has them too, as `with_tests_of` says, and so does each Rust file that `rust_test_files` finds. + modules stand as the planted file has them too, as `with_tests_of` says, and so does each file that `rust_test_files` finds in + the planted tree. Raises OSError where a file cannot be copied.""" shutil.copytree(planted, into, symlinks=True) - # `rust_test_files` is None for a tree whose declarations it cannot resolve, which the bench passes over where it plants the bug. + # `rust_test_files` is None for a tree with a declaration whose file it can't find, and the bench plants no bug in such a tree. rust_tests = (rust_test_files(planted) or set()) if rust_tests_planted else set() before, after = set(entries(planted)), set(entries(copy)) for path in before - after: @@ -209,8 +210,8 @@ def of_tests(path: str, rust_tests: typing.AbstractSet[str] = frozenset()) -> bo def rust_test_files(tree: str) -> set[str] | None: - """The Rust files under tree that a `#[cfg(test)] mod name;` declaration names, by their paths from tree. None where a - declaration names no file there, or `declared` cannot tell a file's declarations. + """The Rust files under tree that a `#[cfg(test)] mod name;` declaration names, by their paths from tree. None where a declaration + names no file there, or a string or comment of a Rust file is never closed: the tree may hold a test file this can't find. Raises OSError where a file cannot be read.""" files = set(entries(tree)) @@ -222,10 +223,10 @@ def rust_test_files(tree: str) -> set[str] | None: if names is None: return None for name in names: - standing = [home for home in homes(path, name) if home in files] + standing = files.intersection(homes(path, name)) if not standing: return None - found.add(standing[0]) + found |= standing return found diff --git a/bin/task_bench/rust_test_modules.py b/bin/task_bench/rust_test_modules.py index 2ebed22c..1588b8b7 100644 --- a/bin/task_bench/rust_test_modules.py +++ b/bin/task_bench/rust_test_modules.py @@ -1,6 +1,6 @@ """The `#[cfg(test)]` modules of a Rust file, which stand in the file of the code they test or, as `mod name;` declares, in a file of -their own. Here are where each inline one is, which files hold the others, and a file with the modules of another file put in place -of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone.""" +their own. Here are where each inline one is, which modules a file declares and where their files may stand, and a file with the +modules of another file put in place of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone.""" import pathlib import re @@ -20,9 +20,7 @@ COMMENT_EDGE = re.compile(rb"/\*|\*/") # What follows the attribute that starts an inline module: any other attributes, an optional visibility, then `mod name {`. MODULE = re.compile(rb"\s*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*\{") # What follows the attribute that starts a module kept in a file of its own: any other attributes, an optional visibility, then `mod name;`. -DECLARATION = re.compile(rb"\s*(?P(?:#\[[^\]]*\]\s*)*)(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*;") -PATH_ATTRIBUTE = re.compile(rb"#\[\s*path\b") -KEEP_BESIDE = ("lib.rs", "main.rs", "mod.rs") +DECLARATION = re.compile(rb"\s*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*;") def tells_apart(path: str, source: bytes) -> bool: @@ -59,8 +57,8 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: def declared(source: bytes) -> list[str] | None: - """The name of each `#[cfg(test)] mod name;` of source, a test module kept in a file of its own, in the order they stand. - None where a `#[path]` attribute moves such a file, or a string or comment is never closed.""" + """The name of each `#[cfg(test)] mod name;` of source, a test module kept in a file of its own, in the order they stand. None where + a string or comment is never closed.""" names = [] position = 0 while match := SCAN.search(source, position): @@ -68,18 +66,16 @@ def declared(source: bytes) -> list[str] | None: return None position = after if match.group() == b"#[cfg(test)]" and (declaration := DECLARATION.match(source, position)): - if PATH_ATTRIBUTE.search(declaration.group("attributes")): - return None names.append(declaration.group("name").decode()) return names def homes(path: str, name: str) -> list[str]: - """Where the file of the module `name`, declared in the Rust file at path, may stand, by its path from the same top. A crate root - (`lib.rs`, `main.rs`) and a `mod.rs` keep their modules beside them; any other file keeps them in a folder of its own name.""" + """Each place the file of the module `name`, declared in the Rust file at path, may stand, by its path from the same top. Rust keeps + it in the folder of the declaring file, or in a folder of that file's name where it is a module file, `a.rs` for `a/`; which of the + two the file is depends on what the crate's root is, so both count.""" declaring = pathlib.PurePosixPath(path) - folder = declaring.parent if declaring.name in KEEP_BESIDE else declaring.parent / declaring.stem - return [str(folder / f"{name}.rs"), str(folder / name / "mod.rs")] + return [str(folder / part) for folder in (declaring.parent, declaring.parent / declaring.stem) for part in (f"{name}.rs", f"{name}/mod.rs")] def after_token(source: bytes, match: re.Match[bytes]) -> int | None: @@ -121,7 +117,10 @@ def with_tests_of(planted: bytes, copy: bytes) -> bytes: Where planted's modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where planted has some and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module - to put them in.""" + to put them in. The same holds for the `mod name;` declarations of planted, whose files stand as planted: a fix that drops one + would leave its tests uncompiled.""" + if not set(declared(planted) or []) <= set(declared(copy) or []): + return planted before, after = modules(planted), modules(copy) # Haiku's file stands where planted's modules can't be told apart. The bench never plants a bug in such a file, and a guess at # which module is which could swap one test for another. Haiku's file is also what the check took before the bench put back diff --git a/bin/task_bench/test_rust_test_modules.py b/bin/task_bench/test_rust_test_modules.py index cfd977c5..6acb2e27 100644 --- a/bin/task_bench/test_rust_test_modules.py +++ b/bin/task_bench/test_rust_test_modules.py @@ -7,7 +7,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from task_bench import rust_test_modules -from task_bench.rust_test_modules import tells_apart +from task_bench.rust_test_modules import homes, tells_apart LIB = textwrap.dedent("""\ pub fn add(a: i32, b: i32) -> i32 { @@ -118,15 +118,20 @@ class DeclaredTest(unittest.TestCase): source = '// #[cfg(test)]\n// mod a;\n/* #[cfg(test)] mod b; */\nconst C: &str = "#[cfg(test)] mod c;";\nconst D: &str = r#"#[cfg(test)] mod d;"#;\n' self.assertEqual(declared(source), []) - def test_cannot_tell_where_a_declaration_moves_its_file_with_a_path_attribute(self): - self.assertIsNone(declared('#[cfg(test)]\n#[path = "elsewhere.rs"]\nmod tests;\n')) - def test_cannot_tell_where_a_string_or_comment_is_never_closed(self): for source in ("#[cfg(test)]\nmod tests;\nconst A: &str = \"\n", "/* open\n#[cfg(test)]\nmod tests;\n"): with self.subTest(source=source): self.assertIsNone(declared(source)) +class HomesTest(unittest.TestCase): + def test_lists_where_the_file_of_a_declared_module_may_stand(self): + self.assertEqual(homes("src/pick.rs", "tests"), ["src/tests.rs", "src/tests/mod.rs", "src/pick/tests.rs", "src/pick/tests/mod.rs"]) + + def test_lists_the_places_by_the_path_from_the_top_of_a_file_there(self): + self.assertEqual(homes("lib.rs", "t"), ["t.rs", "t/mod.rs", "lib/t.rs", "lib/t/mod.rs"]) + + class TellsApartTest(unittest.TestCase): def test_tells_the_modules_of_a_rust_file_apart_where_they_can_be(self): self.assertEqual([tells_apart("lib.rs", b"fn a() {}"), tells_apart("lib.rs", b"fn a() {")], [True, False]) @@ -136,6 +141,16 @@ class TellsApartTest(unittest.TestCase): class WithTestsOfTest(unittest.TestCase): + def test_takes_the_planted_file_where_the_fix_dropped_a_declaration_of_a_test_file(self): + planted = "fn a() { 1 }\n#[cfg(test)]\nmod tests;\n#[cfg(test)]\nmod more;\n" + for name, fixed in {"dropped": "fn a() { 2 }\n", "one of two kept": "fn a() { 2 }\n#[cfg(test)]\nmod more;\n", "string never closed": 'fn a() { "\n#[cfg(test)]\nmod tests;\n#[cfg(test)]\nmod more;\n'}.items(): + with self.subTest(name): + self.assertEqual(with_tests_of(planted, fixed), planted) + + def test_takes_the_fixed_file_where_it_keeps_each_declaration_and_adds_one(self): + fixed = "fn a() { 2 }\n#[cfg(test)]\nmod more;\n#[cfg(test)]\nmod tests;\n" + self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed) + def test_takes_the_code_as_fixed_and_the_tests_as_planted(self): planted = LIB.replace("a + b", "a - b") fixed = LIB.replace("assert_eq!(add(1, 2), 3);", "assert_eq!(add(1, 2), 0);") diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 5e36a5aa..199569c7 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -338,7 +338,7 @@ class BenchTest(unittest.TestCase): # Passing tests with the bug planted: no message to tell Haiku. (self.repo / "calc_test.go").write_text("exit 0\n") self.commit("Tests that pass with the bug") - self.assertEqual(self.bench(), Failure("None of the 2 mutants the tests kill becomes a bug: each is on a line the head changed, or the test it fails doesn't print a message.")) + self.assertEqual(self.bench(), Failure("None of the 2 mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, in a Rust file, a `#[cfg(test)] mod name;` of the tree names a file the bench can't find.")) def test_a_run_the_api_refuses_fails_the_bench_and_still_removes_what_it_made(self): self.env["FAKE_REFUSED_FROM"] = "1" @@ -639,7 +639,7 @@ class RunOutcomesTest(unittest.TestCase): bench = self.rust_bench({"src/lib.rs": self.ADD, "src/tests.rs": "", "src/other.rs": ""}) (self.tree / "src/other.rs").chmod(0) self.addCleanup((self.tree / "src/other.rs").chmod, 0o644) - self.assertFailsWith(main.planted(bench, 1, self.ADDING), "could not find the Rust test files beside src/lib.rs: ") + self.assertFailsWith(main.planted(bench, 1, self.ADDING), "could not read the Rust files for the mutant in src/lib.rs: ") class ContainersTest(unittest.TestCase): @@ -808,6 +808,12 @@ class CheckedTreeTest(unittest.TestCase): checked_tree(planted, copy, str(self.root / "check")) self.assertEqual(self.held("check"), {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n", "src/tests.rs": "old tests", "src/other.rs": "fixed"}) + def test_takes_the_planted_rust_file_where_the_fix_dropped_the_declaration_of_a_test_file(self): + planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) + copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n", "src/tests.rs": "old tests"}) + checked_tree(planted, copy, str(self.root / "check")) + self.assertEqual(self.held("check"), {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) + def test_takes_a_rust_test_file_the_fix_deleted_as_planted(self): planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n"}) @@ -831,6 +837,7 @@ class CheckedTreeTest(unittest.TestCase): "beside a crate root": ({"src/lib.rs": self.DECLARING, "src/tests.rs": ""}, {"src/tests.rs"}), "as a folder with a mod.rs": ({"src/main.rs": self.DECLARING, "src/tests/mod.rs": ""}, {"src/tests/mod.rs"}), "in the folder of a module file": ({"src/pick.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), + "beside another crate root": ({"src/bin/tool.rs": self.DECLARING, "src/bin/tests.rs": ""}, {"src/bin/tests.rs"}), "beside a mod.rs": ({"src/pick/mod.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), "declared by no file": ({"src/lib.rs": "fn a() {}\n", "src/tests.rs": ""}, set()), } @@ -843,11 +850,11 @@ class CheckedTreeTest(unittest.TestCase): os.symlink("missing.rs", os.path.join(tree, "src/ghost.rs")) self.assertEqual(rust_test_files(tree), {"src/tests.rs"}) - def test_cannot_find_a_rust_test_file_that_is_not_where_its_declaration_puts_it_or_cannot_be_read_from_it(self): + def test_cannot_find_a_rust_test_file_that_is_not_where_its_declaration_puts_it_or_cannot_be_read_from_the_tree(self): cases = { "missing": {"src/lib.rs": self.DECLARING}, - "beside a module file, where only a crate root has its modules": {"src/pick.rs": self.DECLARING, "src/tests.rs": ""}, "moved by a path attribute": {"src/lib.rs": '#[cfg(test)]\n#[path = "t.rs"]\nmod tests;\n', "src/t.rs": ""}, + "inside an inline module": {"src/lib.rs": "mod a {\n#[cfg(test)]\nmod tests;\n}\n", "src/a/tests.rs": ""}, "in a declaring file whose string is never closed": {"src/lib.rs": '#[cfg(test)]\nmod tests;\nconst A: &str = "\n', "src/tests.rs": ""}, } for name, files in cases.items(): -- 2.52.0 From cd916e58e3593b5f71ea8aa6c87fa1ac6edb7a92 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:05:37 +0100 Subject: [PATCH 07/13] =?UTF-8?q?Answer=20product-owner=20round=201:=201?= =?UTF-8?q?=20=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20the=20he?= =?UTF-8?q?lp=20and=20the=20no-bug=20message=20say=20which=20tree=20makes?= =?UTF-8?q?=20a=20Rust=20mutant=20pass=20over?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 826997c2..a6558e03 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -38,14 +38,14 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. A test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder. The bench tells a test by its path: a folder named `test`, `tests` or `__tests__`, or a file named `test_*.py`, `*_test.py`, `*_test.go`, `*.test.*` or `*.spec.*`. A test of any other name counts as code, such as `src/PickTest.php` or - `src/pick-test.js`, so Haiku's change to it stands. In a Rust file, each - inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. Where the planted file has such - modules and Haiku's file lacks one of them, or its modules cannot be told apart, the planted file stands whole; where the planted - file has none, or its modules cannot be told apart, Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment - is never closed, is passed over. A Rust file that a `#[cfg(test)] mod name;` in another file of the planted tree names, as - `src/name.rs` or `src/name/mod.rs` beside a `lib.rs`, `main.rs` or `mod.rs`, or in the folder of any other file's name, is a - test: it stands as the planted tree has it, and no mutant is planted in it. A Rust mutant in a tree where such a declaration - names no file there, as one that `#[path]` moves does, is passed over. + `src/pick-test.js`, so Haiku's change to it stands. In a Rust file, each inline `#[cfg(test)]` module stands as the planted + file has it, and the rest is as Haiku left it. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it + names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where the + planted file has such modules or declarations and Haiku's file lacks one of them, or its modules cannot be told apart, the + planted file stands whole; where the planted file has none, or its modules cannot be told apart, Haiku's stands. A Rust mutant + whose file's modules cannot be told apart, as where two share a name or a brace, string or comment is never closed, is passed + over. So is each Rust mutant of a tree where a `#[cfg(test)] mod name;` names no file the bench finds, or where a Rust file has a + string or comment that is never closed. No bug is planted in a file that such a declaration names. --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 @@ -529,7 +529,7 @@ def planted_tasks(bench: Bench, mutants: list[Mutant], seed: int, bugs: int) -> return task tasks += [task] if task else [] if not tasks: - return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, or the test it fails doesn't print a message.") + return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, in a Rust file, a `#[cfg(test)] mod name;` of the tree names a file the bench can't find.") return Planned(tasks, [] if len(tasks) == bugs else [f"Planted {len(tasks)} of the {bugs} bugs asked for: no other mutant the tests kill becomes one."], {"seed": seed}) @@ -590,9 +590,9 @@ def planted(bench: Bench, number: int, mutant: Mutant) -> Task | Failure | None: # The check keeps a Rust file's test modules as planted, which it can only do where it tells them apart. if bugs is None or not all(tells_apart(mutant.path, source) for source in bugs.values()): return None - # ... and a Rust test in a file of its own, which it can only keep where it finds each such file. + # ... and the Rust test files of each side's tree, which it keeps only where it finds every one. A mutant in one of them is no bug. if mutant.path.endswith(".rs"): - standing = on_disk(f"find the Rust test files beside {mutant.path}", lambda: [rust_test_files(tree) for tree in bench.trees.values()]) + standing = on_disk(f"read the Rust files for the mutant in {mutant.path}", lambda: [rust_test_files(tree) for tree in bench.trees.values()]) if isinstance(standing, Failure): return standing if any(tests is None or mutant.path in tests for tests in standing): -- 2.52.0 From a720f461c21b1ae2baa41799e1261a87b452f4d5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:05:37 +0100 Subject: [PATCH 08/13] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20docstrings,?= =?UTF-8?q?=20comments=20and=20help=20reworded=20in=20the=20two=20commits?= =?UTF-8?q?=20above?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 86efe8fa57f96b105aa995d41bf864c58c034795 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:11:30 +0100 Subject: [PATCH 09/13] =?UTF-8?q?Answer=20product-owner=20round=202:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20name=20t?= =?UTF-8?q?he=20Rust=20causes=20in=20the=20no-bug=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/main.py | 2 +- bin/task_bench/test_task_bench.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index a6558e03..7dba4ee9 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -529,7 +529,7 @@ def planted_tasks(bench: Bench, mutants: list[Mutant], seed: int, bugs: int) -> return task tasks += [task] if task else [] if not tasks: - return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, in a Rust file, a `#[cfg(test)] mod name;` of the tree names a file the bench can't find.") + return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, for a Rust mutant, it stands in a test file or the tree holds a `#[cfg(test)] mod name;` that names no file the bench finds or a string or comment that is never closed.") return Planned(tasks, [] if len(tasks) == bugs else [f"Planted {len(tasks)} of the {bugs} bugs asked for: no other mutant the tests kill becomes one."], {"seed": seed}) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 199569c7..7498f8b1 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -338,7 +338,7 @@ class BenchTest(unittest.TestCase): # Passing tests with the bug planted: no message to tell Haiku. (self.repo / "calc_test.go").write_text("exit 0\n") self.commit("Tests that pass with the bug") - self.assertEqual(self.bench(), Failure("None of the 2 mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, in a Rust file, a `#[cfg(test)] mod name;` of the tree names a file the bench can't find.")) + self.assertEqual(self.bench(), Failure("None of the 2 mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, for a Rust mutant, it stands in a test file or the tree holds a `#[cfg(test)] mod name;` that names no file the bench finds or a string or comment that is never closed.")) def test_a_run_the_api_refuses_fails_the_bench_and_still_removes_what_it_made(self): self.env["FAKE_REFUSED_FROM"] = "1" -- 2.52.0 From ce92bedde98eb009644a84de533c9d74af2e5596 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:11:31 +0100 Subject: [PATCH 10/13] =?UTF-8?q?Answer=20prose=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(0=20misread);=20say=20what?= =?UTF-8?q?=20with=5Ftests=5Fof=20returns=20first,=20and=20word=20the=20Ru?= =?UTF-8?q?st=20help=20and=20docstrings=20plainly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/main.py | 7 ++++--- bin/task_bench/rust_test_modules.py | 16 ++++++++-------- bin/task_bench/test_rust_test_modules.py | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 7dba4ee9..9d4375be 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -40,9 +40,10 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. `*_test.go`, `*.test.*` or `*.spec.*`. A test of any other name counts as code, such as `src/PickTest.php` or `src/pick-test.js`, so Haiku's change to it stands. In a Rust file, each inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it - names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where the - planted file has such modules or declarations and Haiku's file lacks one of them, or its modules cannot be told apart, the - planted file stands whole; where the planted file has none, or its modules cannot be told apart, Haiku's stands. A Rust mutant + names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where + Haiku's file lacks a module or declaration of the planted file's, or the planted file has inline modules and Haiku's cannot be + told apart, the planted file stands whole; where the planted file's inline modules cannot be told apart, or it has none and + Haiku's cannot be told apart, Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment is never closed, is passed over. So is each Rust mutant of a tree where a `#[cfg(test)] mod name;` names no file the bench finds, or where a Rust file has a string or comment that is never closed. No bug is planted in a file that such a declaration names. diff --git a/bin/task_bench/rust_test_modules.py b/bin/task_bench/rust_test_modules.py index 1588b8b7..c5759683 100644 --- a/bin/task_bench/rust_test_modules.py +++ b/bin/task_bench/rust_test_modules.py @@ -57,7 +57,7 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: def declared(source: bytes) -> list[str] | None: - """The name of each `#[cfg(test)] mod name;` of source, a test module kept in a file of its own, in the order they stand. None where + """The name of each `#[cfg(test)] mod name;` of source, in the order they stand. The module's code is in a file of its own. None where a string or comment is never closed.""" names = [] position = 0 @@ -71,9 +71,9 @@ def declared(source: bytes) -> list[str] | None: def homes(path: str, name: str) -> list[str]: - """Each place the file of the module `name`, declared in the Rust file at path, may stand, by its path from the same top. Rust keeps - it in the folder of the declaring file, or in a folder of that file's name where it is a module file, `a.rs` for `a/`; which of the - two the file is depends on what the crate's root is, so both count.""" + """Each place the file of the module `name`, declared in the Rust file at path, may stand, as paths from the same top: beside the + declaring file, or in a folder named for it without `.rs`. Which of the two holds depends on the kind of file the declarer is, which + this doesn't know, so both count.""" declaring = pathlib.PurePosixPath(path) return [str(folder / part) for folder in (declaring.parent, declaring.parent / declaring.stem) for part in (f"{name}.rs", f"{name}/mod.rs")] @@ -115,10 +115,10 @@ def with_tests_of(planted: bytes, copy: bytes) -> bytes: """copy with each of its test modules replaced by the one of that name in planted, and each that planted lacks left out. So a test a fix changed, removed or added doesn't count. - Where planted's modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where - planted has some and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module - to put them in. The same holds for the `mod name;` declarations of planted, whose files stand as planted: a fix that drops one - would leave its tests uncompiled.""" + Where copy lacks a `mod name;` declaration of planted's, or cannot have its declarations told apart, planted is returned: the file + of that module stands as planted, and a fix that drops the declaration would leave its tests uncompiled. Otherwise, where planted's + modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where planted has some + and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module to put them in.""" if not set(declared(planted) or []) <= set(declared(copy) or []): return planted before, after = modules(planted), modules(copy) diff --git a/bin/task_bench/test_rust_test_modules.py b/bin/task_bench/test_rust_test_modules.py index 6acb2e27..6fd3fef9 100644 --- a/bin/task_bench/test_rust_test_modules.py +++ b/bin/task_bench/test_rust_test_modules.py @@ -6,8 +6,8 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from task_bench import rust_test_modules from task_bench.rust_test_modules import homes, tells_apart +from task_bench import rust_test_modules LIB = textwrap.dedent("""\ pub fn add(a: i32, b: i32) -> i32 { -- 2.52.0 From f5940f265d97adc250e81960aed76e80638292a2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:38:20 +0100 Subject: [PATCH 11/13] Test that rust_test_files gathers the files of every declaring file --- bin/task_bench/test_task_bench.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 7498f8b1..15b669d8 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -839,6 +839,7 @@ class CheckedTreeTest(unittest.TestCase): "in the folder of a module file": ({"src/pick.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), "beside another crate root": ({"src/bin/tool.rs": self.DECLARING, "src/bin/tests.rs": ""}, {"src/bin/tests.rs"}), "beside a mod.rs": ({"src/pick/mod.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), + "declared in two files": ({"src/lib.rs": self.DECLARING, "src/tests.rs": "", "src/pick.rs": self.DECLARING.replace("tests", "checks"), "src/pick/checks.rs": ""}, {"src/tests.rs", "src/pick/checks.rs"}), "declared by no file": ({"src/lib.rs": "fn a() {}\n", "src/tests.rs": ""}, set()), } for name, (files, found) in cases.items(): -- 2.52.0 From 814779c9a137d301f3a28477944b519470d78b68 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:43:33 +0100 Subject: [PATCH 12/13] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20compare=20e?= =?UTF-8?q?ach=20test=20declaration's=20whole=20text,=20so=20an=20attribut?= =?UTF-8?q?e=20a=20fix=20adds=20to=20it=20counts=20as=20a=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/main.py | 2 +- bin/task_bench/runs.py | 6 +++--- bin/task_bench/rust_test_modules.py | 18 ++++++++++-------- bin/task_bench/test_rust_test_modules.py | 14 ++++++++++++-- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 9d4375be..0267c490 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -41,7 +41,7 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. `src/pick-test.js`, so Haiku's change to it stands. In a Rust file, each inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where - Haiku's file lacks a module or declaration of the planted file's, or the planted file has inline modules and Haiku's cannot be + Haiku's file lacks a module of the planted file's or a declaration as written there, or the planted file has inline modules and Haiku's cannot be told apart, the planted file stands whole; where the planted file's inline modules cannot be told apart, or it has none and Haiku's cannot be told apart, Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment is never closed, is passed diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index 3d94c29a..85d380f9 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -219,10 +219,10 @@ def rust_test_files(tree: str) -> set[str] | None: for path in sorted(files): if not path.endswith(".rs") or os.path.islink(os.path.join(tree, path)): continue - names = declared(pathlib.Path(tree, path).read_bytes()) - if names is None: + declarations = declared(pathlib.Path(tree, path).read_bytes()) + if declarations is None: return None - for name in names: + for name, _ in declarations: standing = files.intersection(homes(path, name)) if not standing: return None diff --git a/bin/task_bench/rust_test_modules.py b/bin/task_bench/rust_test_modules.py index c5759683..c32a3a04 100644 --- a/bin/task_bench/rust_test_modules.py +++ b/bin/task_bench/rust_test_modules.py @@ -56,18 +56,19 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: return found if depth == 0 and inside is None else None -def declared(source: bytes) -> list[str] | None: - """The name of each `#[cfg(test)] mod name;` of source, in the order they stand. The module's code is in a file of its own. None where +def declared(source: bytes) -> list[tuple[str, str]] | None: + """Each `#[cfg(test)] mod name;` of source, in the order they stand, as the module's name and the declaration's text from the + `#[cfg(test)]` to the `;` with its spaces and newlines squeezed to one space. The module's code is in a file of its own. None where a string or comment is never closed.""" - names = [] + found = [] position = 0 while match := SCAN.search(source, position): if (after := after_token(source, match)) is None: return None position = after if match.group() == b"#[cfg(test)]" and (declaration := DECLARATION.match(source, position)): - names.append(declaration.group("name").decode()) - return names + found.append((declaration.group("name").decode(), " ".join(source[match.start():declaration.end()].decode().split()))) + return found def homes(path: str, name: str) -> list[str]: @@ -115,11 +116,12 @@ def with_tests_of(planted: bytes, copy: bytes) -> bytes: """copy with each of its test modules replaced by the one of that name in planted, and each that planted lacks left out. So a test a fix changed, removed or added doesn't count. - Where copy lacks a `mod name;` declaration of planted's, or cannot have its declarations told apart, planted is returned: the file - of that module stands as planted, and a fix that drops the declaration would leave its tests uncompiled. Otherwise, where planted's + Where copy lacks a `mod name;` declaration of planted's, as written, or cannot have its declarations told apart, planted is + returned: the file of that module stands as planted, and a fix that drops the declaration or adds an attribute such as `#[path]` + to it would leave its tests uncompiled or unrun. Otherwise, where planted's modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where planted has some and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module to put them in.""" - if not set(declared(planted) or []) <= set(declared(copy) or []): + if not {text for _, text in declared(planted) or []} <= {text for _, text in declared(copy) or []}: return planted before, after = modules(planted), modules(copy) # Haiku's file stands where planted's modules can't be told apart. The bench never plants a bug in such a file, and a guess at diff --git a/bin/task_bench/test_rust_test_modules.py b/bin/task_bench/test_rust_test_modules.py index 6fd3fef9..83e7ecf1 100644 --- a/bin/task_bench/test_rust_test_modules.py +++ b/bin/task_bench/test_rust_test_modules.py @@ -103,13 +103,13 @@ class ModulesTest(unittest.TestCase): self.assertIsNone(modules(source)) -def declared(source: str) -> list[str] | None: +def declared(source: str) -> list[tuple[str, str]] | None: return rust_test_modules.declared(source.encode()) class DeclaredTest(unittest.TestCase): def test_lists_each_test_module_the_file_declares_without_a_body(self): - self.assertEqual(declared("#[cfg(test)]\nmod tests;\n#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks;\n"), ["tests", "checks"]) + self.assertEqual(declared("#[cfg(test)]\nmod tests;\n#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks;\n"), [("tests", "#[cfg(test)] mod tests;"), ("checks", "#[cfg(test)] #[allow(dead_code)] pub(crate) mod checks;")]) def test_leaves_out_an_inline_module_and_a_declaration_that_is_no_test_module(self): self.assertEqual(declared(LIB + "mod util;\n#[cfg(feature = \"x\")]\nmod extra;\n"), []) @@ -147,6 +147,16 @@ class WithTestsOfTest(unittest.TestCase): with self.subTest(name): self.assertEqual(with_tests_of(planted, fixed), planted) + def test_takes_the_planted_file_where_the_fix_keeps_a_declaration_but_changes_it(self): + planted = "fn a() { 1 }\n#[cfg(test)]\nmod tests;\n" + for name, declaration in {"never compiled": "#[cfg(test)]\n#[cfg(any())]\nmod tests;", "another file": '#[cfg(test)]\n#[path = "empty.rs"]\nmod tests;', "renamed": "#[cfg(test)]\nmod other;"}.items(): + with self.subTest(name): + self.assertEqual(with_tests_of(planted, f"fn a() {{ 2 }}\n{declaration}\n"), planted) + + def test_takes_the_fixed_file_where_it_keeps_a_declaration_with_other_spacing(self): + fixed = "fn a() { 2 }\n#[cfg(test)] mod tests;\n" + self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed) + def test_takes_the_fixed_file_where_it_keeps_each_declaration_and_adds_one(self): fixed = "fn a() { 2 }\n#[cfg(test)]\nmod more;\n#[cfg(test)]\nmod tests;\n" self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed) -- 2.52.0 From 177122f18abf14670f46e93479cc341928cdcf9a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 18:44:25 +0100 Subject: [PATCH 13/13] Finish item 539 in the plan --- CHANGELOG.md | 1 + todo.md | 13 ------------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8838b6b..929dd94b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- task-bench leaves out of a fix a change Haiku makes to a Rust test kept in a file of its own, `#[cfg(test)] mod name;` and the file it names, and plants no bug in that file. - The technical principles ask code to read why a call failed from a status code, a documented exit code or a typed error, and not from message text. - `chunk-preflight` reports a project whose tracked code is mostly space-indented while no `.editorconfig` or formatter setting sets the indent, and the technical principles' hard-tabs default is overridden only by such a setting plus a recorded decision. - `chunk-pr push` waits for the forge to show the pushed commit as the head of the branch's open pull request before it asks for a review, and fails naming the pull request where the forge does not. diff --git a/todo.md b/todo.md index 6394897f..44557cbe 100644 --- a/todo.md +++ b/todo.md @@ -17,7 +17,6 @@ | 523 | 0.17.0 | | | **Make the security pass and stability-reviewer check that a new secret's docs name its scope and its reach, such as the other repositories its account can use.** | 1 | 1 | 2 | 2 | 1 | 1.1 by 2 | 0.9 | | 541 | 0.17.0 | | | **Find a Gitea pull request by its branch and head however many pull requests are newer, so `chunk-pr clean`, `chunk-pr merge` and `chunk-preflight` see an older one.** | 2 | 2 | 3 | 5 | 2 | 1 by 2 | 0.8 | | 545 | 0.17.0 | | | **Have chunk-preflight name each next-release item with no `Touches:` list while others wait, and have loop-claude launch a subagent that writes the lists before it starts the next chunk.** | 3 | 2 | 3 | 6 | 6 | 1.1 by 4 | 0.6 | -| 539 | 0.17.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a Rust test kept in a file of its own.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | | 544 | 0.17.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a PHP or JavaScript test that PHPUnit or `node --test` finds by a name `is_test` does not know.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | | 480 | 0.18.0 | | owner | **Resolve every path the tools use in one module: the release root (the folder the running code ships in), the config folder, the state folder and the Claude home. Then only that module names `~/.claude`, and the loop still runs from `~/.claude`.** | 3 | 2 | 3 | 6 | 6 | 1.6 by 3, code health by 3 | 2.4 | | 481 | 0.18.0 | 480 | owner | **Put the release's tools on `PATH` for every session the loop starts and every hook it runs, name them bare in the prose in place of `~/.claude/bin/`, and refuse the old spelling in new prose.** | 3 | 2 | 3 | 6 | 6 | 1.4 by 2, code health by 2 | 1.6 | @@ -144,18 +143,6 @@ Three changes: Test each with a fake plan: all lists present, one missing with other items waiting, one missing alone in its release, and a list the item's edit made stale is left alone. -### 539. Leave out of a `task-bench` fix a change Haiku makes to a Rust test kept in a file of its own. - -Rust may keep its unit tests out of line: `#[cfg(test)] mod tests;` in `src/lib.rs`, the tests in `src/tests.rs`. `mutate_changes.changed_lines.is_test` tells a test by a folder named `test`, `tests` or `__tests__`, or by a file name such as `test_*.py` or `*_test.go`, so `src/tests.rs` counts as code, and `checked_tree` in `bin/task_bench/runs.py` takes it as Haiku left it. 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. - -Recommended: treat as a test a `.rs` file that a `#[cfg(test)] mod ;` declaration in another file of the planted tree names (src/.rs or src//mod.rs, beside the declaring file), found with the scanner in `bin/task_bench/rust_test_modules.py`; where the file cannot be found, pass the mutant over. A product-owner / stability finding on item 532's chunk raised this. Changing `is_test` itself would change what `mutate-changes` skips, so keep the change inside task-bench. - -Touches: -- `bin/task_bench/runs.py`: `of_tests`, `checked_tree` (small) -- `bin/task_bench/rust_test_modules.py` -- `bin/task_bench/test_task_bench.py` -- `bin/task_bench/main.py`: lines 30-37 - ### 544. Leave out of a `task-bench` fix a change Haiku makes to a PHP or JavaScript test that PHPUnit or `node --test` finds by a name `is_test` does not know. PHPUnit finds a test by `*Test.php`, wherever it stands, and `node --test` also by `*-test.js`, `*_test.js`, `test-*.js` and `test.js`, with `.ts`, `.mjs` and `.cjs` alike. `mutate_changes.changed_lines.is_test` tells a test by a folder named `test`, `tests` or `__tests__`, or by a name such as `*.test.*`, so `src/PickTest.php` and `src/pick-test.js` count as code. `checked_tree` in `bin/task_bench/runs.py` then takes such a file as Haiku left it, so a fix that edits or deletes the failing test passes, at both sides alike, and `place_files` in `bin/task_bench/bugs/plant.py` may hand the file to the mutation tool as code. The help's Check paragraph says so. -- 2.52.0