Record a task-bench's figures in the comprehension history with larv-review record-bench, and run the bench beside a scoring run
CI / tests (pull_request) Failing after 5m6s

This commit is contained in:
2026-11-23 14:21:56 +01:00
parent 56a82245ad
commit 6b36f43062
7 changed files with 126 additions and 3 deletions
+64
View File
@@ -0,0 +1,64 @@
"""`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."""
import pathlib
import re
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 text_files.utc_stamp import utc
# 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.
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()
if isinstance(checkout, Failure):
return checkout
branch = git("rev-parse", "--abbrev-ref", "HEAD")
if isinstance(branch, Failure):
return branch
review = made_review_folder(checkout, home)
if isinstance(review, Failure):
return review
with held(review) as folder:
if isinstance(folder, Failure):
return folder
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`")
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {folder / DIGEST}: {failure}")
entry = bench_entry(digest, branch.strip(), now)
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")
name, text = entry
read = held_history(home)
if isinstance(read, Failure):
return read
history, found = read
if f", {name}\n" in found.text:
return Failure(f"{history.label} already holds {name}; record each bench once")
written = history.write(appended(found.text, text), found.version)
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:
"""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."""
sides = SIDES.search(digest)
table = [line for line in digest.splitlines() if line.startswith("|")]
rows = [line for line in table if line.startswith(OVER_ALL)]
if not sides or len(rows) != 3:
return None
base, head = (commit[:COMMIT_LENGTH] for commit in sides.groups())
name = f"task-bench of {branch}: head {head} against base {base}"
return name, "\n".join([f"## {utc(now)}, {name}", "", *table[:2], *rows]) + "\n"
+9
View File
@@ -114,6 +114,13 @@ 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.
@@ -185,6 +192,7 @@ 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
@@ -234,6 +242,7 @@ 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),
+33 -1
View File
@@ -4,6 +4,7 @@ import itertools
import json
import os
import pathlib
import re
import subprocess
import sys
import tempfile
@@ -1063,6 +1064,37 @@ 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)
@@ -1085,7 +1117,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", "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", "record-bench", "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):