Record a bench in the comprehension history with task-bench record-figures, and run the bench beside a scoring run
CI / tests (pull_request) Failing after 4m58s
CI / tests (pull_request) Failing after 4m58s
This commit is contained in:
@@ -114,13 +114,6 @@ record-ruling and record-scoring append each entry to the history, created when
|
||||
heading of the current UTC time and the seats file's first line. Each commit that line names must be
|
||||
in the checkout. Each exits 1 when the history already holds an entry on what that line reads.
|
||||
|
||||
record-bench appends the figures of the task-bench last run in this checkout, a report beside the
|
||||
panel's entries that no command here reads: the bench's table, cut to its three rows over every bug,
|
||||
under a heading of the current UTC time and `task-bench of <branch>: head <commit> against base
|
||||
<commit>`. It reads the digest in the bench's folder, `task-bench` in the chunk's review folder, so
|
||||
run it before `task-bench gather`, which removes that folder; it waits for a bench that still runs.
|
||||
It exits 1 where the folder holds no digest, or the history already holds that bench.
|
||||
|
||||
places prints the places seats found hard since the newest scored commit: the places of each scoring
|
||||
run on it, and,
|
||||
in each later ruling, each place opening with a dimension, or Overall, that its seat voted worse.
|
||||
@@ -192,7 +185,6 @@ from larv_review.owed import owed_scoring_run
|
||||
from review_rules.review_passes import PASSES, REVIEWERS
|
||||
from larv_review.scoring_due import plan_reasons
|
||||
from larv_review.scoring_setup import prepare_scoring
|
||||
from larv_review.bench_record import record_bench
|
||||
from larv_review.history_commands import read_agreement, read_places, record_ruling, record_scoring
|
||||
from larv_review.round_title import round_title
|
||||
|
||||
@@ -242,7 +234,6 @@ COMMANDS = {
|
||||
"record-ruling": Command("record-ruling <votes file>", lambda given: len(given) == 1, lambda given: printed(record_ruling(pathlib.Path(given[0]), pathlib.Path.home(), time.time()))),
|
||||
"prepare-scoring": Command("prepare-scoring", no_arguments, lambda given: prepared_scoring()),
|
||||
"record-scoring": Command("record-scoring <scores file> [<item ID>...]", lambda given: bool(given) and are_ids(given[1:]), run_record_scoring, ids_from=1),
|
||||
"record-bench": Command("record-bench", no_arguments, lambda given: printed(record_bench(pathlib.Path.home(), time.time()))),
|
||||
"places": Command("places", no_arguments, lambda given: printed(read_places(pathlib.Path.home()))),
|
||||
"agreement": Command("agreement", no_arguments, lambda given: printed(read_agreement(pathlib.Path.home()))),
|
||||
"reviewer-header": Command("reviewer-header <pass> [--rerun]", fits_reviewer_header, run_reviewer_header),
|
||||
|
||||
@@ -4,7 +4,6 @@ import itertools
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -1064,37 +1063,6 @@ class LarvReviewTool(unittest.TestCase):
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("could not make the review folder", ran.stderr)
|
||||
|
||||
def bench_digest(self, text):
|
||||
folder = pathlib.Path(self.run_tool("review-folder").stdout.strip()) / "task-bench"
|
||||
folder.mkdir()
|
||||
(folder / "digest.md").write_text(text)
|
||||
|
||||
def test_record_bench_appends_the_rows_over_every_bug_under_a_heading_that_is_no_ruling_or_scoring_run(self):
|
||||
table = "| Bug | Side | Passed | Output |\n|---|---|---|---|\n"
|
||||
rows_over_all = "| All | base | 3/4 | 900 |\n| All | head | 4/4 | 700 |\n| All | change | +1 | -22% |\n"
|
||||
self.bench_digest(f"# task-bench digest\n\nBase {'a' * 40}, head {'b' * 40}. A bug's name gives its line at the base.\n\n{table}| 1: pick.go:12 | base | 3/4 | 900 |\n| 1: pick.go:12 | head | 4/4 | 700 |\n{rows_over_all}\n## 1: pick.go:12\n\n| not | the | table |\n")
|
||||
self.commit("history", {"docs/comprehension-history.md": "# Comprehension history\n\n" + SCORING})
|
||||
ran = self.run_tool("record-bench")
|
||||
self.assertEqual((ran.returncode, ran.stdout), (0, f"Appended to {self.checkout / 'docs/comprehension-history.md'}.\n"), ran.stderr)
|
||||
history = (self.checkout / "docs/comprehension-history.md").read_text()
|
||||
self.assertRegex(history, rf"\n\n## \d{{4}}-\d\d-\d\dT\d\d:\d\d:\d\dZ, task-bench of chunk: head bbbbbbbb against base aaaaaaaa\n\n{re.escape(table + rows_over_all)}$")
|
||||
self.assertEqual([entry.heading for entry in entries(history)], ["2026-10-08T12:00:00Z, PR #1 at aaaaaaa"])
|
||||
again = self.run_tool("record-bench")
|
||||
self.assertEqual(again.returncode, 1)
|
||||
self.assertIn("already holds task-bench of chunk: head bbbbbbbb against base aaaaaaaa", again.stderr)
|
||||
self.assertEqual((self.checkout / "docs/comprehension-history.md").read_text(), history)
|
||||
|
||||
def test_record_bench_fails_without_a_digest_and_on_one_without_its_commits_or_its_rows_over_every_bug(self):
|
||||
ran = self.run_tool("record-bench")
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("holds no digest: run task-bench in this checkout first", ran.stderr)
|
||||
self.bench_digest("# task-bench digest\n\n| Bug | Side |\n|---|---|\n| All | base |\n")
|
||||
ran = self.run_tool("record-bench")
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("digest.md is no task-bench digest", ran.stderr)
|
||||
self.assertFalse((self.checkout / "docs/comprehension-history.md").exists())
|
||||
self.assertIn("unknown arguments", self.run_tool("record-bench", "x").stderr)
|
||||
|
||||
def test_review_folder_fails_outside_a_checkout(self):
|
||||
ran = subprocess.run([sys.executable, str(TOOL), "review-folder"], capture_output=True, cwd=self.checkout.parent, env=self.env, text=True)
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
@@ -1117,7 +1085,7 @@ class LarvReviewTool(unittest.TestCase):
|
||||
def test_help_and_the_usage_line_list_the_same_commands(self):
|
||||
usage = next(line for line in self.run_tool("--help").stdout.splitlines() if line.startswith("usage: larv-review "))
|
||||
listed = usage.removeprefix("usage: larv-review ").split(" | ")
|
||||
self.assertEqual([shape.split()[0] for shape in listed], ["review-folder", "ruling-base", "round-count", "needs-scoring-run", "scoring-run-owed", "record-ruling", "prepare-scoring", "record-scoring", "record-bench", "places", "agreement", "reviewer-header", "round-title", "reviewer-context"])
|
||||
self.assertEqual([shape.split()[0] for shape in listed], ["review-folder", "ruling-base", "round-count", "needs-scoring-run", "scoring-run-owed", "record-ruling", "prepare-scoring", "record-scoring", "places", "agreement", "reviewer-header", "round-title", "reviewer-context"])
|
||||
self.assertIn(f"usage: larv-review {' | '.join(listed)}", self.run_tool().stderr)
|
||||
|
||||
def test_takes_a_local_main_without_origin_and_reads_origin_as_last_fetched_when_the_fetch_fails(self):
|
||||
|
||||
+14
-1
@@ -2,6 +2,7 @@ r"""Measure how hard a project's code is to fix a bug in, at a base commit and a
|
||||
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>]
|
||||
task-bench 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`
|
||||
@@ -52,6 +53,11 @@ 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.
|
||||
`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
|
||||
table's heading and its three All rows, under a heading of the current UTC time and `task-bench of <branch>: head <commit>
|
||||
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
|
||||
bench that still runs, and leaves the bench's folder, so run it before gather.
|
||||
|
||||
`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.
|
||||
That claude files an item with `todo-item add` for each place the runs show to be hard, and leaves the plan's file uncommitted.
|
||||
@@ -64,6 +70,8 @@ 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
|
||||
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.
|
||||
record-figures exits 1, saying why, outside a checkout, without a digest, on a digest without its commits or its three All
|
||||
rows, where no config names the checkout, and where the history already holds that bench or cannot be written.
|
||||
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.
|
||||
"""
|
||||
@@ -76,6 +84,7 @@ import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
import tarfile
|
||||
import time
|
||||
import typing
|
||||
import uuid
|
||||
|
||||
@@ -94,9 +103,10 @@ 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
|
||||
from larv_review.history_commands import read_places
|
||||
from task_bench.record_figures import record_figures
|
||||
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>], 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>], task-bench 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", "--runs", "--seed", "--test")
|
||||
COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1"}
|
||||
@@ -154,6 +164,9 @@ def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[
|
||||
home = pathlib.Path(env.get("HOME") or pathlib.Path.home())
|
||||
if argv[:1] == ["gather"]:
|
||||
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:
|
||||
given = options(argv, env)
|
||||
if isinstance(given, Failure):
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
"""`larv-review record-bench`: a task-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 re
|
||||
import typing
|
||||
|
||||
from failure import Failure
|
||||
from git_cli.git_repo import git, top
|
||||
from larv_review.history_commands import held_history
|
||||
from review_rules.comprehension_history import appended
|
||||
from review_rules.review_folder import made_review_folder
|
||||
from task_bench.bench_folder import held
|
||||
from task_bench.gather import DIGEST
|
||||
from failure import Failure
|
||||
from git_cli import git_repo
|
||||
from task_bench.bench_folder import held
|
||||
from larv_review.history_commands import held_history
|
||||
from review_rules.review_folder import made_review_folder
|
||||
from git_cli.git_repo import top
|
||||
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.
|
||||
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: 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.
|
||||
OVER_ALL = "| All |"
|
||||
COMMIT_LENGTH = 8
|
||||
|
||||
|
||||
def record_bench(home: pathlib.Path, now: float) -> str | Failure:
|
||||
"""Appends the entry of the bench whose digest the chunk's review folder holds, and returns the line the tool prints. It waits for a bench that still runs there."""
|
||||
checkout = top()
|
||||
def record_figures(env: typing.Mapping[str, str], home: pathlib.Path, now: float) -> 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."""
|
||||
git = functools.partial(git_repo.git, env=env)
|
||||
checkout = top(git)
|
||||
if isinstance(checkout, Failure):
|
||||
return checkout
|
||||
branch = git("rev-parse", "--abbrev-ref", "HEAD")
|
||||
@@ -35,7 +40,7 @@ def record_bench(home: pathlib.Path, now: float) -> str | Failure:
|
||||
try:
|
||||
digest = (folder / DIGEST).read_text(encoding="utf-8")
|
||||
except FileNotFoundError:
|
||||
return Failure(f"{folder} holds no digest: run task-bench in this checkout first, and record it before `task-bench gather`")
|
||||
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}")
|
||||
entry = bench_entry(digest, branch.strip(), now)
|
||||
@@ -0,0 +1,105 @@
|
||||
"""`task-bench record-figures`: the entry a bench's digest becomes in the comprehension history, and what it refuses."""
|
||||
import contextlib
|
||||
import io
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from review_rules.comprehension_history import entries
|
||||
from failure import Failure
|
||||
from task_bench import main
|
||||
from test_env import isolated_env
|
||||
from task_bench.record_figures import record_figures
|
||||
|
||||
SCORING = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n"
|
||||
TABLE = "| Bug | Side | Passed | Output |\n|---|---|---|---|\n"
|
||||
PER_BUG = "| 1: pick.go:12 | base | 3/4 | 900 |\n| 1: pick.go:12 | head | 4/4 | 700 |\n"
|
||||
OVER_ALL = "| All | base | 3/4 | 900 |\n| All | head | 4/4 | 700 |\n| All | change | +1 | -22% |\n"
|
||||
DIGEST = f"# task-bench digest\n\nBase {'a' * 40}, head {'b' * 40}. A bug's name gives its line at the base.\n\n{TABLE}{PER_BUG}{OVER_ALL}\n## 1: pick.go:12\n\n| not | the | table |\n"
|
||||
PROJECT_CONFIG = """checkout = "~/code/calc"
|
||||
plan = "checkout:todo.md"
|
||||
working-rules = "checkout:AGENTS.md"
|
||||
decisions = "checkout:docs/decisions.md"
|
||||
score-anchors = "checkout:docs/score-anchors.md"
|
||||
comprehension-history = "checkout:docs/comprehension-history.md"
|
||||
reading-cost = "checkout:docs/reading-cost.md"
|
||||
changelog = "checkout:CHANGELOG.md"
|
||||
goals-and-audience = "checkout:README.md"
|
||||
principles = "~/principles"
|
||||
standards = "~/standards"
|
||||
"""
|
||||
# 2026-11-23T10:00:00Z
|
||||
NOW = 1795428000.0
|
||||
|
||||
|
||||
class RecordFiguresTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
folder = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(folder.cleanup)
|
||||
self.home = pathlib.Path(folder.name).resolve() / "home"
|
||||
self.repo = self.home / "code/calc"
|
||||
self.repo.mkdir(parents=True)
|
||||
self.env = {**isolated_env(), "HOME": str(self.home)}
|
||||
subprocess.run(["git", "init", "--quiet", "--initial-branch", "item-7"], cwd=self.repo, 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=self.repo, env=self.env, check=True)
|
||||
config = self.home / ".claude-projects/calc/config.toml"
|
||||
config.parent.mkdir(parents=True)
|
||||
config.write_text(PROJECT_CONFIG)
|
||||
self.bench = self.home / ".local/state/larv-review/code/calc/task-bench"
|
||||
self.bench.mkdir(parents=True)
|
||||
self.history = self.repo / "docs/comprehension-history.md"
|
||||
self.enterContext(contextlib.chdir(self.repo))
|
||||
|
||||
def recorded(self) -> str:
|
||||
found = record_figures(self.env, self.home, NOW)
|
||||
return found.reason if isinstance(found, Failure) else found
|
||||
|
||||
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.write_text("# Comprehension history\n\n" + SCORING)
|
||||
self.assertEqual(self.recorded(), 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}"
|
||||
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((self.bench / "digest.md").read_text(), DIGEST)
|
||||
|
||||
def test_starts_a_history_where_the_project_has_none(self):
|
||||
(self.bench / "digest.md").write_text(DIGEST)
|
||||
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"))
|
||||
|
||||
def test_refuses_a_bench_the_history_already_holds(self):
|
||||
(self.bench / "digest.md").write_text(DIGEST)
|
||||
self.recorded()
|
||||
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.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):
|
||||
for digest in (DIGEST.replace("Base ", "From "), DIGEST.replace("| All | change | +1 | -22% |\n", "")):
|
||||
with self.subTest(digest=digest):
|
||||
(self.bench / "digest.md").write_text(digest)
|
||||
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())
|
||||
|
||||
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__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user