368 lines
25 KiB
Python
368 lines
25 KiB
Python
import decimal
|
|
import itertools
|
|
import os
|
|
import pathlib
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import textwrap
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
from comprehension_history import appended, entries, HistoryChange, latest_places, Place, recorded, ruling_entry, scoring_entry, ScoringRun, Seat
|
|
import comprehension_history
|
|
from larv_review.ruling import counted, ruling, split, votes
|
|
from failure import Failure
|
|
from test_env import isolated_env
|
|
from todo_table import Item, items
|
|
from larv_review.scoring import means, under_floor
|
|
from larv_review.ruling_base import measured_commit
|
|
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"
|
|
|
|
|
|
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, "C": 3, "A": 1, "G": 1}, ("1",))
|
|
|
|
|
|
def todo(*rows: str) -> str:
|
|
return "## Items\n\n| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n" + "".join(f"{row}\n" for row in rows)
|
|
|
|
|
|
class Seats(unittest.TestCase):
|
|
def test_reads_each_seats_line_and_places_and_joins_a_wrapped_place(self):
|
|
given = seats_file(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", 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(seats_file("PR #2 at abc1234\n\nMid A worse\n"), Failure)
|
|
self.assertIsInstance(seats_file("PR #2 at abc1234\n\nMid A: worse\n\nMid A: same\n"), Failure)
|
|
self.assertIsInstance(seats_file(""), Failure)
|
|
|
|
def test_counts_each_vote_of_a_seat_naming_no_place_as_same(self):
|
|
seats = [Seat("Mid A", said("worse", "worse"), ["Locality: the whole skill"]), Seat("Inherited architect", said("better"), ["Overall: `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_counts_a_dimensions_vote_only_where_a_place_names_that_dimension(self):
|
|
seats = [Seat("Mid A", said("better", "worse"), ["Shape: `a.py:3` `f`: the Locality of it, reshaped"]), Seat("Inherited architect", said("better", "worse"), ["Locality, Shape: `a.py:3` `f`: 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"), ["Locality, self sufficiency: `a.py:3` `f`: x"]), seats[1]]), Failure)
|
|
self.assertIsInstance(votes([Seat("Mid A", said("better"), ["`a.py:3` `f`: Locality: x"]), seats[1]]), Failure)
|
|
self.assertEqual(votes(seats), {seat.name: written[seat.name] for seat in seats})
|
|
|
|
def test_refuses_two_more_seats_once_the_first_two_agree_overall(self):
|
|
seats = [Seat(name, said(vote), ["Overall: `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_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", 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_rules_by_a_lead_of_two_and_splits_two_seats_that_differ(self):
|
|
cases = [
|
|
(["worse", "worse"], "worse"),
|
|
(["same", "same"], "same"),
|
|
(["worse", "same"], None),
|
|
(["worse", "better", "worse", "worse"], "worse"),
|
|
(["worse", "same", "worse", "same"], "same"),
|
|
(["worse", "same", "worse", "better"], "same"),
|
|
(["better", "same", "better", "better"], "better"),
|
|
]
|
|
for counted, expected in cases:
|
|
with self.subTest(counted):
|
|
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"
|
|
seats = [Seat(name, line, []) for name in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect")]
|
|
self.assertEqual(scores(seats)["Mid A"], ["7", "6.5", "7", "6.5", "7"])
|
|
self.assertIsInstance(scores(seats[:3]), Failure)
|
|
self.assertIsInstance(scores([*seats[:3], Seat("Inherited architect", line.replace("Overall 7", "Overall 8"), [])]), Failure)
|
|
self.assertIsInstance(scores([*seats[:3], Seat("Inherited architect", line.replace("Shape 7", "Shape 11"), [])]), Failure)
|
|
self.assertEqual(score_line("Mean", "Navigation 7.38, Locality 7.38, Shape 8, Self-sufficiency 8, Overall 8.38")[-1], "8.38")
|
|
|
|
def test_rounds_each_mean_half_up_and_names_each_under_the_floor(self):
|
|
found = means([["7.5", "6.5", "7", "7", "7"], ["7.5", "7", "7", "6.5", "7"], ["7", "6.5", "7", "6.5", "6.5"], ["7.5", "6.5", "7", "6.5", "7"]])
|
|
self.assertEqual([str(mean) for mean in found], ["7.38", "6.63", "7.00", "6.63", "6.88"])
|
|
self.assertEqual(under_floor(found), ["Locality 6.63", "Self-sufficiency 6.63", "Overall 6.88"])
|
|
self.assertEqual(under_floor([decimal.Decimal("7.00")] * 5), [])
|
|
|
|
|
|
class History(unittest.TestCase):
|
|
def test_writes_the_sample_entry_its_parser_shows(self):
|
|
source = pathlib.Path(comprehension_history.__file__).read_text(encoding="utf-8").splitlines()
|
|
start = next(index for index, line in enumerate(source) if line.startswith("# ## "))
|
|
sample = [line.removeprefix("#").removeprefix(" ") for line in itertools.takewhile(lambda line: line.startswith("#"), source[start:])]
|
|
seat = Seat("Mid A", said("better", "worse"), ["Locality: `bin/x.py:12` `run`: three branches to hold at once"])
|
|
votes = {"Mid A": ["better", "worse", "same", "same", "better"]}
|
|
self.assertEqual(ruling_entry("2026-10-09T09:47:25Z, PR #232 at 324d650, against 12d6d75", [seat], votes, votes, "same"), "\n".join(sample) + "\n")
|
|
|
|
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 = 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")
|
|
history = appended(appended("", scoring_entry("2026-10-08T12:00:00Z, PR #1 at aaaaaaa", 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, no place naming Locality) | 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((found[0].scored_places, found[1].ruled_places), ([Place("bin/b.py", "h")], [Place("bin/a.py", "f"), Place("bin/a.py", "g")]))
|
|
self.assertTrue(recorded(history, "PR #2 at bbbbbbb, against aaaaaaa"))
|
|
self.assertFalse(recorded(history, "PR #2 at bbbbbbb"))
|
|
self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 7.00 | 7.00 |\n\nJunior A, hardest first:", history)
|
|
self.assertEqual([entry.paired for entry in found], [False, True])
|
|
|
|
def test_names_the_places_found_hard_since_the_newest_entry_that_scored_the_project(self):
|
|
scored = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n\nJunior A, hardest first:\n\n- `bin/b.py:4` `h`: long\n and wrapped\n\nInherited architect, would restructure first:\n\n- `bin/c.py:1` `k`: tangled\n"
|
|
seats = [Seat("Mid A", "", ["Locality, Shape: `bin/a.py:3` `f`: held at once", "Navigation: `README.md:4` \"Tools\": easier to find"]), Seat("Inherited architect", "", ["Locality: `bin/d.py:2` `m`: deep"])]
|
|
said = {"Mid A": ["better", "same", "worse", "same", "worse"], "Inherited architect": ["same", "worse", "same", "same", "worse"]}
|
|
ruled = ruling_entry("2026-10-10T12:00:00Z, PR #2 at bbbbbbb, against aaaaaaa", seats, said, {**said, "Inherited architect": ["same"] * 5}, "same")
|
|
older = paired("2026-10-07T12:00:00Z", "worse") + "\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | same | worse | same | same | worse |\n\nMid A, decided by:\n\n- Locality: `bin/e.py:1` `n`: old\n"
|
|
self.assertIsNone(latest_places(""))
|
|
self.assertIsNone(latest_places(appended("", paired("2026-10-07T12:00:00Z", "same"))))
|
|
self.assertIsNone(latest_places(appended("", paired("2026-10-07T12:00:00Z", "worse") + "\n| Seat | Vote | Locality |\n|---|---|---|\n| Mid A | same | worse |\n\n- Locality: `bin/k.py:1` `t`: before any label\n\nMid A, decided by:\n\n- Locality: `bin/e.py:1` `n`: old\n")))
|
|
unscored = "## 2026-10-11T12:00:00Z, PR #4 at eeeeeee\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n"
|
|
self.assertIsNone(latest_places(appended(appended("", scored), unscored)))
|
|
hard_since = "## 2026-10-10T12:00:00Z, PR #2 at bbbbbbb, against aaaaaaa\n\nMid A, decided by:\n\n- Locality, Shape: `bin/a.py:3` `f`: held at once\n"
|
|
self.assertEqual(latest_places(appended(appended(appended("", older), ruled), scored)), "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\nJunior A, hardest first:\n\n- `bin/b.py:4` `h`: long\n and wrapped\n\nInherited architect, would restructure first:\n\n- `bin/c.py:1` `k`: tangled\n\n" + hard_since)
|
|
self.assertEqual(latest_places(appended(appended("", ruled), older)), "## 2026-10-07T12:00:00Z, PR #2 at bbbbbbb, against aaaaaaa\n\nMid A, decided by:\n\n- Locality: `bin/e.py:1` `n`: old\n\n" + hard_since)
|
|
wrapped = "## 2026-10-09T12:00:00Z, PR #3 at ccccccc\n\nJunior A, hardest first:\n\n an indented line before any bullet\n- `bin/f.py:1` `p`: long,\n like `bin/g.py:2` `q`\n"
|
|
calm = paired("2026-10-09T13:00:00Z", "same", "ddddddd") + "\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | same | same | same | same | same |\n\nMid A, decided by:\n\n- Locality: `bin/h.py:1` `r`: as before\n"
|
|
history = appended(appended(appended("", wrapped), calm), ruled)
|
|
self.assertEqual(entries(history)[0].scored_places, [Place("bin/f.py", "p")])
|
|
self.assertEqual(latest_places(history), "## 2026-10-09T12:00:00Z, PR #3 at ccccccc\n\nJunior A, hardest first:\n\n- `bin/f.py:1` `p`: long,\n like `bin/g.py:2` `q`\n\n" + hard_since)
|
|
fell = ruled.replace("2026-10-10T12:00:00Z", "2026-10-09T12:00:00Z") + "\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | 7 | 6 | 7 | 7 | 7 |\n| Mean | 7 | 6 | 7 | 7 | 7 |\n\nJunior A, hardest first:\n\n- `bin/j.py:5` `s`: wide\n"
|
|
self.assertEqual(latest_places(appended(appended("", scored), fell)), hard_since.replace("2026-10-10T12:00:00Z", "2026-10-09T12:00:00Z") + "\nJunior A, hardest first:\n\n- `bin/j.py:5` `s`: wide\n")
|
|
|
|
|
|
class Base(unittest.TestCase):
|
|
def test_takes_the_newest_change_adding_an_entry(self):
|
|
older = HistoryChange("old", "", SCORING)
|
|
same = HistoryChange("same", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "same"))
|
|
self.assertEqual(measured_commit([same, older]), "same")
|
|
worse = HistoryChange("worse", SCORING, SCORING + paired("2026-10-08T14:00:00Z", "worse"))
|
|
self.assertEqual(measured_commit([worse, older]), "worse")
|
|
self.assertEqual(measured_commit([HistoryChange("none", SCORING, SCORING + "\nAn edit outside any entry.\n"), older]), "old")
|
|
self.assertIsNone(measured_commit([HistoryChange("none", SCORING, SCORING)]))
|
|
|
|
|
|
class ScoringRunDue(unittest.TestCase):
|
|
def test_reads_each_rows_id_release_and_tagline(self):
|
|
self.assertEqual(items(todo("| 3 | 0.1.0 | | **Do it.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |")), [item(3, (0, 1, 0))])
|
|
self.assertIsNone(items("# todo\n"))
|
|
self.assertIsInstance(items(todo("| 0 | 0.1.0 | | **Do it.** | 1 | 1 | 3 | 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))]
|
|
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), [])
|
|
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), [])
|
|
|
|
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), [])
|
|
|
|
|
|
class LarvReviewTool(unittest.TestCase):
|
|
def setUp(self):
|
|
temp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(temp.cleanup)
|
|
root = pathlib.Path(os.path.realpath(temp.name))
|
|
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)
|
|
self.commit("start", {"todo.md": todo("| 1 | 0.1.0 | | **Do it.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |", "| 2 | 0.2.0 | | **Then this.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |", "| 3 | 0.2.0 | | **And this.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |")})
|
|
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
|
|
|
|
def commit(self, title, files=None):
|
|
for name, text in (files or {}).items():
|
|
(self.checkout / name).parent.mkdir(parents=True, exist_ok=True)
|
|
(self.checkout / name).write_text(text)
|
|
self.git("add", name)
|
|
self.git("commit", "-q", "--allow-empty", "-m", title)
|
|
|
|
def run_tool(self, *args):
|
|
return subprocess.run([sys.executable, str(TOOL), *args], capture_output=True, cwd=self.checkout, env=self.env, text=True)
|
|
|
|
def seats_file(self, text, name="seats.md"):
|
|
path = self.checkout.parent / name
|
|
path.write_text(textwrap.dedent(text))
|
|
return str(path)
|
|
|
|
def test_takes_the_merge_base_until_a_merged_change_records_an_entry(self):
|
|
start = self.git("rev-parse", "HEAD").strip()
|
|
self.commit("work")
|
|
ran = self.run_tool("ruling-base")
|
|
self.assertEqual((ran.returncode, ran.stdout.splitlines()[0]), (0, start), ran.stderr)
|
|
self.git("switch", "-q", "-c", "measured", "main")
|
|
self.commit("Merge a scoring run", {"docs/comprehension-history.md": "# Comprehension history\n\n" + SCORING})
|
|
self.git("push", "-q", "origin", "HEAD:main")
|
|
measured = self.git("rev-parse", "HEAD").strip()
|
|
self.git("switch", "-q", "chunk")
|
|
self.assertEqual(self.run_tool("ruling-base").stdout.splitlines()[0], measured)
|
|
|
|
def test_counts_rounds_on_this_branch_alone(self):
|
|
self.commit("Answer stability round 1: a")
|
|
self.commit("Answer stability round 2: b")
|
|
self.commit("Answer prose round 1: c")
|
|
self.commit("Answer stability round 3: d")
|
|
ran = self.run_tool("round-count")
|
|
self.assertIn("stability: 3, at the cap: ask the human before another round\n", ran.stdout)
|
|
self.commit("Answer stability round 4: e")
|
|
self.assertIn("stability: 4, past the cap: ask the human before another round\n", self.run_tool("round-count").stdout)
|
|
self.assertIn("prose: 1\n", ran.stdout)
|
|
self.assertIn("architecture: 0\n", ran.stdout)
|
|
|
|
def test_says_whether_a_scoring_run_is_due_and_refuses_an_unknown_item(self):
|
|
self.assertEqual(self.run_tool("needs-scoring-run", "1").stdout, "Scoring run due: the chunk leaves release 0.1.0 with no plan item.\n")
|
|
self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "No scoring run due.\n")
|
|
unknown = self.run_tool("needs-scoring-run", "9")
|
|
self.assertEqual(unknown.returncode, 1)
|
|
self.assertIn("item 9", unknown.stderr)
|
|
self.assertEqual(self.run_tool("needs-scoring-run").stdout, "No scoring run due.\n")
|
|
self.assertIn("todo.md's ID column", self.run_tool("needs-scoring-run", "item-85").stderr)
|
|
|
|
def test_reads_a_default_branch_plan_without_a_table_as_empty_and_refuses_a_checkout_without_one(self):
|
|
self.git("switch", "-q", "-c", "reshape", "main")
|
|
self.commit("Plan as a list", {"todo.md": "# todo\n\n- [ ] Do it.\n"})
|
|
self.git("push", "-q", "origin", "HEAD:main")
|
|
self.git("switch", "-q", "chunk")
|
|
self.assertEqual(self.run_tool("needs-scoring-run", "2").returncode, 0)
|
|
(self.checkout / "todo.md").write_text("# todo\n")
|
|
ran = self.run_tool("needs-scoring-run", "2")
|
|
self.assertEqual(ran.returncode, 1)
|
|
self.assertIn("the checkout's todo.md has no items table", ran.stderr)
|
|
|
|
def test_records_a_ruling_once_four_seats_settle_a_split(self):
|
|
lines = """\
|
|
PR #2 at {start}, against {start}
|
|
|
|
Mid A: {worse}
|
|
|
|
- Overall: `bin/a.py:3` `f`: three branches
|
|
|
|
Inherited architect: {same}
|
|
"""
|
|
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 += f"\n\t\t\tMaintainability senior: {said('worse')}\n\n\t\t\t- Overall: `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. 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].ruled_places, [Place("bin/a.py", "f")] * 2)
|
|
self.assertIn("| Junior A | same | same | same | same | same (voted worse, naming no place) |", history.read_text())
|
|
|
|
def test_records_a_ruling_whose_dimension_fell_and_takes_no_scores_file(self):
|
|
place = "\n\n- Locality, Overall: `bin/a.py:3` `f`: shorter\n\n"
|
|
votes_file = 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}", "votes.md")
|
|
extra = self.run_tool("record-ruling", votes_file, votes_file)
|
|
self.assertEqual(extra.returncode, 1)
|
|
self.assertIn("unknown arguments", extra.stderr)
|
|
ran = self.run_tool("record-ruling", votes_file)
|
|
self.assertEqual(ran.returncode, 0, ran.stderr)
|
|
self.assertTrue(ran.stdout.startswith("Ruling: better. Overall votes as counted:"))
|
|
again = self.run_tool("record-ruling", votes_file)
|
|
self.assertEqual((again.returncode, again.stdout), (1, ""))
|
|
self.assertIn("already holds an entry on", again.stderr)
|
|
self.assertEqual([entry.ruling for entry in entries((self.checkout / "docs" / "comprehension-history.md").read_text())], ["better"])
|
|
|
|
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"))
|
|
uncalled = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats))
|
|
self.assertEqual(uncalled.returncode, 1)
|
|
self.assertIn("no plan item or release calls this scoring run", uncalled.stderr)
|
|
ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats), "1")
|
|
self.assertEqual(ran.returncode, 0, ran.stderr)
|
|
self.assertIn("\nFloor: Locality 6.50, Self-sufficiency 6.50 under the floor of 7.0.\n", ran.stdout)
|
|
self.assertIn("not /", self.run_tool("record-scoring", "1", self.seats_file(f"PR #2 at {self.start}\n" + seats)).stderr)
|
|
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(entries(text)[0].scored_places, [Place("bin/a.py", "f")] * 4)
|
|
|
|
def test_prints_the_places_seats_found_hard_since_the_newest_scoring_run(self):
|
|
self.assertEqual(self.run_tool("places").stdout, "Seats found no places hard.\n")
|
|
self.commit("Record a scoring run", {"docs/comprehension-history.md": appended("", SCORING + "\nJunior A, hardest first:\n\n- `bin/b.py:4` `h`: long\n")})
|
|
ran = self.run_tool("places")
|
|
self.assertEqual((ran.returncode, ran.stdout), (0, "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\nJunior A, hardest first:\n\n- `bin/b.py:4` `h`: long\n"), ran.stderr)
|
|
self.assertIn("unknown arguments", self.run_tool("places", "x").stderr)
|
|
outside = subprocess.run([sys.executable, str(TOOL), "places"], capture_output=True, cwd=self.checkout.parent, env=self.env, text=True)
|
|
self.assertEqual((outside.returncode, outside.stdout), (1, ""))
|
|
|
|
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"))
|
|
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: {said('same')}\n\nInherited architect: {said('same')}\n"))
|
|
self.assertEqual(lacking.returncode, 1)
|
|
self.assertIn("abcdef1, which is no commit", lacking.stderr)
|
|
|
|
def test_states_its_rules_and_finds_origins_default_branch_where_the_clone_recorded_none(self):
|
|
helped = self.run_tool("--help")
|
|
self.assertEqual(helped.returncode, 0, helped.stderr)
|
|
self.assertIn("cap of 3 rounds", helped.stdout)
|
|
self.git("remote", "set-head", "origin", "--delete")
|
|
self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "No scoring run due.\n")
|
|
|
|
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__":
|
|
unittest.main()
|