Bench adding a data source in task-bench, from a register a seeded script generates

This commit is contained in:
2026-11-23 18:48:03 +01:00
parent f6b180fd9d
commit c45472397e
12 changed files with 320 additions and 56 deletions
+25 -11
View File
@@ -1,9 +1,9 @@
r"""Measure how hard a project's code is to fix a bug in, or to build a feature in, at a base commit and at a head: plant bugs its
tests catch, have Haiku fix each several times at both, and print how often the fix passes and what it took. With --tasks features,
Haiku builds the project's bench features instead.
Haiku builds the project's bench features instead, and with --tasks data-sources it adds made-up data sources.
usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures]
task-bench --tasks features --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures]
task-bench --tasks features|data-sources --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures]
task-bench gather
Run it in a checkout, under ~/.claude/bin/run-heavy, with a long-lived token in CLAUDE_CODE_OAUTH_TOKEN, which `claude setup-token`
@@ -49,6 +49,18 @@ command doesn't find the acceptance tests, which fail by design: outside the che
skips `testdata`. The table then has a row per feature and side, and `-` for the reads. Gremlins
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, 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.
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
the run first opened the file the bug is in. The median of the reads leaves out a run that never opened that file. Then come a row
@@ -71,7 +83,8 @@ passed, so the pass rate's noise is unmeasured.
With --record-figures, a bench that finishes appends its figures to the project's comprehension history: an entry with the
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. No tool reads the entry as a
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.
`task-bench gather`, run in the same checkout, turns the digest into plan items. It starts a claude on the project's rung, the
@@ -107,7 +120,7 @@ import time
import typing
import uuid
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, FEATURE, Kind, KINDS, on_disk, Planned, Task, tests_in_copy
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, Task, tests_in_copy
from task_bench.plant import bug_at_sides, drawn, killed_mutants, Mutant, place_files, task_text
from claude_code.reply import Claude
from task_bench.bench_folder import clear_left, held
@@ -189,11 +202,11 @@ def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] |
if not given.get(name):
return Failure(f"{name} is missing")
if given.setdefault(TASKS, "bugs") not in KINDS:
return Failure(f"{TASKS} takes {' or '.join(KINDS)}, not {given[TASKS]}")
of_features = KINDS[given[TASKS]] is FEATURE
return Failure(f"{TASKS} takes {', '.join(list(KINDS)[:-1])} or {list(KINDS)[-1]}, not {given[TASKS]}")
of_features = KINDS[given[TASKS]] is not BUG
for name in OF_BUGS:
if of_features and name in given:
return Failure(f"{name} is for a bench of bugs, so it doesn't go with {TASKS} features")
return Failure(f"{name} is for a bench of bugs, so it doesn't go with {TASKS} {given[TASKS]}")
for name, default in COUNTS.items():
if of_features and name in OF_BUGS:
continue
@@ -212,9 +225,9 @@ def progress(line: str) -> None:
def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Callable[[pathlib.Path], str | Failure], home: pathlib.Path) -> list[str] | Failure:
"""The report of one bench of the checkout the process runs in, where `read` reads what `larv-review places` prints. It tells
its progress on stderr."""
# Only bugs are planted at the seats' places. Each kind reads what it makes its tasks from before anything is copied or built,
# Only bugs are planted at the seats' places; features and data sources come from the project's folder. Each kind reads what it makes its tasks from before anything is copied or built,
# so a fault there stops the bench at once.
tasks_from = read(home) if KINDS[given[TASKS]] is BUG else read_features(home)
tasks_from = read(home) if KINDS[given[TASKS]] is BUG else read_features(home, KINDS[given[TASKS]])
if isinstance(tasks_from, Failure):
return tasks_from
git = functools.partial(git_repo.git, env=env)
@@ -238,7 +251,8 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Cal
def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[str, str], tasks_from: str | Features, checkout: str, sides: dict[Side, str], git: Git) -> list[str] | Failure:
"""The report of a bench of the commits sides names, which empties folder and keeps its runs there. The bench plants bugs at
the places tasks_from names, where it is what `larv-review places` prints, and has Haiku build the features it holds otherwise."""
the places tasks_from names, where it is what `larv-review places` prints, and has Haiku build the features, or add the data
sources, it holds otherwise."""
containers = Containers(docker_cli(env), f"task-bench-{uuid.uuid4().hex[:12]}", given["--test"], int(env.get(SHARE_VARIABLE) or MEMORY_MIB), f"{os.getuid()}:{os.getgid()}")
shutil.rmtree(folder, ignore_errors=True)
trees: dict[Side, str] = {}
@@ -249,7 +263,7 @@ def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[st
trees[side] = tree
planned: typing.Callable[[Bench], Planned | Failure] | Failure
if isinstance(tasks_from, Features):
asked, planned = Asked(FEATURE, int(given["--runs"])), features_planner(tasks_from, checkout, trees)
asked, planned = Asked(KINDS[given[TASKS]], int(given["--runs"])), features_planner(tasks_from, checkout, trees)
else:
asked, planned = Asked(BUG, int(given["--runs"])), bugs_planner(given, env, tasks_from, trees["base"])
if isinstance(planned, Failure):