Start an epic's issues in order of score, scoring each that holds none

This commit is contained in:
Lilleman
2026-11-20 14:30:30 +01:00
parent abaf54bc46
commit 5f2a4b6385
19 changed files with 615 additions and 83 deletions
+139 -19
View File
@@ -23,14 +23,16 @@ from plan.todo_table import parse_moves
from do_epic import planning
RANKED = "## Goals\n1. **Achieve:** Ship the import.\n\n## Audience\nThe client's team.\n\n## Scoring\n`Score = V`\n"
GOALS = "## Goals\n\n**Void:** code health, since it is a one-off script.\n\n1. **Achieve:** Serve the API.\n\n## Audience\nIts callers.\n"
ANSWER = {"L": 2, "E": 1, "I": 2, "S": 3, "moves": "epic 1 by 9", "comment": "Scored to decide what starts first."}
LIMIT = {"type": "result", "is_error": True, "api_error_status": 429, "result": "You've hit your limit"}
def scored(key: str, moves: str, *labels: str, blockers: tuple[str, ...] = (), by_loop: bool = True) -> EpicIssue:
def scored(key: str, moves: str, *labels: str, blockers: tuple[str, ...] = (), by_loop: bool = True, parent: str = "ABC-12") -> EpicIssue:
"""An open issue the loop filed, holding scores and moving the goals moves names."""
parsed = parse_moves(key, moves)
assert not isinstance(parsed, Failure), parsed
return dataclasses.replace(issue(key, *labels, blockers=blockers), scores={"L": 1, "E": 1, "I": 1, "S": 1}, moves=parsed, by_loop=by_loop)
return dataclasses.replace(issue(key, *labels, blockers=blockers, parent=parent), scores={"L": 1, "E": 1, "I": 1, "S": 1}, moves=parsed, by_loop=by_loop)
class Planning(DoEpicTest):
@@ -44,14 +46,28 @@ class Planning(DoEpicTest):
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(self.asked):
read = store.read()
assert not isinstance(read, Failure)
self.epic = epic
issues, stopped = planning.planned(epic, read)
return issues if stopped is None else stopped, store, out.getvalue()
def rule(self) -> None:
"""Writes the rule every plan item is scored by."""
(self.home / planning.RULE).parent.mkdir(parents=True, exist_ok=True)
(self.home / planning.RULE).write_text("L is how much the item changes.\n", encoding="utf-8")
def repo(self, name: str) -> None:
"""Checks out the repo called name, whose goals file voids code health and states one achieve goal."""
checkout = self.home / "code" / name
configured(self, checkout, home=self.home)
(checkout / "README.md").write_text(GOALS, encoding="utf-8")
def labels(self, store: MemoryEpic) -> dict[str, tuple[str, ...]]:
return {each.key: each.labels for each in store.issues}
def test_an_issue_a_label_places_is_planned_without_claude(self) -> None:
self.issues = [issue("ABC-20", "repo:api"), issue("ABC-21", "do-epic-claude"), issue("ABC-22", "split-by-repo"), issue("ABC-23", done=True)]
self.description = RANKED
self.repo("api")
self.issues = [scored("ABC-20", "epic 1 by 9", "repo:api"), scored("ABC-21", "epic 1 by 2", "do-epic-claude"), issue("ABC-22", "split-by-repo"), issue("ABC-23", done=True)]
fake = FakeEffects()
found, _, out = self.plan(fake)
self.assertEqual((found, out, fake.made("claude")), (self.issues, "", []))
@@ -59,13 +75,16 @@ class Planning(DoEpicTest):
def test_an_epic_shaped_as_a_teams_is_planned_without_claude_and_without_a_write(self) -> None:
with (self.home / ".claude-projects/do-epic/config.toml").open("a", encoding="utf-8") as config:
config.write('\n[label-repos]\ntwu-4 = "tenant-web-ui-4"\ncore-4 = "core-4"\n')
self.description = RANKED
self.repo("tenant-web-ui-4")
self.repo("core-4")
self.issues = [
issue("ABC-19", "twu-4"),
scored("ABC-19", "epic 1 by 5", "twu-4", by_loop=False),
issue("ABC-20"),
issue("ABC-23", "core-4", parent="ABC-20"),
issue("ABC-24", "twu-4", parent="ABC-20"),
scored("ABC-23", "epic 1 by 5", "core-4", by_loop=False, parent="ABC-20"),
scored("ABC-24", "epic 1 by 5", "twu-4", by_loop=False, parent="ABC-20"),
issue("ABC-21", "urgent"),
issue("ABC-25", "core-4", parent="ABC-21"),
scored("ABC-25", "epic 1 by 5", "core-4", by_loop=False, parent="ABC-21"),
]
fake = FakeEffects()
found, store, out = self.plan(fake)
@@ -93,9 +112,8 @@ class Planning(DoEpicTest):
def test_splits_an_issue_that_changes_several_repos_into_a_sub_task_for_each_and_picks_no_repo_for_it(self) -> None:
self.issues = [issue("ABC-20")]
fake = FakeEffects(claude=[says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."})])
found, store, out = self.plan(fake)
assert not isinstance(found, Failure | Limited), found
self.assertEqual([(each.key, each.parent, each.labels) for each in found], [("ABC-20", "ABC-12", ("split-by-repo",)), ("ABC-101", "ABC-20", ("repo:api",)), ("ABC-102", "ABC-20", ("repo:web",))])
_, store, out = self.plan(fake)
self.assertEqual([(each.key, each.parent, each.labels) for each in store.issues], [("ABC-20", "ABC-12", ("split-by-repo",)), ("ABC-101", "ABC-20", ("repo:api",)), ("ABC-102", "ABC-20", ("repo:web",))])
# A person filed ABC-20, so the team is told.
self.assertEqual(store.comments, {"ABC-20": ["Split by repo: api and web."]})
self.assertIn("ABC-20 is split into a sub-task for each of api, web\n", out)
@@ -179,8 +197,7 @@ class Planning(DoEpicTest):
self.configure_team('sub-task-summary = "{label}: {Summary}"')
self.issues = [issue("ABC-20")]
parts = says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Delat per repo."})
found, store, _ = self.plan(FakeEffects(claude=[parts]))
assert not isinstance(found, Failure | Limited), found
_, store, _ = self.plan(FakeEffects(claude=[parts]))
self.assertEqual([(each.summary, each.labels) for each in store.issues if each.parent == "ABC-20"], [("backend: Do ABC-20", ("backend",)), ("web: Do ABC-20", ("repo:web",))])
def test_records_the_teams_label_for_a_repo_the_human_types_by_name_and_names_it(self) -> None:
@@ -271,17 +288,15 @@ class Planning(DoEpicTest):
def test_re_ranks_the_loops_scored_issues_by_score_with_a_blocker_first_and_leaves_every_other_issue_in_place(self) -> None:
self.description = RANKED
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude", by_loop=False), scored("ABC-22", "epic 1 by 5", "do-epic-claude", blockers=("ABC-24",)), dataclasses.replace(issue("ABC-23", "do-epic-claude"), by_loop=True), scored("ABC-24", "epic 1 by 3", "do-epic-claude")]
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude", by_loop=False), scored("ABC-22", "epic 1 by 5", "do-epic-claude", blockers=("ABC-24",)), dataclasses.replace(issue("ABC-23", "do-epic-human"), by_loop=True), scored("ABC-24", "epic 1 by 3", "do-epic-claude")]
found, store, out = self.plan(FakeEffects())
assert not isinstance(found, Failure | Limited), found
# ABC-22 scores highest, and ABC-24 blocks it. ABC-21 is a person's, and nobody scored ABC-23.
# ABC-22 scores highest, and ABC-24 blocks it. ABC-21 is a person's, and ABC-23 is a human's task, which holds no scores.
self.assertEqual([each.key for each in found], ["ABC-24", "ABC-21", "ABC-22", "ABC-23", "ABC-20"])
self.assertIn("re-ranking the issues do-epic filed in ABC-12's backlog\n", out)
def test_ranks_an_issue_in_a_repo_by_that_repos_goals_after_the_epics(self) -> None:
checkout = self.home / "code" / "api"
configured(self, checkout, home=self.home)
(checkout / "README.md").write_text("## Goals\n\n**Void:** code health, since it is a one-off script.\n\n1. **Achieve:** Serve the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
self.repo("api")
self.description = RANKED
self.issues = [scored("ABC-20", "repo 1 by 9", "repo:api"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
found, _, _ = self.plan(FakeEffects())
@@ -308,7 +323,7 @@ class Planning(DoEpicTest):
def test_fails_where_two_issues_to_rank_share_a_number(self) -> None:
self.description = RANKED
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("XYZ-20", "epic 1 by 9", "do-epic-claude")]
self.assertEqual(self.plan(FakeEffects())[0], Failure("ABC-20 and XYZ-20 share a number in different Jira projects, so the issues do-epic filed in the epic ABC-12 cannot be ranked; move one of the two to the other's Jira project"))
self.assertEqual(self.plan(FakeEffects())[0], Failure("ABC-20 and XYZ-20 share a number in different Jira projects, so the issues of the epic ABC-12 cannot be put in order of score; move one of the two to the other's Jira project"))
def test_fails_where_the_description_cannot_be_read_to_rank_by(self) -> None:
self.description = Failure("Jira answered 503")
@@ -333,9 +348,114 @@ class Planning(DoEpicTest):
self.assertEqual([each.key for each in found], ["ABC-21", "ABC-20"])
def test_one_scored_issue_needs_no_formula(self) -> None:
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), issue("ABC-21", "do-epic-claude")]
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), issue("ABC-21", "do-epic-human")]
self.assertEqual(self.plan(FakeEffects())[0], self.issues)
def test_scores_each_bare_issue_whoever_filed_it_and_tells_its_team_without_ranking_a_persons(self) -> None:
self.rule()
self.description = RANKED
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude", by_loop=False), issue("ABC-21", "do-epic-claude")]
fake = FakeEffects(claude=[says(ANSWER)])
found, store, out = self.plan(fake)
assert not isinstance(found, Failure | Limited), found
# ABC-20's scores stay, and a person filed both, so neither changes its position in the backlog.
self.assertEqual([(each.key, each.scores) for each in found], [("ABC-20", {"L": 1, "E": 1, "I": 1, "S": 1}), ("ABC-21", {"L": 2, "E": 1, "I": 2, "S": 3})])
self.assertEqual(store.writes, ["score ABC-21 L 2, E 1, I 2, S 3, Moves epic 1 by 9, with the comment: Scored to decide what starts first."])
self.assertEqual(out, "<1790000000> scoring ABC-21\n<1790000000> ABC-21 is scored L 2, E 1, I 2, S 3, Moves epic 1 by 9\n")
self.assertEqual(planning.start_order(self.epic, found), ["ABC-21", "ABC-20"])
(asked,) = fake.made("claude")
for part in ("L is how much the item changes.", "Write the comment in English", "An item moves only these: `epic 1`.", "## Item ABC-21: Do ABC-21", "Labels: do-epic-claude"):
self.assertIn(part, asked[1])
self.assertIn("--json-schema", asked[0])
def test_scores_no_human_task_and_no_issue_that_is_the_only_one_to_start(self) -> None:
self.rule()
self.description = RANKED
self.issues = [issue("ABC-20", "do-epic-claude"), issue("ABC-21", "do-epic-human")]
fake = FakeEffects()
found, store, out = self.plan(fake)
self.assertEqual((found, store.writes, out, fake.made("claude")), (self.issues, [], "", []))
def test_names_an_issue_whose_scoring_fails_and_scores_the_next(self) -> None:
self.rule()
self.description = RANKED
self.issues = [issue("ABC-20", "do-epic-claude"), issue("ABC-21", "do-epic-claude"), issue("ABC-22", "do-epic-claude"), issue("ABC-23", "do-epic-claude")]
fake = FakeEffects(claude=[says({"L": "big"}), says(ANSWER | {"moves": "epic 7 by 5"}), says(ANSWER | {"L": 99}), says(ANSWER)])
found, store, out = self.plan(fake)
assert not isinstance(found, Failure | Limited), found
self.assertIn('ABC-20 is not scored: the scoring answered {"L": "big"}; expected a whole number for each of L, E, I, S, the moves as text and a comment\n', out)
self.assertIn("ABC-21 is not scored: item 21 names epic 7, which the epic's ## Goals does not number\n", out)
self.assertIn("ABC-22 is not scored: ", out)
self.assertEqual([each.key for each in found if each.scores], ["ABC-23"])
self.assertEqual([write.split(" L ")[0] for write in store.writes], ["score ABC-23"])
# An issue without scores starts after each that holds them, in the backlog's order.
self.assertEqual(planning.start_order(self.epic, found), ["ABC-23"])
def test_a_usage_limit_ends_the_scoring(self) -> None:
self.rule()
self.description = RANKED
self.issues = [issue("ABC-20", "do-epic-claude"), issue("ABC-21", "do-epic-claude")]
fake = FakeEffects(claude=[subprocess.CompletedProcess([], 0, json.dumps(LIMIT), "")])
found, store, _ = self.plan(fake)
self.assertIsInstance(found, Limited)
self.assertEqual((store.writes, len(fake.made("claude"))), ([], 1))
def test_names_a_score_the_tracker_refuses(self) -> None:
self.rule()
self.description = RANKED
self.issues = [issue("ABC-20", "do-epic-claude"), issue("ABC-21", "do-epic-human"), scored("ABC-22", "epic 1 by 2", "do-epic-claude")]
store = MemoryEpic("ABC-12", list(self.issues))
store.fails = "Jira answered 503"
out = io.StringIO()
config = load(self.home)
assert not isinstance(config, Failure), config
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, FakeEffects(claude=[says(ANSWER)]).effects()) # type: ignore[arg-type]
with contextlib.redirect_stdout(out):
found, stopped = planning.scored(epic, list(self.issues))
self.assertEqual((found, stopped, out.getvalue()), (self.issues, None, "<1790000000> scoring ABC-20\n<1790000000> ABC-20 is not scored: Jira answered 503\n"))
def test_scores_no_issue_without_the_scoring_rule_or_the_epics_formula(self) -> None:
self.issues = [issue("ABC-20", "do-epic-claude"), issue("ABC-21", "do-epic-claude")]
self.description = RANKED
fake = FakeEffects()
found, _, _ = self.plan(fake)
assert isinstance(found, Failure), found
self.assertIn(f"cannot read the scoring rule {self.home}/.claude/rules/todo-items.md, so no issue is scored: ", found.reason)
self.rule()
self.description = "## Goals\n1. **Achieve:** Ship the import.\n\n## Audience\nThe client's team.\n\n## Scoring\n"
found, _, _ = self.plan(fake)
assert isinstance(found, Failure), found
self.assertIn("states `Score = ...` 0 times under ## Scoring", found.reason)
self.assertEqual(fake.made("claude"), [])
def test_scores_a_sub_task_on_its_own_against_its_repos_goals_in_the_epics_language(self) -> None:
self.rule()
self.repo("api")
self.description = RANKED + "\n**Language:** Swedish\n"
self.issues = [issue("ABC-20", "split-by-repo"), issue("ABC-30", "repo:api", parent="ABC-20"), scored("ABC-21", "epic 1 by 2", "do-epic-claude")]
fake = FakeEffects(claude=[says(ANSWER | {"moves": "repo 1 by 4"})])
found, store, _ = self.plan(fake)
assert not isinstance(found, Failure | Limited), found
self.assertEqual(store.writes, ["score ABC-30 L 2, E 1, I 2, S 3, Moves repo 1 by 4, with the comment: Scored to decide what starts first."])
(asked,) = fake.made("claude")
for part in ("The goals of the repo api, each named `repo <its number>`:", "Serve the API.", "An item moves only these: `epic 1`, `repo 1`.", "Write the comment in Swedish"):
self.assertIn(part, asked[1])
self.assertNotIn("`code health` is the goal", asked[1])
def test_starts_what_blocks_an_issue_or_its_parent_before_it_and_a_split_blockers_sub_tasks_too(self) -> None:
self.repo("api")
self.description = RANKED
self.issues = [
scored("ABC-20", "epic 1 by 9", "do-epic-claude", blockers=("ABC-21",)),
dataclasses.replace(issue("ABC-21", "split-by-repo"), blockers=("ABC-22",)),
scored("ABC-30", "epic 1 by 5", "repo:api", parent="ABC-21"),
scored("ABC-22", "epic 1 by 1", "do-epic-claude"),
]
found, _, _ = self.plan(FakeEffects())
assert not isinstance(found, Failure | Limited), found
# By score alone the order is ABC-20, ABC-30, ABC-22.
self.assertEqual(planning.start_order(self.epic, found), ["ABC-22", "ABC-30", "ABC-20"])
def planned_on(self, store: MemoryEpic, fake: FakeEffects) -> tuple[list[EpicIssue], Failure | Limited | None]:
"""What planning answers for self.issues on a store that doesn't read as MemoryEpic does."""
config = load(self.home)