Leave out of a task-bench fix a change Haiku makes to a PHP or JavaScript test that PHPUnit or node --test finds by its name

This commit is contained in:
2026-11-27 21:57:32 +01:00
parent 2abe472919
commit 53b0f6ed30
7 changed files with 58 additions and 8 deletions
+3 -2
View File
@@ -7,7 +7,8 @@ import typing
from failure import Failure
from task_bench.bugs import go_bugs, php_bugs, python_bugs, rust_bugs, typescript_bugs
from mutate_changes.changed_lines import is_test, STRYKER
from mutate_changes.changed_lines import STRYKER
from task_bench.framework_tests import is_test_file
from task_bench.bugs.planted_mutant import Mutant
from mutate_changes.tool_process import Run
@@ -43,7 +44,7 @@ def language_of(path: str, languages: tuple[Language, ...] = LANGUAGES) -> Langu
def place_files(places: str) -> list[str]:
"""The files that hold a place in what `larv-review places` prints and are in a language of LANGUAGES, test files left out, in
the order of their paths."""
return sorted({path for path in PLACE.findall(places) if language_of(path) and not is_test(path)})
return sorted({path for path in PLACE.findall(places) if language_of(path) and not is_test_file(path)})
def killed_mutants(top: str, files: list[str], run: Run, jobs: int, languages: tuple[Language, ...] = LANGUAGES) -> list[Mutant] | Failure:
+3
View File
@@ -39,6 +39,9 @@ class PlaceFilesTest(unittest.TestCase):
def test_names_none_where_the_places_name_only_test_files_or_another_suffix(self):
self.assertEqual(place_files("- `tests/test_geo.py:3` `load`\n- `geo_test.py:3` `load`\n- `notes.pyc:1` `x`\n"), [])
def test_names_none_where_the_places_name_only_php_or_javascript_files_that_phpunit_or_node_test_finds(self):
self.assertEqual(place_files("- `src/PickTest.php:3` `load`\n- `src/pick-test.js:3` `load`\n- `src/Pick.php:3` `load`\n"), ["src/Pick.php"])
class DrawnTest(unittest.TestCase):
MUTANTS = [mutant("a.go", line) for line in range(1, 40)]
+15
View File
@@ -0,0 +1,15 @@
"""Which files PHPUnit and `node --test` find as tests by their names, beyond the ones `mutate_changes.changed_lines.is_test` tells.
`is_test` stays as it is: changing it would change what `mutate-changes` skips."""
import posixpath
import re
from mutate_changes.changed_lines import is_test, STRYKER
# PHPUnit's default suffix, wherever the file stands; node --test's `*-test`, `*_test`, `test-*` and `test` stems, in each suffix
# Stryker covers. node --test's `*.test.*` is `is_test`'s already.
FRAMEWORK_NAME = re.compile(rf".*Test\.php|(?:.*[-_]test|test|test-.*)(?:{'|'.join(re.escape(suffix) for suffix in STRYKER)})")
def is_test_file(path: str) -> bool:
"""Whether path is a test by its name or folder alone, as `is_test` or PHPUnit or `node --test` tells it."""
return is_test(path) or bool(FRAMEWORK_NAME.fullmatch(posixpath.basename(path)))
+3 -3
View File
@@ -37,9 +37,9 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream.
- Check. The test command runs over the planted tree with each file that is no test as Haiku left it; a fix passes where it exits 0.
A test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder. 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. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it
`*_test.go`, `*.test.*`, `*.spec.*` or `*Test.php`, or, in a JavaScript or TypeScript suffix, `*-test.*`, `*_test.*`,
`test-*.*` or `test.*`. A test of any other name counts as code, 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
+3 -3
View File
@@ -11,7 +11,7 @@ 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.framework_tests import is_test_file
from task_bench.api_proxy import PORT
MODEL = "claude-haiku-5-5"
@@ -205,8 +205,8 @@ def keep_rust_tests(planted_file: str, target: str) -> None:
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
"""Whether path is a test by its path alone, as `is_test_file` tells it, or one of rust_tests."""
return is_test_file(path) or "testdata" in pathlib.PurePath(path).parts or path in rust_tests
def rust_test_files(tree: str) -> set[str] | None:
+25
View File
@@ -0,0 +1,25 @@
import unittest
from task_bench.framework_tests import is_test_file
class IsTestFileTest(unittest.TestCase):
def test_tells_a_php_file_ending_in_Test_wherever_it_stands(self):
for path in ("src/PickTest.php", "PickTest.php", "app/Models/UserTest.php"):
with self.subTest(path=path):
self.assertTrue(is_test_file(path))
def test_tells_the_names_node_test_finds_in_each_suffix_stryker_covers(self):
for path in ("src/pick-test.js", "pick_test.mjs", "src/test-pick.cjs", "src/test.ts", "a/b/pick-test.tsx", "test.jsx", "x_test.mts", "test-x.cts"):
with self.subTest(path=path):
self.assertTrue(is_test_file(path))
def test_tells_what_is_test_tells(self):
for path in ("src/pick.test.js", "src/pick.spec.ts", "tests/pick.php", "a/__tests__/pick.js", "pick_test.go", "test_pick.py"):
with self.subTest(path=path):
self.assertTrue(is_test_file(path))
def test_takes_other_code_as_code(self):
for path in ("src/Pick.php", "src/Tester.php", "src/PickTest.phps", "src/pick.js", "src/latest.js", "src/pick-tests.js", "src/pickTest.js", "src/test-pick.json", "src/contest.ts", "src/Test.php.bak"):
with self.subTest(path=path):
self.assertFalse(is_test_file(path))
+6
View File
@@ -775,6 +775,12 @@ class CheckedTreeTest(unittest.TestCase):
checked_tree(planted, copy, str(self.root / "check"))
self.assertEqual(self.held("check"), {".git/HEAD": "ref", "calc.go": "fixed", "calc_test.go": "tests", "sub/new.go": "new", "sub/old_test.go": "old tests"})
def test_takes_a_php_or_javascript_test_by_the_name_its_framework_finds_it_by_as_planted(self):
planted = self.tree("planted", {"src/Pick.php": "bug", "src/PickTest.php": "tests", "src/pick.js": "bug", "src/pick-test.js": "tests", "src/gone-test.mjs": "old tests"})
copy = self.tree("copy", {"src/Pick.php": "fixed", "src/PickTest.php": "rewritten", "src/pick.js": "fixed", "src/pick-test.js": "rewritten", "src/new_test.ts": "added"})
checked_tree(planted, copy, str(self.root / "check"))
self.assertEqual(self.held("check"), {"src/Pick.php": "fixed", "src/PickTest.php": "tests", "src/gone-test.mjs": "old tests", "src/pick-test.js": "tests", "src/pick.js": "fixed"})
def test_takes_the_files_under_testdata_as_planted_since_a_test_reads_what_it_expects_there(self):
planted = self.tree("planted", {"calc.go": "bug", "testdata/want.golden": "3", "sub/testdata/gone.golden": "4", "testdata.go": "code"})
copy = self.tree("copy", {"calc.go": "fixed", "testdata/want.golden": "-1", "testdata/added.golden": "5", "testdata.go": "fixed"})