Answer architecture round 1: give loop-claude's prompt text one home, split larv-review's plan trigger and ruling base out, share todo.md's table and the project key, and name the scoring run, the checkout roots and the test env for what they are
This commit is contained in:
@@ -3,7 +3,7 @@ import subprocess
|
||||
|
||||
from failure import Failure
|
||||
from comprehension_history import HISTORY
|
||||
from larv_review.base import HistoryChange
|
||||
from larv_review.ruling_base import HistoryChange
|
||||
|
||||
|
||||
def git(*args: str) -> str | Failure:
|
||||
|
||||
+27
-20
@@ -2,6 +2,11 @@
|
||||
|
||||
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file> [<item ID>...]
|
||||
|
||||
The comprehension check keeps a project from reading worse, two ways. In a paired ruling, seats read
|
||||
the branch's head beside a base and vote better, same or worse, overall and on each dimension; a
|
||||
worse ruling blocks the merge, which is the ratchet. In a scoring run, four seats score the project
|
||||
from 1 to 10; a mean under the floor of {floor} blocks the merge.
|
||||
|
||||
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 reads origin as
|
||||
@@ -16,7 +21,8 @@ ruling names; with no ruling either, it is the merge base of HEAD and the defaul
|
||||
|
||||
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.
|
||||
and each name in such a title that is not a pass. It only reports: larv-review asks the human in
|
||||
place of a further round.
|
||||
|
||||
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.` It is due when the chunk ships
|
||||
@@ -80,16 +86,17 @@ import sys
|
||||
import time
|
||||
import typing
|
||||
|
||||
from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, recorded, ruling_entry, Scoring, scoring_entry, vote_text
|
||||
from larv_review.base import base
|
||||
from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, recorded, ruling_entry, scoring_entry, ScoringRun, vote_text
|
||||
from larv_review.ruling_base import base
|
||||
from larv_review.rounds import CAP, PASSES, round_counts
|
||||
from larv_review.git import commit_exists, default_branch, file_at, git, history_changes, landed_since_release, top
|
||||
from larv_review.ruling import counted, fallen, ruling, votes
|
||||
from larv_review.ruling import counted, fallen, ruling, split, votes
|
||||
from failure import Failure
|
||||
from larv_review.scoring import fall_ruling, fall_step, FLOOR, means, plan_items, scoring_run_due, under_floor
|
||||
from rank_todo import ITEMS_HEADER
|
||||
from larv_review.scoring import fall_ruling, FLOOR, means, under_floor
|
||||
from todo_table import items, ITEMS_HEADER
|
||||
from file_writes import replace_file
|
||||
from larv_review.seats import scores, seats_file, SeatsFile
|
||||
from larv_review.plan import scoring_run_due
|
||||
|
||||
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file> [<item ID>...]"
|
||||
|
||||
@@ -182,10 +189,10 @@ def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure:
|
||||
except (OSError, UnicodeDecodeError) as failure:
|
||||
return Failure(f"could not read todo.md: {failure}")
|
||||
# While a chunk reshapes todo.md into one table, the default branch's todo.md has no items table.
|
||||
planned = plan_items(before) if ITEMS_HEADER in before.splitlines() else []
|
||||
planned = items(before) if ITEMS_HEADER in before.splitlines() else []
|
||||
if isinstance(planned, Failure):
|
||||
return Failure(f"{default}'s todo.md: {planned.reason}")
|
||||
chunk = plan_items(after)
|
||||
chunk = items(after)
|
||||
if isinstance(chunk, Failure):
|
||||
return Failure(f"the checkout's todo.md: {chunk.reason}")
|
||||
landed = landed_since_release(default)
|
||||
@@ -204,21 +211,21 @@ def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = N
|
||||
return said
|
||||
count = counted(given.seats, said)
|
||||
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:
|
||||
overall = [each[-1] for each in count.values()]
|
||||
if split(overall):
|
||||
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
|
||||
ruled = ruling(overall)
|
||||
fell = fallen(count) if ruled != "worse" else []
|
||||
if fell and not scores_file:
|
||||
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {named.label} at {named.commit}, write their lines to a scores file, and run this again with both files.")
|
||||
return None
|
||||
if scores_file and not fell:
|
||||
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
|
||||
scoring = None
|
||||
notes = []
|
||||
match fall_step(fell, scores_file is not None):
|
||||
case "ask":
|
||||
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {named.label} at {named.commit}, write their lines to a scores file, and run this again with both files.")
|
||||
return None
|
||||
case "refuse":
|
||||
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
|
||||
if scores_file:
|
||||
scored = read_scoring(scores_file, named)
|
||||
scored = read_fall_scores(scores_file, named)
|
||||
if isinstance(scored, Failure):
|
||||
return scored
|
||||
scoring = scored
|
||||
@@ -247,7 +254,7 @@ def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> F
|
||||
return append(given.read, scoring_entry(named.title, scoring))
|
||||
|
||||
|
||||
def read_scoring(scores_file: pathlib.Path, votes: Heading) -> Scoring | Failure:
|
||||
def read_fall_scores(scores_file: pathlib.Path, votes: Heading) -> ScoringRun | Failure:
|
||||
"""The scores a fall called, once their file names what the votes file read."""
|
||||
read = read_seats(scores_file, paired=False, fresh=False)
|
||||
if isinstance(read, Failure):
|
||||
@@ -258,11 +265,11 @@ def read_scoring(scores_file: pathlib.Path, votes: Heading) -> Scoring | Failure
|
||||
return scored_seats(given)
|
||||
|
||||
|
||||
def scored_seats(given: SeatsFile) -> Scoring | Failure:
|
||||
def scored_seats(given: SeatsFile) -> ScoringRun | Failure:
|
||||
found = scores(given.seats)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
return Scoring(given.seats, found, means(list(found.values())))
|
||||
return ScoringRun(given.seats, found, means(list(found.values())))
|
||||
|
||||
|
||||
def read_seats(path: pathlib.Path, paired: bool, fresh: bool = True) -> tuple[Heading, SeatsFile] | Failure:
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from failure import Failure
|
||||
from todo_table import Item
|
||||
|
||||
|
||||
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.
|
||||
|
||||
A chunk that ships an item naming the floor is due one, so it can prove the floor met. So is a chunk that empties a release towards which work has landed, so no release ends unmeasured: it ships one of the release's items, or the release is the next one, the earliest before names, and landed holds. That covers a release whose last item moved to another release.
|
||||
"""
|
||||
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)
|
||||
@@ -39,16 +39,20 @@ def place_dimensions(place: str) -> list[str]:
|
||||
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 split(overall: list[str]) -> bool:
|
||||
"""Whether only the first two seats voted overall and they differ, so two more must vote."""
|
||||
return len(overall) == 2 and overall[0] != overall[1]
|
||||
|
||||
|
||||
def ruling(overall: list[str]) -> str:
|
||||
return lead(overall) or "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"]
|
||||
return [name for name, column in zip(DIMENSIONS[:-1], zip(*counted.values())) if lead(list(column)) == "worse"]
|
||||
|
||||
|
||||
def lead(votes: list[str]) -> str | None:
|
||||
"""The vote that leads each other vote by two or more, if one does."""
|
||||
return next((vote for vote in VOTES if all(votes.count(vote) >= votes.count(other) + 2 for other in VOTES if other != vote)), None)
|
||||
|
||||
@@ -12,7 +12,10 @@ class HistoryChange:
|
||||
|
||||
|
||||
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, that adds a scoring run to the history, or whose last added paired ruling is better.
|
||||
|
||||
It is the ratchet's base. A ruling of same leaves the base where it was, so a run of small falls each ruled same still adds up against one commit. Entry times are UTC stamps in ISO order, so they sort as text.
|
||||
"""
|
||||
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]
|
||||
@@ -1,22 +1,10 @@
|
||||
import decimal
|
||||
import typing
|
||||
|
||||
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 fall_step(fell: list[str], scored: bool) -> typing.Literal["ask", "refuse", "rule"]:
|
||||
"""What record-ruling does next: ask for the scoring seats when a dimension fell and no scores file came, refuse a scores file no fall calls, or rule."""
|
||||
if fell and not scored:
|
||||
return "ask"
|
||||
if scored and not fell:
|
||||
return "refuse"
|
||||
return "rule"
|
||||
|
||||
|
||||
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."""
|
||||
if under := [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]:
|
||||
@@ -35,38 +23,3 @@ def mean(values: list[decimal.Decimal]) -> decimal.Decimal:
|
||||
|
||||
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)
|
||||
|
||||
@@ -9,15 +9,16 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from comprehension_history import appended, entries, Place, recorded, ruling_entry, Scoring, Seat
|
||||
from larv_review.base import base, first_ruling, HistoryChange, measured_commit
|
||||
from larv_review.ruling import counted, fallen, ruling, votes
|
||||
from comprehension_history import appended, entries, Place, recorded, ruling_entry, ScoringRun, Seat
|
||||
from larv_review.ruling_base import base, first_ruling, HistoryChange, measured_commit
|
||||
from larv_review.ruling import counted, fallen, ruling, split, votes
|
||||
from failure import Failure
|
||||
from larv_review.scoring import fall_ruling, fall_step, means, plan_items, scoring_run_due, under_floor
|
||||
from host_env import host_env
|
||||
from rank_todo import Item
|
||||
from larv_review.scoring import fall_ruling, means, under_floor
|
||||
from test_env import isolated_env
|
||||
from todo_table import Item, items
|
||||
from larv_review.rounds import round_counts
|
||||
from larv_review.seats import score_line, scores, seats_file
|
||||
from larv_review.plan import scoring_run_due
|
||||
|
||||
TOOL = pathlib.Path(__file__).resolve().parents[1] / "larv-review"
|
||||
SCORING = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n"
|
||||
@@ -93,7 +94,7 @@ class Seats(unittest.TestCase):
|
||||
]
|
||||
for counted, expected in cases:
|
||||
with self.subTest(counted):
|
||||
self.assertEqual(ruling(counted), expected)
|
||||
self.assertEqual(None if split(counted) else ruling(counted), expected)
|
||||
|
||||
def test_reads_four_seats_scores_and_refuses_an_overall_above_the_lowest_by_more_than_one(self):
|
||||
line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 6.5, Overall 7"
|
||||
@@ -115,7 +116,7 @@ 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"]}
|
||||
scoring = Scoring([Seat("Junior A", "", ["`bin/b.py:4` `h`: long"])], {"Junior A": ["7", "6.5", "7", "7", "7"]}, [decimal.Decimal(mean) for mean in ("7.00", "6.50", "7.00", "7.00", "7.00")])
|
||||
scoring = ScoringRun([Seat("Junior A", "", ["`bin/b.py:4` `h`: long"])], {"Junior A": ["7", "6.5", "7", "7", "7"]}, [decimal.Decimal(mean) for mean in ("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}, "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"))
|
||||
@@ -136,9 +137,6 @@ class FallRuling(unittest.TestCase):
|
||||
self.assertEqual(fall_ruling("better", ["Locality", "Shape"], found), ("worse", "Fell: Locality, Shape. Under the floor of 7.0: 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."))
|
||||
|
||||
def test_asks_for_scores_on_a_fall_refuses_them_without_one_and_rules_otherwise(self):
|
||||
self.assertEqual([fall_step(["Locality"], False), fall_step([], True), fall_step(["Locality"], True), fall_step([], False)], ["ask", "refuse", "rule", "rule"])
|
||||
|
||||
|
||||
class Base(unittest.TestCase):
|
||||
def test_takes_the_newest_change_adding_a_scoring_run_or_ending_on_a_better_ruling(self):
|
||||
@@ -174,9 +172,9 @@ class Rounds(unittest.TestCase):
|
||||
|
||||
class ScoringRunDue(unittest.TestCase):
|
||||
def test_reads_each_rows_id_release_and_tagline(self):
|
||||
self.assertEqual(plan_items(todo("| 3 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")), [item(3, (0, 1, 0))])
|
||||
self.assertIsInstance(plan_items("# todo\n"), Failure)
|
||||
self.assertIsInstance(plan_items(todo("| 0 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")), Failure)
|
||||
self.assertEqual(items(todo("| 3 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")), [item(3, (0, 1, 0))])
|
||||
self.assertIsInstance(items("# todo\n"), Failure)
|
||||
self.assertIsInstance(items(todo("| 0 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")), Failure)
|
||||
|
||||
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))]
|
||||
@@ -208,7 +206,7 @@ class LarvReviewTool(unittest.TestCase):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
root = pathlib.Path(os.path.realpath(temp.name))
|
||||
self.env = {**host_env(), "GIT_CONFIG_GLOBAL": os.devnull, "HOME": str(root)}
|
||||
self.env = {**isolated_env(), "GIT_CONFIG_GLOBAL": os.devnull, "HOME": str(root)}
|
||||
self.checkout = root / "proj"
|
||||
subprocess.run(["git", "init", "-q", "--bare", "-b", "main", str(root / "origin.git")], check=True, env=self.env)
|
||||
subprocess.run(["git", "clone", "-q", str(root / "origin.git"), str(self.checkout)], check=True, env=self.env, capture_output=True)
|
||||
|
||||
Reference in New Issue
Block a user