Keep a Rust file's test modules as planted when task-bench checks a fix
CI / tests (pull_request) Failing after 5m10s
CI / tests (pull_request) Failing after 5m10s
This commit is contained in:
+16
-1
@@ -11,6 +11,7 @@ import typing
|
||||
from mutate_changes.tool_process import failed, Ran
|
||||
from failure import Failure
|
||||
from mutate_changes.changed_lines import is_test
|
||||
from task_bench.rust_test_modules import with_tests_of
|
||||
from task_bench.api_proxy import PORT
|
||||
|
||||
MODEL = "claude-haiku-5-5"
|
||||
@@ -166,7 +167,7 @@ def in_tree(containers: Containers, tree: str) -> list[str]:
|
||||
def checked_tree(planted: str, copy: str, into: str) -> None:
|
||||
"""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.
|
||||
a `testdata` folder, where Go's tests keep the output they expect. A Rust file's `#[cfg(test)]` modules are the planted file's.
|
||||
|
||||
Raises OSError where a file cannot be copied."""
|
||||
shutil.copytree(planted, into, symlinks=True)
|
||||
@@ -184,6 +185,20 @@ def checked_tree(planted: str, copy: str, into: str) -> None:
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
os.unlink(target)
|
||||
shutil.copy2(os.path.join(copy, path), target, follow_symlinks=False)
|
||||
if path.endswith(".rs"):
|
||||
keep_rust_tests(os.path.join(planted, path), target)
|
||||
|
||||
|
||||
def keep_rust_tests(planted_file: str, target: str) -> None:
|
||||
"""Puts into the Rust file at target, a copy of Haiku's, the test modules of planted_file; see `with_tests_of`. A file the planted
|
||||
tree lacks, as a link or as a file, is left as it is, since it has no test to keep.
|
||||
|
||||
Raises OSError where a file cannot be read or written."""
|
||||
if os.path.islink(planted_file) or os.path.islink(target) or not os.path.isfile(planted_file):
|
||||
return
|
||||
# A Rust file is UTF-8; a byte that isn't survives the round trip.
|
||||
planted, copied = (pathlib.Path(file).read_bytes().decode("utf-8", "surrogateescape") for file in (planted_file, target))
|
||||
pathlib.Path(target).write_bytes(with_tests_of(planted, copied).encode("utf-8", "surrogateescape"))
|
||||
|
||||
|
||||
def of_tests(path: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user