Rule each dimension in the paired ruling, and count a better ruling as worse when a dimension it rules fallen is under the floor
This commit is contained in:
+75
-34
@@ -10,7 +10,7 @@ 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, first_ruling, means, measured_commit, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes
|
||||
from larv_review.rules import base, counted, fallen, fell_under_floor, first_ruling, means, measured_commit, pending_fall, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes
|
||||
from failure import Failure
|
||||
from test_loop_claude_black_box import host_env
|
||||
from rank_todo import Item
|
||||
@@ -24,6 +24,10 @@ def paired(time: str, verdict: str, commit: str = "bbbbbbb") -> str:
|
||||
return f"## {time}, PR #2 at {commit}, against aaaaaaa\n\nRuling: {verdict}\n"
|
||||
|
||||
|
||||
def said(overall: str, locality: str = "same") -> str:
|
||||
return f"Navigation same, Locality {locality}, Shape same, Self-sufficiency same, Overall {overall}"
|
||||
|
||||
|
||||
def item(id_: int, release: tuple[int, int, int], tagline: str = "**Do it.**") -> Item:
|
||||
return Item(id_, release, "", tagline, {"R": 1, "S": 1, "A": 1, "G": 1}, ("1",))
|
||||
|
||||
@@ -34,28 +38,38 @@ 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("PR #2 at abc1234, against def5678\n\nMid A: worse\n\n- `a.py:1` `f`: hard\n to read\n\nInherited architect: same\n")
|
||||
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")
|
||||
self.assertEqual(given.read, "PR #2 at abc1234, against def5678")
|
||||
self.assertEqual(given.seats, [Seat("Mid A", "worse", ["`a.py:1` `f`: hard to read"]), Seat("Inherited architect", "same", [])])
|
||||
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)
|
||||
|
||||
def test_counts_a_vote_naming_no_place_as_same(self):
|
||||
seats = [Seat("Mid A", "worse", ["the whole skill"]), Seat("Inherited architect", "better", ["`a.py:3` `f`: shorter"])]
|
||||
self.assertEqual(votes(seats), {"Mid A": "same", "Inherited architect": "better"})
|
||||
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"])]
|
||||
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_refuses_two_more_seats_once_the_first_two_agree(self):
|
||||
seats = [Seat(name, vote, ["`f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))]
|
||||
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"))]
|
||||
self.assertIsInstance(votes(seats), Failure)
|
||||
|
||||
def test_takes_the_first_two_seats_then_the_other_two_in_order(self):
|
||||
first = [Seat("Mid A", "same", []), Seat("Inherited architect", "same", [])]
|
||||
def test_takes_the_first_two_seats_then_the_other_two_in_order_and_each_dimensions_vote(self):
|
||||
first = [Seat("Mid A", said("same"), []), Seat("Inherited architect", said("same"), [])]
|
||||
self.assertIsInstance(votes(first[::-1]), Failure)
|
||||
self.assertIsInstance(votes(first + [Seat("Junior A", "same", [])]), Failure)
|
||||
self.assertIsInstance(votes([first[0], Seat("Inherited architect", "worst", [])]), Failure)
|
||||
self.assertIsInstance(votes(first + [Seat("Junior A", said("same"), [])]), Failure)
|
||||
self.assertIsInstance(votes([first[0], Seat("Inherited architect", said("worst"), [])]), Failure)
|
||||
self.assertIsInstance(votes([first[0], Seat("Inherited architect", "same", [])]), Failure)
|
||||
|
||||
def test_finds_each_dimension_ruled_worse_by_a_lead_of_two(self):
|
||||
self.assertEqual(fallen({"Mid A": ["same", "worse", "worse", "same", "better"], "Inherited architect": ["same", "worse", "same", "same", "better"]}), ["Locality"])
|
||||
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"]}), [])
|
||||
self.assertEqual(fell_under_floor(["Locality", "Shape"], [decimal.Decimal(score) for score in ("6", "6.5", "7", "6", "6")]), ["Locality 6.5"])
|
||||
|
||||
def test_rules_by_a_lead_of_two_and_splits_two_seats_that_differ(self):
|
||||
cases = [
|
||||
@@ -90,17 +104,27 @@ class Seats(unittest.TestCase):
|
||||
class History(unittest.TestCase):
|
||||
def test_reads_back_what_it_writes(self):
|
||||
seats = [Seat("Mid A", "worse", ["`bin/a.py:3` `f`: hard, with `:9` `g`"]), Seat("Inherited architect", "worse", [])]
|
||||
ruled = ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, {"Mid A": "worse", "Inherited architect": "same"}, "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"])
|
||||
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 (voted worse, naming no place) |", history)
|
||||
self.assertIn("| Inherited architect | same | same (voted worse, naming no place) | same | same | same (voted worse, naming no place) |", history)
|
||||
found = entries(history)
|
||||
self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in found], [("aaaaaaa", None, None), ("bbbbbbb", "aaaaaaa", "worse")])
|
||||
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])
|
||||
|
||||
|
||||
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(SCORING + fell), ["Locality", "Shape"])
|
||||
self.assertEqual(pending_fall(fell + SCORING.replace("12:00:00Z", "14:00:00Z")), [])
|
||||
self.assertEqual(pending_fall(SCORING + paired("2026-10-08T13:00:00Z", "better")), [])
|
||||
self.assertEqual(pending_fall(""), [])
|
||||
|
||||
|
||||
class Base(unittest.TestCase):
|
||||
def test_takes_the_newest_change_adding_a_scoring_run_or_ending_on_a_better_ruling(self):
|
||||
older = HistoryChange("old", "", SCORING)
|
||||
@@ -139,27 +163,31 @@ 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 better 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):
|
||||
@@ -230,25 +258,38 @@ class LarvReviewTool(unittest.TestCase):
|
||||
lines = """\
|
||||
PR #2 at {start}, against {start}
|
||||
|
||||
Mid A: worse
|
||||
Mid A: {worse}
|
||||
|
||||
- `bin/a.py:3` `f`: three branches
|
||||
|
||||
Inherited architect: same
|
||||
Inherited architect: {same}
|
||||
"""
|
||||
lines = lines.replace("{start}", self.start)
|
||||
lines = lines.replace("{start}", self.start).replace("{worse}", said("worse")).replace("{same}", said("same"))
|
||||
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."))
|
||||
history = self.checkout / "docs" / "comprehension-history.md"
|
||||
self.assertFalse(history.exists())
|
||||
lines += "\n\t\t\tMaintainability senior: worse\n\n\t\t\t- `bin/a.py:3` `f`: hard\n\n\t\t\tJunior A: worse\n"
|
||||
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"
|
||||
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 (voted worse, naming no place).")
|
||||
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())
|
||||
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())
|
||||
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):
|
||||
place = "\n\n- `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 better paired ruling in which Locality fell.\n")
|
||||
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 6.50 fell under the floor of 7.0.", scored.stdout)
|
||||
self.assertIn("\n\nRatchet: the paired ruling counts as worse", (self.checkout / "docs" / "comprehension-history.md").read_text())
|
||||
self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "No scoring run due.\n")
|
||||
|
||||
def test_records_a_scoring_run_with_its_means(self):
|
||||
line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 6.5, Overall 7"
|
||||
@@ -262,10 +303,10 @@ class LarvReviewTool(unittest.TestCase):
|
||||
self.assertEqual([entry.places for entry in entries(text)], [[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: same\n\nInherited architect: same\n"))
|
||||
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"))
|
||||
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"))
|
||||
lacking = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against abcdef1\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n"))
|
||||
self.assertEqual(lacking.returncode, 1)
|
||||
self.assertIn("abcdef1, which is no commit", lacking.stderr)
|
||||
|
||||
@@ -286,7 +327,7 @@ class LarvReviewTool(unittest.TestCase):
|
||||
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: same\n\nInherited architect: same\n"))
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user