From d2bb2c56e166a6221b46e12b490e133383b0b970 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 13:07:27 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20product-owner=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(1=20misread);=20finish=20a?= =?UTF-8?q?=20chunk=20whose=20clean=20removed=20the=20worktree=20before=20?= =?UTF-8?q?failing,=20say=20its=20reason,=20and=20reword=20the=20help?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/do_epic/gates.py | 1 - bin/do_epic/main.py | 4 ++-- bin/do_epic/parking.py | 11 +++++++---- bin/do_epic/test_gates.py | 6 +++--- bin/do_epic/test_main.py | 12 ++++++++++-- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bin/do_epic/gates.py b/bin/do_epic/gates.py index d88f6d35..126321f6 100644 --- a/bin/do_epic/gates.py +++ b/bin/do_epic/gates.py @@ -38,7 +38,6 @@ class Open: @dataclasses.dataclass(frozen=True) class Unopened(Open): """An Open whose worktree stands though no pull request is open at its head: one that was merged or closed, whose chunk still has its worktree to remove.""" - # The chunk's worktree. worktree: str diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index f0dc3850..c7df8282 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -67,7 +67,7 @@ A chunk whose worker ends its run while its pull request waits on its checks, an is parked: it frees its place for the next chunk, and its window's name says what it awaits. Its worker goes on once the checks pass, the approval comes or a reviewer comments, and a place is free; until one is, the name says `awaits a slot`. In a repo whose config sets `merge = "human"`, a chunk never merges: once its pull -request is ready, with nothing else to wait on, the window's name says `awaits your merge`. Once you merged it, do-epic removes the chunk's worktree with `chunk-pr clean` and finishes the chunk, without a worker or a place; a pull request closed unmerged goes on to its worker. A parked chunk survives a reboot: run do-epic again to go on polling. +request is ready, with nothing else to wait on, the window's name says `awaits your merge`. Once you merged it, do-epic removes the chunk's worktree with `chunk-pr clean` and finishes the chunk, without a worker or a place. Where it cannot, as for a pull request closed unmerged or a worktree with unsaved files, the worker goes on once a place is free. A parked chunk survives a reboot: run do-epic again to go on polling. --status doesn't start any chunk. It prints a line per open issue: that its chunk runs or asks you a question, or why it waits, such as the gate a parked chunk awaits and since when. --dry-run runs the planning and the scheduling against the epic as Jira holds it. It doesn't write anything to Jira, start a window or ask a question, and it doesn't start any issue in Jira as a real run's chunk does. It prints each label, sub-task, comment, score and rank move that planning would write, each move of a parent issue whose sub-tasks a person filed, the order the issues would start in, each chunk that would start and why each other issue waits. A sub-task not yet filed shows a key such as ABC-new1. A question planning would ask is printed instead of asked. Planning's claude calls still run. A repo that is missing isn't cloned. Planning then stops there, so its writes are only those made before it, and the issues of that repo wait, and a chunk of another repo may start in the place a real run gives them; a real run would clone it and go on. @@ -355,7 +355,7 @@ class Landed(enum.Enum): def landed_in(repo: str | None, based: str | None) -> Landed: - """Where the work of a chunk in the repo called repo landed: on the epic's working branch where based names it, else on the repo's default branch, nowhere for a chunk without a repo.""" + """Where the work of a chunk in the repo called repo landed: on the epic's working branch where based names it, otherwise on the repo's default branch, or nowhere for a chunk without a repo.""" return Landed.ON_EPIC_BRANCH if based is not None else Landed.ON_DEFAULT_BRANCH if repo is not None else Landed.NOWHERE diff --git a/bin/do_epic/parking.py b/bin/do_epic/parking.py index 56005611..66a6c2b6 100644 --- a/bin/do_epic/parking.py +++ b/bin/do_epic/parking.py @@ -21,7 +21,7 @@ class Merged: def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finished: bool, based: str | None) -> str | Stop | Merged: - """Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. Or Merged, where the chunk's pull request merged and `merged_and_cleaned` removed its worktree, which needs no worker and no running slot. told is the news its last cycle's worker got, None where the window just started, and finished says the judge ruled the chunk finished. based is the epic's working branch that `epic_based` recorded as the chunk's base when the window started, None where it recorded none. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh. + """Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. Or Merged, where the chunk's pull request merged and `merged_and_cleaned` removed its worktree: the chunk then needs no worker and no running slot. told is the news its last cycle's worker got, None where the window just started, and finished says the judge ruled the chunk finished. based is the epic's working branch that `epic_based` recorded as the chunk's base when the window started, None where it recorded none. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh. Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. For such a finished chunk, a gate that cannot be read is read again until it can (`Poll.first_gate`), and what the worker must still do is news (`news_after`), unless the pull request merged already and do-epic removes the worktree itself. @@ -150,10 +150,13 @@ class Told: 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: Merged where it removed the worktree. None where it didn't, so that the worker decides, as for a pull request closed unmerged. 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, so a worktree that holds work the merge lacks stays.""" - if isinstance(poll.epic.forge_at(unopened.worktree)(["chunk-pr", "clean"]), Failure): + """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. + + 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"]) + if isinstance(cleaned, Failure) and gates.worktree_of(poll.key, poll.epic.forge_at(poll.loop.root)) is not None: return None - say(f"pull request merged: removed {unopened.worktree}", poll.epic.effects, stdout=True) + 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 6b7969ee..453786b6 100644 --- a/bin/do_epic/test_gates.py +++ b/bin/do_epic/test_gates.py @@ -28,7 +28,7 @@ def comment(by: str, at: str) -> dict: class Forge: """Stands in for git and the forge's CLI in the checkout and the chunk's worktree; `ran` holds each folder a command ran in. Only the CLI of origin's forge answers: `gh` fails on a Gitea origin, and `tea` on a GitHub one.""" - def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x", base: str = "main", merged: bool = False) -> None: + def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x", base: str = "main", merged: bool = False, clean_fails: str = "") -> None: self.cli = "gh" if "github.com" in origin else "tea" self.ran: list[str] = [] self.commands: list[list[str]] = [] @@ -39,8 +39,8 @@ class Forge: "git rev-parse": HEAD + "\n", "git symbolic-ref": "origin/main\n", "git config": Failure("git config: unset"), - # chunk-pr removes the worktree only of a pull request the forge reports merged at the worktree's head. - "chunk-pr clean": "" if merged else Failure("chunk-pr clean: no merged pull request, so its worktree and branch stay"), + # 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"), "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 e6c52793..2d45a71c 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -767,7 +767,7 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): def test_where_a_person_merges_it_parks_on_that_merge_and_works_again_once_merged(self) -> None: self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8") - self.forges = [awaiting(), awaiting(decision="APPROVED"), awaiting(pulls=""), CLEANED] + self.forges = [awaiting(), awaiting(decision="APPROVED"), awaiting(pulls=""), awaiting(pulls=""), CLEANED] fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("unfinished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW) code, out, err, prompts = self.parked_run(fake) self.assertEqual(code, 0, err) @@ -948,8 +948,16 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): self.assertEqual(main.landed_in("api", "ABC-12"), main.Landed.ON_EPIC_BRANCH) self.assertEqual(main.landed_in(None, None), main.Landed.NOWHERE) + def test_a_merged_chunk_whose_clean_failed_after_removing_the_worktree_is_finished_and_the_reason_said(self) -> None: + self.forges = [awaiting(), awaiting(pulls="", clean_fails="its main checkout has uncommitted files"), CLEANED] + 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.assertIn("pull request merged: removed /code/api-ABC-20, but chunk-pr clean: its main checkout has uncommitted files\n", out) + self.assertFalse(self.file.exists()) + def test_a_parked_chunk_whose_worktree_chunk_pr_keeps_goes_to_a_worker_as_before(self) -> None: - self.forges = [awaiting(), awaiting(pulls=""), CLEANED] + self.forges = [awaiting(), awaiting(pulls=""), awaiting(pulls=""), CLEANED] 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)