From c1412f598c17ab023a39da721e0a97d80cdc6574 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 12:39:28 +0100 Subject: [PATCH] Run each side's tests in a committed copy, so tests that call git work --- bin/task_bench/main.py | 4 ++-- bin/task_bench/tasks.py | 8 ++++++-- bin/task_bench/test_task_bench.py | 13 ++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 467ed46b..d96fc969 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -514,7 +514,7 @@ def benched(bench: Bench, planned: Planner) -> list[str] | Failure: def baseline_failure(bench: Bench) -> Failure | None: """Why a side's tests don't pass without a task; None where they pass at both sides.""" for side, tree in bench.trees.items(): - ran = tests_in_copy(bench.containers, tree, bench.folder) + ran = tests_in_copy(bench.containers, tree, bench.folder, bench.git) if isinstance(ran, Failure) or ran.code: return ran if isinstance(ran, Failure) else failed(f"The tests fail at the {side} without {bench.asked.kind.without}: the test command", ran) return None @@ -630,7 +630,7 @@ def planted_tree(bench: Bench, side: Side, tree: pathlib.Path, path: str, change (tree / path).write_bytes(changed) except OSError as failure: return Failure(f"could not plant the bug in {tree}: {failure}") - ran = tests_in_copy(bench.containers, str(tree), bench.folder) + ran = tests_in_copy(bench.containers, str(tree), bench.folder, bench.git) # Tests that never end under the bug have no message. if isinstance(ran, TimedOut): return None diff --git a/bin/task_bench/tasks.py b/bin/task_bench/tasks.py index d2e7f893..63123b9f 100644 --- a/bin/task_bench/tasks.py +++ b/bin/task_bench/tasks.py @@ -103,12 +103,16 @@ def committed(git: Git, tree: str) -> Failure | None: return None -def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path) -> Ran | Failure: - """The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree.""" +def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path, git: Git) -> Ran | Failure: + """The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree. The copy is + committed first, since a project's tests may call git and a tree from `git archive` holds no repository.""" copy = folder / "tested" copied = on_disk(f"copy {tree} to test it", lambda: shutil.copytree(tree, copy, symlinks=True)) if isinstance(copied, Failure): return copied + if failure := committed(git, str(copy)): + shutil.rmtree(copy, ignore_errors=True) + return failure try: return ran_tests(containers, str(copy)) finally: diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 9205c16a..5c0f4d2a 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -298,6 +298,11 @@ class BenchTest(unittest.TestCase): self.assertEqual(log, "task-bench Import\n") self.assertEqual(subprocess.run(["git", "status", "--porcelain"], cwd=tree, env=self.env, check=True, capture_output=True, text=True).stdout, "") + def test_tests_that_call_git_run_in_a_repository_at_each_side(self): + # The sides' trees come from `git archive`, which leaves out `.git`; `git ls-files` exits 128 in a tree that isn't a repository. + found = self.bench(**{"--test": "git ls-files --error-unmatch calc.go >/dev/null && sh calc_test.go"}) + self.assertNotIsInstance(found, Failure, found) + def test_claude_runs_in_the_benchs_image_on_its_network_with_the_message_alone_and_the_token_by_name(self): self.bench(**{"--runs": "1"}) calls = self.calls() @@ -589,7 +594,13 @@ class RunOutcomesTest(unittest.TestCase): def test_a_tree_that_cannot_be_copied_for_its_tests_fails_the_bench_naming_it(self): gone = str(self.folder / "gone") - self.assertFailsWith(main.tests_in_copy(self.containers(), gone, self.folder), f"could not copy {gone} to test it: ") + self.assertFailsWith(main.tests_in_copy(self.containers(), gone, self.folder, self.bench().git), f"could not copy {gone} to test it: ") + + def test_a_copy_that_cannot_be_committed_fails_the_bench_and_is_removed(self): + tree = self.folder / "tree" + tree.mkdir(exist_ok=True) + self.assertFailsWith(main.tests_in_copy(self.containers(), str(tree), self.folder, lambda *args, **given: Failure("no git")), "no git") + self.assertFalse((self.folder / "tested").exists()) def test_a_tree_whose_folder_cannot_be_made_fails_the_bench_naming_it(self): (self.folder / "file").write_text("")