Answer architecture round 1: move the base fallback, heading check and seat names into the pure modules, move legacy scores through record-scoring, and read origin as last fetched when a fetch fails

This commit is contained in:
2026-10-09 01:18:57 +02:00
parent 53ed5150be
commit 05efbb1d8a
10 changed files with 168 additions and 89 deletions
+39 -10
View File
@@ -9,9 +9,9 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from larv_review.history import appended, entries, Place, ruling_entry, scoring_runs
from larv_review.history import appended, entries, HistoryChange, Place, ruling_entry, scoring_runs
from larv_review.rules import base, first_ruling, means, measured_commit, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes
from failure import Failure
from larv_review.rules import first_ruling, HistoryChange, means, measured_commit, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes
from test_loop_claude_black_box import host_env
from rank_todo import Item
from larv_review.seats import report, scores, Seat
@@ -108,6 +108,12 @@ class Base(unittest.TestCase):
self.assertEqual(measured_commit([worse_last, older]), "old")
self.assertIsNone(measured_commit([same]))
def test_falls_back_to_the_first_rulings_base_then_to_the_merge_base(self):
ruled = paired("2026-10-08T13:00:00Z", "worse")
self.assertEqual(base([HistoryChange("c", "", ruled)], ruled, "m", "main")[0], "aaaaaaa")
self.assertEqual(base([], "", "m", "main")[0], "m")
self.assertEqual(base([HistoryChange("c", "", SCORING)], SCORING, "m", "main")[0], "c")
def test_finds_the_earliest_ruling_by_its_time(self):
ruled = first_ruling(paired("2026-10-08T14:00:00Z", "same", "ccccccc") + paired("2026-10-08T13:00:00Z", "worse"))
self.assertEqual(ruled and ruled.commit, "bbbbbbb")
@@ -116,19 +122,20 @@ class Base(unittest.TestCase):
class Rounds(unittest.TestCase):
def test_counts_each_passs_highest_round(self):
counts = round_counts(["Answer prose round 1: x", "Answer full scan round 2: y", "Answer full scan round 1: z", "Answer stability: no round", "Answer stabilty round 1: typo", "Rescore: w"])
self.assertEqual((counts["prose"], counts["full scan"], counts["stability"], counts["architecture"], counts["stabilty"]), (1, 2, 0, 0, 1))
counts = round_counts(["Answer prose round 1: x", "Answer full scan round 2: y", "Answer full scan round 1: z", "Answer stability: no round", "Answer stabilty round 1: typo", "Answer security round 1: rename round 2: x", "Rescore: w"])
self.assertEqual((counts["prose"], counts["full scan"], counts["stability"], counts["architecture"], counts["stabilty"], counts["security"]), (1, 2, 0, 0, 1, 1))
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.assertEqual(plan_items("# todo\n"), [])
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)
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)
def test_is_due_when_the_chunk_ships_a_releases_last_item(self):
plan = [item(1, (0, 1, 0)), item(2, (0, 2, 0))]
@@ -163,6 +170,7 @@ class LarvReviewTool(unittest.TestCase):
self.git("push", "-q", "origin", "HEAD:main")
self.git("remote", "set-head", "origin", "main")
self.git("switch", "-q", "-c", "chunk")
self.start = self.git("rev-parse", "--short", "HEAD").strip()
def git(self, *args):
return subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], cwd=self.checkout, check=True, env=self.env, capture_output=True, text=True).stdout
@@ -213,7 +221,7 @@ class LarvReviewTool(unittest.TestCase):
def test_records_a_ruling_once_four_seats_settle_a_split(self):
lines = """\
PR #2 at abc1234, against def5678
PR #2 at {start}, against {start}
Mid A: worse
@@ -221,6 +229,7 @@ class LarvReviewTool(unittest.TestCase):
Inherited architect: same
"""
lines = lines.replace("{start}", self.start)
split = self.run_tool("record-ruling", self.seats_file(lines))
self.assertEqual(split.returncode, 0, split.stderr)
self.assertTrue(split.stdout.startswith("Split: Mid A worse, Inherited architect same."))
@@ -230,14 +239,14 @@ class LarvReviewTool(unittest.TestCase):
ran = self.run_tool("record-ruling", self.seats_file(lines))
self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same.")
recorded = entries(history.read_text())
self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in recorded], [("abc1234", "def5678", "same")])
self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in recorded], [(self.start, self.start, "same")])
self.assertEqual(recorded[0].places, [Place("bin/a.py", "f")] * 2)
self.assertIn("| Junior A | same (voted worse, naming no place) |", history.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("PR #2 at abc1234\n" + seats))
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)
text = (self.checkout / "docs" / "comprehension-history.md").read_text()
@@ -245,10 +254,30 @@ class LarvReviewTool(unittest.TestCase):
self.assertIn("Inherited architect, would restructure first:", text)
self.assertEqual([run.places for run in scoring_runs(text)], [[Place("bin/a.py", "f")] * 4])
def test_refuses_a_ruling_file_that_names_no_base(self):
ran = self.run_tool("record-ruling", self.seats_file("PR #2 at abc1234\n\nMid A: same\n\nInherited architect: same\n"))
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: same\n\nInherited architect: same\n"))
self.assertEqual(ran.returncode, 1)
self.assertIn("against <base>", ran.stderr)
lacking = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against abcdef1\n\nMid A: same\n\nInherited architect: same\n"))
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_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"))
offline = self.run_tool("round-count")
self.assertEqual(offline.returncode, 0, offline.stderr)
self.assertIn("reading origin as last fetched", offline.stderr)
self.assertIn("prose: 1\n", offline.stdout)
self.git("remote", "remove", "origin")
self.assertIn("prose: 1\n", self.run_tool("round-count").stdout)
if __name__ == "__main__":