Pass over a data source whose script the image cannot run

This commit is contained in:
2026-11-23 20:37:46 +01:00
parent 5727456738
commit c9948496eb
5 changed files with 34 additions and 11 deletions
+8 -8
View File
@@ -54,14 +54,14 @@ doesn't run, so --seed, --bugs and --prefix don't go with it.
a folder out. Before Haiku starts, the bench runs the script at the top of a copy of each side's tree, in the image with no
network, and the files it adds are the register: a made-up dataset in the format a real publisher would use. The container
holds that tree and the script alone, so the script can't read another file of the task's folder. Seed the script, so that it
writes the same bytes at both sides. The bench passes over a task whose script doesn't exit 0, runs for 30 minutes, adds no
file, adds a link or anything else that is no regular file, writes a `.git`, or writes one register at the base and another at
the head; the report says which, with the last line a failing script printed. `spec.md` tells Haiku where the register is and
what to add: say, the importer, the data it imports and the licence entry. The reference patch adds them, and the acceptance
tests check them, as by running the importer again and comparing what it writes with the committed data. A task counts, and a
run passes, as for a feature; the tree that is checked holds the register as Haiku left it. Name the made-up publisher's
country by a code no real data could carry: one ISO 3166-1 leaves to its users, such as QZ, and never XK, which is Kosovo's in
practice. The table has a row per data source and side.
writes the same bytes at both sides. The bench passes over a task whose script doesn't exit 0, as where the image lacks its
interpreter, runs for 30 minutes, adds no file, adds a link or anything else that is no regular file, writes a `.git`, or
writes one register at the base and another at the head; the report says which, with the last line a failing script printed.
`spec.md` tells Haiku where the register is and what to add: say, the importer, the data it imports and the licence entry. The
reference patch adds them, and the acceptance tests check them, as by running the importer again and comparing what it writes
with the committed data. A task counts, and a run passes, as for a feature; the tree that is checked holds the register as
Haiku left it. Name the made-up publisher's country by a code no real data could carry: one ISO 3166-1 leaves to its users,
such as QZ, and never XK, which is Kosovo's in practice. The table has a row per data source and side.
It prints the base and the head, then a table: a row per bug and side with how many fixes passed and the medians, over the runs
that finished, of the input, cache-write, cache-read and output tokens, the turns, the wall time, and the reads and searches before
+6 -1
View File
@@ -6,7 +6,7 @@ import pathlib
import shutil
from task_bench.tasks import Bench, committed, on_disk
from task_bench.runs import Containers, entries, in_tree, run_in_image, TimedOut
from task_bench.runs import Containers, entries, in_tree, NotStarted, run_in_image, TimedOut
from failure import Failure
from task_bench.figures import Side, SIDES
@@ -15,6 +15,8 @@ from task_bench.figures import Side, SIDES
GENERATE = "generate-register"
# Where a container finds the script, outside the tree, so the tree never holds it.
MOUNTED = f"/{GENERATE}"
# What `docker run` exits with where docker itself failed, before any container started.
DOCKER_FAILED = 125
class NotGenerated(Failure):
@@ -53,6 +55,9 @@ def generated(containers: Containers, tree: str, script: str) -> dict[str, bytes
ran = run_in_image(containers, ["--network", "none", *in_tree(containers, tree), "--volume", f"{script}:{MOUNTED}:ro", containers.image, MOUNTED])
if isinstance(ran, TimedOut):
return NotGenerated(f"its {GENERATE} runs out of time")
# With 126 or 127 the container started and the image could not run the script, as the task's fault as any other exit.
if isinstance(ran, NotStarted) and ran.ran.code != DOCKER_FAILED:
ran = ran.ran
if isinstance(ran, Failure):
return ran
if ran.code:
+7 -1
View File
@@ -41,6 +41,12 @@ class TimedOut(Failure):
"""docker still ran when its time was up."""
@dataclasses.dataclass(frozen=True)
class NotStarted(Failure):
"""`docker run` exited with one of NOT_STARTED, as ran holds it."""
ran: Ran
class Docker(typing.Protocol):
"""Runs `docker <args>` and waits for it, at most `seconds`, and is TimedOut after that. Its output goes to `stdout` and its
errors to `stderr` where the call gives them, and into the Ran otherwise."""
@@ -148,7 +154,7 @@ def run_in_image(containers: Containers, args: list[str], stdout: typing.IO[byte
containers.docker(["rm", "--force", containers.running], seconds=120)
return ran
if ran.code in NOT_STARTED:
return Failure(f"docker run could not start its command, and exited {ran.code}: {ran.output.strip()}".removesuffix(": "))
return NotStarted(f"docker run could not start its command, and exited {ran.code}: {ran.output.strip()}".removesuffix(": "), ran)
return ran
+10
View File
@@ -192,6 +192,16 @@ class GeneratedTest(unittest.TestCase):
ran = generated(self.containers(lambda args, **_: Ran(3, f"first\nsecond\n{'x' * 201}\n")), str(self.tree), "/tasks/generate-register")
self.assertEqual(ran.reason, f"its generate-register exits 3 after printing `{'x' * 200}`")
def test_a_script_the_image_cannot_run_is_the_tasks_fault_and_a_docker_that_fails_is_not(self):
docker = lambda code: lambda args, **_: Ran(code, "exec /generate-register: no such file or directory\n")
for code in (126, 127):
ran = generated(self.containers(docker(code)), str(self.tree), "/tasks/generate-register")
self.assertIsInstance(ran, NotGenerated)
self.assertEqual(ran.reason, f"its generate-register exits {code} after printing `exec /generate-register: no such file or directory`")
ran = generated(self.containers(docker(125)), str(self.tree), "/tasks/generate-register")
self.assertNotIsInstance(ran, NotGenerated)
self.assertEqual(ran.reason, "docker run could not start its command, and exited 125: exec /generate-register: no such file or directory")
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")
+3 -1
View File
@@ -632,7 +632,9 @@ class ContainersTest(unittest.TestCase):
def test_a_run_whose_command_never_started_is_a_failure_that_says_what_docker_printed(self):
for code in (125, 126, 127):
self.assertEqual(ran_tests(self.containers(run=Ran(code, "sh: gotestsum: not found\n")), "/tree"), Failure(f"docker run could not start its command, and exited {code}: sh: gotestsum: not found"))
ran = ran_tests(self.containers(run=Ran(code, "sh: gotestsum: not found\n")), "/tree")
self.assertIsInstance(ran, Failure)
self.assertEqual(ran.reason, f"docker run could not start its command, and exited {code}: sh: gotestsum: not found")
self.assertEqual(ran_tests(self.containers(run=Ran(124, "late")), "/tree"), Ran(124, "late"))
self.assertEqual(ran_tests(self.containers(run=Ran(128, "killed")), "/tree"), Ran(128, "killed"))
self.assertEqual(fix_attempted(self.containers(run=Ran(125, "")), "/tree", "got 3", self.stream), Failure(f"docker run could not start its command, and exited 125; its errors are in {self.stream.with_suffix('.stderr')}"))