From 814779c9a137d301f3a28477944b519470d78b68 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:43:33 +0100 Subject: [PATCH] =?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)