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:
@@ -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."""
|
||||
import functools
|
||||
"""`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 pathlib
|
||||
import re
|
||||
import typing
|
||||
@@ -7,16 +6,12 @@ import typing
|
||||
from review_rules.comprehension_history import appended
|
||||
from task_bench.gather import DIGEST
|
||||
from failure import Failure
|
||||
from git_cli import git_repo
|
||||
from task_bench.bench_folder import held
|
||||
from record_store.held import Held
|
||||
from larv_review.history_commands import held_history
|
||||
from review_rules.review_folder import made_review_folder
|
||||
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
|
||||
|
||||
# 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, 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
|
||||
|
||||
|
||||
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
|
||||
def recorded_bench(run: typing.Callable[[], list[str] | Failure], folder: pathlib.Path, git: Git, home: pathlib.Path, now: typing.Callable[[], float]) -> list[str] | Failure:
|
||||
"""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."""
|
||||
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 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)
|
||||
if isinstance(unreadable := held_history(home), Failure):
|
||||
return unreadable
|
||||
report = run()
|
||||
if isinstance(report, Failure):
|
||||
return report
|
||||
recorded = record_figures(folder, branch.strip(), home, now())
|
||||
if isinstance(recorded, Failure):
|
||||
return Failure(f"the bench finished and {folder} holds its results, but its figures are not recorded: {recorded.reason}")
|
||||
return [*report, recorded]
|
||||
|
||||
|
||||
def record_figures(folder: pathlib.Path, branch: str, home: pathlib.Path, now: float) -> str | Failure:
|
||||
"""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:
|
||||
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)
|
||||
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:
|
||||
"""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."""
|
||||
def bench_appended(history: RecordStore, held: Held, name: str, entry: str) -> str | Failure:
|
||||
"""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:
|
||||
return Failure(f"{history.label} already holds {name}; record each bench once")
|
||||
written = history.write(appended(held.text, entry), held.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."""
|
||||
"""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)
|
||||
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())
|
||||
# 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}"
|
||||
return name, "\n".join([f"## {utc(now)}, {name}", "", *table[:2], *rows]) + "\n"
|
||||
|
||||
Reference in New Issue
Block a user