Test what planning prints, asks and refuses

This commit is contained in:
2026-11-19 04:04:32 +01:00
parent 59c02ef8d1
commit 94b34e509f
+80 -5
View File
@@ -34,13 +34,13 @@ def scored(key: str, moves: str, *labels: str, blockers: tuple[str, ...] = (), b
class Planning(DoEpicTest):
def plan(self, fake: FakeEffects) -> tuple[list[EpicIssue] | Failure | Limited, MemoryEpic, str]:
"""What planning answers for self.issues, the store it changed and what it printed."""
"""What planning answers for self.issues, the store it changed and what it printed on stdout. self.asked holds what it asked the human, on stderr."""
config = load(self.home)
assert not isinstance(config, Failure), config
store = MemoryEpic("ABC-12", list(self.issues))
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, fake.effects()) # type: ignore[arg-type]
out = io.StringIO()
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(out):
out, self.asked = io.StringIO(), io.StringIO()
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(self.asked):
read = store.read()
assert not isinstance(read, Failure)
return planning.planned(epic, read), store, out.getvalue()
@@ -81,6 +81,48 @@ class Planning(DoEpicTest):
# 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)
self.assertIn("in English, that tells the team why it is split by repo", fake.made("claude")[0][1])
def test_plans_the_issue_after_one_that_is_split(self) -> None:
self.issues = [issue("ABC-20"), issue("ABC-21")]
parts = says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."})
_, store, _ = self.plan(FakeEffects(claude=[parts, says({"parts": []}), says({"pick": "human"})]))
self.assertEqual(self.labels(store)["ABC-21"], ("do-epic-human",))
def test_writes_to_the_team_in_the_epics_language(self) -> None:
self.description = "**Language:** Swedish\n"
self.issues = [issue("ABC-20")]
fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})])
self.plan(fake)
self.assertIn("in Swedish, that tells the team why it is split by repo", fake.made("claude")[0][1])
def test_each_claude_call_runs_in_the_epics_state_folder(self) -> None:
self.issues = [issue("ABC-20")]
fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})])
effects, folders = fake.effects(), []
def claude(args: object, cwd: str, stdin: object) -> object:
folders.append(cwd)
return effects.claude(args, cwd, stdin) # type: ignore[arg-type]
config = load(self.home)
epic = planning.Planned("ABC-12", config, MemoryEpic("ABC-12", list(self.issues)), EpicRecord(Description("")), self.home, dataclasses.replace(effects, claude=claude)) # type: ignore[arg-type]
with contextlib.redirect_stdout(io.StringIO()):
planning.planned(epic, list(self.issues))
folder = self.home / ".local" / "state" / "do-epic" / "ABC-12"
self.assertEqual((folders, folder.is_dir()), ([str(folder)] * 2, True))
def test_a_model_off_the_routing_ladder_has_no_rung(self) -> None:
found = planning.planning_rung("claude-nope-1")
assert isinstance(found, Failure), found
self.assertIn("`repoless-model` names claude-nope-1, which is not on the routing ladder ", found.reason)
def test_fails_where_a_labelled_repo_has_no_checkout_to_read(self) -> None:
self.issues = [issue("ABC-19", "repo:ghost"), issue("ABC-20")]
fake = FakeEffects()
found, _, _ = self.plan(fake)
assert isinstance(found, Failure), found
self.assertIn("ghost", found.reason)
self.assertEqual(fake.made("claude"), [])
def test_the_split_reads_the_checkout_of_each_repo_a_label_of_the_epic_names(self) -> None:
checkout = self.home / "code" / "api"
@@ -96,8 +138,8 @@ class Planning(DoEpicTest):
fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "unclear", "question": "Is the importer in api or in web?"})], inputs=["api", " repo:web "])
found, store, out = self.plan(fake)
self.assertEqual(found, [issue("ABC-20", "repo:web")])
self.assertIn("ABC-20, Do ABC-20: Is the importer in api or in web?\n", out)
self.assertIn("`api` is none of those labels\n", out)
self.assertIn("ABC-20, Do ABC-20: Is the importer in api or in web?\n", self.asked.getvalue())
self.assertIn("`api` is none of those labels\n", self.asked.getvalue())
self.assertEqual(fake.made("input"), ["The label that says where ABC-20 is worked, `repo:<name>`, `do-epic-claude` or `do-epic-human`: "] * 2)
def test_an_unclear_issue_waits_where_nobody_can_answer_and_the_next_is_planned(self) -> None:
@@ -107,6 +149,7 @@ class Planning(DoEpicTest):
self.issues = [issue("ABC-20"), issue("ABC-21")]
_, store, out = self.plan(fake)
self.assertEqual(self.labels(store), {"ABC-20": (), "ABC-21": ("do-epic-claude",)})
self.assertNotIn("ABC-20 is labelled", out)
if not fake.terminal:
self.assertIn("ABC-20 waits for your answer: Is the importer in api or in web? Run `do-epic ABC-12` on a terminal to answer, or label the issue in Jira.\n", out)
@@ -155,6 +198,38 @@ class Planning(DoEpicTest):
self.assertEqual(found, Failure("the epic ABC-12's description states `Score = ...` 0 times under ## Scoring; state the formula that ranks its issues once, on a line of its own, such as `Score = 100 * V / (2**S + 32)`"))
self.assertEqual([each.key for each in store.issues], ["ABC-20", "ABC-21"])
def test_fails_where_the_formula_names_a_score_no_issue_holds(self) -> None:
self.description = RANKED.replace("Score = V", "Score = Q")
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
self.assertIsInstance(self.plan(FakeEffects())[0], Failure)
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("two of the loop's issues in the epic ABC-12 share a number in different Jira projects, so they cannot be ranked; move one of them"))
def test_fails_where_the_description_cannot_be_read_to_rank_by(self) -> None:
self.description = Failure("Jira answered 503")
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
self.assertEqual(self.plan(FakeEffects())[0], Failure("the epic ABC-12's description: Jira answered 503"))
def test_fails_naming_the_repo_whose_goals_cannot_be_read(self) -> None:
checkout = self.home / "code" / "api"
configured(self, checkout, home=self.home)
(checkout / "README.md").write_text("# api\n", encoding="utf-8")
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())[0]
assert isinstance(found, Failure), found
self.assertTrue(found.reason.startswith("api: "), found.reason)
def test_ranks_a_security_issue_first(self) -> None:
self.description = RANKED
self.issues = [scored("ABC-20", "epic 1 by 9", "do-epic-claude"), dataclasses.replace(scored("ABC-21", "epic 1 by 2", "do-epic-claude"), exempt="security")]
found = self.plan(FakeEffects())[0]
assert not isinstance(found, Failure | Limited), found
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.assertEqual(self.plan(FakeEffects())[0], self.issues)