Answer principles round 1: 0 🔴, 1 🟡; print the rest of the report when the anchors cannot be read, and still exit 1

This commit is contained in:
2026-10-16 20:00:40 +02:00
parent 0f3434f2c5
commit 717f56d319
3 changed files with 68 additions and 24 deletions
+11 -8
View File
@@ -6,13 +6,14 @@ from score_outcomes.outcomes import Outcome, render
# Where a project names the shipped items that show each level of L, E and I. # Where a project names the shipped items that show each level of L, E and I.
ANCHORS_PATH = "docs/score-anchors.md" ANCHORS_PATH = "docs/score-anchors.md"
# A level, such as `L 1`. # A level, such as `L 1`; every scale tops out below 10.
LEVEL = re.compile(r"([A-Z]) ([0-9]+)") LEVEL = re.compile(r"([A-Z]) ([1-9])")
# Each level the anchors table names, such as `L 1`, with its items' IDs, in the file's order.
Anchors = list[tuple[str, tuple[int, ...]]]
def parse_anchors(text: str) -> list[tuple[str, tuple[int, ...]]] | Failure: def parse_anchors(text: str) -> Anchors | Failure:
"""Each level the anchors table names, such as `L 1`, with its items' IDs, in the file's order.""" found: Anchors = []
found: list[tuple[str, tuple[int, ...]]] = []
for row in (line.strip() for line in text.splitlines() if line.strip().startswith("|")): for row in (line.strip() for line in text.splitlines() if line.strip().startswith("|")):
pair = cells(row, 2) pair = cells(row, 2)
if isinstance(pair, Failure): if isinstance(pair, Failure):
@@ -20,7 +21,7 @@ def parse_anchors(text: str) -> list[tuple[str, tuple[int, ...]]] | Failure:
if pair == ["Level", "Items"] or all(re.fullmatch(r":?-+:?", cell) for cell in pair): if pair == ["Level", "Items"] or all(re.fullmatch(r":?-+:?", cell) for cell in pair):
continue continue
level, ids = LEVEL.fullmatch(pair[0]), parse_ids(pair[1]) level, ids = LEVEL.fullmatch(pair[0]), parse_ids(pair[1])
if not level or not 1 <= int(level[2]) <= LEVELS.get(level[1], 0) or not ids: if not level or int(level[2]) > LEVELS.get(level[1], 0) or not ids:
scales = ", ".join(f"{name} 1 to {top}" for name, top in LEVELS.items()) scales = ", ".join(f"{name} 1 to {top}" for name, top in LEVELS.items())
return Failure(f"{ANCHORS_PATH} cannot read the row {row}; each row names a level, {scales}, and the IDs of shipped items, such as | L 1 | 12, 14 |") return Failure(f"{ANCHORS_PATH} cannot read the row {row}; each row names a level, {scales}, and the IDs of shipped items, such as | L 1 | 12, 14 |")
if pair[0] in dict(found): if pair[0] in dict(found):
@@ -29,8 +30,10 @@ def parse_anchors(text: str) -> list[tuple[str, tuple[int, ...]]] | Failure:
return found return found
def anchor_lines(found: list[tuple[str, tuple[int, ...]]], outcomes: list[Outcome]) -> list[str]: def anchor_lines(found: Anchors | Failure, outcomes: list[Outcome]) -> list[str]:
"""Each level, then each of its anchors with what its chunk measured; where the project names no level, where to name them.""" """Each level, then each of its anchors with what its chunk measured; why none shows where the file cannot be read, and where to name them where it names no level."""
if isinstance(found, Failure):
return [f"- None: {found.reason}"]
if not found: if not found:
return [f"- None: the project's {ANCHORS_PATH} names no level; ~/.claude/rules/todo-items.md says how to choose them."] return [f"- None: the project's {ANCHORS_PATH} names no level; ~/.claude/rules/todo-items.md says how to choose them."]
by_id = {outcome.item.id: outcome for outcome in outcomes} by_id = {outcome.item.id: outcome for outcome in outcomes}
+10 -12
View File
@@ -30,9 +30,9 @@ scored before L, E and I, the newest first among equals. Each line gives what th
measured, which items shipped with it, and its tagline. measured, which items shipped with it, and its tagline.
Then the project's anchors, the shipped items its docs/score-anchors.md names for each level of L, Then the project's anchors, the shipped items its docs/score-anchors.md names for each level of L,
E and I, read from the checkout's working tree, each line as above, or that no merge shipped it. Exit 1 E and I, read from the checkout's working tree, each line as above, or that no merge shipped it. A
on a row that names no level on its scale, a level named twice, or an Items cell that is not a list row that names no level on its scale, a level named twice, or an Items cell that is not a list of
of IDs. IDs leaves the anchors out, saying why, and exits 1 after the rest of the report.
Then the median of the outcome R and S each predict at each value they were guessed at: R against Then the median of the outcome R and S each predict at each value they were guessed at: R against
🔴 findings, S against lines changed. And how well L, E and I each order chunks by review rounds 🔴 findings, S against lines changed. And how well L, E and I each order chunks by review rounds
@@ -48,7 +48,7 @@ import pathlib
import re import re
import sys import sys
from score_outcomes.anchors import anchor_lines, ANCHORS_PATH, parse_anchors from score_outcomes.anchors import anchor_lines, Anchors, ANCHORS_PATH, parse_anchors
from git_repo import default_branch, file_at, full_history, git, top from git_repo import default_branch, file_at, full_history, git, top
from failure import Failure from failure import Failure
from todo_table import LEVELS, risk, TOP_SCORE from todo_table import LEVELS, risk, TOP_SCORE
@@ -78,17 +78,15 @@ def main(argv: list[str]) -> int:
if isinstance(outcomes, Failure): if isinstance(outcomes, Failure):
return failed(outcomes) return failed(outcomes)
anchored = read_anchors() anchored = read_anchors()
if isinstance(anchored, Failure): print(report_text(outcomes, anchored, dict(zip(GIVEN, map(int, argv))) if argv else None))
return failed(anchored) # Anchors the tool cannot read leave the rest of the report standing, and still fail the run.
given = dict(zip(GIVEN, map(int, argv))) return failed(anchored) if isinstance(anchored, Failure) else 0
print(report_text(outcomes, anchored, given))
return 0
def report_text(outcomes: list[Outcome], anchored: list[tuple[str, tuple[int, ...]]], given: dict[str, int]) -> str: def report_text(outcomes: list[Outcome], anchored: Anchors | Failure, given: dict[str, int] | None) -> str:
"""The report: the finished items nearest the given scores, where any are given, then the anchors, then the medians.""" """The report: the finished items nearest the given scores, where any are given, then the anchors, then the medians."""
sections = [] sections = []
if given: if given is not None:
r = risk(given["L"], given["E"], given["I"]) r = risk(given["L"], given["E"], given["I"])
near = [render(outcome) for outcome in nearest(outcomes, given | {"R": r})] or ["- None: no merge commit on the default branch shipped an item from todo.md. A project that merges by squash or fast-forward has none."] near = [render(outcome) for outcome in nearest(outcomes, given | {"R": r})] or ["- None: no merge commit on the default branch shipped an item from todo.md. A project that merges by squash or fast-forward has none."]
sections.append([f"Finished items nearest L {given['L']}, E {given['E']}, I {given['I']}, so R {r}, and S {given['S']}, closest first:", "", *near]) sections.append([f"Finished items nearest L {given['L']}, E {given['E']}, I {given['I']}, so R {r}, and S {given['S']}, closest first:", "", *near])
@@ -102,7 +100,7 @@ def failed(failure: Failure) -> int:
return 1 return 1
def read_anchors() -> list[tuple[str, tuple[int, ...]]] | Failure: def read_anchors() -> Anchors | Failure:
"""The checkout's anchors as its working tree holds them, so a branch that edits them shows its edit; none where it has no such file.""" """The checkout's anchors as its working tree holds them, so a branch that edits them shows its edit; none where it has no such file."""
root = top() root = top()
if isinstance(root, Failure): if isinstance(root, Failure):
+47 -4
View File
@@ -12,6 +12,7 @@ from failure import Failure
from test_env import isolated_env from test_env import isolated_env
from todo_table import Item from todo_table import Item
from score_outcomes.outcomes import nearest, Outcome, outcomes_of, rank_correlation, render, report, shipped from score_outcomes.outcomes import nearest, Outcome, outcomes_of, rank_correlation, render, report, shipped
from score_outcomes.main import report_text
TOOL = pathlib.Path(__file__).resolve().parents[1] / "score-outcomes" TOOL = pathlib.Path(__file__).resolve().parents[1] / "score-outcomes"
HEADER = "| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n" HEADER = "| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n"
@@ -128,16 +129,57 @@ class Anchors(unittest.TestCase):
def test_reads_each_levels_items_in_the_files_order(self): def test_reads_each_levels_items_in_the_files_order(self):
self.assertEqual(parse_anchors(ANCHORS_TEXT), [("L 1", (4, 9)), ("I 3", (5,))]) self.assertEqual(parse_anchors(ANCHORS_TEXT), [("L 1", (4, 9)), ("I 3", (5,))])
def test_refuses_a_level_off_its_scale_a_score_without_levels_a_repeated_level_or_an_unreadable_row(self): def test_reads_each_level_at_the_top_of_its_scale(self):
for row in ("| L 5 | 4 |", "| E 0 | 4 |", "| S 3 | 4 |", "| L 1 | 7 |", "| L 2 | four |", "| L 2 | |", "| L 2 | 4,5 |", "| L 2 | 4 | 5 |"): self.assertEqual(parse_anchors(ANCHORS_TEXT + "| L 4 | 4 |\n| E 3 | 4 |\n| I 5 | 4 |\n")[2:], [("L 4", (4,)), ("E 3", (4,)), ("I 5", (4,))])
def test_refuses_a_level_off_its_scale_a_score_without_levels_or_an_unreadable_row_naming_the_row(self):
for row in ("| L 5 | 4 |", "| E 0 | 4 |", "| S 1 | 4 |", "| L 01 | 4 |", "| L 2 | four |", "| L 2 | |", "| L 2 | 4,5 |", "| L 2 | 4 | 5 |"):
with self.subTest(row): with self.subTest(row):
self.assertIsInstance(parse_anchors(ANCHORS_TEXT + row + "\n"), Failure) failure = parse_anchors(ANCHORS_TEXT + row + "\n")
self.assertIsInstance(failure, Failure)
self.assertIn("docs/score-anchors.md", failure.reason)
self.assertIn(row, failure.reason)
def test_refuses_a_repeated_level_naming_it(self):
self.assertEqual(parse_anchors(ANCHORS_TEXT + "| L 1 | 7 |\n"), Failure("docs/score-anchors.md names L 1 twice"))
def test_lists_each_anchor_with_what_its_chunk_measured_and_says_which_it_cannot_find(self): def test_lists_each_anchor_with_what_its_chunk_measured_and_says_which_it_cannot_find(self):
lines = anchor_lines([("L 1", (4, 9))], [outcome(4, 2, 3, None, findings=(1, 2))]) lines = anchor_lines([("L 1", (4, 9))], [outcome(4, 2, 3, None, findings=(1, 2))])
self.assertEqual(anchor_lines([], []), ["- None: the project's docs/score-anchors.md names no level; ~/.claude/rules/todo-items.md says how to choose them."])
self.assertEqual(lines, ["L 1:", "- Item 4, R 2, S 3: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**", "- Item 9: no merge commit on the default branch shipped it."]) self.assertEqual(lines, ["L 1:", "- Item 4, R 2, S 3: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**", "- Item 9: no merge commit on the default branch shipped it."])
def test_points_to_the_rules_where_the_project_names_no_anchors(self):
self.assertIn("docs/score-anchors.md", anchor_lines([], [])[0])
self.assertIn("~/.claude/rules/todo-items.md", anchor_lines([], [])[0])
def test_says_why_it_shows_no_anchors_it_cannot_read(self):
self.assertEqual(anchor_lines(Failure("docs/score-anchors.md names L 1 twice"), []), ["- None: docs/score-anchors.md names L 1 twice"])
class ReportText(unittest.TestCase):
def test_lists_the_nearest_by_r_then_the_anchors_then_the_medians(self):
found = [outcome(1, 5, 3, None, merged="2026-10-13T10:00:00Z"), outcome(2, 1, 3, None, merged="2026-10-12T10:00:00Z")]
too_few = "chunks that shipped one item record"
self.assertEqual(report_text(found, [("L 1", (2,))], {"L": 1, "E": 1, "I": 1, "S": 3}), f"""Finished items nearest L 1, E 1, I 1, so R 1, and S 3, closest first:
- Item 2, R 1, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡; merged 2026-10-12T10:00:00Z in aaaaaaa. **Item 2.**
- Item 1, R 5, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 1.**
Anchors in docs/score-anchors.md, each level's shipped items:
L 1:
- Item 2, R 1, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡; merged 2026-10-12T10:00:00Z in aaaaaaa. **Item 2.**
Median outcome at each guessed score, among chunks that shipped one item:
- R, 🔴 findings: 2 {too_few} R and its outcome; the report needs 10.
- S, lines changed: 2 {too_few} S and its outcome; the report needs 10.
- L, by review rounds past each pass's first and 🔴 findings: 0 {too_few} L and both outcomes; the report needs 10.
- E, by review rounds past each pass's first and 🔴 findings: 0 {too_few} E and both outcomes; the report needs 10.
- I, by review rounds past each pass's first and 🔴 findings: 0 {too_few} I and both outcomes; the report needs 10.""")
def test_lists_no_nearest_items_where_no_scores_are_given(self):
self.assertTrue(report_text([], [], None).startswith("Anchors in docs/score-anchors.md"))
class ScoreOutcomesTool(unittest.TestCase): class ScoreOutcomesTool(unittest.TestCase):
def setUp(self): def setUp(self):
@@ -193,6 +235,7 @@ class ScoreOutcomesTool(unittest.TestCase):
ran = self.run_tool() ran = self.run_tool()
self.assertEqual(ran.returncode, 1) self.assertEqual(ran.returncode, 1)
self.assertIn("docs/score-anchors.md", ran.stderr) self.assertIn("docs/score-anchors.md", ran.stderr)
self.assertIn("Median outcome at each guessed score", ran.stdout)
def test_takes_each_score_at_the_top_of_its_scale(self): def test_takes_each_score_at_the_top_of_its_scale(self):
ran = self.run_tool("4", "3", "5", "10") ran = self.run_tool("4", "3", "5", "10")