Answer architecture round 8: refuse a scoring run the plan does not call and a second entry on one read, keep a fall's scoring places apart for metric-bench, let the history format write the Ruling line, decide the fall step in a pure function, and state the base rule as the code holds it

This commit is contained in:
2026-10-09 12:29:37 +02:00
parent e694e4154e
commit 2630291af2
12 changed files with 160 additions and 111 deletions
+72 -55
View File
@@ -1,11 +1,11 @@
"""Hold larv-review's mechanical rules: the paired ruling's base and vote count, each pass's rounds, the scoring run's trigger, and the comprehension history's format.
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file>
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file> [<item ID>...]
Run it inside a project checkout or one of its worktrees. ruling-base, round-count and
needs-scoring-run first fetch origin, when the checkout has that remote, and take origin's default
branch, or else the 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 two exit 1. The history is
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
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
@@ -60,13 +60,15 @@ scoring seats on the same commit and run it again with their scores file. With t
ruling counts as worse when a fallen dimension's mean is under the floor of {floor}, and stands
otherwise. It prints `Ruling:` and appends the ruling, with the scores where a fall called them.
record-scoring takes the scores file of a run needs-scoring-run called, whose first line names no
`, against`. It appends the seats' scores and their means, rounded half up to two decimals, prints
the means, and prints a line opening `Floor:` that names each mean under the floor of {floor}.
record-scoring takes the scores file of a run needs-scoring-run calls, whose first line names no
`, against`, and the same item IDs, and exits 1 when they call no run: each scoring run moves the
ratchet's base. It appends the seats' scores and their means, rounded half up to two decimals,
prints the means and, when a mean is under the floor of {floor}, a line opening `Floor:` naming
each one, which blocks the merge.
Each record is appended to the history, created when missing, under a heading of the current UTC
time and the seats file's first line. Each commit that line names must be in the checkout. Each run
appends, so record a ruling or a run once.
time and the seats file's first line. Each commit that line names must be in the checkout. It exits 1
when the history already holds an entry on what that line reads.
Exit 1, saying why, on unknown arguments, an unknown item ID, a seats file it cannot read or that
breaks the shape above, or when git cannot start, finds no checkout or no default branch, cannot
@@ -79,18 +81,18 @@ import sys
import time
import typing
from comprehension_history import appended, DIMENSIONS, heading, HISTORY, ruling_entry, Scoring, scoring_entry, vote_text
from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, recorded, ruling_entry, Scoring, scoring_entry, vote_text
from larv_review.base import base
from larv_review.rounds import CAP, PASSES, round_counts
from larv_review.git import commit_exists, default_branch, file_at, git, history_changes, landed_since_release, top
from larv_review.ruling import counted, fallen, ruling, votes
from failure import Failure
from larv_review.scoring import fall_ruling, FLOOR, means, plan_items, scoring_run_due, under_floor
from larv_review.scoring import fall_ruling, fall_step, FLOOR, means, plan_items, scoring_run_due, under_floor
from rank_todo import ITEMS_HEADER
from file_writes import replace_file
from larv_review.seats import scores, seats_file, SeatsFile
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file>"
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file> [<item ID>...]"
def main(argv: list[str]) -> int:
@@ -106,10 +108,11 @@ def main(argv: list[str]) -> int:
done = with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given]), stale_ok=False)
elif command == "record-ruling" and len(given) in (1, 2):
done = record_ruling(*map(pathlib.Path, given))
elif command == "record-scoring" and len(given) == 1:
done = record_scoring(pathlib.Path(given[0]))
elif command == "needs-scoring-run":
print(f"needs-scoring-run takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in given if not re.fullmatch(r'[0-9]+', id_))}", file=sys.stderr)
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)
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)
return 1
elif not argv:
print(USAGE, file=sys.stderr)
@@ -160,6 +163,15 @@ def round_count(default: str) -> Failure | None:
def needs_scoring_run(default: str, ids: list[int]) -> Failure | None:
reasons = plan_reasons(default, ids)
if isinstance(reasons, Failure):
return reasons
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
return None
def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure:
"""Why the plan calls a scoring run, from the default branch's todo.md and the checkout's."""
checkout = top()
if isinstance(checkout, Failure):
return checkout
@@ -180,18 +192,14 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None:
landed = landed_since_release(default)
if isinstance(landed, Failure):
return landed
reasons = scoring_run_due(planned, chunk, ids, landed)
if isinstance(reasons, Failure):
return reasons
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
return None
return scoring_run_due(planned, chunk, ids, landed)
def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = None) -> Failure | None:
read = read_seats(votes_file, paired=True)
if isinstance(read, Failure):
return read
title, given = read
named, given = read
said = votes(given.seats)
if isinstance(said, Failure):
return said
@@ -202,49 +210,52 @@ def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = N
print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the votes file, and run this again.")
return None
fell = fallen(count) if ruled != "worse" else []
if fell and scores_file is None:
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {given.read.partition(', against')[0]}, write their lines to a scores file, and run this again with both files.")
return None
if scores_file and not fell:
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
lines = [f"Ruling: {ruled}"]
scoring = None
notes = []
match fall_step(fell, scores_file is not None):
case "ask":
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {named.label} at {named.commit}, write their lines to a scores file, and run this again with both files.")
return None
case "refuse":
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
if scores_file:
scored = read_scoring(scores_file, given.read.partition(", against")[0])
scored = read_scoring(scores_file, named)
if isinstance(scored, Failure):
return scored
scoring = scored
ruled, why = fall_ruling(ruled, fell, [decimal.Decimal(value) for value in scoring.means])
lines = [f"Ruling: {ruled}", why]
print(f"{lines[0]}. {' '.join(lines[1:] + [f'Overall votes as counted: {tally}.'])}")
return append(ruling_entry(title, given.seats, said, count, lines, scoring))
ruled, why = fall_ruling(ruled, fell, scoring.means)
notes = [why]
print(f"Ruling: {ruled}. {' '.join(notes + [f'Overall votes as counted: {tally}.'])}")
return append(given.read, ruling_entry(named.title, given.seats, said, count, ruled, notes, scoring))
def record_scoring(scores_file: pathlib.Path) -> Failure | None:
def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> Failure | None:
read = read_seats(scores_file, paired=False)
if isinstance(read, Failure):
return read
title, given = read
named, given = read
scoring = scored_seats(given)
if isinstance(scoring, Failure):
return scoring
found = [decimal.Decimal(value) for value in scoring.means]
print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, found))}.")
if under := under_floor(found):
print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge.")
return append(scoring_entry(title, [], scoring))
reasons = plan_reasons(default, ids)
if isinstance(reasons, Failure):
return reasons
if not reasons:
return Failure("no plan item or release calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them, or record a fall's scores with record-ruling")
print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, scoring.means))}.")
if under := under_floor(scoring.means):
print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge, as the chunk {' and '.join(reasons)}.")
return append(given.read, scoring_entry(named.title, scoring))
def read_scoring(scores_file: pathlib.Path, read: str) -> Scoring | Failure:
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."""
try:
given = seats_file(scores_file.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {scores_file}: {failure}")
if isinstance(given, Failure):
return given
if given.read != read:
return Failure(f"the scores file's first line is not `{read}`, as the votes file reads: {given.read}")
read = read_seats(scores_file, paired=False)
if isinstance(read, Failure):
return read
named, given = read
if (named.label, named.commit) != (votes.label, votes.commit):
return Failure(f"the scores file's first line is not `{votes.label} at {votes.commit}`, as the votes file reads: {given.read}")
return scored_seats(given)
@@ -252,10 +263,10 @@ def scored_seats(given: SeatsFile) -> Scoring | Failure:
found = scores(given.seats)
if isinstance(found, Failure):
return found
return Scoring(given.seats, found, [str(value) for value in means(list(found.values()))])
return Scoring(given.seats, found, means(list(found.values())))
def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Failure:
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."""
try:
given = seats_file(path.read_text(encoding="utf-8"))
@@ -268,19 +279,25 @@ def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Fail
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")
return named.title, given
return named, given
def append(entry: str) -> Failure | None:
def append(read: str, entry: str) -> Failure | None:
"""Append entry unless the history already holds one on what the seats read."""
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 ""
history.parent.mkdir(parents=True, exist_ok=True)
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {history}: {failure}")
if recorded(text, read):
return Failure(f"{history} already holds an entry on {read}; record each ruling or run once")
try:
history.parent.mkdir(parents=True, exist_ok=True)
except OSError as failure:
return Failure(f"could not create {history.parent}: {failure}")
if unwritten := replace_file(history, appended(text, entry).encode()):
return Failure(f"could not write {history}: {unwritten.reason}")
print(f"Appended to {history}.")