Answer security round 1: 1 🔴, 0 🟡 (0 misread); pass over a data source whose script writes a .git, and test the script's failures
CI / tests (pull_request) Successful in 3m45s

This commit is contained in:
2026-11-23 19:18:26 +01:00
parent 82a03e9a1b
commit 2ffa4908c9
3 changed files with 53 additions and 4 deletions
+2 -2
View File
@@ -53,8 +53,8 @@ doesn't run, so --seed, --bugs and --prefix don't go with it.
`bench-tasks` that holds a feature's three parts and `generate-register`, an executable file; --tasks features leaves such 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 script is
seeded, so it writes the same bytes at both sides; the bench passes over a task whose script fails, adds no file, or writes one
register at the base and another at the head. `spec.md` tells Haiku where the register is and what to add: say, the importer,
seeded, so it writes the same bytes at both sides; the bench passes over a task whose script fails, adds no file, writes a
`.git`, or writes one register at the base and another at the head. `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. Make up a publisher no real data could come from: a country code
+5 -1
View File
@@ -1,6 +1,7 @@
"""The register a data-source task hands Haiku: the files the task's `generate-register` writes into the tree Haiku starts in.
The script is seeded, so it writes the same register at the base and at the head, byte for byte; a task whose script doesn't is
passed over."""
import os
import pathlib
import shutil
@@ -46,7 +47,7 @@ def registered_trees(bench: Bench, name: str, script: str) -> dict[Side, str] |
def generated(containers: Containers, tree: str, script: str) -> dict[str, bytes] | Failure:
"""The register script writes when run at the top of tree, in the bench's image with no network: each file new to the tree,
by its path from the top. NotGenerated where the script runs out of time, fails or writes no new file."""
by its path from the top. NotGenerated where the script runs out of time, fails, writes a `.git` or writes no new file."""
before = set(entries(tree))
ran = run_in_image(containers, ["--network", "none", *in_tree(containers, tree), "--volume", f"{script}:{MOUNTED}:ro", containers.image, MOUNTED])
if isinstance(ran, TimedOut):
@@ -55,5 +56,8 @@ def generated(containers: Containers, tree: str, script: str) -> dict[str, bytes
return ran
if ran.code:
return NotGenerated(f"its {GENERATE} exits {ran.code}")
# git runs on the host in this tree next, and would run what a `.git/config` there names, outside the container.
if os.path.lexists(os.path.join(tree, ".git")):
return NotGenerated(f"its {GENERATE} writes a `.git`")
register = on_disk(f"read the register in {tree}", lambda: {path: pathlib.Path(tree, path).read_bytes() for path in entries(tree) if path not in before})
return register or NotGenerated(f"its {GENERATE} doesn't write any new file")
+46 -1
View File
@@ -1,18 +1,23 @@
"""`task-bench --tasks data-sources` from its command line down: a whole bench of the data sources in a project's `bench-tasks`
folder, with docker and claude faked, and the faults of a `generate-register`."""
import json
import os
import pathlib
import sys
import tempfile
import textwrap
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from task_bench.test_feature_tasks import added, BenchOfTasksCase, feature
from task_bench.tasks import DATA_SOURCE
from task_bench.tasks import Asked, Bench, DATA_SOURCE
from task_bench.runs import Containers, TimedOut
from failure import Failure
from task_bench.feature_tasks import features
from task_bench.registers import generated, NotGenerated, registered_trees
from task_bench import main
from mutate_changes.tool_process import Ran
SPEC = "Import `register.csv`, a register of first names, into `names.txt`, with `import.sh`.\n"
# Writes the same register wherever it runs.
@@ -115,6 +120,15 @@ class DataSourceBenchTest(BenchOfTasksCase):
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.")
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.
marker = self.root / "ran-on-the-host"
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.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")
@@ -130,6 +144,37 @@ class DataSourceBenchTest(BenchOfTasksCase):
self.assertIn("names-qz: the tests fail with its reference patch at the base.", report.reason)
class GeneratedTest(unittest.TestCase):
"""What a run of the script leaves, with docker faked as a function."""
def setUp(self):
folder = tempfile.TemporaryDirectory()
self.addCleanup(folder.cleanup)
self.tree = pathlib.Path(folder.name, "tree")
self.tree.mkdir()
def containers(self, docker) -> Containers:
return Containers(docker, "task-bench-test", "true", 512, "1000:1000")
def test_a_script_that_runs_out_of_time_generates_no_register(self):
ran = generated(self.containers(lambda args, **_: TimedOut("docker run still ran after 30 min")), str(self.tree), "/tasks/generate-register")
self.assertIsInstance(ran, NotGenerated)
self.assertEqual(ran.reason, "its generate-register runs out of time")
def test_says_which_register_it_could_not_read(self):
def docker(args, **_):
os.symlink("missing", self.tree / "register.csv")
return Ran(0, "")
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)
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)
trees = registered_trees(bench, "names-qz", "/tasks/generate-register")
self.assertTrue(trees.reason.startswith(f"could not copy the base's tree to {self.tree / 'data-sources/names-qz/base'}: "), trees.reason)
class OptionsTest(unittest.TestCase):
def options(self, *argv: str):
return main.options(["--image", "golang:1.27.4", "--test", "go test ./...", *argv], {"CLAUDE_CODE_OAUTH_TOKEN": "t"})