Answer architecture round 7: decide a fall inside record-ruling with the scoring seats' scores, give the history format one owner in comprehension_history, drop the moved Mean path, and plan the archive and judge restructures in items 83 and 62

This commit is contained in:
2026-10-09 12:22:13 +02:00
parent b02bdd0bf4
commit e694e4154e
17 changed files with 238 additions and 363 deletions
@@ -2,25 +2,35 @@ import dataclasses
import re
import time
from larv_review.seats import ARCHITECT, DIMENSIONS, MEAN, Seat
from failure import Failure
from markdown_sections import sections
DATED = re.compile(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}(?:T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)?, ")
ARCHITECT = "Inherited architect"
DECIDED_BY = "decided by"
FELL = re.compile(r"^Fell: (.+)$", re.M)
RATCHET = re.compile(r"^Ratchet: .+$", re.M)
DIMENSIONS = ("Navigation", "Locality", "Shape", "Self-sufficiency", "Overall")
HARDEST_FIRST = "hardest first"
HEADING = re.compile(r"^([^,]+), (.+) at ([0-9a-f]{7,40})(?:, against ([0-9a-f]{7,40}))?$")
HISTORY = "docs/comprehension-history.md"
JUNIOR = "Junior A"
MEAN = "Mean"
MID = "Mid A"
# `path:line` or `:line`, then the unit's name where one follows.
PLACE = re.compile(r"`([^`\s]*):\d+`(?: `(\w+)`)?")
RESTRUCTURE_FIRST = "would restructure first"
RULING = re.compile(r"^Ruling: (better|same|worse)$", re.M)
SEAT_PLACES = re.compile(rf"^.+, ({DECIDED_BY}|{HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$")
SENIOR = "Maintainability senior"
STAMP = "%Y-%m-%dT%H:%M:%SZ"
TITLE = "# Comprehension history\n"
@dataclasses.dataclass(frozen=True)
class Seat:
name: str
said: str
places: list[str]
@dataclasses.dataclass(frozen=True)
class Place:
path: str
@@ -29,14 +39,12 @@ class Place:
@dataclasses.dataclass(frozen=True)
class Entry:
"""One paired ruling, which names the commit it was against, its ruling and the dimensions that fell unless it is worse, or one scoring run, which names none of them and may hold a `Ratchet:` line."""
"""One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither."""
heading: str
time: str
commit: str
against: str | None
ruling: str | None
fell: list[str]
ratchet: str | None
places: list[Place]
@property
@@ -52,11 +60,11 @@ class Heading:
@dataclasses.dataclass(frozen=True)
class HistoryChange:
"""A merged change on the default branch that touched the history, and the history before and after it."""
commit: str
before: str
after: str
class Scoring:
"""The four scoring seats' lines, their scores as written and the means, in DIMENSIONS' order."""
seats: list[Seat]
scores: dict[str, list[str]]
means: list[str]
def entries(history: str) -> list[Entry]:
@@ -66,9 +74,7 @@ def entries(history: str) -> list[Entry]:
if named := HEADING.match(heading):
body = "\n".join(bodies)
ruling = RULING.search(body)
fell = FELL.search(body)
ratchet = RATCHET.search(body)
found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, [name.strip() for name in fell.group(1).split(",")] if fell else [], ratchet.group(0) if ratchet else None, seat_places(body)))
found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, seat_places(body)))
return found
@@ -96,13 +102,9 @@ def bullet_places(bullet: str) -> list[Place]:
return places
def heading(at: float, read: str, paired: bool, moved: bool) -> Heading | Failure:
"""An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read. A run moved from a decision entry opens instead with the date or time that entry gives."""
if moved and not DATED.match(read):
return Failure(f"a seats file holding a {MEAN} line alone opens with YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ, then `, `: {read}")
if DATED.match(read) and not moved:
return Failure(f"only a seats file holding a {MEAN} line alone opens with a date: {read}")
title = read if moved else f"{time.strftime(STAMP, time.gmtime(at))}, {read}"
def heading(at: float, read: str, paired: bool) -> Heading | Failure:
"""An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read."""
title = f"{time.strftime(STAMP, time.gmtime(at))}, {read}"
if (named := HEADING.match(title)) and bool(named.group(4)) == paired:
return Heading(title, named.group(3), named.group(4))
return Failure(f"the seats file's first line is not `<PR or branch> at <commit>{', against <base>' if paired else ''}`: {read}")
@@ -114,11 +116,12 @@ def appended(history: str, entry: str) -> str:
return f"{text}\n{entry}"
def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], ruled: str, fell: list[str]) -> str:
"""A paired ruling's entry; a seat's vote that counted as same for want of a place says so."""
def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], lines: list[str], scoring: Scoring | None) -> str:
"""A paired ruling's entry, with the scoring run that decided a fall; a seat's vote that counted as same for want of a place says so."""
votes = [[seat.name, *map(vote_text, DIMENSIONS, said[seat.name], counted[seat.name])] for seat in seats]
lines = [f"Ruling: {ruled}"] + ([f"Fell: {', '.join(fell)}"] if fell else [])
return entry_text(title, lines, [["Seat", *DIMENSIONS], *votes], [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats])
tables = [[["Seat", *DIMENSIONS], *votes]] + ([scores_table(scoring)] if scoring else [])
labels = [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats] + (scoring_labels(scoring.seats) if scoring else [])
return entry_text(title, lines, tables, labels)
def vote_text(dimension: str, said: str, counted: str) -> str:
@@ -127,17 +130,21 @@ def vote_text(dimension: str, said: str, counted: str) -> str:
return f"same (voted {said}, naming no place)" if dimension == DIMENSIONS[-1] else f"same (voted {said}, no place naming {dimension})"
def scoring_entry(title: str, seats: list[Seat], scores: dict[str, list[str]], means: list[str], lines: list[str]) -> str:
"""A scoring run's entry, with any lines such as a `Ratchet:` line; a run moved from a decision entry has its means alone."""
rows = [[seat, *values] for seat, values in scores.items()] + [[MEAN, *means]]
labels = [(f"{seat.name}, {RESTRUCTURE_FIRST if seat.name == ARCHITECT else HARDEST_FIRST}:", seat.places) for seat in seats]
return entry_text(title, lines, [["Seat", *DIMENSIONS], *rows], labels)
def scoring_entry(title: str, lines: list[str], scoring: Scoring) -> str:
return entry_text(title, lines, [scores_table(scoring)], scoring_labels(scoring.seats))
def entry_text(title: str, lines: list[str], table: list[list[str]], seats: list[tuple[str, list[str]]]) -> str:
"""The heading, any lines such as `Ruling: same`, a table whose first row is its header, and under each seat's label its places, one bullet each."""
header, *rows = table
parts = [f"## {title}", *lines, "\n".join([row_text(header), "|" + "---|" * len(header), *map(row_text, rows)])]
def scores_table(scoring: Scoring) -> list[list[str]]:
return [["Seat", *DIMENSIONS], *([seat, *values] for seat, values in scoring.scores.items()), [MEAN, *scoring.means]]
def scoring_labels(seats: list[Seat]) -> list[tuple[str, list[str]]]:
return [(f"{seat.name}, {RESTRUCTURE_FIRST if seat.name == ARCHITECT else HARDEST_FIRST}:", seat.places) for seat in seats]
def entry_text(title: str, lines: list[str], tables: list[list[list[str]]], seats: list[tuple[str, list[str]]]) -> str:
"""The heading, any lines such as `Ruling: same`, each table, whose first row is its header, and under each seat's label its places, one bullet each."""
parts = [f"## {title}", *lines, *("\n".join([row_text(header), "|" + "---|" * len(header), *map(row_text, rows)]) for header, *rows in tables)]
parts += [f"{label}\n\n" + "\n".join(f"- {place}" for place in places) for label, places in seats if places]
return "\n\n".join(parts) + "\n"
+5 -6
View File
@@ -1,16 +1,15 @@
from larv_review.history import entries, Entry, HistoryChange
from comprehension_history import entries, Entry
from larv_review.git import HistoryChange
def measured_commit(changes: list[HistoryChange]) -> str | None:
"""The newest change, of changes given newest first, whose last added paired ruling is better, or that adds a scoring run and whose last added paired ruling names no fall."""
"""The newest change, of changes given newest first, that adds a scoring run to the history, or whose last added paired ruling is better."""
for change in changes:
held = {entry.heading for entry in entries(change.before)}
added = [entry for entry in entries(change.after) if entry.heading not in held]
rulings = sorted((entry for entry in added if entry.paired), key=lambda entry: entry.time)
last = rulings[-1] if rulings else None
ruled_better = last is not None and last.ruling == "better"
scored_without_fall = any(not entry.paired for entry in added) and not (last and last.fell)
if ruled_better or scored_without_fall:
ruled_better = bool(rulings) and rulings[-1].ruling == "better"
if ruled_better or any(not entry.paired for entry in added):
return change.commit
return None
+9 -2
View File
@@ -1,10 +1,17 @@
import dataclasses
import re
import subprocess
from failure import Failure
from larv_review.history import HistoryChange
from comprehension_history import HISTORY
HISTORY = "docs/comprehension-history.md"
@dataclasses.dataclass(frozen=True)
class HistoryChange:
"""A merged change on the default branch that touched the history, and the history before and after it."""
commit: str
before: str
after: str
def git(*args: str) -> str | Failure:
+103 -139
View File
@@ -1,38 +1,35 @@
"""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 <seats file> | record-scoring <seats file> [<item ID>...]
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file>
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
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
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
measured commit is the default branch's newest merged change whose last added paired ruling, by
heading time, is better, or that adds a scoring run to the history while that ruling names no fall;
a merge commit counts as one change against its first parent. With none, the base is the one the
history's first paired ruling names; with no ruling either, it is the merge base of HEAD and the
default branch.
measured commit is the default branch's newest merged change that adds a scoring run to the
history, or whose last added paired ruling, by heading time, is better; a merge commit counts as
one change against its first parent. With none, the base is the one the history's first paired
ruling names; with no ruling either, it is the merge base of HEAD and the default branch.
round-count prints each pass's count: the highest <n> among the titles opening `Answer <pass> round
<n>:` of commits the default branch does not hold. It marks each pass at the cap of {cap} rounds,
and each name in such a title that is not a pass.
needs-scoring-run takes the IDs of the todo.md items the chunk ships, none when it ships none, and
prints why the chunk is due a scoring run, or `No scoring run due.` The chunk's entries are those
the checkout's history holds and the default branch's lacks. It is due when the chunk ships an item
whose tagline names the comprehension floor, when it leaves a release with no item in the
checkout's todo.md, less the shipped items, and work has landed towards that release, or when the
chunk's newest entry is a paired ruling with a `Fell:` line. Work has landed when the chunk ships
one of the release's items, or when the release is the earliest the default branch's todo.md names
and the default branch has a commit after its newest v* tag, or has no v* tag.
prints why the chunk is due a scoring run, or `No scoring run due.` It is due when the chunk ships
an item whose tagline names the comprehension floor, or when it leaves a release with no item in
the checkout's todo.md, less the shipped items, and work has landed towards that release. Work has
landed when the chunk ships one of the release's items, or when the release is the earliest the
default branch's todo.md names and the default branch has a commit after its newest v* tag, or has
no v* tag.
record-ruling and record-scoring read a seats file: a first line naming what the seats read, `<PR or
branch> at <commit>`, ending `, against <base>` for a paired ruling, then each seat's line, each
followed by its places, one `- ` bullet each, as the history writes them. A seat's line opens with
its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability senior:` or `Inherited
architect:`.
A seats file's first line names what the seats read, `<PR or branch> at <commit>`, ending
`, against <base>` in a votes file. Each seat's line follows, opening with its label written
exactly: `Junior A:`, `Mid A:`, `Maintainability senior:` or `Inherited architect:`. Its places
follow it, one `- ` bullet each, as the history writes them. A votes file:
PR #231 at abc1234, against def5678
@@ -46,35 +43,30 @@ architect:`.
- Navigation: `README.md:40` "Tools": ...
- Locality: `bin/x.py:12` `run`: ...
A scores file holds Junior A's, Mid A's, the maintainability senior's and the inherited architect's
lines in that order, each `Navigation <n>, Locality <n>, Shape <n>, Self-sufficiency <n>, Overall
<n>`: each score from 1 to 10, and the overall at most 1 above the line's lowest dimension.
record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall, each
better, same or worse. Each place opens with the names from the seat's line that it moves, joined by
`, ` and followed by `: `. A dimension's vote counts as same unless one of the seat's places opens
with that dimension and holds a `path:line` in backticks; the overall vote counts as same unless any
place holds one. The printed votes say so. When the two counted overall votes differ, it appends
nothing and prints `Split:`, saying to add the maintainability senior's and Junior A's lines.
Otherwise the ruling is the overall vote that leads each other vote by two or more, else same; it
prints `Ruling:` and appends the ruling. A dimension falls when its worse votes lead each other vote
by two or more. Unless the ruling is worse, it prints and records a `Fell:` line naming each.
Otherwise the ruling is the overall vote that leads each other vote by two or more, else same. A
dimension falls when its worse votes lead each other vote by two or more. When a better or same
ruling has a fallen dimension, it appends nothing and prints `Fell:`, saying to run the four
scoring seats on the same commit and run it again with their scores file. With that file, the
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 a seats file and the IDs of the items the chunk ships, as needs-scoring-run
does. The file holds Junior A's, Mid A's, the maintainability senior's and the inherited architect's
lines in that order, or a `Mean:` line alone for a run moved from a decision entry. Each line is
`Navigation <n>, Locality <n>, Shape <n>, Self-sufficiency <n>, Overall <n>`, each score from 1 to
10 and the overall at most 1 above the line's lowest dimension. Its first line names no `, against`.
It appends the seats' scores and their means, rounded half up to two decimals, and prints the means,
the item IDs it read, and each mean under the floor of {floor}. It exits 1 on a run with seats that
no plan item, release or fall calls. A line opening `Floor:` says the means under the floor block
the merge, as they do when needs-scoring-run would give a reason besides a fall. It reads the
chunk's entries as needs-scoring-run does. When a fall is pending, it says whether the paired ruling
stands. When a fallen dimension's mean is under the floor, the ruling counts as worse, and it prints
and records a `Ratchet:` line. needs-scoring-run repeats that line, prefixed with `Still standing:`,
until a paired ruling follows it. Once a scoring run follows a fall, the fall calls no other. A file
holding a `Mean:` line alone prints only its means.
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}.
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. A file holding a `Mean:` line alone opens with the date or
time its decision entry gives, and that line alone is the heading. Each commit the 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. Each run
appends, so record a ruling or a run once.
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
@@ -87,18 +79,18 @@ import sys
import time
import typing
from larv_review.history import appended, heading, ruling_entry, scoring_entry, vote_text
from comprehension_history import appended, DIMENSIONS, heading, HISTORY, 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.scoring import chunk_entries, fall, Fall, fall_outcome, fall_reasons, FLOOR, floor_verdict, means, plan_items, scoring_run_due, uncalled, under_floor
from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top
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 larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores
from failure import Failure
from larv_review.scoring import fall_ruling, 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 <seats file> | record-scoring <seats file> [<item ID>...]"
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file>"
def main(argv: list[str]) -> int:
@@ -112,13 +104,12 @@ def main(argv: list[str]) -> int:
done = with_default_branch(round_count, stale_ok=True)
elif command == "needs-scoring-run" and all(re.fullmatch(r"[0-9]+", id_) for id_ in given):
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) == 1:
done = record_ruling(pathlib.Path(given[0]))
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)
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)
return 1
elif not argv:
print(USAGE, file=sys.stderr)
@@ -169,21 +160,6 @@ def round_count(default: str) -> Failure | None:
def needs_scoring_run(default: str, ids: list[int]) -> Failure | None:
state = chunk_fall(default)
if isinstance(state, Failure):
return state
planned = plan_reasons(default, ids)
if isinstance(planned, Failure):
return planned
reasons = planned + fall_reasons(state)
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
if state.ratchet:
print(f"Still standing: {state.ratchet} Fix it and rule again.")
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
@@ -204,22 +180,15 @@ def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure:
landed = landed_since_release(default)
if isinstance(landed, Failure):
return landed
return scoring_run_due(planned, chunk, ids, 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
def chunk_fall(default: str) -> Fall | Failure:
"""Where the chunk stands in the fall sequence, from the entries the checkout's history holds and the default branch's lacks."""
held = file_at(default, HISTORY)
if isinstance(held, Failure):
return held
read = history_text()
if isinstance(read, Failure):
return read
return fall(chunk_entries(held, read[1]))
def record_ruling(seats_file: pathlib.Path) -> Failure | None:
read = read_seats(seats_file, paired=True)
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
@@ -230,65 +199,71 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | None:
tally = ", ".join(f"{seat.name} {vote_text(DIMENSIONS[-1], said[seat.name][-1], count[seat.name][-1])}" for seat in given.seats)
ruled = ruling([each[-1] for each in count.values()])
if ruled is None:
print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the seats file, and run this again.")
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 []
print(f"Ruling: {ruled}. Overall votes as counted: {tally}.")
if fell:
print(f"Fell: {', '.join(fell)}. A scoring run is due; the ruling counts as worse if that run scores {' or '.join(fell)} under the floor of {FLOOR}.")
return append(ruling_entry(title, given.seats, said, count, ruled, fell))
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
if scores_file:
scored = read_scoring(scores_file, given.read.partition(", against")[0])
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))
def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Failure | None:
read = read_seats(seats_file, paired=False)
def record_scoring(scores_file: pathlib.Path) -> Failure | None:
read = read_seats(scores_file, paired=False)
if isinstance(read, Failure):
return read
title, given = read
if given.moved_mean is not None:
return record_moved_mean(title, given.moved_mean)
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))
def read_scoring(scores_file: pathlib.Path, read: str) -> 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}")
return scored_seats(given)
def scored_seats(given: SeatsFile) -> Scoring | Failure:
found = scores(given.seats)
if isinstance(found, Failure):
return found
mean = means(list(found.values()))
state = chunk_fall(default)
if isinstance(state, Failure):
return state
planned = plan_reasons(default, ids)
if isinstance(planned, Failure):
return planned
if not (planned or state.pending):
return Failure(uncalled(state))
print(f"Means: {means_text(mean)}.")
print(f"Item IDs read: {', '.join(map(str, ids)) or 'none'}.")
print(floor_verdict(under_floor(mean), planned))
outcome = fall_outcome(state.pending, mean)
if outcome:
print(outcome[0])
return append(scoring_entry(title, given.seats, found, [str(value) for value in mean], outcome[1] if outcome else []))
return Scoring(given.seats, found, [str(value) for value in means(list(found.values()))])
def record_moved_mean(title: str, line: str) -> Failure | None:
moved = score_line(MEAN, line)
if isinstance(moved, Failure):
return moved
mean = means([moved])
print(f"Means: {means_text(mean)}.")
return append(scoring_entry(title, [], {}, [str(value) for value in mean], []))
def means_text(mean: list[decimal.Decimal]) -> str:
return ", ".join(f"{name} {value}" for name, value in zip(DIMENSIONS, mean))
def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | Failure:
def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Failure:
"""The seats file, and the heading its record goes under, once each commit it names is in the checkout."""
try:
given = report(seats_file.read_text(encoding="utf-8"))
given = seats_file(path.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {seats_file}: {failure}")
return Failure(f"could not read {path}: {failure}")
if isinstance(given, Failure):
return given
named = heading(time.time(), given.read, paired, given.moved_mean is not None)
named = heading(time.time(), given.read, paired)
if isinstance(named, Failure):
return named
if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]:
@@ -296,27 +271,16 @@ def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | F
return named.title, given
def history_text() -> tuple[pathlib.Path, str] | Failure:
"""The checkout's history and its text, empty when the file is missing."""
def append(entry: str) -> Failure | None:
checkout = top()
if isinstance(checkout, Failure):
return checkout
history = pathlib.Path(checkout, HISTORY)
try:
return history, history.read_text(encoding="utf-8") if history.exists() else ""
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}")
def append(entry: str) -> Failure | None:
read = history_text()
if isinstance(read, Failure):
return read
history, text = read
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}.")
+2 -2
View File
@@ -1,6 +1,6 @@
from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS, vote_line
from comprehension_history import DIMENSIONS, PLACE, Seat
from failure import Failure
from larv_review.history import PLACE
from larv_review.seats import FIRST_SEATS, SPLIT_SEATS, vote_line
VOTES = ("better", "same", "worse")
+7 -53
View File
@@ -1,64 +1,18 @@
import dataclasses
import decimal
import itertools
from larv_review.seats import DIMENSIONS
from larv_review.history import entries, Entry
from comprehension_history import DIMENSIONS
from failure import Failure
from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows
FLOOR = decimal.Decimal("7.0")
def chunk_entries(default_history: str, history: str) -> list[Entry]:
"""The checkout's entries whose headings the default branch's history lacks, oldest first; entries sharing a time keep their file order."""
held = {entry.heading for entry in entries(default_history)}
return sorted((entry for entry in entries(history) if entry.heading not in held), key=lambda entry: entry.time)
@dataclasses.dataclass(frozen=True)
class Fall:
"""Where the chunk stands in the fall sequence: a paired ruling with a `Fell:` line leaves its dimensions pending until a scoring run follows; that run records a `Ratchet:` line when a fallen dimension is under the floor, and the ratchet stands until the next paired ruling."""
pending: list[str]
ratchet: str | None
scored_last: bool
def fall(chunk: list[Entry]) -> Fall:
newest = chunk[-1] if chunk else None
since_ruling = list(itertools.takewhile(lambda entry: not entry.paired, reversed(chunk)))
ratchet = next((entry.ratchet for entry in since_ruling if entry.ratchet), None)
return Fall(newest.fell if newest and newest.paired else [], ratchet, newest is not None and not newest.paired)
def fall_reasons(state: Fall) -> list[str]:
return [f"has a paired ruling in which {' and '.join(state.pending)} fell"] if state.pending else []
def uncalled(state: Fall) -> str:
"""Why a scoring run nothing calls fails, and what to do instead."""
if state.scored_last:
return "the chunk's newest entry is already a scoring run; record a paired ruling first, or name the item IDs the chunk ships"
return "no plan item, release or fall calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them"
def floor_verdict(under: list[str], reasons: list[str]) -> str:
"""Whether the means under the floor block the merge: they do on a run the plan calls, its reasons given."""
if not under:
return f"None under the floor of {FLOOR}."
if reasons:
return f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge, as the chunk {' and '.join(reasons)}."
return f"Under the floor of {FLOOR}, blocking nothing, as only a fall called this run: {', '.join(under)}."
def fall_outcome(fell: list[str], found: list[decimal.Decimal]) -> tuple[str, list[str]] | None:
"""What a scoring run says of a pending fall, and the lines it records: a `Ratchet:` line when a fallen dimension's mean is under the floor."""
if not fell:
return None
if dropped := [f"{name} is {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]:
line = f"Ratchet: the paired ruling counts as worse, as {' and '.join(fell)} fell and {', '.join(dropped)}, under the floor of {FLOOR}."
return line, [line]
return f"The paired ruling stands: {' and '.join(fell)} fell and each stays at or above the floor of {FLOOR}.", []
def fall_ruling(ruled: str, fell: list[str], found: list[decimal.Decimal]) -> tuple[str, str]:
"""The ruling once the scoring run has scored the dimensions that fell, and the line that says why: worse when one of their means is under the floor."""
under = [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]
if under:
return "worse", f"Fell: {', '.join(fell)}, under the floor of {FLOOR} at {', '.join(under)}, so the {ruled} ruling counts as worse."
return ruled, f"Fell: {', '.join(fell)}, each at or above the floor of {FLOOR}, so the {ruled} ruling stands."
def means(lines: list[list[str]]) -> list[decimal.Decimal]:
+7 -26
View File
@@ -2,16 +2,10 @@ import dataclasses
import decimal
import re
from comprehension_history import ARCHITECT, DIMENSIONS, JUNIOR, MID, Seat, SENIOR
from failure import Failure
ARCHITECT = "Inherited architect"
DIMENSIONS = ("Navigation", "Locality", "Shape", "Self-sufficiency", "Overall")
JUNIOR = "Junior A"
# A scoring run moved from a `comprehension floor:` decision entry kept only the seats' means.
MEAN = "Mean"
MID = "Mid A"
SCORES = re.compile(", ".join(rf"{name} ([0-9]+(?:\.[0-9]+)?)" for name in DIMENSIONS))
SENIOR = "Maintainability senior"
FIRST_SEATS = (MID, ARCHITECT)
SCORING_SEATS = (JUNIOR, MID, SENIOR, ARCHITECT)
@@ -21,32 +15,19 @@ VOTE_LINE = re.compile(", ".join(rf"{name} (better|same|worse)" for name in DIME
@dataclasses.dataclass(frozen=True)
class Seat:
name: str
said: str
places: list[str]
@dataclasses.dataclass(frozen=True)
class Report:
"""A seats file: what the seats read, `<PR or branch> at <commit>`, with `, against <base>` for a paired ruling, then each seat's line and its places, or, for a run moved from a decision entry, its Mean line alone."""
class SeatsFile:
"""What the seats read, `<PR or branch> at <commit>`, with `, against <base>` for a paired ruling, then each seat's line and its places."""
read: str
seats: list[Seat]
moved_mean: str | None
def report(text: str) -> Report | Failure:
def seats_file(text: str) -> SeatsFile | Failure:
lines = [line for line in text.splitlines() if line.strip()]
if not lines:
return Failure("the seats file is empty; its first line names what the seats read: <PR or branch> at <commit>")
seats: list[Seat] = []
moved_mean = None
for line in lines[1:]:
if line.startswith(f"{MEAN}: ") and not seats and moved_mean is None:
moved_mean = line[len(MEAN) + 2:].strip()
elif moved_mean is not None:
return Failure(f"a {MEAN} line stands alone in its seats file: {line}")
elif seat := SEAT_LINE.match(line):
if seat := SEAT_LINE.match(line):
if seat.group(1) in [known.name for known in seats]:
return Failure(f"{seat.group(1)} appears twice in the seats file")
seats.append(Seat(seat.group(1), seat.group(2).strip(), []))
@@ -56,13 +37,13 @@ def report(text: str) -> Report | Failure:
seats[-1].places[-1] += " " + line.strip()
else:
return Failure(f"the seats file has a line that is neither a seat's line, opening with one of {', '.join(SCORING_SEATS)} and a colon, nor one of its places: {line}")
return Report(lines[0].strip(), seats, moved_mean)
return SeatsFile(lines[0].strip(), seats)
def scores(seats: list[Seat]) -> dict[str, list[str]] | Failure:
"""Each seat's five scores as written, in DIMENSIONS' order."""
if [seat.name for seat in seats] != list(SCORING_SEATS):
return Failure(f"a scoring run's seats are {', '.join(SCORING_SEATS)}, in that order, or a {MEAN} line alone; the file has {', '.join(seat.name for seat in seats) or 'none'}")
return Failure(f"a scoring run's seats are {', '.join(SCORING_SEATS)}, in that order; the file has {', '.join(seat.name for seat in seats) or 'none'}")
found = {}
for seat in seats:
values = score_line(seat.name, seat.said)
+1 -1
View File
@@ -4,7 +4,7 @@ import dataclasses
import os
import statistics
from larv_review.history import Place
from comprehension_history import Place
from metric_bench.python_units import Unit
METRICS: dict[str, Callable[[Unit, dict[str, int]], int]] = {
+1 -1
View File
@@ -35,7 +35,7 @@ import subprocess
import sys
from metric_bench.bench import bench, co_changed, medians, METRICS, resolved, RunScores, Score
from larv_review.history import entries, Entry
from comprehension_history import entries, Entry
from failure import Failure
from metric_bench.python_units import measured, python_units, Unit
+44 -86
View File
@@ -9,15 +9,16 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from larv_review.history import appended, entries, HistoryChange, Place, ruling_entry
from comprehension_history import appended, entries, Place, ruling_entry, Scoring, Seat
from larv_review.base import base, first_ruling, measured_commit
from larv_review.scoring import chunk_entries, fall, fall_outcome, fall_reasons, means, plan_items, scoring_run_due, under_floor
from larv_review.ruling import counted, fallen, ruling, votes
from failure import Failure
from larv_review.scoring import fall_ruling, means, plan_items, scoring_run_due, under_floor
from larv_review.git import HistoryChange
from test_loop_claude_black_box import host_env
from rank_todo import Item
from larv_review.seats import report, score_line, scores, Seat
from larv_review.rounds import round_counts
from larv_review.seats import score_line, scores, seats_file
TOOL = pathlib.Path(__file__).resolve().parent / "larv-review"
SCORING = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n"
@@ -41,14 +42,14 @@ def todo(*rows: str) -> str:
class Seats(unittest.TestCase):
def test_reads_each_seats_line_and_places_and_joins_a_wrapped_place(self):
given = report(f"PR #2 at abc1234, against def5678\n\nMid A: {said('worse')}\n\n- `a.py:1` `f`: hard\n to read\n\nInherited architect: {said('same')}\n")
given = seats_file(f"PR #2 at abc1234, against def5678\n\nMid A: {said('worse')}\n\n- `a.py:1` `f`: hard\n to read\n\nInherited architect: {said('same')}\n")
self.assertEqual(given.read, "PR #2 at abc1234, against def5678")
self.assertEqual(given.seats, [Seat("Mid A", said("worse"), ["`a.py:1` `f`: hard to read"]), Seat("Inherited architect", said("same"), [])])
def test_refuses_a_line_that_is_neither_a_seat_nor_a_place_and_a_seat_twice(self):
self.assertIsInstance(report("PR #2 at abc1234\n\nMid A worse\n"), Failure)
self.assertIsInstance(report("PR #2 at abc1234\n\nMid A: worse\n\nMid A: same\n"), Failure)
self.assertIsInstance(report(""), Failure)
self.assertIsInstance(seats_file("PR #2 at abc1234\n\nMid A worse\n"), Failure)
self.assertIsInstance(seats_file("PR #2 at abc1234\n\nMid A: worse\n\nMid A: same\n"), Failure)
self.assertIsInstance(seats_file(""), Failure)
def test_counts_each_vote_of_a_seat_naming_no_place_as_same(self):
seats = [Seat("Mid A", said("worse", "worse"), ["Locality: the whole skill"]), Seat("Inherited architect", said("better"), ["Overall: `a.py:3` `f`: shorter"])]
@@ -80,11 +81,6 @@ class Seats(unittest.TestCase):
four = {name: ["same", vote, "same", "same", "better"] for name, vote in (("Mid A", "worse"), ("Inherited architect", "same"), ("Maintainability senior", "worse"), ("Junior A", "worse"))}
self.assertEqual(fallen(four), ["Locality"])
self.assertEqual(fallen({**four, "Junior A": ["same", "better", "same", "same", "better"]}), [])
found = [decimal.Decimal(score) for score in ("6", "6.5", "7", "6", "6")]
ratchet = "Ratchet: the paired ruling counts as worse, as Locality and Shape fell and Locality is 6.5, under the floor of 7.0."
self.assertEqual(fall_outcome(["Locality", "Shape"], found), (ratchet, [ratchet]))
self.assertEqual(fall_outcome(["Shape"], found), ("The paired ruling stands: Shape fell and each stays at or above the floor of 7.0.", []))
self.assertIsNone(fall_outcome([], found))
def test_rules_by_a_lead_of_two_and_splits_two_seats_that_differ(self):
cases = [
@@ -120,39 +116,24 @@ class History(unittest.TestCase):
def test_reads_back_what_it_writes(self):
seats = [Seat("Mid A", said("better", "worse"), ["`bin/a.py:3` `f`: hard, with `:9` `g`"]), Seat("Inherited architect", said("worse", "worse"), [])]
written = {"Mid A": ["same", "worse", "same", "same", "better"], "Inherited architect": ["same", "worse", "same", "same", "worse"]}
ruled = ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, {**written, "Inherited architect": ["same"] * 5}, "better", ["Locality"])
scoring = Scoring([Seat("Junior A", "", ["`bin/b.py:4` `h`: long"])], {"Junior A": ["7", "6.5", "7", "7", "7"]}, ["7.00", "6.50", "7.00", "7.00", "7.00"])
ruled = ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, {**written, "Inherited architect": ["same"] * 5}, ["Ruling: worse", "Fell: Locality, under the floor."], scoring)
history = appended(appended("", SCORING), ruled)
self.assertTrue(history.startswith("# Comprehension history\n\n## 2026-10-08T12:00:00Z"))
self.assertNotIn("Inherited architect, decided by:", history)
self.assertIn("| Inherited architect | same | same (voted worse, no place naming Locality) | same | same | same (voted worse, naming no place) |", history)
found = entries(history)
self.assertEqual([(entry.commit, entry.against, entry.ruling, entry.fell) for entry in found], [("aaaaaaa", None, None, []), ("bbbbbbb", "aaaaaaa", "better", ["Locality"])])
self.assertEqual(found[1].places, [Place("bin/a.py", "f"), Place("bin/a.py", "g")])
self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in found], [("aaaaaaa", None, None), ("bbbbbbb", "aaaaaaa", "worse")])
self.assertEqual(found[1].places, [Place("bin/a.py", "f"), Place("bin/a.py", "g"), Place("bin/b.py", "h")])
self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 7.00 | 7.00 |\n\nMid A, decided by:", history)
self.assertEqual([entry.paired for entry in found], [False, True])
class FallState(unittest.TestCase):
def test_gives_the_fall_its_own_reason_outside_the_plans(self):
plan = [item(1, (0, 1, 0)), item(2, (0, 1, 0))]
self.assertEqual(scoring_run_due(plan, plan, [], True), [])
self.assertEqual(fall_reasons(fall(chunk_entries("", paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality")))), ["has a paired ruling in which Locality fell"])
def test_finds_a_fall_in_the_newest_entry_when_it_is_a_better_ruling(self):
fell = paired("2026-10-08T13:00:00Z", "better\n\nFell: Locality,Shape")
self.assertEqual(fall(chunk_entries("", SCORING + fell)).pending, ["Locality", "Shape"])
later = SCORING.replace("12:00:00Z", "14:00:00Z").replace("| Mean | 7.00 |", "Ratchet: worse.\n\n| Mean | 7.00 |")
self.assertEqual(fall(chunk_entries("", fell + later)).pending, [])
self.assertEqual(fall(chunk_entries("", fell + later)).ratchet, "Ratchet: worse.")
self.assertEqual(fall(chunk_entries("", SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality"))).pending, ["Locality"])
self.assertEqual(fall(chunk_entries("", "")).pending, [])
rescored = SCORING.replace("12:00:00Z", "15:00:00Z")
self.assertEqual(fall(chunk_entries("", fell + later + rescored)).ratchet, "Ratchet: worse.")
self.assertIsNone(fall(chunk_entries("", fell + later + paired("2026-10-08T16:00:00Z", "same"))).ratchet)
def test_reads_only_the_entries_the_default_branch_lacks(self):
fell = paired("2026-10-08T13:00:00Z", "better\n\nFell: Locality")
merged = SCORING.replace("12:00:00Z", "14:00:00Z").replace("PR #1", "PR #9")
self.assertEqual(fall(chunk_entries(merged, fell + merged)).pending, ["Locality"])
class FallRuling(unittest.TestCase):
def test_counts_a_ruling_worse_when_a_fallen_dimensions_mean_is_under_the_floor(self):
found = [decimal.Decimal(score) for score in ("6", "6.5", "7", "6", "6")]
self.assertEqual(fall_ruling("better", ["Locality", "Shape"], found), ("worse", "Fell: Locality, Shape, under the floor of 7.0 at Locality 6.5, so the better ruling counts as worse."))
self.assertEqual(fall_ruling("same", ["Shape"], found), ("same", "Fell: Shape, each at or above the floor of 7.0, so the same ruling stands."))
class Base(unittest.TestCase):
@@ -166,11 +147,6 @@ class Base(unittest.TestCase):
worse_last = HistoryChange("worse", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "better") + paired("2026-10-08T14:00:00Z", "worse"))
self.assertEqual(measured_commit([worse_last, older]), "old")
self.assertIsNone(measured_commit([same]))
run = SCORING.replace("12:00:00Z", "14:00:00Z").replace("PR #1", "PR #2")
same_fell = HistoryChange("same fell", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality") + run)
self.assertEqual(measured_commit([same_fell, older]), "old")
better_fell = HistoryChange("better fell", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "better\n\nFell: Locality") + run)
self.assertEqual(measured_commit([better_fell, older]), "better fell")
def test_falls_back_to_the_first_rulings_base_then_to_none(self):
ruled = paired("2026-10-08T13:00:00Z", "worse")
@@ -249,8 +225,8 @@ class LarvReviewTool(unittest.TestCase):
def run_tool(self, *args):
return subprocess.run([sys.executable, str(TOOL), *args], capture_output=True, cwd=self.checkout, env=self.env, text=True)
def seats_file(self, text):
path = self.checkout.parent / "seats.md"
def seats_file(self, text, name="seats.md"):
path = self.checkout.parent / name
path.write_text(textwrap.dedent(text))
return str(path)
@@ -309,45 +285,41 @@ class LarvReviewTool(unittest.TestCase):
self.assertEqual(recorded[0].places, [Place("bin/a.py", "f")] * 2)
self.assertIn("| Junior A | same | same | same | same | same (voted worse, naming no place) |", history.read_text())
def test_holds_a_better_ruling_that_hides_a_fall_until_a_scoring_run_decides_it(self):
def test_asks_for_the_scoring_seats_when_a_dimension_falls_and_rules_with_their_scores(self):
place = "\n\n- Locality, Overall: `bin/a.py:3` `f`: shorter\n\n"
ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('better', 'worse')}{place}Inherited architect: {said('better', 'worse')}{place}"))
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertIn("Fell: Locality. A scoring run is due", ran.stdout)
self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "Scoring run due: the chunk has a paired ruling in which Locality fell.\n")
votes_file = self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('better', 'worse')}{place}Inherited architect: {said('better', 'worse')}{place}", "votes.md")
asked = self.run_tool("record-ruling", votes_file)
self.assertEqual(asked.returncode, 0, asked.stderr)
self.assertTrue(asked.stdout.startswith(f"Fell: Locality, in a better ruling. Launch the four scoring seats on PR #2 at {self.start},"))
history = self.checkout / "docs" / "comprehension-history.md"
self.assertFalse(history.exists())
line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 7, Overall 7"
seats = "".join(f"\n{seat}: {line}\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect"))
scored = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats))
self.assertIn("Ratchet: the paired ruling counts as worse, as Locality fell and Locality is 6.50, under the floor of 7.0.", scored.stdout)
self.assertIn("blocking nothing, as only a fall called this run: Locality 6.50.", scored.stdout)
scores_text = f"PR #2 at {self.start}\n" + "".join(f"\n{seat}: {line}\n\n- `bin/b.py:4` `h`: long\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect"))
ruled = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text, "scores.md"))
self.assertEqual(ruled.returncode, 0, ruled.stderr)
self.assertTrue(ruled.stdout.startswith("Ruling: worse. Fell: Locality, under the floor of 7.0 at Locality 6.50, so the better ruling counts as worse."))
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())
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 #2", "PR #3"), "scores.md"))
self.assertIn("the scores file's first line is not", other.stderr)
self.assertIn("\n\nRatchet: the paired ruling counts as worse", (self.checkout / "docs" / "comprehension-history.md").read_text())
self.assertTrue(self.run_tool("needs-scoring-run", "2").stdout.startswith("No scoring run due.\nStill standing: Ratchet:"))
again = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats))
self.assertIn("already a scoring run; record a paired ruling first", again.stderr)
same = self.run_tool("record-ruling", self.seats_file(f"PR #3 at {self.start}, against {self.start}\n\nMid A: {said('same', 'worse')}{place}Inherited architect: {said('same', 'worse')}{place}"))
self.assertIn("Fell: Locality.", same.stdout, same.stderr)
stands = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats.replace("Locality 6.5", "Locality 7")))
self.assertIn("The paired ruling stands: Locality fell and each stays at or above the floor of 7.0.", stands.stdout)
def test_names_no_fall_on_a_worse_ruling(self):
def test_names_no_fall_on_a_worse_ruling_and_takes_no_scores_file_without_one(self):
place = "\n\n- Locality, Overall: `bin/a.py:3` `f`: longer\n\n"
ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('worse', 'worse')}{place}Inherited architect: {said('worse', 'worse')}{place}"))
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertNotIn("Fell:", ran.stdout + (self.checkout / "docs" / "comprehension-history.md").read_text())
extra = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('worse')}{place}Inherited architect: {said('worse')}{place}"), self.seats_file("PR #2", "scores.md"))
self.assertIn("takes no scores file", extra.stderr)
def test_records_a_scoring_run_with_its_means(self):
line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 6.5, Overall 7"
seats = "".join(f"\n{seat}: {line}\n\n- `bin/a.py:3` `f`: long\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect"))
uncalled = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats))
self.assertEqual(uncalled.returncode, 1)
self.assertIn("name the item IDs the chunk ships", uncalled.stderr)
due = self.run_tool("record-scoring", self.seats_file(f"PR #3 at {self.start}\n" + seats), "1")
self.assertEqual(due.returncode, 0, due.stderr)
self.assertIn("\nItem IDs read: 1.\nFloor: Locality 6.50, Self-sufficiency 6.50 under the floor of 7.0 block the merge, as the chunk leaves release 0.1.0 with no plan item.\n", due.stdout)
swapped = self.run_tool("record-scoring", "1", self.seats_file(f"PR #3 at {self.start}\n" + seats))
self.assertEqual(swapped.returncode, 1)
self.assertIn("not /", swapped.stderr)
ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats))
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertIn("\nFloor: Locality 6.50, Self-sufficiency 6.50 under the floor of 7.0 block the merge.\n", ran.stdout)
text = (self.checkout / "docs" / "comprehension-history.md").read_text()
self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 6.50 | 7.00 |", text)
self.assertIn("Inherited architect, would restructure first:", text)
@@ -361,13 +333,6 @@ class LarvReviewTool(unittest.TestCase):
self.assertEqual(lacking.returncode, 1)
self.assertIn("abcdef1, which is no commit", lacking.stderr)
def test_moves_a_dated_mean_from_a_decision_entry_as_a_scoring_run(self):
mean = "Mean: Navigation 7.38, Locality 6.63, Shape 7.0, Self-sufficiency 6.88, Overall 6.88\n"
ran = self.run_tool("record-scoring", self.seats_file(f"2026-10-04, PR #1 merged at {self.start}\n\n{mean}"))
self.assertEqual(ran.returncode, 0, ran.stderr)
text = (self.checkout / "docs" / "comprehension-history.md").read_text()
self.assertIn(f"## 2026-10-04, PR #1 merged at {self.start}\n\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mean | 7.38 | 6.63 | 7.00 | 6.88 | 6.88 |\n", text)
def test_states_its_rules_and_finds_origins_default_branch_where_the_clone_recorded_none(self):
helped = self.run_tool("--help")
self.assertEqual(helped.returncode, 0, helped.stderr)
@@ -375,13 +340,6 @@ class LarvReviewTool(unittest.TestCase):
self.git("remote", "set-head", "origin", "--delete")
self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "No scoring run due.\n")
def test_refuses_a_dated_first_line_except_for_a_mean_alone_and_a_mean_without_one(self):
mean = "Mean: Navigation 7, Locality 7, Shape 7, Self-sufficiency 7, Overall 7\n"
self.assertEqual(self.run_tool("record-scoring", self.seats_file(f"PR #1 at {self.start}\n\n{mean}")).returncode, 1)
ruled = self.run_tool("record-ruling", self.seats_file(f"2026-10-08, PR #2 at {self.start}, against {self.start}\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n"))
self.assertEqual(ruled.returncode, 1)
self.assertIn("only a seats file holding a Mean line alone", ruled.stderr)
def test_takes_a_local_main_without_origin_and_reads_origin_as_last_fetched_when_the_fetch_fails(self):
self.commit("Answer prose round 1: a")
self.git("remote", "set-url", "origin", str(self.checkout.parent / "gone.git"))
+1 -1
View File
@@ -11,7 +11,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from metric_bench.bench import auc, bench, co_changed, resolved, top_k
from metric_bench.python_units import cognitive, measured, python_units, Unit
from larv_review.history import entries, Place
from comprehension_history import entries, Place
from failure import Failure
from test_loop_claude_black_box import host_env
+1 -1
View File
@@ -11,5 +11,5 @@ class Types(unittest.TestCase):
self.assertIsNotNone(floor, "README.md's Install names `Python 3.N or newer`")
if shutil.which("uv") is None:
self.fail("uv on PATH fetches mypy; see README.md's Test line")
ran = subprocess.run(["uv", "tool", "run", "--python", "%d.%d" % floor, "mypy==2.3.1", "--cache-dir=/dev/null", "--check-untyped-defs", "--disallow-untyped-defs", "-p", "larv_review", "-p", "loop_claude", "-p", "metric_bench", "-m", "rank_todo", "-p", "reading_cost", "-m", "statusline"], capture_output=True, cwd=ROOT / "bin", text=True)
ran = subprocess.run(["uv", "tool", "run", "--python", "%d.%d" % floor, "mypy==2.3.1", "--cache-dir=/dev/null", "--check-untyped-defs", "--disallow-untyped-defs", "-m", "comprehension_history", "-p", "larv_review", "-p", "loop_claude", "-p", "metric_bench", "-m", "rank_todo", "-p", "reading_cost", "-m", "statusline"], capture_output=True, cwd=ROOT / "bin", text=True)
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)