Bench features in task-bench with --tasks features, from the folder the config names as bench-tasks
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
This commit is contained in:
+138
-128
@@ -1,7 +1,9 @@
|
||||
r"""Measure how hard a project's code is to fix a bug 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.
|
||||
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.
|
||||
|
||||
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 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`
|
||||
@@ -33,6 +35,17 @@ example:
|
||||
docker run --rm --memory 16g --memory-swap 16g -v "$PWD:$PWD" -w "$PWD" golang:1.27.4 \
|
||||
sh -c 'shift; exec go run github.com/go-gremlins/gremlins/cmd/gremlins@v0.6.0 "$@"' sh
|
||||
|
||||
--tasks features benches features instead of bugs; --tasks bugs is the default. The features are the folders in the folder the
|
||||
project's config names as `bench-tasks`, in the order of their names. Each holds:
|
||||
- `spec.md`, all that Haiku is told of the feature;
|
||||
- `reference.patch`, a patch `git apply` takes at the tree's top, which builds the feature;
|
||||
- `acceptance`, a folder of tests Haiku never sees, each at the path it takes from the tree's top. The test command must run them.
|
||||
A feature counts where, at the base and at the head, the test command fails with the acceptance tests in the tree, and passes
|
||||
once the reference patch is applied too. The bench passes over any other feature, and the report says which and why. Haiku
|
||||
works in a copy of the side's tree without the `bench-tasks` folder, and a build passes where the test command exits 0 over the
|
||||
tree it left, with the acceptance tests put over it. 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.
|
||||
|
||||
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
|
||||
@@ -42,7 +55,7 @@ the bench's folder: `task-bench` in the chunk's review folder.
|
||||
|
||||
That folder holds each run's result and stream, and digest.md, which says why runs failed in a few kilobytes per bug:
|
||||
- the table;
|
||||
- per bug its decoys, the files more than half of its failing runs read that the bug isn't in;
|
||||
- per bug its decoys, the files more than half of its failing runs read that the bug isn't in; per feature its spec instead;
|
||||
- per bug up to two traces: of a failing run, one that didn't finish or else the one that spent the most tokens, and of the
|
||||
passing run with the median tokens. A trace has a line per tool call, such as `Read pick.go:120-180` or `Grep "readName" → 4
|
||||
hits`, and the first 3 lines of what Haiku wrote between calls.
|
||||
@@ -54,7 +67,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. No tool reads the entry as a
|
||||
<commit> against base <commit>`, where <branch> is the branch checked out, whatever --head names. A bench of features is
|
||||
`task-bench features of <branch>: ...` there. 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
|
||||
@@ -66,8 +80,10 @@ 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, 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. Where the API refuses a run, the bench stops there and exits 1 too, after the table of
|
||||
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 the 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.
|
||||
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
|
||||
@@ -88,17 +104,19 @@ import time
|
||||
import typing
|
||||
import uuid
|
||||
|
||||
from task_bench.digest import Bug, counted, digest, Run
|
||||
from task_bench.tasks import Asked, Bench, BUG, committed, FEATURE, Kind, KINDS, on_disk, Planned, Task, tests_in_copy, with_acceptance
|
||||
from task_bench.plant import bug_at_sides, drawn, killed_mutants, Mutant, place_files, task_text
|
||||
from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, TimedOut, TOKEN, WORK
|
||||
from claude_code.reply import Claude
|
||||
from task_bench.bench_folder import clear_left, held
|
||||
from task_bench.digest import counted, digest, Run, TaskRuns
|
||||
from machine_load.slots import CPUS_PER_SLOT
|
||||
from git_cli.git_repo import default_ref, Git, top
|
||||
from task_bench.gather import DIGEST, gather, run_claude
|
||||
from claude_code.entries import entry_from, json_objects
|
||||
from mutate_changes.tool_process import failed, Ran, run_tool
|
||||
from failure import Failure
|
||||
from task_bench.feature_tasks import feature_tasks, kept_features
|
||||
from task_bench.figures import figures, Result, Side, SIDES, table
|
||||
from git_cli import git_repo
|
||||
from review_rules.review_folder import made_review_folder, REPORTS
|
||||
@@ -106,49 +124,17 @@ from larv_review.history_commands import read_places
|
||||
from task_bench.record_figures import recorded_bench
|
||||
from run_heavy.capped_docker import SHARE_VARIABLE
|
||||
|
||||
USAGE = "usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures], or task-bench gather"
|
||||
USAGE = "usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures], or task-bench --tasks features --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures], or task-bench gather"
|
||||
# A panel of three readers, seated as the README's audience, picked these options on 2026-11-21, each 3 to 0.
|
||||
OPTIONS = ("--base", "--bugs", "--head", "--image", "--prefix", "--record-figures", "--runs", "--seed", "--test")
|
||||
OPTIONS = ("--base", "--bugs", "--head", "--image", "--prefix", "--record-figures", "--runs", "--seed", "--tasks", "--test")
|
||||
# The one option that takes no value.
|
||||
RECORD = "--record-figures"
|
||||
COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1"}
|
||||
TASKS = "--tasks"
|
||||
# Opens the report's last line, which names the bench's folder.
|
||||
KEPT = "The digest, and each run's result and stream, until `task-bench gather` files plan items from them or the next bench starts: "
|
||||
# The planted commit doesn't name anyone, and neither a hook nor a signing key of the caller's reaches it.
|
||||
COMMIT = ["-c", "user.name=task-bench", "-c", "user.email=task-bench@localhost", "-c", "commit.gpgsign=false", "-c", "core.hooksPath=/dev/null", "commit", "--quiet", "--message", "Import"]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Task:
|
||||
"""A bug to fix: its number from 1, the mutant at the base, and per side the planted tree and what Haiku is told there."""
|
||||
number: int
|
||||
mutant: Mutant
|
||||
trees: dict[Side, str]
|
||||
messages: dict[Side, str]
|
||||
|
||||
def named(self) -> str:
|
||||
return f"{self.mutant.path}:{self.mutant.line}:{self.mutant.column} {self.mutant.mutator}"
|
||||
|
||||
|
||||
class Asked(typing.NamedTuple):
|
||||
"""What the caller asked of a bench: the seed that orders the mutants, how many bugs to plant and how often to run each fix."""
|
||||
seed: int
|
||||
bugs: int
|
||||
runs: int
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Bench:
|
||||
"""What a bench's phases share: the checkout, per side its commit and its tree without a bug, what the caller asked, the
|
||||
containers, the bench's folder, git, and say, which tells the caller each run's outcome as it finishes."""
|
||||
checkout: str
|
||||
sides: dict[Side, str]
|
||||
trees: dict[Side, str]
|
||||
asked: Asked
|
||||
containers: Containers
|
||||
folder: pathlib.Path
|
||||
git: Git
|
||||
say: typing.Callable[[str], None]
|
||||
# The options that choose the bugs to plant.
|
||||
OF_BUGS = ("--seed", "--bugs", "--prefix")
|
||||
|
||||
|
||||
class Fixes(typing.NamedTuple):
|
||||
@@ -171,7 +157,8 @@ def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[
|
||||
if isinstance(given, Failure):
|
||||
print(f"{given.reason}; {USAGE}", file=sys.stderr)
|
||||
return 1
|
||||
places = read(home)
|
||||
# Only bugs are planted at the seats' places.
|
||||
places = read(home) if KINDS[given[TASKS]] is BUG else ""
|
||||
report = places if isinstance(places, Failure) else bench(given, env, places, home)
|
||||
if isinstance(report, Failure):
|
||||
print(report.reason, file=sys.stderr)
|
||||
@@ -200,7 +187,15 @@ def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] |
|
||||
for name in ("--image", "--test"):
|
||||
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]}")
|
||||
features = KINDS[given[TASKS]] is FEATURE
|
||||
for name in OF_BUGS:
|
||||
if features and name in given:
|
||||
return Failure(f"{name} chooses the bugs to plant, so it doesn't go with {TASKS} features")
|
||||
for name, default in COUNTS.items():
|
||||
if features and name in OF_BUGS:
|
||||
continue
|
||||
if not given.setdefault(name, default).isdecimal() or int(given[name]) < 1:
|
||||
return Failure(f"{name} takes a whole number from 1, not {given[name]}")
|
||||
if not env.get(TOKEN):
|
||||
@@ -213,14 +208,6 @@ def progress(line: str) -> None:
|
||||
print(line, file=sys.stderr)
|
||||
|
||||
|
||||
def on_disk[T](doing: str, act: typing.Callable[[], T]) -> T | Failure:
|
||||
"""act's answer, or a Failure that says what could not be done where the filesystem refuses act."""
|
||||
try:
|
||||
return act()
|
||||
except OSError as failure:
|
||||
return Failure(f"could not {doing}: {failure}")
|
||||
|
||||
|
||||
def bench(given: dict[str, str], env: typing.Mapping[str, str], places: str, home: pathlib.Path, say: typing.Callable[[str], None] = progress) -> list[str] | Failure:
|
||||
"""The report of one bench of the checkout the process runs in, with `places` what `larv-review places` prints there; say
|
||||
tells the caller the bench's progress."""
|
||||
@@ -239,12 +226,18 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], places: str, hom
|
||||
if isinstance(folder, Failure):
|
||||
return folder
|
||||
clear_left(home / REPORTS)
|
||||
run = functools.partial(bench_in, folder, given, env, places, checkout, sides, git, say)
|
||||
run = functools.partial(bench_in, folder, given, env, places, checkout, sides, git, say, home)
|
||||
return recorded_bench(run, folder, git, home, time.time) if RECORD in given else run()
|
||||
|
||||
|
||||
def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[str, str], places: str, checkout: str, sides: dict[Side, str], git: Git, say: typing.Callable[[str], None]) -> list[str] | Failure:
|
||||
"""The report of a bench of the commits sides names, which empties folder and keeps its runs there."""
|
||||
def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[str, str], places: str, checkout: str, sides: dict[Side, str], git: Git, say: typing.Callable[[str], None], home: pathlib.Path) -> list[str] | Failure:
|
||||
"""The report of a bench of the commits sides names, which empties folder and keeps its runs there. home holds the config
|
||||
that names the features' folder."""
|
||||
kind = KINDS[given.get(TASKS, "bugs")]
|
||||
# Read before anything is copied or built, so a folder at fault stops the bench at once.
|
||||
kept = kept_features(home) if kind is FEATURE else None
|
||||
if isinstance(kept, Failure):
|
||||
return kept
|
||||
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] = {}
|
||||
@@ -253,20 +246,36 @@ def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[st
|
||||
if isinstance(tree, Failure):
|
||||
return tree
|
||||
trees[side] = tree
|
||||
files = [path for path in place_files(places) if pathlib.Path(trees["base"], path).is_file()]
|
||||
if not files:
|
||||
return Failure("The places the seats found hard don't name any Go file that the base holds, so there is nowhere to plant a bug.")
|
||||
run = functools.partial(run_tool, prefix=given.get("--prefix"), env=env, killpg=os.killpg)
|
||||
mutants = killed_mutants(trees["base"], files, run, CPUS_PER_SLOT)
|
||||
if isinstance(mutants, Failure):
|
||||
return mutants
|
||||
planned: typing.Callable[[Bench], Planned | Failure]
|
||||
if kept:
|
||||
# Haiku's copy leaves the features' folder out, with its acceptance tests and reference patches.
|
||||
if kept.folder.is_relative_to(checkout):
|
||||
for tree in trees.values():
|
||||
shutil.rmtree(pathlib.Path(tree, kept.folder.relative_to(checkout)), ignore_errors=True)
|
||||
asked = Asked(kind, int(given["--runs"]))
|
||||
planned = functools.partial(feature_tasks, found=kept.features, folder=kept.folder)
|
||||
else:
|
||||
mutants = killed_at_places(given, env, places, trees["base"])
|
||||
if isinstance(mutants, Failure):
|
||||
return mutants
|
||||
asked = Asked(kind, int(given["--runs"]), int(given["--seed"]), int(given["--bugs"]))
|
||||
planned = functools.partial(planted_tasks, mutants=mutants)
|
||||
try:
|
||||
found = opened(containers, given["--image"]) or benched(Bench(checkout, sides, trees, Asked(int(given["--seed"]), int(given["--bugs"]), int(given["--runs"])), containers, folder, git, say), mutants)
|
||||
found = opened(containers, given["--image"]) or benched(Bench(checkout, sides, trees, asked, containers, folder, git, say), planned)
|
||||
finally:
|
||||
closed(containers)
|
||||
return found if isinstance(found, Failure) else [*found, f"{KEPT}{folder}"]
|
||||
|
||||
|
||||
def killed_at_places(given: dict[str, str], env: typing.Mapping[str, str], places: str, base: str) -> list[Mutant] | Failure:
|
||||
"""The mutants the tests kill in the Go files of the tree at base that hold a place in places."""
|
||||
files = [path for path in place_files(places) if pathlib.Path(base, path).is_file()]
|
||||
if not files:
|
||||
return Failure("The places the seats found hard don't name any Go file that the base holds, so there is nowhere to plant a bug.")
|
||||
run = functools.partial(run_tool, prefix=given.get("--prefix"), env=env, killpg=os.killpg)
|
||||
return killed_mutants(base, files, run, CPUS_PER_SLOT)
|
||||
|
||||
|
||||
def commits(given: dict[str, str], checkout: str, git: Git) -> dict[Side, str] | Failure:
|
||||
"""The base's commit and the head's."""
|
||||
head = git("rev-parse", "--verify", f"{given.get('--head', 'HEAD')}^{{commit}}", cwd=checkout)
|
||||
@@ -298,39 +307,44 @@ def archived(commit: str, into: pathlib.Path, checkout: str, git: Git) -> str |
|
||||
return removed if isinstance(removed, Failure) else str(into)
|
||||
|
||||
|
||||
def benched(bench: Bench, mutants: list[Mutant]) -> list[str] | Failure:
|
||||
"""Plants the bugs, runs each fix, writes the results into the bench's folder and returns the report."""
|
||||
def benched(bench: Bench, planned: typing.Callable[[Bench], Planned | Failure]) -> list[str] | Failure:
|
||||
"""Makes the tasks that planned plans, runs each, writes the results into the bench's folder and returns the report."""
|
||||
if failure := baseline_failure(bench):
|
||||
return failure
|
||||
tasks = planted_tasks(bench, mutants)
|
||||
if isinstance(tasks, Failure):
|
||||
return tasks
|
||||
plan = planned(bench)
|
||||
if isinstance(plan, Failure):
|
||||
return plan
|
||||
tasks = plan.tasks
|
||||
total = bench.asked.runs * len(tasks) * len(SIDES)
|
||||
fixes = ran_fixes(bench, tasks, total)
|
||||
if fixes.stopped and not fixes.results:
|
||||
return fixes.stopped
|
||||
names = {task.number: task.named() for task in tasks}
|
||||
names = {task.number: task.name for task in tasks}
|
||||
if failure := kept(bench, tasks, names, fixes.results):
|
||||
return failure
|
||||
if fixes.stopped:
|
||||
return stopped_report(fixes.stopped, fixes.results, total, names, bench.folder)
|
||||
return report(bench.sides, names, bench.asked, fixes.results)
|
||||
return stopped_report(fixes.stopped, fixes.results, total, names, bench.folder, bench.asked.kind)
|
||||
return report(bench.sides, names, bench.asked, fixes.results, plan.left_out)
|
||||
|
||||
|
||||
def baseline_failure(bench: Bench) -> Failure | None:
|
||||
"""Why a side's tests don't pass without a planted bug; None where they pass at both sides."""
|
||||
"""Why a side's tests don't pass without a task; None where they pass at both sides."""
|
||||
for side, tree in bench.trees.items():
|
||||
ran = tests_in_copy(bench.containers, tree, bench.folder)
|
||||
if isinstance(ran, Failure) or ran.code:
|
||||
return ran if isinstance(ran, Failure) else failed(f"The tests fail at the {side} without a planted bug: the test command", ran)
|
||||
return ran if isinstance(ran, Failure) else failed(f"The tests fail at the {side} without {bench.asked.kind.without}: the test command", ran)
|
||||
return None
|
||||
|
||||
|
||||
def planted_tasks(bench: Bench, mutants: list[Mutant]) -> list[Task] | Failure:
|
||||
"""The mutants that become bugs, in the order the seed draws them, until the bench has as many as asked for."""
|
||||
def planted_tasks(bench: Bench, mutants: list[Mutant]) -> Planned | Failure:
|
||||
"""The mutants that become bugs, in the order the seed draws them, until the bench has as many as asked for; with a line that
|
||||
says so where it has fewer."""
|
||||
seed, bugs = bench.asked.seed, bench.asked.bugs
|
||||
# A bench of bugs is asked with both.
|
||||
assert seed is not None and bugs is not None
|
||||
tasks: list[Task] = []
|
||||
for mutant in drawn(mutants, bench.asked.seed):
|
||||
if len(tasks) == bench.asked.bugs:
|
||||
for mutant in drawn(mutants, seed):
|
||||
if len(tasks) == bugs:
|
||||
break
|
||||
task = planted(bench, len(tasks) + 1, mutant)
|
||||
if isinstance(task, Failure):
|
||||
@@ -338,26 +352,28 @@ def planted_tasks(bench: Bench, mutants: list[Mutant]) -> list[Task] | Failure:
|
||||
tasks += [task] if task else []
|
||||
if not tasks:
|
||||
return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, or the test it fails doesn't print a message.")
|
||||
return tasks
|
||||
return Planned(tasks, [] if len(tasks) == bugs else [f"Planted {len(tasks)} of the {bugs} bugs asked for: no other mutant the tests kill becomes one."])
|
||||
|
||||
|
||||
def ran_fixes(bench: Bench, tasks: list[Task], total: int) -> Fixes:
|
||||
"""Each task's fix at each side, as many times as asked for, the sides in turn, until a run stops the bench."""
|
||||
results: list[Result] = []
|
||||
for number, task, side in itertools.product(range(1, bench.asked.runs + 1), tasks, SIDES):
|
||||
result = fixed(task, side, number, bench.containers, bench.folder)
|
||||
result = fixed(task, side, number, bench.containers, bench.folder, bench.asked.kind)
|
||||
if isinstance(result, Failure):
|
||||
return Fixes(results, result)
|
||||
results.append(result)
|
||||
bench.say(f"task-bench: run {len(results)} of {total}, bug {task.number} at the {side}: {'passed' if result.passed else 'not passed'}.")
|
||||
bench.say(f"task-bench: run {len(results)} of {total}, {bench.asked.kind.noun} {task.number} at the {side}: {'passed' if result.passed else 'not passed'}.")
|
||||
return Fixes(results, None)
|
||||
|
||||
|
||||
def kept(bench: Bench, tasks: list[Task], names: dict[int, str], results: list[Result]) -> Failure | None:
|
||||
"""Writes results.json and the digest into the bench's folder. names holds each bug's name by its number."""
|
||||
"""Writes results.json and the digest 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())
|
||||
recorded_runs = json.dumps({"sides": bench.sides, "seed": bench.asked.seed, "bugs": names, "runs": [recorded(result) for result in results]}, indent="\t") + "\n"
|
||||
digest_text = digest(bench.sides, table(results, names), [digested(task, results, bench.folder) for task in tasks], in_a_tree)
|
||||
noun = bench.asked.kind.noun
|
||||
seed = {} if bench.asked.seed is None else {"seed": bench.asked.seed}
|
||||
recorded_runs = json.dumps({"sides": bench.sides, **seed, 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 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")
|
||||
@@ -366,23 +382,23 @@ def kept(bench: Bench, tasks: list[Task], names: dict[int, str], results: list[R
|
||||
return None
|
||||
|
||||
|
||||
def report(sides: dict[Side, str], names: dict[int, str], asked: Asked, results: list[Result]) -> list[str]:
|
||||
"""What a finished bench prints: the commits, the bugs named in names, what ran them, and the table."""
|
||||
def report(sides: dict[Side, str], names: dict[int, str], asked: Asked, results: list[Result], left_out: list[str]) -> list[str]:
|
||||
"""What a finished bench prints: the commits, the tasks named in names, what ran them, a line of left_out on each thing the
|
||||
bench left out, and the table."""
|
||||
ran_on = sorted({f"{found.model} in Claude Code {found.version}" for result in results if (found := result.figures)})
|
||||
short = [] if len(names) == asked.bugs else [f"Planted {len(names)} of the {asked.bugs} bugs asked for: no other mutant the tests kill becomes one."]
|
||||
return [
|
||||
f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}. {counted(len(names), 'bug')}, each run {counted(asked.runs, 'time')} at each side by {' and '.join(ran_on) or 'no run that finished'}.",
|
||||
*short,
|
||||
f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}. {counted(len(names), asked.kind.noun)}, each run {counted(asked.runs, 'time')} at each side by {' and '.join(ran_on) or 'no run that finished'}.",
|
||||
*left_out,
|
||||
"",
|
||||
*table(results, names),
|
||||
*table(results, names, asked.kind.noun),
|
||||
"",
|
||||
]
|
||||
|
||||
|
||||
def stopped_report(stopped: Failure, results: list[Result], total: int, names: dict[int, str], folder: pathlib.Path) -> Failure:
|
||||
def stopped_report(stopped: Failure, results: list[Result], total: int, names: dict[int, str], folder: pathlib.Path, kind: Kind) -> Failure:
|
||||
"""Why the bench stopped, then the table of the runs that finished: they took hours and tokens, so the bench shows them
|
||||
before it fails."""
|
||||
return Failure("\n".join([stopped.reason, f"task-bench stopped after {len(results)} of {total} runs, which results.json holds in {folder}:", "", *table(results, names)]))
|
||||
return Failure("\n".join([stopped.reason, f"task-bench stopped after {len(results)} of {total} runs, which results.json holds in {folder}:", "", *table(results, names, kind.noun)]))
|
||||
|
||||
|
||||
def planted(bench: Bench, number: int, mutant: Mutant) -> Task | Failure | None:
|
||||
@@ -404,7 +420,7 @@ def planted(bench: Bench, number: int, mutant: Mutant) -> Task | Failure | None:
|
||||
if message is None or isinstance(message, Failure):
|
||||
return message
|
||||
trees[side], messages[side] = str(tree), message
|
||||
return Task(number, mutant, trees, messages)
|
||||
return Task(number, f"{mutant.path}:{mutant.line}:{mutant.column} {mutant.mutator}", trees, messages, file=mutant.path)
|
||||
|
||||
|
||||
def planted_tree(bench: Bench, side: Side, tree: pathlib.Path, path: str, changed: bytes) -> str | Failure | None:
|
||||
@@ -425,37 +441,21 @@ def planted_tree(bench: Bench, side: Side, tree: pathlib.Path, path: str, change
|
||||
message = task_text(ran.output)
|
||||
if message is None:
|
||||
return None
|
||||
for args in (["init", "--quiet"], ["add", "--all", "--force"], COMMIT):
|
||||
done = bench.git(*args, cwd=str(tree))
|
||||
if isinstance(done, Failure):
|
||||
return done
|
||||
return message
|
||||
return committed(bench.git, str(tree)) or message
|
||||
|
||||
|
||||
def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path) -> Ran | Failure:
|
||||
"""The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree."""
|
||||
copy = folder / "tested"
|
||||
copied = on_disk(f"copy {tree} to test it", lambda: shutil.copytree(tree, copy, symlinks=True))
|
||||
if isinstance(copied, Failure):
|
||||
return copied
|
||||
try:
|
||||
return ran_tests(containers, str(copy))
|
||||
finally:
|
||||
shutil.rmtree(copy, ignore_errors=True)
|
||||
|
||||
|
||||
def fixed(task: Task, side: Side, number: int, containers: Containers, folder: pathlib.Path) -> Result | Failure:
|
||||
"""One run: Haiku's fix of task at side in a copy of its planted tree, then the tests over what it changed. 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)
|
||||
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)
|
||||
copy, check = folder / "copy", folder / "check"
|
||||
try:
|
||||
try:
|
||||
stream.parent.mkdir(exist_ok=True)
|
||||
shutil.copytree(task.trees[side], copy, symlinks=True)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not copy bug {task.number}'s tree at the {side}: {failure}")
|
||||
attempted = fix_attempted(containers, str(copy), task.messages[side], stream)
|
||||
return Failure(f"could not copy {kind.noun} {task.number}'s tree at the {side}: {failure}")
|
||||
attempted = fix_attempted(containers, str(copy), kind.prompt.format(told=task.told[side]), stream)
|
||||
if isinstance(attempted, Failure):
|
||||
return attempted
|
||||
raw = on_disk(f"read {stream}", stream.read_bytes)
|
||||
@@ -463,10 +463,10 @@ def fixed(task: Task, side: Side, number: int, containers: Containers, folder: p
|
||||
return raw
|
||||
events = json_objects(raw)
|
||||
entries = [entry_from(event) for event in events]
|
||||
found = figures(events, os.path.join(WORK, task.mutant.path))
|
||||
found = figures(events, task.file and os.path.join(WORK, task.file))
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
checked = on_disk(f"make the tree that checks bug {task.number}'s fix at the {side}", lambda: checked_tree(task.trees[side], str(copy), str(check)))
|
||||
checked = on_disk(f"make the tree that checks {kind.noun} {task.number}'s fix at the {side}", lambda: check_made(task, side, str(copy), str(check)))
|
||||
if isinstance(checked, Failure):
|
||||
return checked
|
||||
ran = ran_tests(containers, str(check))
|
||||
@@ -478,20 +478,30 @@ 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) -> pathlib.Path:
|
||||
"""The file that holds the stream of the run result names. Its name without the suffix is the run's id in the digest."""
|
||||
return folder / "runs" / f"bug-{result.task}-{result.side}-{result.run}.jsonl"
|
||||
def check_made(task: Task, side: Side, copy: str, check: str) -> None:
|
||||
"""Makes at check the tree that checks what Haiku left in copy: `checked_tree`'s, then a feature's acceptance tests over it.
|
||||
|
||||
Raises OSError where a file cannot be copied."""
|
||||
checked_tree(task.trees[side], copy, check)
|
||||
if task.acceptance:
|
||||
with_acceptance(check, task.acceptance)
|
||||
|
||||
|
||||
def digested(task: Task, results: list[Result], folder: pathlib.Path) -> Bug:
|
||||
"""The bug 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).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 Bug(f"{task.number}: {task.named()}", task.mutant.path, task.messages["base"], runs)
|
||||
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
|
||||
the run's id in the digest."""
|
||||
return folder / "runs" / f"{noun}-{result.task}-{result.side}-{result.run}.jsonl"
|
||||
|
||||
|
||||
def recorded(result: Result) -> dict:
|
||||
"""A run as results.json holds it."""
|
||||
run = {"bug": result.task, "side": result.side, "run": result.run, "passed": result.passed, "finished": result.figures is not None}
|
||||
def digested(task: Task, results: list[Result], folder: pathlib.Path, noun: 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]
|
||||
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}
|
||||
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}
|
||||
|
||||
Reference in New Issue
Block a user