Answer architecture round 9: refuse a repeat record before any output, count a fall's scores once in metric-bench, fetch origin for record-scoring as for needs-scoring-run, type fall_step's outcomes, and state the duplicate rule as the code holds it

This commit is contained in:
2026-10-09 12:59:45 +02:00
parent 745818826a
commit 8cee26b1d6
6 changed files with 42 additions and 15 deletions
+23 -9
View File
@@ -4,8 +4,8 @@ usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...]
Run it inside a project checkout or one of its worktrees. Each command but record-ruling first
fetches origin, when the checkout has that remote, and takes origin's default branch, or else the
local main or master, as the default branch. When the fetch fails, round-count and record-scoring
read origin as last fetched and say so on stderr; the other two exit 1. The history is
local main or master, as the default branch. When the fetch fails, round-count reads origin as
last fetched and says so on stderr; the other three exit 1. The history is
docs/comprehension-history.md in the checkout.
ruling-base prints the commit a paired ruling reads against, then which of these found it. The last
@@ -109,7 +109,7 @@ def main(argv: list[str]) -> int:
elif command == "record-ruling" and len(given) in (1, 2):
done = record_ruling(*map(pathlib.Path, given))
elif command == "record-scoring" and given and all(re.fullmatch(r"[0-9]+", id_) for id_ in given[1:]):
done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=True)
done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=False)
elif command in ("needs-scoring-run", "record-scoring") and given:
named = given[1:] if command == "record-scoring" else given
print(f"{command} takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in named if not re.fullmatch(r'[0-9]+', id_))}; {USAGE}", file=sys.stderr)
@@ -250,7 +250,7 @@ def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> F
def read_scoring(scores_file: pathlib.Path, votes: Heading) -> Scoring | Failure:
"""The scores a fall called, once their file names what the votes file read."""
read = read_seats(scores_file, paired=False)
read = read_seats(scores_file, paired=False, fresh=False)
if isinstance(read, Failure):
return read
named, given = read
@@ -266,8 +266,8 @@ def scored_seats(given: SeatsFile) -> Scoring | Failure:
return Scoring(given.seats, found, means(list(found.values())))
def read_seats(path: pathlib.Path, paired: bool) -> tuple[Heading, SeatsFile] | Failure:
"""The seats file, and the heading its record goes under, once each commit it names is in the checkout."""
def read_seats(path: pathlib.Path, paired: bool, fresh: bool = True) -> tuple[Heading, SeatsFile] | Failure:
"""The seats file, and the heading its record goes under, once each commit it names is in the checkout and, when fresh, before anything is printed, once the history holds no entry on what it reads."""
try:
given = seats_file(path.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError) as failure:
@@ -279,19 +279,33 @@ def read_seats(path: pathlib.Path, paired: bool) -> tuple[Heading, SeatsFile] |
return named
if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]:
return Failure(f"the seats file names {', '.join(unknown)}, which is no commit in this checkout")
if fresh:
history = history_file()
if isinstance(history, Failure):
return history
if recorded(history[1], given.read):
return Failure(f"{history[0]} already holds an entry on {given.read}; record each ruling or run once")
return named, given
def append(read: str, entry: str) -> Failure | None:
"""Append entry unless the history already holds one on what the seats read."""
def history_file() -> tuple[pathlib.Path, str] | Failure:
"""The checkout's history and its text, empty when the file is missing."""
checkout = top()
if isinstance(checkout, Failure):
return checkout
history = pathlib.Path(checkout, HISTORY)
try:
text = history.read_text(encoding="utf-8") if history.exists() else ""
return history, history.read_text(encoding="utf-8") if history.exists() else ""
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {history}: {failure}")
def append(read: str, entry: str) -> Failure | None:
"""Append entry unless the history already holds one on what the seats read."""
read_history = history_file()
if isinstance(read_history, Failure):
return read_history
history, text = read_history
if recorded(text, read):
return Failure(f"{history} already holds an entry on {read}; record each ruling or run once")
try:
+2 -1
View File
@@ -1,4 +1,5 @@
import decimal
import typing
from comprehension_history import DIMENSIONS
from failure import Failure
@@ -7,7 +8,7 @@ from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows
FLOOR = decimal.Decimal("7.0")
def fall_step(fell: list[str], scored: bool) -> str:
def fall_step(fell: list[str], scored: bool) -> typing.Literal["ask", "refuse", "rule"]:
"""What record-ruling does next: ask for the scoring seats when a dimension fell and no scores file came, refuse a scores file no fall calls, or rule."""
if fell and not scored:
return "ask"
+7 -1
View File
@@ -78,11 +78,17 @@ def read_history(given: pathlib.Path | None) -> tuple[str, pathlib.Path, str] |
return Failure(f"could not read {history}: {failure}")
def scored_runs(found: list[Entry]) -> list[Entry]:
"""Each scoring run, and each paired ruling holding the scores a fall called unless a scoring run on its commit records them too."""
runs = {entry.commit for entry in found if not entry.paired}
return [entry for entry in found if not entry.paired or entry.scored_places and entry.commit not in runs]
def bench_runs(text: str, top: str) -> tuple[list[tuple[str, RunScores]], list[str]] | Failure:
"""Each scored run's heading and scores, and a note for each run skipped or not scored and each file left out."""
rows = []
notes = []
for run in [entry for entry in entries(text) if entry.scored_places or not entry.paired]:
for run in scored_runs(entries(text)):
if isinstance(missing := git(["cat-file", "-e", f"{run.commit}^{{commit}}"], top), Failure):
notes.append(f"Skipped, its commit is not in {top}: {run.heading} ({missing.reason})")
continue
+3 -1
View File
@@ -306,6 +306,7 @@ class LarvReviewTool(unittest.TestCase):
self.assertTrue(ruled.stdout.startswith("Ruling: worse. Fell: Locality. Under the floor of 7.0: Locality 6.50, so the better ruling counts as worse."))
again = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text, "scores.md"))
self.assertIn("already holds an entry on", again.stderr)
self.assertEqual(self.run_tool("record-ruling", votes_file).stdout, "")
recorded = entries(history.read_text())
self.assertEqual([entry.ruling for entry in recorded], ["worse"])
self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 7.00 | 7.00 |", history.read_text())
@@ -313,7 +314,8 @@ class LarvReviewTool(unittest.TestCase):
scores_text = scores_text.replace("PR #2", "PR #3")
stands = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("Locality 6.5", "Locality 7"), "scores.md"))
self.assertTrue(stands.stdout.startswith("Ruling: better. Fell: Locality, each at or above the floor of 7.0, so the better ruling stands."), stands.stderr)
other = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("PR #3", "PR #4"), "scores.md"))
votes_file = self.seats_file(pathlib.Path(votes_file).read_text().replace("PR #3", "PR #4"), "votes.md")
other = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("PR #3", "PR #5"), "scores.md"))
self.assertIn("the scores file's first line is not", other.stderr)
def test_names_no_fall_on_a_worse_ruling_and_takes_no_scores_file_without_one(self):
+6 -2
View File
@@ -14,6 +14,7 @@ from metric_bench.python_units import cognitive, measured, python_units, Unit
from comprehension_history import entries, Place
from failure import Failure
from test_loop_claude_black_box import host_env
from metric_bench.main import scored_runs
TOOL = pathlib.Path(__file__).resolve().parent / "metric-bench"
@@ -141,9 +142,12 @@ class Places(unittest.TestCase):
- `bin/tool/cycle/run.py:1` `step`
""")
def test_reads_each_scoring_runs_places_and_leaves_paired_rulings_out(self):
runs = [entry for entry in entries(self.HISTORY) if not entry.paired]
def test_reads_each_scoring_runs_places_and_leaves_rulings_out_unless_they_hold_a_falls_scores(self):
runs = scored_runs(entries(self.HISTORY))
self.assertEqual([(run.heading, run.commit) for run in runs], [("2026-10-08T12:50:49Z, PR #224 at a58a0a8", "a58a0a8")])
fall = "\n## 2026-10-09T09:00:00Z, PR #232 at {commit}, against 12d6d75\n\nRuling: worse\n\nJunior A, hardest first:\n\n- `bin/a.py:3` `f`\n"
self.assertEqual([run.commit for run in scored_runs(entries(self.HISTORY + fall.format(commit="bbbbbbb")))], ["a58a0a8", "bbbbbbb"])
self.assertEqual([run.commit for run in scored_runs(entries(self.HISTORY + fall.format(commit="a58a0a8")))], ["a58a0a8"])
self.assertEqual(runs[0].scored_places, [Place("skills/x/SKILL.md", None), Place("bin/tool/cycle/states.py", "transition"), Place("cycle/run.py", "step"), Place("cycle/run.py", "close"), Place("bin/tool/cycle/judge.py", "run_judge")])
def test_resolves_a_shortened_path_to_the_file_nearest_the_one_before_it(self):