From 57fef64105f5b764f36dcc1bbda254352081c495 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 14:02:59 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(1=20misread);=20run=20chunk?= =?UTF-8?q?-pr=20by=20its=20path,=20say=20why=20a=20clean=20left=20the=20w?= =?UTF-8?q?orktree,=20test=20the=20working-branch=20move?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/do_epic/parking.py | 27 ++++++++++++++++++--------- bin/do_epic/test_gates.py | 3 ++- bin/do_epic/test_main.py | 18 ++++++++++++++---- bin/do_epic/test_parking.py | 14 ++++++++++---- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/bin/do_epic/parking.py b/bin/do_epic/parking.py index 66a6c2b6..b63f8cf6 100644 --- a/bin/do_epic/parking.py +++ b/bin/do_epic/parking.py @@ -7,12 +7,15 @@ from do_epic.epic_run import chunks_started, EpicRun, POLL_SECONDS, scheduled_ep from project_config.main import located as config_located from failure import Failure from chunk_driver.this_loop import Loop +from loop_state.paths import RELEASE_ROOT from loop_effects.effects import say from agent_cycle.stop import Stop from agent_cycle import tmux # How the news for a chunk that was parked opens. DRIVER_PARKED = f"{chunk_prompt.DRIVER} parked the chunk while" +# do-epic's PATH holds only what its user linked there, so chunk-pr is run by its path. +CHUNK_PR = str(RELEASE_ROOT / "bin" / "chunk-pr") @dataclasses.dataclass(frozen=True) @@ -39,8 +42,11 @@ def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finis if key in recorded_as: return resumed_news(poll, recorded_as[key].on, shown=None) entered = None if told is None else poll.first_gate(again=finished) - if finished and poll.by_human and isinstance(entered, gates.Unopened) and (done := merged_and_cleaned(poll, entered)): - return done + if finished and poll.by_human and isinstance(entered, gates.Unopened): + left = merged_and_cleaned(poll, entered) + if not isinstance(left, gates.Unopened): + return left + entered = left if not isinstance(entered, gates.Gate): if isinstance(entered, Failure): say(f"cannot tell whether the chunk's pull request waits on a gate, so the chunk isn't parked: {entered.reason}", epic.effects, stdout=True) @@ -115,8 +121,11 @@ def resumed_news(poll: Poll, on: str, shown: str | None) -> str | Stop | Merged: while True: now = poll.gate() if isinstance(now, gates.Open): - if isinstance(now, gates.Unopened) and (done := merged_and_cleaned(poll, now)): - return done + if isinstance(now, gates.Unopened): + left = merged_and_cleaned(poll, now) + if not isinstance(left, gates.Unopened): + return left + now = left full = resumed(poll.repo, poll.loop, poll.epic) if full is None: return unparked(poll, on, now) @@ -149,13 +158,13 @@ class Told: self.reason = reason -def merged_and_cleaned(poll: Poll, unopened: gates.Unopened) -> Merged | Stop | None: - """Runs `chunk-pr clean` in the worktree of a chunk whose pull request is no longer open, and removes the chunk's file once the worktree is gone: Merged then. None where the worktree stands, so that its worker decides, as for a pull request closed unmerged. +def merged_and_cleaned(poll: Poll, unopened: gates.Unopened) -> Merged | Stop | gates.Unopened: + """Runs `chunk-pr clean` in the worktree of a chunk whose pull request is no longer open, and removes the chunk's file once the worktree is gone: Merged then. Where the worktree stands, so that its worker decides, as for a pull request closed unmerged: unopened, its news adding why chunk-pr left it. - chunk-pr acts only on a pull request the forge reports merged at the commit checked out, and refuses a worktree with uncommitted or untracked files. It removes the worktree before it fails on the main checkout (another branch checked out, unsaved files or commits origin lacks), so a failure with the worktree gone still leaves the chunk merged, and its reason is said.""" - cleaned = poll.epic.forge_at(unopened.worktree)(["chunk-pr", "clean"]) + chunk-pr acts only on a pull request the forge reports merged at the commit checked out, and refuses a worktree with uncommitted or untracked files. It removes the worktree before it fails on the main checkout (another branch checked out, uncommitted or untracked files, or commits origin lacks), so a failure with the worktree gone still leaves the chunk merged, and its reason is said.""" + cleaned = poll.epic.forge_at(unopened.worktree)([CHUNK_PR, "clean"]) if isinstance(cleaned, Failure) and gates.worktree_of(poll.key, poll.epic.forge_at(poll.loop.root)) is not None: - return None + return dataclasses.replace(unopened, news=f"{unopened.news}; {cleaned.reason}") say(f"pull request merged: removed {unopened.worktree}" + (f", but {cleaned.reason}" if isinstance(cleaned, Failure) else ""), poll.epic.effects, stdout=True) failed = parked.unpark(poll.folder, poll.key) return Stop(1, failed.reason) if failed else Merged() diff --git a/bin/do_epic/test_gates.py b/bin/do_epic/test_gates.py index 453786b6..d735eec1 100644 --- a/bin/do_epic/test_gates.py +++ b/bin/do_epic/test_gates.py @@ -6,6 +6,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from do_epic.gates import APPROVAL, CHECKS, gate, Gate, MERGE, NEW_REVIEW, Open, Unmergeable, Unopened +from do_epic.parking import CHUNK_PR from failure import Failure WORKTREES = "worktree /code/billing\nHEAD aaa\nbranch refs/heads/main\n\nworktree /code/billing-ABC-21\nHEAD abc\nbranch refs/heads/ABC-21\n" @@ -40,7 +41,7 @@ class Forge: "git symbolic-ref": "origin/main\n", "git config": Failure("git config: unset"), # chunk-pr clean fails unless the forge reports the pull request merged at the worktree's head. - "chunk-pr clean": Failure(f"chunk-pr clean: {clean_fails}") if clean_fails else "" if merged else Failure("chunk-pr clean: no merged pull request, so its worktree and branch stay"), + f"{CHUNK_PR} clean": Failure(f"chunk-pr clean: {clean_fails}") if clean_fails else "" if merged else Failure("chunk-pr clean: no merged pull request, so its worktree and branch stay"), "gh pr list": pulls, "gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments), "mergeable": mergeable, "mergeStateStatus": merge_state, "baseRefName": base}), "gh pr checks": json.dumps([{"bucket": bucket} for bucket in buckets]), diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index e65a9e5e..0c13cb5f 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -12,6 +12,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) +from do_epic.parking import CHUNK_PR from do_epic import chunk_prompt, epic_run, main, planning from chunk_driver.chunk_run import ChunkRun from project_config.doubles import configured @@ -927,8 +928,8 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW + "ABC-22\t0\t@10\n") code, out, err, prompts = self.parked_run(fake) self.assertEqual((code, len(prompts)), (0, 1), err) - self.assertEqual(self.forges[1].commands.count(["chunk-pr", "clean"]), 1) - self.assertEqual({folder for folder, command in zip(self.forges[1].ran, self.forges[1].commands) if command[0] == "chunk-pr"}, {"/code/api-ABC-20"}) + self.assertEqual(self.forges[1].commands.count([CHUNK_PR, "clean"]), 1) + self.assertEqual({folder for folder, command in zip(self.forges[1].ran, self.forges[1].commands) if command[0] == CHUNK_PR}, {"/code/api-ABC-20"}) self.assertFalse(self.file.exists()) self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval"]) self.assertIn("the chunk finished; ", out) @@ -975,7 +976,7 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW) code, _, err, prompts = self.parked_run(fake) self.assertEqual((code, len(prompts)), (0, 2), err) - self.assertEqual(self.forges[1].commands.count(["chunk-pr", "clean"]), 1) + self.assertEqual(self.forges[1].commands.count([CHUNK_PR, "clean"]), 1) self.assertIn("no pull request from origin's ABC-20 is open", prompts[1].split("\n\n")[0]) def test_where_a_person_merged_before_the_cycle_closed_a_finished_chunk_is_cleaned_by_do_epic(self) -> None: @@ -984,7 +985,7 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW) code, out, err, prompts = self.parked_run(fake) self.assertEqual((code, len(prompts)), (0, 1), err) - self.assertEqual(self.forges[0].commands.count(["chunk-pr", "clean"]), 1) + self.assertEqual(self.forges[0].commands.count([CHUNK_PR, "clean"]), 1) self.assertIn("the chunk finished; ", out) def test_a_chunk_parks_and_resumes_though_the_next_chunk_cannot_start(self) -> None: @@ -1198,6 +1199,15 @@ class AnEpicsWorkingBranch(DoEpicTest): self.assertIn("The chunk's pull request goes into the epic's working branch `ABC-12`", prompts[0]) self.assertIn(("config", "branch.ABC-20.chunk-base", "ABC-12"), [args for args, _ in self.git_calls]) + def test_a_parked_chunk_whose_pull_request_merged_into_the_branch_gets_its_issue_moved_by_do_epic_as_no_automation_does_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 = [self.recorded(base="ABC-12"), self.recorded(base="ABC-12", pulls="", merged=True)] + fake = self.with_git(FakeEffects(streams=[self.worker()], claude=[judged("finished")], windows=PARKED_WINDOW)) + code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS) + self.assertEqual(code, 0, err) + self.assertIn("pull request merged: removed /code/api-ABC-20\n", out) + 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"]) + def test_a_chunk_parked_on_a_persons_merge_into_the_default_branch_stays_parked_until_its_pull_request_goes_into_the_branch(self) -> None: self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-merged-status = "Release Ready"\n') session = main.session_named("A ABC-12 do-epic ABC-20", paths_from(self.home).claude_code_transcripts) diff --git a/bin/do_epic/test_parking.py b/bin/do_epic/test_parking.py index 912705fa..0cca3b48 100644 --- a/bin/do_epic/test_parking.py +++ b/bin/do_epic/test_parking.py @@ -1,5 +1,6 @@ import contextlib import io +import os import pathlib import sys import tempfile @@ -8,6 +9,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) +from do_epic.parking import CHUNK_PR from do_epic import chunk_prompt, parked from failure import Failure from loop_effects.doubles import FakeEffects @@ -62,26 +64,30 @@ class TheCleanupOfAChunkWhosePullRequestIsNoLongerOpen(unittest.TestCase): def forge_at(self, folder: str): def run(command: list[str]) -> str | Failure: self.ran.append((folder, command)) - return self.clean if command[0] == "chunk-pr" else self.listed + return self.clean if command[0] == CHUNK_PR else self.listed return run - def cleaned(self) -> tuple[Merged | Stop | None, str]: + def cleaned(self) -> tuple[Merged | Stop | Unopened, str]: out = io.StringIO() with contextlib.redirect_stdout(out): return merged_and_cleaned(self.poll, UNOPENED), out.getvalue() + def test_chunk_pr_is_run_by_a_path_that_exists_since_do_epics_path_does_not_hold_it(self) -> None: + path = pathlib.Path(CHUNK_PR) + self.assertTrue(path.is_absolute() and path.is_file() and os.access(path, os.X_OK), CHUNK_PR) + def test_a_clean_that_removed_the_worktree_finishes_the_chunk_and_unparks_it(self) -> None: done, out = self.cleaned() self.assertEqual(done, Merged()) self.assertIn(" pull request merged: removed /code/api-ABC-20\n", out) - self.assertEqual(self.ran[0], ("/code/api-ABC-20", ["chunk-pr", "clean"])) + self.assertEqual(self.ran[0], ("/code/api-ABC-20", [CHUNK_PR, "clean"])) self.assertEqual(parked.parked_chunks(self.folder), {}) def test_a_clean_that_failed_with_the_worktree_standing_leaves_the_chunk_to_its_worker(self) -> None: self.clean = Failure("chunk-pr clean: no merged pull request") self.listed = "worktree /code/api\nbranch refs/heads/main\n\nworktree /code/api-ABC-20\nbranch refs/heads/ABC-20\n" done, out = self.cleaned() - self.assertEqual((done, out), (None, "")) + self.assertEqual((done, out), (Unopened("no pull request is open; chunk-pr clean: no merged pull request", "/code/api-ABC-20"), "")) self.assertEqual(self.ran[1], ("/code/api", ["git", "worktree", "list", "--porcelain"])) self.assertEqual(list(parked.parked_chunks(self.folder)), ["ABC-20"])