Let a project's config name a working branch per epic that chunks branch off and merge into
CI / tests (pull_request) Successful in 5m4s

This commit is contained in:
Lilleman
2026-11-20 19:32:59 +01:00
parent 9531e5c337
commit 72a4d346d7
33 changed files with 991 additions and 56 deletions
+84
View File
@@ -983,6 +983,90 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
self.assertIn(f"cannot remove {self.file}: Permission denied", err)
class AnEpicsWorkingBranch(DoEpicTest):
"""A chunk in a repo whose config sets `epic-branch`, so its pull request goes into the branch ABC-12."""
def setUp(self) -> None:
super().setUp()
self.repo_config = self.repo_chunk() / "config.toml"
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'epic-branch = "{epic}"\nmerge = "human"\n', encoding="utf-8")
self.checkout = str(self.home / "code/api")
self.store = MemoryEpic("ABC-12", [self.issues[0], issue("ABC-22", "do-epic-claude", blockers=("ABC-20",))])
self.backend = lambda config, key: (self.store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
self.git_calls: list[tuple[tuple[str, ...], str | None]] = []
def settings(self, more: str) -> None:
(self.home / ".claude-projects" / "do-epic" / "config.toml").write_text(SETTINGS + more, encoding="utf-8")
def with_git(self, fake: FakeEffects, **answers: str | Failure) -> FakeEffects:
"""fake, whose git answers each command by its first word: as answers has it, else as a checkout whose origin has the branch ABC-12, which holds origin/main."""
answered = {"symbolic-ref": "origin/main\n", "fetch": "", "rev-parse": "aaa\n", "rev-list": "0\n", "config": ""} | {name.replace("_", "-"): answer for name, answer in answers.items()}
def git(*args: str, cwd: str | None = None, **more: object) -> str | Failure:
self.git_calls.append((args, cwd))
return answered.get(args[0], Failure("no git"))
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, git=git) # type: ignore[method-assign]
return fake
def test_a_chunk_that_starts_levels_the_branch_and_records_it_as_the_chunks_base(self) -> None:
fake = self.with_git(FakeEffects())
out = io.StringIO()
with contextlib.redirect_stdout(out):
self.assertEqual(main.epic_based("ABC-20", self.checkout, self.epic_run(fake)), "ABC-12")
self.assertEqual(self.git_calls, [(args, self.checkout) for args in (("symbolic-ref", "--short", "refs/remotes/origin/HEAD"), ("fetch", "--quiet", "origin"), ("rev-parse", "--quiet", "--verify", "refs/remotes/origin/ABC-12"), ("rev-list", "--count", "origin/ABC-12..origin/main"), ("config", "branch.ABC-20.chunk-base", "ABC-12"))])
self.assertIn("origin/ABC-12 already holds origin/main; ABC-20's pull request goes into ABC-12\n", out.getvalue())
def test_a_repo_whose_config_sets_no_epic_branch_has_none_and_runs_no_git(self) -> None:
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8").replace('epic-branch = "{epic}"\n', ""), encoding="utf-8")
self.assertIsNone(main.epic_based("ABC-20", self.checkout, self.epic_run(self.with_git(FakeEffects()))))
self.assertEqual(self.git_calls, [])
def test_a_default_branch_that_conflicts_stops_the_loop_for_a_person_and_records_no_base(self) -> None:
stop = main.epic_based("ABC-20", self.checkout, self.epic_run(self.with_git(FakeEffects(), rev_list="1\n", merge_tree=Failure("CONFLICT"))))
self.assertEqual(stop, main.Stop(1, f"cannot ready the epic's working branch ABC-12 in {self.checkout} for ABC-20: origin/main doesn't merge into origin/ABC-12 cleanly, so a person merges it: check ABC-12 out, run `git merge origin/main`, resolve the conflicts and push; once that is settled, run `do-epic ABC-12` to start the chunk again"))
self.assertNotIn("config", [args[0] for args, _ in self.git_calls])
def test_a_checkout_that_names_no_default_branch_stops_before_the_branch_is_touched(self) -> None:
stop = main.epic_based("ABC-20", self.checkout, self.epic_run(self.with_git(FakeEffects(), symbolic_ref=Failure("no origin/HEAD"))))
self.assertIsInstance(stop, main.Stop)
self.assertIn("no origin/HEAD", stop.reason)
self.assertEqual(len(self.git_calls), 1)
def test_its_issue_moves_as_the_pull_request_opens_and_merges_and_no_person_merges_it(self) -> None:
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-automation-moves-issues = true\njira-pull-request-open-status = "Code Review"\njira-pull-request-merged-status = "Release Ready"\n')
self.forges = [awaiting(), awaiting(), awaiting(decision="APPROVED")]
fake = self.with_git(FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], windows=PARKED_WINDOW))
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
prompts = [what[what.index("-p") + 1] for seam, what in fake.calls if seam == "stream_claude"]
self.assertEqual(code, 0, err)
self.assertEqual([write for write in self.store.writes if write.startswith("move ")], ["move ABC-20 to Code Review", "move ABC-20 to Release Ready"])
self.assertEqual({each.key: (each.status, each.done) for each in self.store.issues}["ABC-20"], ("Release Ready", False))
# Approved, the pull request awaits no person's merge, though the repo's config says `merge = "human"`.
self.assertEqual(out.count("parked: "), 1)
self.assertIn("parked: pull request #7 awaits an approval\n", out)
self.assertIn("the chunk finished; started ABC-22\n", out)
self.assertIn("The chunk's pull request goes into the epic's working branch `ABC-12`", prompts[0])
def test_without_a_merged_status_a_finished_chunk_stops_where_automation_moves_issues_and_is_done_where_it_doesnt(self) -> None:
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-automation-moves-issues = true\n')
stop = main.handed_on("ABC-20", self.epic_run(FakeEffects()), in_repo=True, to_epic_branch=True)
self.assertEqual(stop, main.Stop(1, "the chunk finished, but its issue stays as it is: its pull request merged into the epic's working branch, where the team's automation moves no issue, and do-epic's config names no `jira-pull-request-merged-status` to move it to. Move ABC-20 in Jira, then run `do-epic ABC-12` to start the chunks it blocks"))
self.assertEqual(self.store.writes, [])
self.settings("")
out = io.StringIO()
with contextlib.redirect_stdout(out):
self.assertEqual(main.handed_on("ABC-20", self.epic_run(FakeEffects(windows="")), in_repo=True, to_epic_branch=True).code, 0)
self.assertTrue(self.store.issues[0].done)
def test_an_issue_that_cannot_move_to_the_merged_status_stops_and_says_what_to_do(self) -> None:
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-merged-status = "Release Ready"\n')
self.store.fails = "Jira answered 503"
stop = main.handed_on("ABC-20", self.epic_run(FakeEffects()), in_repo=True, to_epic_branch=True)
self.assertEqual(stop.code, 1)
self.assertTrue(stop.reason.startswith("the chunk finished, but its issue could not move to 'Release Ready': "), stop.reason)
self.assertTrue(stop.reason.endswith("once it has that status in Jira, run `do-epic ABC-12` to start the chunks it blocks"), stop.reason)
class TheStatus(DoEpicTest):
def test_prints_what_each_open_issue_does_and_starts_nothing(self) -> None:
self.issues = [issue("ABC-21", "repo:api"), issue("ABC-24", "repo:api"), issue("ABC-27")]