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/bin/task_bench/main.py b/bin/task_bench/main.py index e7d9971b..0267c490 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -38,12 +38,15 @@ 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 test in a file of its own, as `#[cfg(test)] mod tests;` names, counts, since the bench - tells no such file from code. + `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 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 + 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 @@ -200,7 +203,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 @@ -527,7 +530,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, 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}) @@ -588,6 +591,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 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"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): + 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..85d380f9 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 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,22 @@ 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 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 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: - 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 +204,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 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)) + found = set() + for path in sorted(files): + if not path.endswith(".rs") or os.path.islink(os.path.join(tree, path)): + continue + declarations = declared(pathlib.Path(tree, path).read_bytes()) + if declarations is None: + return None + for name, _ in declarations: + standing = files.intersection(homes(path, name)) + if not standing: + return None + found |= standing + 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..c32a3a04 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 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 # What the scan steps over or stops at. A string, a char and a comment may hold a brace. @@ -17,6 +19,8 @@ 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*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*;") def tells_apart(path: str, source: bytes) -> bool: @@ -32,16 +36,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 +53,41 @@ 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[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.""" + 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)): + found.append((declaration.group("name").decode(), " ".join(source[match.start():declaration.end()].decode().split()))) + return found + + +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, 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")] + + +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: @@ -81,9 +116,13 @@ 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.""" + 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 {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 # 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 6db68697..83e7ecf1 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.rust_test_modules import homes, tells_apart from task_bench import rust_test_modules -from task_bench.rust_test_modules import tells_apart LIB = textwrap.dedent("""\ pub fn add(a: i32, b: i32) -> i32 { @@ -103,6 +103,35 @@ class ModulesTest(unittest.TestCase): self.assertIsNone(modules(source)) +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", "#[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"), []) + + 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_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]) @@ -112,6 +141,26 @@ 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_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) + 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 9d0c1d1c..15b669d8 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 @@ -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, 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" @@ -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 read the Rust files for the mutant in 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,68 @@ 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_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"}) + 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 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(): + 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_the_tree(self): + cases = { + "missing": {"src/lib.rs": self.DECLARING}, + "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(): + 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"}) 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 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.