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
+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"})