Refuse a register entry that is no regular file, and say data source in what task-bench prints

This commit is contained in:
2026-11-23 19:49:22 +01:00
parent c798278406
commit 44c0f13883
11 changed files with 94 additions and 63 deletions
+29 -12
View File
@@ -7,6 +7,7 @@ import sys
import tempfile
import textwrap
import unittest
import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
@@ -40,7 +41,7 @@ REFERENCE = textwrap.dedent(f"""\
+Ada
+Bo
""")
# Imports the register right at the head. At the base it commits data its importer doesn't make. It logs its prompt and the files
# Imports the register correctly at the head. At the base it commits data its importer doesn't make. It logs its prompt and the files
# it was handed.
CLAUDE = textwrap.dedent(f"""\
import json, os, pathlib, sys
@@ -75,9 +76,9 @@ class DataSourceBenchTest(BenchOfTasksCase):
folder = pathlib.Path(report[-1].removeprefix(main.KEPT))
# halve, which has no generate-register, is a feature: no task of this bench.
self.assertEqual(report[:-1], [
f"task-bench: base {self.base[:12]}, head {self.head[:12]}. 1 data-source, each run 2 times at each side by claude-haiku-5-5 in Claude Code 2.1.330.",
f"task-bench: base {self.base[:12]}, head {self.head[:12]}. 1 data source, each run 2 times at each side by claude-haiku-5-5 in Claude Code 2.1.330.",
"",
"| Data-source | Side | Passed | Input | Cache write | Cache read | Output | Turns | Wall, s | Reads |",
"| Data source | Side | Passed | Input | Cache write | Cache read | Output | Turns | Wall, s | Reads |",
"|---|---|---|---|---|---|---|---|---|---|",
"| 1: names-qz | base | 0/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |",
"| 1: names-qz | head | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |",
@@ -94,7 +95,7 @@ class DataSourceBenchTest(BenchOfTasksCase):
results = json.loads((folder / "results.json").read_text())
self.assertEqual((results["data-sources"], results["runs"][0]["data-source"]), ({"1": "names-qz"}, 1))
self.assertTrue((folder / "runs/data-source-1-base-1.jsonl").is_file())
self.assertIn(f"\n## Data-source 1: names-qz\n\nThe spec Haiku was told:\n\n {SPEC}", (folder / "digest.md").read_text())
self.assertIn(f"\n## Data source 1: names-qz\n\nThe spec Haiku was told:\n\n {SPEC}", (folder / "digest.md").read_text())
# The script ran without a network, and git doesn't show Haiku that the register is new.
runs = [json.loads(line) for line in self.log.read_text().splitlines()]
generated = [args for args in runs if args[-1] == "/generate-register"]
@@ -112,13 +113,13 @@ class DataSourceBenchTest(BenchOfTasksCase):
self.assertEqual([found.name for found in features(self.tasks, DATA_SOURCE)], ["names-qz"])
def test_passes_over_a_data_source_whose_script_fails_writes_no_file_or_writes_another_register_at_the_head(self):
data_source(self.tasks / "a-fails", generate="#!/bin/sh\nexit 3\n")
data_source(self.tasks / "a-fails", generate="#!/bin/sh\necho made half\necho no seed given >&2\nexit 3\n")
data_source(self.tasks / "b-empty", generate="#!/bin/sh\ntrue\n")
# The register follows the tree it is generated in, so a seed doesn't regenerate it byte for byte.
data_source(self.tasks / "c-unseeded", generate="#!/bin/sh\nwc -c < calc.go > register.csv\n")
report = self.bench()
self.assertIsInstance(report, Failure)
self.assertEqual(report.reason, f"None of the 3 data-sources in {self.tasks} counts. a-fails: its generate-register exits 3 at the base. b-empty: its generate-register doesn't write any new file at the base. c-unseeded: its generate-register writes one register at the base and another at the head.")
self.assertEqual(report.reason, f"None of the 3 data sources in {self.tasks} counts. a-fails: its generate-register exits 3 after printing `no seed given` at the base. b-empty: its generate-register doesn't write any new file at the base. c-unseeded: its generate-register writes one register at the base and another at the head.")
def test_passes_over_a_data_source_whose_script_writes_a_git_folder_before_git_runs_in_its_tree(self):
# git on the host would run the filter as it adds the files, outside the container and with the token.
@@ -126,15 +127,15 @@ class DataSourceBenchTest(BenchOfTasksCase):
planted = f"#!/bin/sh\necho x > register.csv\nmkdir .git\nprintf '[filter \"x\"]\\n\\tclean = touch {marker}; cat\\n' > .git/config\necho '* filter=x' > .gitattributes\n"
data_source(self.tasks / "names-qz", generate=planted)
report = self.bench()
self.assertEqual(report.reason, f"None of the 1 data-sources in {self.tasks} counts. names-qz: its generate-register writes a `.git` at the base.")
self.assertEqual(report.reason, f"None of the 1 data sources in {self.tasks} counts. names-qz: its generate-register writes a `.git` at the base.")
self.assertFalse(marker.exists())
def test_fails_before_any_container_starts_where_a_part_is_at_fault_or_the_folder_holds_no_data_source(self):
empty = self.bench()
self.assertEqual(empty.reason, f"{self.tasks} holds no data-source: a folder for each, with spec.md, reference.patch, generate-register and the acceptance tests under acceptance")
self.assertEqual(empty.reason, f"{self.tasks} holds no data source: a folder for each, with spec.md, reference.patch, generate-register and the acceptance tests under acceptance")
data_source(self.tasks / "names-qz", mode=0o644)
unrunnable = self.bench()
self.assertEqual(unrunnable.reason, f"the data-source in {self.tasks / 'names-qz'} has a generate-register that is no executable file")
self.assertEqual(unrunnable.reason, f"the data source in {self.tasks / 'names-qz'} has a generate-register that is no executable file")
self.assertFalse(self.log.exists())
def test_passes_over_a_data_source_whose_reference_patch_leans_on_a_test_file_it_adds(self):
@@ -163,11 +164,27 @@ class GeneratedTest(unittest.TestCase):
def test_says_which_register_it_could_not_read(self):
def docker(args, **_):
os.symlink("missing", self.tree / "register.csv")
(self.tree / "register.csv").write_text("x")
return Ran(0, "")
ran = generated(self.containers(docker), str(self.tree), "/tasks/generate-register")
with unittest.mock.patch.object(pathlib.Path, "read_bytes", side_effect=PermissionError("denied")):
ran = generated(self.containers(docker), str(self.tree), "/tasks/generate-register")
self.assertNotIsInstance(ran, NotGenerated)
self.assertTrue(ran.reason.startswith(f"could not read the register in {self.tree}: "), ran.reason)
self.assertEqual(ran.reason, f"could not read the register in {self.tree}: denied")
def test_a_link_or_a_pipe_is_no_register_and_the_host_reads_neither(self):
for name, write in (("register.csv", lambda path: os.symlink("/etc/hostname", path)), ("made/pipe", lambda path: (path.parent.mkdir(), os.mkfifo(path)))):
with self.subTest(name):
def docker(args, **_):
(self.tree / "plain.csv").write_text("x")
write(self.tree / name)
return Ran(0, "")
ran = generated(self.containers(docker), str(self.tree), "/tasks/generate-register")
self.assertIsInstance(ran, NotGenerated)
self.assertEqual(ran.reason, f"its generate-register writes `{name}`, which is no regular file")
def test_a_script_that_fails_without_a_word_is_named_by_its_exit_code_alone(self):
ran = generated(self.containers(lambda args, **_: Ran(2, "\n")), str(self.tree), "/tasks/generate-register")
self.assertEqual(ran.reason, "its generate-register exits 2")
def test_says_which_tree_it_could_not_copy(self):
bench = Bench("/checkout", {}, {"base": str(self.tree / "missing")}, Asked(DATA_SOURCE, 1), self.containers(None), self.tree, None, print)