Answer architecture round 2: fail a place naming no dimension, keep a ratchet until a ruling follows, leave the base on a fall-called run, let record-scoring say whether the floor blocks, and name the missing dimension in a discounted vote

This commit is contained in:
2026-10-09 11:04:01 +02:00
parent 75b0e46326
commit 9de87e04cf
8 changed files with 95 additions and 56 deletions
+7 -5
View File
@@ -115,14 +115,16 @@ def appended(history: str, entry: str) -> str:
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, with a `Fell:` line when it is better or same and fell names dimensions; a seat's vote that counted as same for naming no place says so."""
votes = [[seat.name, *map(vote_text, said[seat.name], counted[seat.name])] for seat in seats]
lines = [f"Ruling: {ruled}"] + ([f"Fell: {', '.join(fell)}"] if ruled != "worse" and fell else [])
"""A paired ruling's entry, with a `Fell:` line when fell names dimensions; 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])
def vote_text(said: str, counted: str) -> str:
return counted if counted == said else f"same (voted {said}, naming no place)"
def vote_text(dimension: str, said: str, counted: str) -> str:
if counted == said:
return counted
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:
+42 -31
View File
@@ -9,8 +9,8 @@ read origin as last fetched and say so on stderr; the other two exit 1. The hist
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 that adds a scoring run to the
history, or whose last added paired ruling, by heading time, is better; a merge commit counts as
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.
@@ -37,30 +37,34 @@ opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability s
Mid A: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse
- `bin/x.py:12` `run`: three branches to hold at once
- `bin/x.py:12` `run`: Locality: three branches to hold at once
Inherited architect: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse
- `bin/x.py:12` `run`: ...
- `bin/x.py:12` `run`: Locality: ...
record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall,
each better, same or worse. A dimension's vote counts as same unless one of the seat's places in
each better, same or worse. Each place names the dimensions it moves, or Overall, spelled as the
seat's line spells them. A dimension's vote counts as same unless one of the seat's places in
backticks, `path:line`, names that dimension; the overall vote counts as same unless the seat names
any place. The printed votes say so. When the two counted overall votes differ, it appends
any such place. 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.
record-scoring takes Junior A's, Mid A's, the maintainability senior's and the inherited
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 and each one under the floor of {floor}. When the history ends on a
decimals, and prints the means and each one under the floor of {floor}. A `Floor:` line says the
means under the floor block the merge, as they do when needs-scoring-run would give a reason
besides a fall. When the history ends on a
paired ruling with a `Fell:` line, it says whether the ruling stands; when a dimension that fell is
under the floor, the ruling counts as worse, and it prints and records a `Ratchet:` line, which
needs-scoring-run repeats until a paired ruling follows it. Both read only the entries the default
needs-scoring-run repeats as `Still standing:` until a paired ruling follows it. Both read only the entries the default
branch's history lacks.
Each record is appended to the history, created when missing, under a heading of the current UTC
@@ -79,14 +83,14 @@ import time
import typing
from larv_review.history import appended, Entry, heading, ruling_entry, scoring_entry, vote_text
from larv_review.rules import base, CAP, chunk_entries, counted, fall_outcome, fallen, FLOOR, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes
from larv_review.rules import base, CAP, chunk_entries, counted, fall_outcome, fallen, FLOOR, floor_verdict, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes
from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top
from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores
from failure import Failure
from rank_todo import ITEMS_HEADER
from file_writes import replace_file
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <seats file> | record-scoring <seats file>"
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <seats file> | record-scoring <seats file> [<item ID>...]"
def main(argv: list[str]) -> int:
@@ -102,10 +106,10 @@ 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) == 1:
done = record_ruling(pathlib.Path(given[0]))
elif command == "record-scoring" and len(given) == 1:
done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0])), stale_ok=True)
elif command == "needs-scoring-run":
print(f"needs-scoring-run takes item IDs, the numbers in todo.md's ID column: {' '.join(given)}", 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:
print(f"{command} takes item IDs, the numbers in todo.md's ID column: {' '.join(given)}", file=sys.stderr)
return 1
elif not argv:
print(USAGE, file=sys.stderr)
@@ -156,6 +160,20 @@ def round_count(default: str) -> Failure | None:
def needs_scoring_run(default: str, ids: list[int]) -> Failure | None:
recorded = chunk_history(default)
if isinstance(recorded, Failure):
return recorded
reasons = due_reasons(default, ids, pending_fall(recorded))
if isinstance(reasons, Failure):
return reasons
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
if ratchet := standing_ratchet(recorded):
print(f"Still standing: {ratchet} Fix it and rule again.")
return None
def due_reasons(default: str, ids: list[int], fell: list[str]) -> list[str] | Failure:
"""Why the chunk is due a scoring run, from the default branch's plan and the checkout's."""
checkout = top()
if isinstance(checkout, Failure):
return checkout
@@ -176,16 +194,7 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None:
landed = landed_since_release(default)
if isinstance(landed, Failure):
return landed
recorded = chunk_history(default)
if isinstance(recorded, Failure):
return recorded
reasons = scoring_run_due(planned, chunk, ids, landed, pending_fall(recorded))
if isinstance(reasons, Failure):
return reasons
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
if ratchet := standing_ratchet(recorded):
print(f"Still standing: {ratchet} Fix it and rule again.")
return None
return scoring_run_due(planned, chunk, ids, landed, fell)
def chunk_history(default: str) -> list[Entry] | Failure:
@@ -208,19 +217,19 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | None:
if isinstance(said, Failure):
return said
count = counted(given.seats, said)
tally = ", ".join(f"{seat.name} {vote_text(said[seat.name][-1], count[seat.name][-1])}" for seat in given.seats)
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.")
return None
fell = fallen(count)
fell = fallen(count) if ruled != "worse" else []
print(f"Ruling: {ruled}. Overall votes as counted: {tally}.")
if ruled != "worse" and fell:
if fell:
print(f"Fell: {', '.join(fell)}. A scoring run is due; the ruling counts as worse if it puts {' or '.join(fell)} under the floor of {FLOOR}.")
return append(ruling_entry(title, given.seats, said, count, ruled, fell))
def record_scoring(default: str, seats_file: pathlib.Path) -> Failure | None:
def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Failure | None:
read = read_seats(seats_file, paired=False)
if isinstance(read, Failure):
return read
@@ -232,11 +241,13 @@ def record_scoring(default: str, seats_file: pathlib.Path) -> Failure | None:
if isinstance(moved, Failure):
return moved
mean = means(list(found.values()) or [moved])
under = under_floor(mean)
print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {f'Under the floor of {FLOOR}: ' + ', '.join(under) if under else f'None under the floor of {FLOOR}'}.")
recorded = chunk_history(default)
if isinstance(recorded, Failure):
return recorded
blocking = due_reasons(default, ids, [])
if isinstance(blocking, Failure):
return blocking
print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {floor_verdict(under_floor(mean), blocking)}")
outcome = fall_outcome([] if given.moved_mean else pending_fall(recorded), mean)
if outcome:
print(outcome[0])
+23 -6
View File
@@ -23,6 +23,8 @@ def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure:
line = vote_line(seat.name, seat.said)
if isinstance(line, Failure):
return line
if unnamed := [place for place in seat.places if not any(re.search(rf"\b{name}\b", place) for name in DIMENSIONS)]:
return Failure(f"{seat.name}'s place names none of {', '.join(DIMENSIONS)}, spelled so: {unnamed[0]}")
said[seat.name] = line
first, second, *more = (each[-1] for each in counted(seats, said).values())
if more and first == second:
@@ -31,12 +33,12 @@ def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure:
def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]:
"""Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places names that dimension, and the overall vote unless the seat names any place."""
"""Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places names that dimension, and the overall vote unless the seat names any such place."""
return {seat.name: [vote if names_a_place(seat, name) else "same" for name, vote in zip(DIMENSIONS, said[seat.name])] for seat in seats}
def names_a_place(seat: Seat, dimension: str) -> bool:
return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or dimension.lower() in place.lower()) for place in seat.places)
return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or re.search(rf"\b{dimension}\b", place)) for place in seat.places)
def ruling(counted: list[str]) -> str | None:
@@ -66,8 +68,22 @@ def pending_fall(chunk: list[Entry]) -> list[str]:
def standing_ratchet(chunk: list[Entry]) -> str | None:
"""The `Ratchet:` line of the chunk's newest entry, which no paired ruling has followed yet."""
return chunk[-1].ratchet if chunk else None
"""The chunk's newest `Ratchet:` line, unless a paired ruling has followed it."""
for entry in reversed(chunk):
if entry.paired:
return None
if entry.ratchet:
return entry.ratchet
return None
def floor_verdict(under: list[str], reasons: list[str]) -> str:
"""Whether the means under the floor block the merge: they do on a run due for a reason besides a fall."""
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 on a run due for no reason besides a fall: {', '.join(under)}."
def fall_outcome(fell: list[str], found: list[decimal.Decimal]) -> tuple[str, list[str]] | None:
@@ -103,12 +119,13 @@ def round_counts(titles: list[str]) -> dict[str, int]:
def measured_commit(changes: list[HistoryChange]) -> str | None:
"""The newest change, of changes given newest first, that adds a scoring run to the history, or whose last added paired ruling is better."""
"""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."""
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)
if any(not entry.paired for entry in added) or rulings and rulings[-1].ruling == "better":
last = rulings[-1] if rulings else None
if last and last.ruling == "better" or any(not entry.paired for entry in added) and not (last and last.fell):
return change.commit
return None
+18 -9
View File
@@ -48,14 +48,16 @@ class Seats(unittest.TestCase):
self.assertIsInstance(report(""), Failure)
def test_counts_each_vote_of_a_seat_naming_no_place_as_same(self):
seats = [Seat("Mid A", said("worse", "worse"), ["the whole skill"]), Seat("Inherited architect", said("better"), ["`a.py:3` `f`: shorter"])]
seats = [Seat("Mid A", said("worse", "worse"), ["Locality: the whole skill"]), Seat("Inherited architect", said("better"), ["`a.py:3` `f`: Overall: shorter"])]
written = votes(seats)
self.assertEqual(written, {"Mid A": ["same", "worse", "same", "same", "worse"], "Inherited architect": ["same", "same", "same", "same", "better"]})
self.assertEqual(counted(seats, written)["Mid A"], ["same"] * 5)
def test_counts_a_dimensions_vote_only_where_a_place_names_that_dimension(self):
seats = [Seat("Mid A", said("better", "worse"), ["`a.py:3` `f`: shorter"]), Seat("Inherited architect", said("better", "worse"), ["`a.py:3` `f`: locality, held at once"])]
self.assertEqual([votes[1:] for votes in counted(seats, {seat.name: [*said("better", "worse").replace(",", "").split()[1::2]] for seat in seats}).values()], [["same", "same", "same", "better"], ["worse", "same", "same", "better"]])
seats = [Seat("Mid A", said("better", "worse"), ["`a.py:3` `f`: Shape, reshaped"]), Seat("Inherited architect", said("better", "worse"), ["`a.py:3` `f`: Locality, held at once"])]
written = {seat.name: ["same", "worse", "same", "same", "better"] for seat in seats}
self.assertEqual(counted(seats, written), {"Mid A": ["same", "same", "same", "same", "better"], "Inherited architect": written["Inherited architect"]})
self.assertIsInstance(votes([Seat("Mid A", said("better"), ["`a.py:3` `f`: self sufficiency"]), seats[1]]), Failure)
def test_refuses_two_more_seats_once_the_first_two_agree_overall(self):
seats = [Seat(name, said(vote), ["`f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))]
@@ -117,12 +119,11 @@ class History(unittest.TestCase):
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, naming no place) | same | same | same (voted worse, naming no place) |", 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.paired for entry in found], [False, True])
self.assertNotIn("Fell:", ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, written, "worse", ["Locality"]))
class PendingFall(unittest.TestCase):
@@ -276,7 +277,7 @@ class LarvReviewTool(unittest.TestCase):
Mid A: {worse}
- `bin/a.py:3` `f`: three branches
- `bin/a.py:3` `f`: Overall: three branches
Inherited architect: {same}
"""
@@ -286,7 +287,7 @@ class LarvReviewTool(unittest.TestCase):
self.assertTrue(split.stdout.startswith("Split: Mid A worse, Inherited architect same."))
history = self.checkout / "docs" / "comprehension-history.md"
self.assertFalse(history.exists())
lines += f"\n\t\t\tMaintainability senior: {said('worse')}\n\n\t\t\t- `bin/a.py:3` `f`: hard\n\n\t\t\tJunior A: {said('worse')}\n"
lines += f"\n\t\t\tMaintainability senior: {said('worse')}\n\n\t\t\t- `bin/a.py:3` `f`: Overall: hard\n\n\t\t\tJunior A: {said('worse')}\n"
ran = self.run_tool("record-ruling", self.seats_file(lines))
self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Overall votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same (voted worse, naming no place).")
recorded = entries(history.read_text())
@@ -312,16 +313,24 @@ class LarvReviewTool(unittest.TestCase):
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 stays at or above the floor of 7.0.", stands.stdout)
def test_names_no_fall_on_a_worse_ruling(self):
place = "\n\n- `bin/a.py:3` `f`: Locality, 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())
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"))
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("Under the floor of 7.0: Locality 6.50, Self-sufficiency 6.50.", ran.stdout)
self.assertIn("Under the floor of 7.0, blocking nothing on a run due for no reason besides a fall: Locality 6.50, Self-sufficiency 6.50.", ran.stdout)
due = self.run_tool("record-scoring", self.seats_file(f"PR #3 at {self.start}\n" + seats), "1")
self.assertIn("Floor: 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.", due.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)
self.assertEqual([entry.places for entry in entries(text)], [[Place("bin/a.py", "f")] * 4])
self.assertEqual(entries(text)[0].places, [Place("bin/a.py", "f")] * 4)
def test_refuses_a_ruling_file_that_names_no_base_or_a_commit_the_checkout_lacks(self):
ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n"))