diff --git a/bin/rank_todo.py b/bin/rank_todo.py index 7df500b9..f5dcc125 100755 --- a/bin/rank_todo.py +++ b/bin/rank_todo.py @@ -91,6 +91,8 @@ class Scoring: class Ranked: text: str under_bar: list[str] + # Each blocker ID the ranking dropped because the table no longer holds it, which a typo would look like too. + dropped: list[str] def main(argv: list[str]) -> int: @@ -116,7 +118,7 @@ def main(argv: list[str]) -> int: unwritten = write(todo, ranked.text) if unwritten: return fail(unwritten) - for line in ranked.under_bar: + for line in ranked.dropped + ranked.under_bar: print(f"{todo}: {line}", file=sys.stderr) return 1 if ranked.under_bar else 0 @@ -188,7 +190,9 @@ def rank(text: str, readme: str, decisions: str) -> Ranked | Failure: if isinstance(ranked, Failure): return ranked under_bar = [under_the_bar(item, value, scoring.bar, items) for item, value in scored if not item.exempt and round(value, 1) < scoring.bar] - return Ranked(ranked, under_bar) + held = {item.id for item in items} + dropped = [f"item {item.id}: dropped {', '.join(map(str, gone))} from its {BLOCKED_BY}; the table no longer holds it" for item in items if (gone := sorted(set(item.blocked_by) - held))] + return Ranked(ranked, under_bar, dropped) def blocked_through(id_: int, items: list[Item]) -> set[int]: @@ -252,7 +256,7 @@ def read_items(lines: list[str], scoring: Scoring) -> tuple[list[Item], Table] | return Failure("todo.md's items table has no C column; add one after S, and score each item's C from 1 to 10 per rank_todo.py --help") # Ranking writes COLUMNS, so it would drop a column it does not know. if unknown := [column for column in table.columns if column not in COLUMNS]: - return Failure(f"todo.md's items table has the column {', '.join(unknown)}, which this rank_todo.py does not know; move this machine to the release that added it") + return Failure(f"todo.md's items table has the column {', '.join(unknown)}, which this rank_todo.py does not know; its columns are {', '.join(COLUMNS)}. Rename it, or move this machine to the release that added it") if misplaced := outside_items(lines, table): return misplaced items = [] diff --git a/bin/test_rank_todo.py b/bin/test_rank_todo.py index d0bd87b0..f313e1ee 100644 --- a/bin/test_rank_todo.py +++ b/bin/test_rank_todo.py @@ -155,7 +155,10 @@ class Blockers(unittest.TestCase): def test_drops_a_blocker_the_table_no_longer_holds_as_finished(self): finished = TODO.replace("| 4 | 0.1.0 | | security | **Rotate the leaked key.** | 9 | 2 | 3 | 1 | 1 | 2.1 | 0 |\n", "").replace("| 2 | 0.1.0 | |", "| 2 | 0.1.0 | 4 |") - self.assertIn("| 2 | 0.1.0 | | | **Tighten the tests.**", self.ranked(finished).text) + ranked = self.ranked(finished) + self.assertIn("| 2 | 0.1.0 | | | **Tighten the tests.**", ranked.text) + self.assertEqual(ranked.dropped, ["item 2: dropped 4 from its Blocked by; the table no longer holds it"]) + self.assertEqual(self.ranked(ranked.text).dropped, []) def test_refuses_a_blocker_in_a_later_release_a_loop_and_an_id_past_next_id(self): cases = { @@ -178,7 +181,7 @@ class Blockers(unittest.TestCase): def test_refuses_a_column_it_does_not_know_rather_than_drop_it_and_asks_for_c_beside_blocked_by(self): extra = TODO.replace("| Goals | Score |\n|---|", "| Goals | Score | Later |\n|---|---|").replace(" | 0 |\n", " | 0 | x |\n") - self.assertEqual(self.ranked(extra), Failure("todo.md's items table has the column Later, which this rank_todo.py does not know; move this machine to the release that added it")) + self.assertEqual(self.ranked(extra), Failure("todo.md's items table has the column Later, which this rank_todo.py does not know; its columns are ID, Release, Blocked by, Exempt, Item, R, S, C, A, G, Goals, Score. Rename it, or move this machine to the release that added it")) self.assertEqual([item.id for item in todo_table.items(extra)], [1, 2, 3, 4, 5]) without_c = TODO.replace("| R | S | C |", "| R | S |").replace("|---|---|---|---|---|---|---|---|---|---|---|---|", "|---|---|---|---|---|---|---|---|---|---|---|") without_c = re.sub(r"(\*\* \| \d+ \| \d+) \| \d+ \|", r"\1 |", without_c) @@ -245,4 +248,4 @@ class ThisRepo(unittest.TestCase): def test_todo_md_is_ranked_with_nothing_under_the_bar(self): text = (ROOT / "todo.md").read_text(encoding="utf-8") ranked = rank_todo.rank(text, (ROOT / "README.md").read_text(encoding="utf-8"), (ROOT / "docs" / "decisions.md").read_text(encoding="utf-8")) - self.assertEqual(ranked, rank_todo.Ranked(text, [])) + self.assertEqual(ranked, rank_todo.Ranked(text, [], []))