Answer architecture round 6: split rules into ruling, rounds, base and scoring modules, read the fall sequence as one Fall state, and give the plan's reasons and the fall's their own functions

This commit is contained in:
2026-10-09 11:53:08 +02:00
parent 9ca791435f
commit 4cda8551b4
7 changed files with 260 additions and 243 deletions
+29
View File
@@ -0,0 +1,29 @@
from larv_review.history import entries, Entry, 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."""
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:
return change.commit
return None
def first_ruling(history: str) -> Entry | None:
rulings = sorted((entry for entry in entries(history) if entry.paired), key=lambda entry: entry.time)
return rulings[0] if rulings else None
def base(changes: list[HistoryChange], history: str) -> tuple[str, str] | None:
"""The commit a paired ruling reads against, and which fallback found it; None leaves the merge base of HEAD and the default branch. history is the default branch's."""
if found := measured_commit(changes):
return found, "the last measured commit"
if (first := first_ruling(history)) and first.against:
return first.against, "the base the history's first paired ruling names"
return None
+30 -27
View File
@@ -87,9 +87,12 @@ import sys
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, floor_verdict, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, uncalled, under_floor, votes
from larv_review.history import appended, heading, ruling_entry, 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.ruling import counted, fallen, ruling, votes
from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores
from failure import Failure
from rank_todo import ITEMS_HEADER
@@ -166,20 +169,21 @@ 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
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 ratchet := standing_ratchet(recorded):
print(f"Still standing: {ratchet} Fix it and rule again.")
if state.ratchet:
print(f"Still standing: {state.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."""
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
@@ -200,18 +204,18 @@ def due_reasons(default: str, ids: list[int], fell: list[str]) -> list[str] | Fa
landed = landed_since_release(default)
if isinstance(landed, Failure):
return landed
return scoring_run_due(planned, chunk, ids, landed, fell)
return scoring_run_due(planned, chunk, ids, landed)
def chunk_history(default: str) -> list[Entry] | Failure:
"""The entries the checkout's history holds and the default branch's lacks."""
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 chunk_entries(held, read[1])
return fall(chunk_entries(held, read[1]))
def record_ruling(seats_file: pathlib.Path) -> Failure | None:
@@ -246,19 +250,18 @@ def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Fa
if isinstance(found, Failure):
return found
mean = means(list(found.values()))
recorded = chunk_history(default)
if isinstance(recorded, Failure):
return recorded
blocking = due_reasons(default, ids, [])
if isinstance(blocking, Failure):
return blocking
fell = pending_fall(recorded)
if not (blocking or fell):
return Failure(uncalled(recorded))
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), blocking))
outcome = fall_outcome(fell, mean)
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 []))
+14
View File
@@ -0,0 +1,14 @@
import re
CAP = 3
PASSES = ("architecture", "full scan", "security", "stability", "product-owner", "prose")
ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):")
def round_counts(titles: list[str]) -> dict[str, int]:
"""Each pass's highest round among the branch's `Answer <pass> round <n>:` commit titles; a pass with none has 0, and a title naming no known pass adds its name."""
counts = dict.fromkeys(PASSES, 0)
for title in titles:
if named := ROUND.match(title):
counts[named.group(1)] = max(counts.get(named.group(1), 0), int(named.group(2)))
return counts
-196
View File
@@ -1,196 +0,0 @@
import decimal
import re
from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS, vote_line
from larv_review.history import entries, Entry, HistoryChange, PLACE
from failure import Failure
from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows
CAP = 3
FLOOR = decimal.Decimal("7.0")
PASSES = ("architecture", "full scan", "security", "stability", "product-owner", "prose")
ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):")
VOTES = ("better", "same", "worse")
def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure:
"""Each seat's five votes as written, in DIMENSIONS' order."""
names = [seat.name for seat in seats]
if names[:2] != list(FIRST_SEATS) or names[2:] not in ([], list(SPLIT_SEATS)):
return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their overall votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}")
said = {}
for seat in seats:
line = vote_line(seat.name, seat.said)
if isinstance(line, Failure):
return line
if unnamed := [place for place in seat.places if not place_dimensions(place)]:
return Failure(f"{seat.name}'s place does not open with the dimensions it moves, each one of {', '.join(DIMENSIONS)}, then `: `: {unnamed[0]}")
said[seat.name] = line
first, second, *more = (each[-1] for each in counted(seats, said).values())
if more and first == second:
return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first} overall, which settles the ruling; drop the other seats' lines")
return said
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 opens with 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 in place_dimensions(place)) for place in seat.places)
def place_dimensions(place: str) -> list[str]:
"""The dimensions a place opens with, as in `Locality, Shape: `path:line` ...`; empty when any name before the first `: ` is no dimension."""
named = place.partition(": ")[0].split(", ")
return named if all(name in DIMENSIONS for name in named) else []
def ruling(counted: list[str]) -> str | None:
"""The vote that leads each other vote by two or more, else same; None when only the first two seats voted and they differ, so two more must vote."""
if len(counted) == 2 and counted[0] != counted[1]:
return None
for vote in VOTES:
if all(counted.count(vote) >= counted.count(other) + 2 for other in VOTES if other != vote):
return vote
return "same"
def fallen(counted: dict[str, list[str]]) -> list[str]:
"""Each dimension, Overall aside, that the seats rule worse by a lead of two."""
return [name for name, column in zip(DIMENSIONS[:-1], zip(*counted.values())) if ruling(list(column)) == "worse"]
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)
def pending_fall(chunk: list[Entry]) -> list[str]:
"""The dimensions that fell in the chunk's newest entry, empty unless that entry is a paired ruling."""
return chunk[-1].fell if chunk and chunk[-1].paired else []
def uncalled(chunk: list[Entry]) -> str:
"""Why a scoring run nothing calls fails, and what to do instead."""
if chunk and not chunk[-1].paired:
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 standing_ratchet(chunk: list[Entry]) -> str | 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, 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 means(lines: list[list[str]]) -> list[decimal.Decimal]:
"""The mean of each score across the lines, in DIMENSIONS' order, rounded half up to two decimals."""
return [mean([decimal.Decimal(score) for score in column]) for column in zip(*lines)]
def mean(values: list[decimal.Decimal]) -> decimal.Decimal:
return (sum(values, decimal.Decimal(0)) / len(values)).quantize(decimal.Decimal("0.01"), decimal.ROUND_HALF_UP)
def under_floor(found: list[decimal.Decimal]) -> list[str]:
return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if value < FLOOR]
def round_counts(titles: list[str]) -> dict[str, int]:
"""Each pass's highest round among the branch's `Answer <pass> round <n>:` commit titles; a pass with none has 0, and a title naming no known pass adds its name."""
counts = dict.fromkeys(PASSES, 0)
for title in titles:
if named := ROUND.match(title):
counts[named.group(1)] = max(counts.get(named.group(1), 0), int(named.group(2)))
return counts
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."""
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:
return change.commit
return None
def first_ruling(history: str) -> Entry | None:
rulings = sorted((entry for entry in entries(history) if entry.paired), key=lambda entry: entry.time)
return rulings[0] if rulings else None
def base(changes: list[HistoryChange], history: str) -> tuple[str, str] | None:
"""The commit a paired ruling reads against, and which fallback found it; None leaves the merge base of HEAD and the default branch. history is the default branch's."""
if found := measured_commit(changes):
return found, "the last measured commit"
if (first := first_ruling(history)) and first.against:
return first.against, "the base the history's first paired ruling names"
return None
def plan_items(todo: str) -> list[Item] | Failure:
"""Each row of a todo.md's items table, read as `rank_todo.py` reads it."""
table = table_rows(todo.splitlines(), ITEMS_HEADER)
if isinstance(table, Failure):
return table
items = []
for row in table.rows:
item = parse_row(row)
if isinstance(item, Failure):
return item
items.append(item)
return items
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool, fell: list[str]) -> list[str] | Failure:
"""Why the chunk takes a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, landed whether the default branch holds a commit after its newest release tag, and fell what pending_fall finds in the chunk's history. Work has landed towards an emptied release when the chunk ships one of its items, or when it is the next release, the earliest before names, and landed holds."""
plan = {item.id: item for item in before + after}
if unknown := sorted(set(ships) - set(plan)):
return Failure(f"neither plan holds item {', '.join(map(str, unknown))}")
shipped = [plan[id_] for id_ in ships]
reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()]
if fell:
reasons.append(f"has a paired ruling in which {' and '.join(fell)} fell")
next_release = min((item.release for item in before), default=None)
for release in emptied(before, after, shipped):
if any(item.release == release for item in shipped) or (release == next_release and landed):
reasons.append(f"leaves release {'.'.join(map(str, release))} with no plan item")
return reasons
def emptied(before: list[Item], after: list[Item], shipped: list[Item]) -> list[tuple[int, int, int]]:
"""Each release the default branch's plan or a shipped item names that the chunk's plan, less the shipped items, names no longer."""
named = {item.release for item in before + shipped}
left = {item.release for item in after if item.id not in {ship.id for ship in shipped}}
return sorted(named - left)
+54
View File
@@ -0,0 +1,54 @@
from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS, vote_line
from failure import Failure
from larv_review.history import PLACE
VOTES = ("better", "same", "worse")
def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure:
"""Each seat's five votes as written, in DIMENSIONS' order."""
names = [seat.name for seat in seats]
if names[:2] != list(FIRST_SEATS) or names[2:] not in ([], list(SPLIT_SEATS)):
return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their overall votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}")
said = {}
for seat in seats:
line = vote_line(seat.name, seat.said)
if isinstance(line, Failure):
return line
if unnamed := [place for place in seat.places if not place_dimensions(place)]:
return Failure(f"{seat.name}'s place does not open with the dimensions it moves, each one of {', '.join(DIMENSIONS)}, then `: `: {unnamed[0]}")
said[seat.name] = line
first, second, *more = (each[-1] for each in counted(seats, said).values())
if more and first == second:
return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first} overall, which settles the ruling; drop the other seats' lines")
return said
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 opens with 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 in place_dimensions(place)) for place in seat.places)
def place_dimensions(place: str) -> list[str]:
"""The dimensions a place opens with, as in `Locality, Shape: `path:line` ...`; empty when any name before the first `: ` is no dimension."""
named = place.partition(": ")[0].split(", ")
return named if all(name in DIMENSIONS for name in named) else []
def ruling(counted: list[str]) -> str | None:
"""The vote that leads each other vote by two or more, else same; None when only the first two seats voted and they differ, so two more must vote."""
if len(counted) == 2 and counted[0] != counted[1]:
return None
for vote in VOTES:
if all(counted.count(vote) >= counted.count(other) + 2 for other in VOTES if other != vote):
return vote
return "same"
def fallen(counted: dict[str, list[str]]) -> list[str]:
"""Each dimension, Overall aside, that the seats rule worse by a lead of two."""
return [name for name, column in zip(DIMENSIONS[:-1], zip(*counted.values())) if ruling(list(column)) == "worse"]
+109
View File
@@ -0,0 +1,109 @@
import dataclasses
import decimal
import itertools
from larv_review.seats import DIMENSIONS
from larv_review.history import entries, Entry
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 means(lines: list[list[str]]) -> list[decimal.Decimal]:
"""The mean of each score across the lines, in DIMENSIONS' order, rounded half up to two decimals."""
return [mean([decimal.Decimal(score) for score in column]) for column in zip(*lines)]
def mean(values: list[decimal.Decimal]) -> decimal.Decimal:
return (sum(values, decimal.Decimal(0)) / len(values)).quantize(decimal.Decimal("0.01"), decimal.ROUND_HALF_UP)
def under_floor(found: list[decimal.Decimal]) -> list[str]:
return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if value < FLOOR]
def plan_items(todo: str) -> list[Item] | Failure:
"""Each row of a todo.md's items table, read as `rank_todo.py` reads it."""
table = table_rows(todo.splitlines(), ITEMS_HEADER)
if isinstance(table, Failure):
return table
items = []
for row in table.rows:
item = parse_row(row)
if isinstance(item, Failure):
return item
items.append(item)
return items
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str] | Failure:
"""Why the plan calls a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, and landed whether the default branch holds a commit after its newest release tag. Work has landed towards an emptied release when the chunk ships one of its items, or when it is the next release, the earliest before names, and landed holds."""
plan = {item.id: item for item in before + after}
if unknown := sorted(set(ships) - set(plan)):
return Failure(f"neither plan holds item {', '.join(map(str, unknown))}")
shipped = [plan[id_] for id_ in ships]
reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()]
next_release = min((item.release for item in before), default=None)
for release in emptied(before, after, shipped):
if any(item.release == release for item in shipped) or (release == next_release and landed):
reasons.append(f"leaves release {'.'.join(map(str, release))} with no plan item")
return reasons
def emptied(before: list[Item], after: list[Item], shipped: list[Item]) -> list[tuple[int, int, int]]:
"""Each release the default branch's plan or a shipped item names that the chunk's plan, less the shipped items, names no longer."""
named = {item.release for item in before + shipped}
left = {item.release for item in after if item.id not in {ship.id for ship in shipped}}
return sorted(named - left)
+24 -20
View File
@@ -10,11 +10,14 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from larv_review.history import appended, entries, HistoryChange, Place, ruling_entry
from larv_review.rules import base, chunk_entries, counted, fall_outcome, fallen, first_ruling, means, measured_commit, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes
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 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
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"
@@ -131,20 +134,20 @@ class History(unittest.TestCase):
class PendingFall(unittest.TestCase):
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(pending_fall(chunk_entries("", SCORING + fell)), ["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(pending_fall(chunk_entries("", fell + later)), [])
self.assertEqual(standing_ratchet(chunk_entries("", fell + later)), "Ratchet: worse.")
self.assertEqual(pending_fall(chunk_entries("", SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality"))), ["Locality"])
self.assertEqual(pending_fall(chunk_entries("", "")), [])
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(standing_ratchet(chunk_entries("", fell + later + rescored)), "Ratchet: worse.")
self.assertIsNone(standing_ratchet(chunk_entries("", fell + later + paired("2026-10-08T16:00:00Z", "same"))))
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(pending_fall(chunk_entries(merged, fell + merged)), ["Locality"])
self.assertEqual(fall(chunk_entries(merged, fell + merged)).pending, ["Locality"])
class Base(unittest.TestCase):
@@ -190,31 +193,32 @@ class ScoringRunDue(unittest.TestCase):
def test_is_due_for_an_item_naming_the_floor(self):
plan = [item(1, (0, 1, 0), "**Lift the project to the Comprehension floor.**"), item(2, (0, 1, 0))]
self.assertEqual(scoring_run_due(plan, plan, [1], True, []), ["ships item 1, which names the comprehension floor"])
self.assertIsInstance(scoring_run_due(plan, plan, [9], True, []), Failure)
self.assertEqual(scoring_run_due(plan, plan, [1], True), ["ships item 1, which names the comprehension floor"])
self.assertIsInstance(scoring_run_due(plan, plan, [9], True), Failure)
def test_is_due_when_the_chunk_ships_a_releases_last_item(self):
plan = [item(1, (0, 1, 0)), item(2, (0, 2, 0))]
self.assertEqual(scoring_run_due(plan, plan, [1], False, []), ["leaves release 0.1.0 with no plan item"])
self.assertEqual(scoring_run_due(plan, plan + [item(3, (0, 1, 0))], [1], True, []), [])
self.assertEqual(scoring_run_due(plan, plan, [1], False), ["leaves release 0.1.0 with no plan item"])
self.assertEqual(scoring_run_due(plan, plan + [item(3, (0, 1, 0))], [1], True), [])
def test_is_due_when_the_chunk_removes_the_next_releases_last_item_after_work_landed(self):
before = [item(1, (0, 1, 0)), item(2, (0, 1, 0)), item(3, (0, 2, 0))]
after = [item(2, (0, 1, 0)), item(3, (0, 2, 0))]
self.assertEqual(scoring_run_due(before, after, [2], True, []), ["leaves release 0.1.0 with no plan item"])
self.assertEqual(scoring_run_due(before, after, [], True, []), [])
self.assertEqual(scoring_run_due(before, after, [2], True), ["leaves release 0.1.0 with no plan item"])
self.assertEqual(scoring_run_due(before, after, [], True), [])
emptied = [item(3, (0, 2, 0))]
self.assertEqual(scoring_run_due(before, emptied, [2], False, []), ["leaves release 0.1.0 with no plan item"])
self.assertEqual(scoring_run_due(before, emptied, [], True, []), ["leaves release 0.1.0 with no plan item"])
self.assertEqual(scoring_run_due(before, emptied, [], False, []), [])
self.assertEqual(scoring_run_due(before, emptied, [2], False), ["leaves release 0.1.0 with no plan item"])
self.assertEqual(scoring_run_due(before, emptied, [], True), ["leaves release 0.1.0 with no plan item"])
self.assertEqual(scoring_run_due(before, emptied, [], False), [])
def test_is_due_when_a_better_ruling_hides_a_fall(self):
plan = [item(1, (0, 1, 0)), item(2, (0, 1, 0))]
self.assertEqual(scoring_run_due(plan, plan, [], True, ["Locality"]), ["has a paired ruling in which Locality fell"])
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_is_not_due_when_a_later_release_loses_its_last_item_unshipped(self):
before = [item(1, (0, 1, 0)), item(3, (0, 2, 0))]
self.assertEqual(scoring_run_due(before, before[:1], [], True, []), [])
self.assertEqual(scoring_run_due(before, before[:1], [], True), [])
class LarvReviewTool(unittest.TestCase):