Answer stability round 1: 0 🔴, 1 🟡 (0 misread); record a bench's figures inside the bench with --record-figures, so one that stopped or an older digest is never recorded

This commit is contained in:
2026-11-23 15:36:08 +01:00
parent 1f33e37fe5
commit 9d2e3f1823
4 changed files with 126 additions and 95 deletions
+20 -15
View File
@@ -1,8 +1,7 @@
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 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. each several times at both, and print how often the fix passes and what it took.
usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] 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 record-figures
task-bench gather 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` Run it in a checkout, under ~/.claude/bin/run-heavy, with a long-lived token in CLAUDE_CODE_OAUTH_TOKEN, which `claude setup-token`
@@ -53,10 +52,10 @@ in 19 cases of 20, an All change under 12% in output tokens, 16% in cache-read t
passed, so the pass rate's noise is unmeasured. passed, so the pass rate's noise is unmeasured.
`docs/decisions.md` → `task-bench: a bench takes` has the figures. `docs/decisions.md` → `task-bench: a bench takes` has the figures.
`task-bench record-figures`, run in the same checkout, appends the bench's figures to the project's comprehension history: the With --record-figures, a bench that finishes appends its figures to the project's comprehension history: an entry with the
table's heading and its three All rows, under a heading of the current UTC time and `task-bench of <branch>: head <commit> table's header and its three All rows. The entry's heading gives the current UTC time, then `task-bench of <branch>: head
against base <commit>`. It is a report beside the panel's scores there, which no tool reads as one of them. It waits for a <commit> against base <commit>`, where <branch> is the branch checked out, whatever --head names. No tool reads the entry as a
bench that still runs, and leaves the bench's folder, so run it before gather. 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 `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. cheapest rung of the model loop-claude runs the project on, with the digest and the prompt in gather-prompt.md beside this file.
@@ -70,8 +69,9 @@ Exit 1, saying why, on an unknown or repeated argument, a missing --image or --t
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 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 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
the runs that finished. the runs that finished.
record-figures exits 1, saying why, outside a checkout, without a digest, on a digest without its commits or its three All With --record-figures it also exits 1, saying why: before it plants a bug, where no config names the checkout or the history
rows, where no config names the checkout, and where the history already holds that bench or cannot be written. 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.
gather exits 1, saying why, outside a checkout, without a digest, where loop-claude has saved no model for the project or the gather exits 1, saying why, outside a checkout, without a digest, where loop-claude has saved no model for the project or the
model is not on its routing ladder, and where its claude fails or hits a usage limit. model is not on its routing ladder, and where its claude fails or hits a usage limit.
""" """
@@ -103,12 +103,14 @@ from task_bench.figures import figures, Result, Side, SIDES, table
from git_cli import git_repo from git_cli import git_repo
from review_rules.review_folder import made_review_folder, REPORTS from review_rules.review_folder import made_review_folder, REPORTS
from larv_review.history_commands import read_places from larv_review.history_commands import read_places
from task_bench.record_figures import record_figures from task_bench.record_figures import recorded_bench
from run_heavy.capped_docker import SHARE_VARIABLE 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>], task-bench 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 gather"
# A panel of three readers, seated as the README's audience, picked these options on 2026-11-21, each 3 to 0. # 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", "--runs", "--seed", "--test") OPTIONS = ("--base", "--bugs", "--head", "--image", "--prefix", "--record-figures", "--runs", "--seed", "--test")
# The one option that takes no value.
RECORD = "--record-figures"
COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1"} COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1"}
# Opens the report's last line, which names the bench's folder. # 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: " KEPT = "The digest, and each run's result and stream, until `task-bench gather` files plan items from them or the next bench starts: "
@@ -164,9 +166,6 @@ def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[
home = pathlib.Path(env.get("HOME") or pathlib.Path.home()) home = pathlib.Path(env.get("HOME") or pathlib.Path.home())
if argv[:1] == ["gather"]: if argv[:1] == ["gather"]:
report = gather(env, home, claude) if argv == ["gather"] else Failure(f"gather takes no arguments; {USAGE}") report = gather(env, home, claude) if argv == ["gather"] else Failure(f"gather takes no arguments; {USAGE}")
elif argv[:1] == ["record-figures"]:
recorded = record_figures(env, home, time.time()) if argv == ["record-figures"] else Failure(f"record-figures takes no arguments; {USAGE}")
report = recorded if isinstance(recorded, Failure) else [recorded]
else: else:
given = options(argv, env) given = options(argv, env)
if isinstance(given, Failure): if isinstance(given, Failure):
@@ -190,6 +189,11 @@ def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] |
return Failure(f"unknown argument {name}") return Failure(f"unknown argument {name}")
if name in given: if name in given:
return Failure(f"{name} is given twice") return Failure(f"{name} is given twice")
if name == RECORD:
if equals:
return Failure(f"{name} takes no value")
given[name] = ""
continue
if not equals and not rest: if not equals and not rest:
return Failure(f"{name} needs a value") return Failure(f"{name} needs a value")
given[name] = value if equals else rest.pop(0) given[name] = value if equals else rest.pop(0)
@@ -235,7 +239,8 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], places: str, hom
if isinstance(folder, Failure): if isinstance(folder, Failure):
return folder return folder
clear_left(home / REPORTS) clear_left(home / REPORTS)
return bench_in(folder, given, env, places, checkout, sides, git, say) run = functools.partial(bench_in, folder, given, env, places, checkout, sides, git, say)
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: 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:
+28 -30
View File
@@ -1,5 +1,4 @@
"""`task-bench record-figures`: a bench's figures over every bug, appended to the comprehension history from the bench's digest. The entry is a report beside the panel's: its heading names no `<what> at <commit>`, so nothing that reads the history's rulings and scoring runs takes it for one.""" """`task-bench --record-figures`: a bench's figures over every bug, appended to the comprehension history from the bench's digest. The entry is a report beside the panel's: its heading names no `<what> at <commit>`, so nothing that reads the history's rulings and scoring runs takes it for one."""
import functools
import pathlib import pathlib
import re import re
import typing import typing
@@ -7,16 +6,12 @@ import typing
from review_rules.comprehension_history import appended from review_rules.comprehension_history import appended
from task_bench.gather import DIGEST from task_bench.gather import DIGEST
from failure import Failure from failure import Failure
from git_cli import git_repo
from task_bench.bench_folder import held
from record_store.held import Held from record_store.held import Held
from larv_review.history_commands import held_history from larv_review.history_commands import held_history
from review_rules.review_folder import made_review_folder
from record_store.stores import RecordStore from record_store.stores import RecordStore
from git_cli.git_repo import top from git_cli.git_repo import Git
from text_files.utc_stamp import utc from text_files.utc_stamp import utc
# A panel of three readers, seated as the README's audience, picked on 2026-11-23 the subcommand's name, 3 to 0, and the heading's wording, `task-bench of <branch>: head <commit> against base <commit>`, 2 to 1 for the bench's name first.
# The digest's line that names the commits, as task_bench.digest.digest writes it. # The digest's line that names the commits, as task_bench.digest.digest writes it.
SIDES = re.compile(r"^Base ([0-9a-f]{7,40}), head ([0-9a-f]{7,40})\.", re.M) 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 bug open, as task_bench.figures.table writes them: the base, the head and the head's change. # How the table's three rows over every bug open, as task_bench.figures.table writes them: the base, the head and the head's change.
@@ -24,48 +19,51 @@ OVER_ALL = "| All |"
COMMIT_LENGTH = 8 COMMIT_LENGTH = 8
def record_figures(env: typing.Mapping[str, str], home: pathlib.Path, now: float) -> str | Failure: def recorded_bench(run: typing.Callable[[], list[str] | Failure], folder: pathlib.Path, git: Git, home: pathlib.Path, now: typing.Callable[[], float]) -> list[str] | Failure:
"""Appends the entry of the bench whose digest the checkout's review folder holds, stamped with now, and returns the line the tool prints. It waits for a bench that still runs there, and leaves the folder for gather.""" """The report of the bench that run runs in folder, plus the line that says where its figures went. It refuses before the bench where the history cannot be read, since a bench takes hours. A bench that fails or stops records nothing."""
git = functools.partial(git_repo.git, env=env)
checkout = top(git)
if isinstance(checkout, Failure):
return checkout
branch = git("rev-parse", "--abbrev-ref", "HEAD") branch = git("rev-parse", "--abbrev-ref", "HEAD")
if isinstance(branch, Failure): if isinstance(branch, Failure):
return branch return branch
review = made_review_folder(checkout, home) if isinstance(unreadable := held_history(home), Failure):
if isinstance(review, Failure): return unreadable
return review report = run()
with held(review) as folder: if isinstance(report, Failure):
if isinstance(folder, Failure): return report
return folder recorded = record_figures(folder, branch.strip(), home, now())
try: if isinstance(recorded, Failure):
digest = (folder / DIGEST).read_text(encoding="utf-8") return Failure(f"the bench finished and {folder} holds its results, but its figures are not recorded: {recorded.reason}")
except FileNotFoundError: return [*report, recorded]
return Failure(f"{folder} holds no digest: run task-bench in this checkout first, and record its figures before `task-bench gather`")
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {folder / DIGEST}: {failure}") def record_figures(folder: pathlib.Path, branch: str, home: pathlib.Path, now: float) -> str | Failure:
entry = bench_entry(digest, branch.strip(), now) """Appends the entry of the bench whose digest folder holds, stamped with now, and returns the line the tool prints."""
try:
digest = (folder / DIGEST).read_text(encoding="utf-8")
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {folder / DIGEST}: {failure}")
entry = bench_entry(digest, branch, now)
if entry is None: if entry is None:
return Failure(f"{folder / DIGEST} is no task-bench digest: it lacks the line that names its base and head, or the table's three All rows") return Failure(f"{folder / DIGEST} is no task-bench digest: it lacks the line that names its base and head, or the table's three All rows")
read = held_history(home) read = held_history(home)
return read if isinstance(read, Failure) else appended_to(*read, *entry) return read if isinstance(read, Failure) else bench_appended(*read, *entry)
def appended_to(history: RecordStore, held: Held, name: str, entry: str) -> str | Failure: def bench_appended(history: RecordStore, held: Held, name: str, entry: str) -> str | Failure:
"""Writes entry, of the bench the history calls name, onto held, the history as history's store read it, over held's version; the line the tool prints, or why the entry isn't written.""" """Writes a bench's entry at the end of the history and returns the line the tool prints. held is the history as its store read it, and name is what the entry's heading calls the bench. It refuses a bench the history already holds."""
if f", {name}\n" in held.text: if f", {name}\n" in held.text:
return Failure(f"{history.label} already holds {name}; record each bench once") return Failure(f"{history.label} already holds {name}; record each bench once")
written = history.write(appended(held.text, entry), held.version) written = history.write(appended(held.text, entry), held.version)
return written if isinstance(written, Failure) else f"Appended to {history.label}." return written if isinstance(written, Failure) else f"Appended to {history.label}."
def bench_entry(digest: str, branch: str, now: float) -> tuple[str, str] | None: def bench_entry(digest: str, branch: str, now: float) -> tuple[str, str] | None:
"""What the history calls the bench of branch that digest tells of, and its entry, stamped with now: the table's header and its rows over every bug. None where digest is no task-bench digest.""" """A bench's name in the history and its entry there, stamped with now: the digest's table header and its three rows over every bug. branch is the branch the bench ran on. None where digest is no task-bench digest."""
sides = SIDES.search(digest) sides = SIDES.search(digest)
table = [line for line in digest.splitlines() if line.startswith("|")] table = [line for line in digest.splitlines() if line.startswith("|")]
rows = [line for line in table if line.startswith(OVER_ALL)] rows = [line for line in table if line.startswith(OVER_ALL)]
if not sides or len(rows) != 3: if not sides or len(rows) != 3:
return None return None
base, head = (commit[:COMMIT_LENGTH] for commit in sides.groups()) base, head = (commit[:COMMIT_LENGTH] for commit in sides.groups())
# A panel of three readers, seated as the README's audience, picked this wording on 2026-11-23. Two of the three wanted the bench's name before the commits.
name = f"task-bench of {branch}: head {head} against base {base}" name = f"task-bench of {branch}: head {head} against base {base}"
return name, "\n".join([f"## {utc(now)}, {name}", "", *table[:2], *rows]) + "\n" return name, "\n".join([f"## {utc(now)}, {name}", "", *table[:2], *rows]) + "\n"
+47 -49
View File
@@ -1,6 +1,5 @@
"""`task-bench record-figures`: the entry a bench's digest becomes in the comprehension history, and what it refuses.""" """`task-bench --record-figures`: the entry a bench's digest becomes in the comprehension history, and what it refuses."""
import contextlib import contextlib
import io
import pathlib import pathlib
import subprocess import subprocess
import sys import sys
@@ -9,12 +8,11 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from task_bench.record_figures import appended_to, record_figures from task_bench.record_figures import bench_appended, recorded_bench
from review_rules.comprehension_history import entries from review_rules.comprehension_history import entries
from failure import Failure from failure import Failure
from record_store.held import Held from record_store.held import Held
from test_env import isolated_env from test_env import isolated_env
from task_bench import main
from record_store.fakes import MemoryStore from record_store.fakes import MemoryStore
SCORING = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n" SCORING = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n"
@@ -45,90 +43,90 @@ class RecordFiguresTest(unittest.TestCase):
self.home = pathlib.Path(folder.name).resolve() / "home" self.home = pathlib.Path(folder.name).resolve() / "home"
self.repo = self.home / "code/calc" self.repo = self.home / "code/calc"
self.repo.mkdir(parents=True) self.repo.mkdir(parents=True)
self.env = {**isolated_env(), "HOME": str(self.home)} # The project's config is found from the checkout's top, which git names.
subprocess.run(["git", "init", "--quiet", "--initial-branch", "item-7"], cwd=self.repo, env=self.env, check=True) subprocess.run(["git", "init", "--quiet"], cwd=self.repo, env={**isolated_env(), "HOME": str(self.home)}, check=True)
subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@localhost", "-c", "commit.gpgsign=false", "commit", "--quiet", "--allow-empty", "--message", "Base"], cwd=self.repo, env=self.env, check=True)
config = self.home / ".claude-projects/calc/config.toml" config = self.home / ".claude-projects/calc/config.toml"
config.parent.mkdir(parents=True) config.parent.mkdir(parents=True)
config.write_text(PROJECT_CONFIG) config.write_text(PROJECT_CONFIG)
self.bench = self.home / ".local/state/larv-review/code/calc/task-bench" self.bench = self.home / ".local/state/larv-review/code/calc/task-bench"
self.bench.mkdir(parents=True) self.bench.mkdir(parents=True)
self.history = self.repo / "docs/comprehension-history.md" self.history = self.repo / "docs/comprehension-history.md"
self.ran = 0
self.asked: list[tuple[str, ...]] = []
self.enterContext(contextlib.chdir(self.repo)) self.enterContext(contextlib.chdir(self.repo))
def recorded(self) -> str: def git(self, *args: str) -> str | Failure:
found = record_figures(self.env, self.home, NOW) self.asked.append(args)
return "item-7\n"
def left(self, digest: str | None = DIGEST, report: list[str] | Failure = ["the table"]) -> list[str] | Failure:
"""A bench that leaves digest in its folder and returns report."""
self.ran += 1
if digest is not None:
(self.bench / "digest.md").write_text(digest)
return report
def recorded(self, run=None) -> list[str] | str:
found = recorded_bench(run or self.left, self.bench, self.git, self.home, lambda: NOW)
return found.reason if isinstance(found, Failure) else found return found.reason if isinstance(found, Failure) else found
def unrecorded(self, why: str) -> str:
return f"the bench finished and {self.bench} holds its results, but its figures are not recorded: {why}"
def test_appends_the_rows_over_every_bug_under_a_heading_that_is_no_ruling_or_scoring_run_and_keeps_the_benchs_folder(self): def test_appends_the_rows_over_every_bug_under_a_heading_that_is_no_ruling_or_scoring_run_and_keeps_the_benchs_folder(self):
(self.bench / "digest.md").write_text(DIGEST)
self.history.parent.mkdir() self.history.parent.mkdir()
self.history.write_text("# Comprehension history\n\n" + SCORING) self.history.write_text("# Comprehension history\n\n" + SCORING)
self.assertEqual(self.recorded(), f"Appended to {self.history}.") self.assertEqual(self.recorded(), ["the table", f"Appended to {self.history}."])
entry = f"## 2026-11-23T10:00:00Z, task-bench of item-7: head bbbbbbbb against base aaaaaaaa\n\n{TABLE}{OVER_ALL}" entry = f"## 2026-11-23T10:00:00Z, task-bench of item-7: head bbbbbbbb against base aaaaaaaa\n\n{TABLE}{OVER_ALL}"
self.assertEqual(self.history.read_text(), f"# Comprehension history\n\n{SCORING}\n{entry}") self.assertEqual(self.history.read_text(), f"# Comprehension history\n\n{SCORING}\n{entry}")
self.assertEqual([entry.heading for entry in entries(self.history.read_text())], ["2026-10-08T12:00:00Z, PR #1 at aaaaaaa"]) self.assertEqual([entry.heading for entry in entries(self.history.read_text())], ["2026-10-08T12:00:00Z, PR #1 at aaaaaaa"])
self.assertEqual((self.bench / "digest.md").read_text(), DIGEST) self.assertEqual((self.bench / "digest.md").read_text(), DIGEST)
self.assertEqual(self.asked, [("rev-parse", "--abbrev-ref", "HEAD")])
def test_starts_a_history_where_the_project_has_none(self): def test_starts_a_history_where_the_project_has_none(self):
(self.bench / "digest.md").write_text(DIGEST) self.recorded()
self.assertEqual(self.recorded(), f"Appended to {self.history}.")
self.assertTrue(self.history.read_text().startswith("# Comprehension history\n\n## 2026-11-23T10:00:00Z, task-bench of item-7: head bbbbbbbb")) self.assertTrue(self.history.read_text().startswith("# Comprehension history\n\n## 2026-11-23T10:00:00Z, task-bench of item-7: head bbbbbbbb"))
def test_a_bench_that_fails_or_stops_records_nothing_though_it_left_a_digest(self):
self.assertEqual(self.recorded(lambda: self.left(report=Failure("stopped after 2 of 4 runs"))), "stopped after 2 of 4 runs")
self.assertFalse(self.history.exists())
def test_refuses_before_the_bench_where_git_names_no_branch_or_no_config_names_the_checkout(self):
self.git = lambda *args: Failure("git failed")
self.assertEqual(self.recorded(), "git failed")
del self.git
(self.home / ".claude-projects/calc/config.toml").unlink()
self.assertTrue(self.recorded().startswith(f"no config names the checkout {self.repo}"), self.recorded())
self.assertEqual(self.ran, 0)
def test_refuses_a_bench_the_history_already_holds(self): def test_refuses_a_bench_the_history_already_holds(self):
(self.bench / "digest.md").write_text(DIGEST)
self.recorded() self.recorded()
held = self.history.read_text() held = self.history.read_text()
self.assertEqual(self.recorded(), f"{self.history} already holds task-bench of item-7: head bbbbbbbb against base aaaaaaaa; record each bench once") self.assertEqual(self.recorded(), self.unrecorded(f"{self.history} already holds task-bench of item-7: head bbbbbbbb against base aaaaaaaa; record each bench once"))
self.assertEqual(self.history.read_text(), held) self.assertEqual(self.history.read_text(), held)
def test_refuses_without_a_digest(self):
self.assertEqual(self.recorded(), f"{self.bench} holds no digest: run task-bench in this checkout first, and record its figures before `task-bench gather`")
def test_refuses_a_digest_without_its_commits_or_without_its_three_rows_over_every_bug(self): def test_refuses_a_digest_without_its_commits_or_without_its_three_rows_over_every_bug(self):
for digest in (DIGEST.replace("Base ", "From "), DIGEST.replace("| All | change | +1 | -22% |\n", "")): for digest in (DIGEST.replace("Base ", "From "), DIGEST.replace("| All | change | +1 | -22% |\n", "")):
with self.subTest(digest=digest): with self.subTest(digest=digest):
(self.bench / "digest.md").write_text(digest) self.assertEqual(self.recorded(lambda: self.left(digest)), self.unrecorded(f"{self.bench / 'digest.md'} is no task-bench digest: it lacks the line that names its base and head, or the table's three All rows"))
self.assertEqual(self.recorded(), f"{self.bench / 'digest.md'} is no task-bench digest: it lacks the line that names its base and head, or the table's three All rows")
self.assertFalse(self.history.exists()) self.assertFalse(self.history.exists())
def test_refuses_a_digest_it_cannot_read(self): def test_refuses_a_digest_it_cannot_read(self):
(self.bench / "digest.md").mkdir() self.assertTrue(self.recorded(lambda: self.left(None)).startswith(self.unrecorded(f"could not read {self.bench / 'digest.md'}: [Errno ")), self.recorded())
self.assertTrue(self.recorded().startswith(f"could not read {self.bench / 'digest.md'}: [Errno "), self.recorded())
def test_says_why_where_no_config_names_the_checkout(self): def test_says_why_where_the_history_cannot_be_read_once_the_bench_has_run(self):
(self.bench / "digest.md").write_text(DIGEST) def run():
(self.home / ".claude-projects/calc/config.toml").unlink() (self.home / ".claude-projects/calc/config.toml").unlink()
self.assertTrue(self.recorded().startswith(f"no config names the checkout {self.repo}"), self.recorded()) return self.left()
self.assertTrue(self.recorded(run).startswith(self.unrecorded(f"no config names the checkout {self.repo}")))
def test_git_runs_in_the_environment_given(self):
(self.bench / "digest.md").write_text(DIGEST)
other = self.home / "code/other"
other.mkdir()
subprocess.run(["git", "init", "--quiet", "--initial-branch", "elsewhere"], cwd=other, env=self.env, check=True)
subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@localhost", "-c", "commit.gpgsign=false", "commit", "--quiet", "--allow-empty", "--message", "Base"], cwd=other, env=self.env, check=True)
self.env = {**self.env, "GIT_DIR": str(other / ".git"), "GIT_WORK_TREE": str(self.repo)}
with contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(main.main(["record-figures"], self.env), 0)
self.assertIn(", task-bench of elsewhere: head ", self.history.read_text())
def test_writes_over_the_version_the_history_was_read_at_and_says_why_a_write_fails(self): def test_writes_over_the_version_the_history_was_read_at_and_says_why_a_write_fails(self):
history = MemoryStore(label="history.md", version=5) history = MemoryStore(label="history.md", version=5)
self.assertEqual(appended_to(history, Held("", "5"), "task-bench of item-7: head b against base a", "## an entry\n"), "Appended to history.md.") self.assertEqual(bench_appended(history, Held("", "5"), "task-bench of item-7: head b against base a", "## an entry\n"), "Appended to history.md.")
self.assertEqual(history.overs, ["5"]) self.assertEqual(history.overs, ["5"])
refused = appended_to(history, Held("", "5"), "task-bench of item-8: head b against base a", "## an entry\n") refused = bench_appended(history, Held("", "5"), "task-bench of item-8: head b against base a", "## an entry\n")
self.assertEqual(refused.reason if isinstance(refused, Failure) else refused, "someone saved history.md since version 5") self.assertEqual(refused.reason if isinstance(refused, Failure) else refused, "someone saved history.md since version 5")
def test_the_tool_prints_the_line_and_refuses_arguments(self):
(self.bench / "digest.md").write_text(DIGEST)
with contextlib.redirect_stdout(io.StringIO()) as out:
self.assertEqual(main.main(["record-figures"], self.env), 0)
self.assertEqual(out.getvalue(), f"Appended to {self.history}.\n")
self.assertIn(", task-bench of item-7: head bbbbbbbb against base aaaaaaaa\n", self.history.read_text())
with contextlib.redirect_stderr(io.StringIO()) as errors:
self.assertEqual(main.main(["record-figures", "x"], self.env), 1)
self.assertEqual(errors.getvalue().split(";")[0], "record-figures takes no arguments")
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
+31 -1
View File
@@ -332,6 +332,36 @@ class BenchTest(unittest.TestCase):
self.assertEqual(lines[-3:-1], ["| All | base | 0/1 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | 1 |", "| All | head | 1/1 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | 1 |"]) self.assertEqual(lines[-3:-1], ["| All | base | 0/1 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | 1 |", "| All | head | 1/1 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | 1 |"])
self.assertEqual([(run["side"], run["run"]) for run in json.loads((folder / "results.json").read_text())["runs"]], [("base", 1), ("head", 1)]) self.assertEqual([(run["side"], run["run"]) for run in json.loads((folder / "results.json").read_text())["runs"]], [("base", 1), ("head", 1)])
def project_config(self) -> pathlib.Path:
"""Writes the config that puts the project's records in the checkout, and returns its comprehension history's path."""
config = self.home / ".claude-projects/calc/config.toml"
config.parent.mkdir(parents=True)
records = {"plan": "todo.md", "working-rules": "AGENTS.md", "decisions": "docs/decisions.md", "score-anchors": "docs/score-anchors.md", "comprehension-history": "docs/comprehension-history.md", "reading-cost": "docs/reading-cost.md", "changelog": "CHANGELOG.md", "goals-and-audience": "README.md"}
config.write_text(f'checkout = "{self.repo}"\n' + "".join(f'{name} = "checkout:{path}"\n' for name, path in records.items()) + 'principles = "~/principles"\nstandards = "~/standards"\n')
return self.repo / "docs/comprehension-history.md"
def test_record_figures_appends_a_finished_benchs_rows_over_every_bug_to_the_comprehension_history(self):
history = self.project_config()
report = self.bench(**{"--record-figures": ""})
self.assertNotIsInstance(report, Failure, report)
self.assertEqual(report[-1], f"Appended to {history}.")
lines = history.read_text().splitlines()
self.assertRegex(lines[2], rf"^## \d{{4}}-\d\d-\d\dT\d\d:\d\d:\d\dZ, task-bench of item-1: head {self.head[:8]} against base {self.base[:8]}$")
self.assertEqual([line.split(" | ")[:2] for line in lines[6:]], [["| All", "base"], ["| All", "head"], ["| All", "change"]])
def test_a_bench_records_no_figures_unless_asked_nor_where_it_stops(self):
history = self.project_config()
self.assertNotIsInstance(self.bench(), Failure)
self.env["FAKE_REFUSED_FROM"] = "3"
self.assertIsInstance(self.bench(**{"--record-figures": ""}), Failure)
self.assertFalse(history.exists())
def test_record_figures_refuses_before_any_container_starts_where_no_config_names_the_checkout(self):
found = self.bench(**{"--record-figures": ""})
self.assertIsInstance(found, Failure)
self.assertTrue(found.reason.startswith(f"no config names the checkout {self.repo}"), found.reason)
self.assertFalse(self.log.exists())
def test_a_change_to_another_file_neither_moves_nor_drops_the_bug(self): def test_a_change_to_another_file_neither_moves_nor_drops_the_bug(self):
(self.repo / "notes.txt").write_text("one\ntwo\nthree\nfour\nfive\nsix\n") (self.repo / "notes.txt").write_text("one\ntwo\nthree\nfour\nfive\nsix\n")
self.commit("Notes") self.commit("Notes")
@@ -390,7 +420,7 @@ class MainTest(unittest.TestCase):
return main.main(list(argv), {"CLAUDE_CODE_OAUTH_TOKEN": token, "HOME": "/nonexistent"}), errors.getvalue() return main.main(list(argv), {"CLAUDE_CODE_OAUTH_TOKEN": token, "HOME": "/nonexistent"}), errors.getvalue()
def test_refuses_an_unknown_repeated_or_valueless_argument(self): def test_refuses_an_unknown_repeated_or_valueless_argument(self):
for argv, said in ((["--imgae", "x"], "unknown argument --imgae"), (["--image", "x", "--image=y"], "--image is given twice"), (["--image"], "--image needs a value")): for argv, said in ((["--imgae", "x"], "unknown argument --imgae"), (["--image", "x", "--image=y"], "--image is given twice"), (["--image"], "--image needs a value"), (["--record-figures=yes"], "--record-figures takes no value"), (["--record-figures", "--record-figures"], "--record-figures is given twice"), (["--record-figures"], "--image is missing")):
code, errors = self.run_main(*argv) code, errors = self.run_main(*argv)
self.assertEqual((code, errors.startswith(f"{said}; usage: task-bench --image")), (1, True), errors) self.assertEqual((code, errors.startswith(f"{said}; usage: task-bench --image")), (1, True), errors)