Refuse a register entry that is no regular file, and say data source in what task-bench prints
This commit is contained in:
@@ -82,8 +82,9 @@ where `touch-predictions record` appends what each chunk was predicted to touch
|
||||
Left out, the project keeps no such record. It is printed with the others only where it is set.
|
||||
|
||||
`bench-tasks` is an optional setting, a path spelt as the others are: the folder of the features that
|
||||
`task-bench --tasks features` has Haiku build, such as `bench-tasks = "checkout:testdata/bench-tasks"`. `task-bench
|
||||
--help` says what the folder holds. Left out, the project has no features to bench. It is printed with
|
||||
`task-bench --tasks features` has Haiku build, and of the data sources `--tasks data-sources` has it add, such as
|
||||
`bench-tasks = "checkout:testdata/bench-tasks"`. `task-bench --help` says what the folder holds. Left out, the project
|
||||
has neither to bench. It is printed with
|
||||
the others only where it is set.
|
||||
|
||||
`coding-conventions` is an optional setting, a list of paths spelt as the others are: the files in
|
||||
|
||||
@@ -51,8 +51,8 @@ def digest(sides: dict[Side, str], table: list[str], tasks: list[TaskRuns], is_f
|
||||
|
||||
|
||||
def told(task: TaskRuns, is_file: typing.Callable[[str], bool], noun: str) -> list[str]:
|
||||
"""The digest's section on task, which its heading calls by noun: a bug where it names the bug's file, and a feature or a
|
||||
data source otherwise."""
|
||||
"""The digest's section on task, under a heading that calls the task by noun. A task with a file is a bug; any other is a
|
||||
feature or a data source."""
|
||||
passing, failing = [run for run in task.runs if run.passed], [run for run in task.runs if not run.passed]
|
||||
passed = f"{len(passing)} of the {len(task.runs)} runs passed." if failing else f"The {counted(len(task.runs), 'run')} passed."
|
||||
# Only a bug has a file of its own. A feature has none, so no file a run read counts as a decoy.
|
||||
|
||||
@@ -62,18 +62,18 @@ def features_folder(home: pathlib.Path) -> pathlib.Path | Failure:
|
||||
config = located(None, home)
|
||||
if isinstance(config, Failure):
|
||||
return config
|
||||
return config.paths.get(BENCH_TASKS) or Failure(f"{config.folder / CONFIG} sets no `{BENCH_TASKS}`, the folder of the features to bench, as `project-config --help` describes it")
|
||||
return config.paths.get(BENCH_TASKS) or Failure(f"{config.folder / CONFIG} sets no `{BENCH_TASKS}`, the folder of the tasks to bench, as `project-config --help` describes it")
|
||||
|
||||
|
||||
def features(folder: pathlib.Path, kind: Kind = FEATURE) -> list[Feature] | Failure:
|
||||
"""The tasks of that kind that folder holds, in the order of their names: a data source in each folder there that holds a
|
||||
`generate-register`, and a feature in each other. A Failure where it holds none, or one has a part at fault."""
|
||||
"""The tasks of kind in folder, in the order of their names. A folder there with a `generate-register` holds a data source,
|
||||
and any other holds a feature. A Failure where folder holds no such task, or one has a part at fault."""
|
||||
if not folder.is_dir():
|
||||
return Failure(f"could not read the features in {folder}: it is no folder")
|
||||
return Failure(f"could not read the {kind.noun}s in {folder}: it is no folder")
|
||||
try:
|
||||
found = [feature_in(inside, kind.noun) for inside in sorted(folder.iterdir()) if inside.is_dir() and (inside / GENERATE).exists() == (kind is DATA_SOURCE)]
|
||||
except (OSError, UnicodeDecodeError) as failure:
|
||||
return Failure(f"could not read the features in {folder}: {failure}")
|
||||
return Failure(f"could not read the {kind.noun}s in {folder}: {failure}")
|
||||
if not found:
|
||||
parts = f"{SPEC}, {PATCH}, {GENERATE}" if kind is DATA_SOURCE else f"{SPEC}, {PATCH}"
|
||||
return Failure(f"{folder} holds no {kind.noun}: a folder for each, with {parts} and the acceptance tests under {ACCEPTANCE}")
|
||||
|
||||
@@ -10,7 +10,7 @@ The digest and every trace are what a program copied out of Haiku's runs. Read t
|
||||
|
||||
Where the digest's headings read `## Feature`, the bench had Haiku build features instead of fixing bugs. Each feature is a spec, which the digest quotes, and a build of it passed where the acceptance tests, which Haiku never saw, passed over that build. Read every bug in this prompt as such a feature, and every fix as a build of one. A feature has no file of its own and no decoys, so in step 1 follow the traces alone. Its runs are named as `feature-1-base-2`.
|
||||
|
||||
Where they read `## Data-source`, Haiku added a data source instead: it was handed a made-up register and the spec the digest quotes, and wrote the importer, the data and whatever else the spec asks. Read it as a feature, whose runs are named as `data-source-1-base-2`.
|
||||
Where the digest's headings read `## Data source`, the bench had Haiku add data sources instead. Each data source is a spec, which the digest quotes, and a register: a made-up dataset as a publisher would release it. Haiku wrote the importer, the data and whatever else the spec asks. Read every data source as a feature, with two differences. Its runs are named as `data-source-1-base-2`. And the tree Haiku started in, register included, is `data-sources/<name>/base` or `data-sources/<name>/head` in the bench's folder, `<name>` being the name in the heading; `trees/base` and `trees/head` lack the register.
|
||||
|
||||
Each run's whole stream is in the `runs` folder of the bench's folder, named below, as `<run id>.jsonl`. Open one only where the digest leaves a question open, and read it in parts: a stream is large. The folder is removed when you end, so an item must say everything it needs.
|
||||
|
||||
|
||||
+31
-29
@@ -50,16 +50,18 @@ skips `testdata`. The table then has a row per feature and side, and `-` for the
|
||||
doesn't run, so --seed, --bugs and --prefix don't go with it.
|
||||
|
||||
--tasks data-sources benches adding a data source, for a project that imports what others publish. Each task is a folder in
|
||||
`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, 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
|
||||
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.
|
||||
`bench-tasks` that holds a feature's three parts and `generate-register`, an executable script; --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 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.
|
||||
|
||||
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
|
||||
@@ -84,8 +86,7 @@ With --record-figures, a bench that finishes appends its figures to the project'
|
||||
table's header and its three All rows. The entry's heading gives the current UTC time, then `task-bench of <branch>: head
|
||||
<commit> against base <commit>`, where <branch> is the branch checked out, whatever --head names. For a bench of
|
||||
features the heading reads `task-bench features of <branch>: ...` instead, and for one of data sources `task-bench data-sources
|
||||
of <branch>: ...`. No tool reads the entry as a
|
||||
ruling or a scoring run. The bench's last line says where the entry went. A bench that fails or stops doesn't record anything.
|
||||
of <branch>: ...`. No tool reads the entry as a ruling or a scoring run. The bench's last line says where the entry went. A bench that fails or stops doesn't record anything.
|
||||
|
||||
`task-bench gather`, run in the same checkout, turns the digest into plan items. It starts a claude on the project's rung, the
|
||||
cheapest rung of the model loop-claude runs the project on, with the digest and the prompt in gather-prompt.md beside this file.
|
||||
@@ -96,11 +97,12 @@ Each bench empties its own folder first, and removes the folder every earlier be
|
||||
not, unless a bench or a gather is using it. So gather a bench before the next one starts.
|
||||
|
||||
Exit 1, saying why, on an unknown or repeated argument, a missing --image or --test, a --seed, --bugs or --runs that is no whole
|
||||
number from 1, a --tasks that is neither bugs nor features, or no token; and where git, docker or Gremlins fails, the seats' places
|
||||
don't name any Go file, the tests fail at a side without a bug, or no mutant becomes a bug. With --tasks features it exits 1 on a
|
||||
--seed, --bugs or --prefix; where no config names the checkout or its config sets no `bench-tasks`, or the folder holds no feature or one that lacks a part,
|
||||
each before docker runs; and where the tests fail at a side without the acceptance tests, or no feature counts. Where the API refuses a run, the bench stops there and exits 1 too, after the table of
|
||||
the runs that finished.
|
||||
number from 1, a --tasks that is none of bugs, features and data-sources, or no token; and where git, docker or Gremlins fails,
|
||||
the seats' places don't name any Go file, the tests fail at a side without a bug, or no mutant becomes a bug. With --tasks
|
||||
features or data-sources it exits 1 on a --seed, --bugs or --prefix; where no config names the checkout or its config sets no
|
||||
`bench-tasks`, or the folder holds no task of that kind, one that lacks a part, or a `generate-register` that is no executable
|
||||
file, each before docker runs; and where the tests fail at a side without the acceptance tests, or no task counts. Where the
|
||||
API refuses a run, the bench stops there and exits 1 too, after the table of the runs that finished.
|
||||
With --record-figures it also exits 1, saying why: before it plants a bug, where no config names the checkout or the history
|
||||
cannot be read; and after the bench, where the history already holds that branch's bench of those two commits or cannot be
|
||||
written. The folder then still holds the bench's results.
|
||||
@@ -387,9 +389,9 @@ def ran_fixes(bench: Bench, tasks: list[Task], total: int) -> Fixes:
|
||||
def kept(bench: Bench, plan: Planned, names: dict[int, str], results: list[Result]) -> Failure | None:
|
||||
"""Writes results.json and the digest of the plan's tasks into the bench's folder. names holds each task's name by its number."""
|
||||
in_a_tree = lambda path: any(pathlib.Path(tree, path).is_file() for tree in bench.trees.values())
|
||||
noun = bench.asked.kind.noun
|
||||
recorded_runs = json.dumps({"sides": bench.sides, **plan.drawn_by, f"{noun}s": names, "runs": [recorded(result, noun) for result in results]}, indent="\t") + "\n"
|
||||
digest_text = digest(bench.sides, table(results, names, noun), [digested(task, results, bench.folder, noun) for task in plan.tasks], in_a_tree, noun)
|
||||
noun, key = bench.asked.kind.noun, bench.asked.kind.key
|
||||
recorded_runs = json.dumps({"sides": bench.sides, **plan.drawn_by, f"{key}s": names, "runs": [recorded(result, key) for result in results]}, indent="\t") + "\n"
|
||||
digest_text = digest(bench.sides, table(results, names, noun), [digested(task, results, bench.folder, key) for task in plan.tasks], in_a_tree, noun)
|
||||
try:
|
||||
(bench.folder / "results.json").write_text(recorded_runs, encoding="utf-8")
|
||||
(bench.folder / DIGEST).write_text(digest_text, encoding="utf-8", errors="replace")
|
||||
@@ -463,7 +465,7 @@ def planted_tree(bench: Bench, side: Side, tree: pathlib.Path, path: str, change
|
||||
def fixed(task: Task, side: Side, number: int, containers: Containers, folder: pathlib.Path, kind: Kind) -> Result | Failure:
|
||||
"""One run: Haiku's work on task at side in a copy of its tree, then the tests over what it changed, with a feature's
|
||||
acceptance tests among them. The stream stays in folder; the copy is removed. Tests that run out of time don't pass."""
|
||||
stream = stream_of(Result(task.number, side, number, False, None), folder, kind.noun)
|
||||
stream = stream_of(Result(task.number, side, number, False, None), folder, kind.key)
|
||||
copy, check = folder / "copy", folder / "check"
|
||||
try:
|
||||
try:
|
||||
@@ -494,21 +496,21 @@ def fixed(task: Task, side: Side, number: int, containers: Containers, folder: p
|
||||
shutil.rmtree(check, ignore_errors=True)
|
||||
|
||||
|
||||
def stream_of(result: Result, folder: pathlib.Path, noun: str) -> pathlib.Path:
|
||||
"""The file that holds the stream of the run result names, of a task the bench calls by noun. Its name without the suffix is
|
||||
def stream_of(result: Result, folder: pathlib.Path, key: str) -> pathlib.Path:
|
||||
"""The file that holds the stream of the run result names, of a task whose kind has that key. Its name without the suffix is
|
||||
the run's id in the digest."""
|
||||
return folder / "runs" / f"{noun}-{result.task}-{result.side}-{result.run}.jsonl"
|
||||
return folder / "runs" / f"{key}-{result.task}-{result.side}-{result.run}.jsonl"
|
||||
|
||||
|
||||
def digested(task: Task, results: list[Result], folder: pathlib.Path, noun: str) -> TaskRuns:
|
||||
def digested(task: Task, results: list[Result], folder: pathlib.Path, key: str) -> TaskRuns:
|
||||
"""The task as the digest tells it, with each of its runs in results. A run that didn't finish has no tokens."""
|
||||
runs = [Run(stream_of(result, folder, noun).stem, result.passed, found.tokens.context() + found.tokens.output if (found := result.figures) else None, result.entries) for result in results if result.task == task.number]
|
||||
runs = [Run(stream_of(result, folder, key).stem, result.passed, found.tokens.context() + found.tokens.output if (found := result.figures) else None, result.entries) for result in results if result.task == task.number]
|
||||
return TaskRuns(f"{task.number}: {task.name}", task.file, task.told["base"], runs)
|
||||
|
||||
|
||||
def recorded(result: Result, noun: str) -> dict:
|
||||
"""A run as results.json holds it, of a task the bench calls by noun."""
|
||||
run = {noun: result.task, "side": result.side, "run": result.run, "passed": result.passed, "finished": result.figures is not None}
|
||||
def recorded(result: Result, key: str) -> dict:
|
||||
"""A run as results.json holds it, of a task whose kind has that key."""
|
||||
run = {key: result.task, "side": result.side, "run": result.run, "passed": result.passed, "finished": result.figures is not None}
|
||||
if not (found := result.figures):
|
||||
return run
|
||||
return {**run, "claude_code": found.version, "model": found.model, "tokens": dataclasses.asdict(found.tokens), "turns": found.turns, "seconds": found.seconds, "reads": found.reads}
|
||||
|
||||
@@ -18,8 +18,8 @@ SIDES = re.compile(r"^Base ([0-9a-f]{7,40}), head ([0-9a-f]{7,40})\.", re.M)
|
||||
# How the table's three rows over every task open, as task_bench.figures.table writes them: the base, the head and the head's change.
|
||||
OVER_ALL = "| All |"
|
||||
COMMIT_LENGTH = 8
|
||||
# By how the table's header opens, as task_bench.figures.table writes it, what a bench's name says its tasks are. A bench of bugs
|
||||
# has the bare name.
|
||||
# What a bench's name says its tasks are, by how its table's header opens, as task_bench.figures.table writes it. A bench of
|
||||
# bugs has the bare name.
|
||||
TASKS_NAMED = {f"| {kind.noun.capitalize()} |": f" {tasks}" for tasks, kind in KINDS.items() if kind is not BUG}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""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."""
|
||||
A task counts only where its script writes the same register at the base and at the head, byte for byte, which a seeded script
|
||||
does."""
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
@@ -47,7 +47,8 @@ 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, writes a `.git` or writes no new file."""
|
||||
by its path from the top. NotGenerated where the script runs out of time, fails, writes a `.git`, writes no new file, or
|
||||
writes one that is no regular 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,9 +56,14 @@ def generated(containers: Containers, tree: str, script: str) -> dict[str, bytes
|
||||
if isinstance(ran, Failure):
|
||||
return ran
|
||||
if ran.code:
|
||||
return NotGenerated(f"its {GENERATE} exits {ran.code}")
|
||||
said = ran.output.strip().splitlines()[-1:]
|
||||
return NotGenerated(f"its {GENERATE} exits {ran.code}" + "".join(f" after printing `{line[:200]}`" for line in said))
|
||||
# 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})
|
||||
new = [path for path in entries(tree) if path not in before]
|
||||
# The host reads each next: it would follow a link into its own files, and never finish reading a pipe.
|
||||
if odd := [path for path in new if os.path.islink(os.path.join(tree, path)) or not os.path.isfile(os.path.join(tree, path))]:
|
||||
return NotGenerated(f"its {GENERATE} writes `{odd[0]}`, which is no regular file")
|
||||
register = on_disk(f"read the register in {tree}", lambda: {path: pathlib.Path(tree, path).read_bytes() for path in new})
|
||||
return register or NotGenerated(f"its {GENERATE} doesn't write any new file")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""What task-bench's two kinds of task share. One kind is a planted bug, the other a feature to build. They share the task itself, the bench it runs in, and the
|
||||
"""What task-bench's three kinds of task share: a planted bug, a feature to build and a data source to add. They share the task itself, the bench it runs in, and the
|
||||
steps that commit a task's tree and run the tests over a copy of one."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
@@ -23,10 +23,15 @@ class Kind(typing.NamedTuple):
|
||||
prompt: str
|
||||
without: str
|
||||
|
||||
@property
|
||||
def key(self) -> str:
|
||||
"""The noun as results.json and a run's file name spell it, without a space."""
|
||||
return self.noun.replace(" ", "-")
|
||||
|
||||
|
||||
BUG = Kind("bug", "A test of this project fails with the message below. Find the bug in the code and fix it. Change no test.\n\n{told}", "a planted bug")
|
||||
FEATURE = Kind("feature", "Build the feature below in this project.\n\n{told}", "a feature's acceptance tests")
|
||||
DATA_SOURCE = Kind("data-source", "Add the data source below to this project.\n\n{told}", "a data source's acceptance tests")
|
||||
DATA_SOURCE = Kind("data source", "Add the data source below to this project.\n\n{told}", "a data source's acceptance tests")
|
||||
# By the value --tasks takes. A panel of three readers, seated as the README's audience, picked `--tasks features` on 2026-11-23,
|
||||
# 3 to 0, over a bare `--features` and a `features` subcommand: it names what the bench runs, and the bugs as its other value.
|
||||
# Such a panel picked `data-sources` the same day, 3 to 0, over `sources` and `imports`, which read as source code and as import
|
||||
|
||||
@@ -81,7 +81,7 @@ def added(path: str) -> str:
|
||||
|
||||
|
||||
class BenchOfTasksCase(unittest.TestCase):
|
||||
"""A checkout whose config names `bench-tasks`, with the feature halve in it, a base and a head, and docker and claude faked."""
|
||||
"""A checkout whose config names `bench-tasks`, with the feature called `halve` in it, a base and a head, and docker and claude faked."""
|
||||
|
||||
def setUp(self):
|
||||
folder = tempfile.TemporaryDirectory()
|
||||
@@ -233,7 +233,7 @@ class FeatureBenchTest(BenchOfTasksCase):
|
||||
(lambda: (self.tasks / "halve/acceptance/halve_test.go").unlink(), f"the feature in {self.tasks / 'halve'} holds no file under acceptance"),
|
||||
(lambda: (self.tasks / "halve").rename(self.root / "moved"), f"{self.tasks} holds no feature: a folder for each, with spec.md, reference.patch and the acceptance tests under acceptance"),
|
||||
(lambda: shutil.rmtree(self.tasks), f"could not read the features in {self.tasks}: it is no folder"),
|
||||
(lambda: self.config.write_text(self.config.read_text().replace('bench-tasks = "checkout:bench-tasks"\n', "")), f"{self.config} sets no `bench-tasks`, the folder of the features to bench, as `project-config --help` describes it"),
|
||||
(lambda: self.config.write_text(self.config.read_text().replace('bench-tasks = "checkout:bench-tasks"\n', "")), f"{self.config} sets no `bench-tasks`, the folder of the tasks to bench, as `project-config --help` describes it"),
|
||||
):
|
||||
with self.subTest(reason=reason):
|
||||
shutil.rmtree(self.tasks, ignore_errors=True)
|
||||
|
||||
@@ -111,7 +111,7 @@ class RecordFiguresTest(unittest.TestCase):
|
||||
self.assertTrue(entry.startswith(f"## 1970-01-01T00:00:00Z, {name}\n\n| Feature | Side |"))
|
||||
|
||||
def test_names_a_bench_of_data_sources_as_one(self):
|
||||
name, _ = bench_entry(DIGEST.replace("| Bug |", "| Data-source |"), "item-7", 0)
|
||||
name, _ = bench_entry(DIGEST.replace("| Bug |", "| Data source |"), "item-7", 0)
|
||||
self.assertEqual(name, "task-bench data-sources of item-7: head bbbbbbbb against base aaaaaaaa")
|
||||
|
||||
def test_refuses_a_digest_without_its_commits_or_without_its_three_rows_over_every_bug(self):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user