Merge remote-tracking branch 'origin/main' into item-481
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
This commit is contained in:
@@ -38,6 +38,7 @@ 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."""
|
||||
worktree: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -65,7 +66,7 @@ def gate(branch: str, checkout: str, at: typing.Callable[[str], Run], by_human:
|
||||
forge = forge_of(origin)
|
||||
pull = open_pull(forge, branch, head, run)
|
||||
if not isinstance(pull, str):
|
||||
return pull or Unopened(f"no pull request from origin's {branch} is open at {head[:12]}; it may be merged or closed already")
|
||||
return pull or Unopened(f"no pull request from origin's {branch} is open at {head[:12]}; it may be merged or closed already", worktree)
|
||||
decision = review_decision(forge, pull, head, run)
|
||||
if not isinstance(decision, str):
|
||||
return decision or Open(f"pull request #{pull} is a draft")
|
||||
|
||||
+10
-3
@@ -34,8 +34,8 @@ from claude_code.reply import Limited
|
||||
from text_files.markdown_text import listed
|
||||
from do_epic.repos import locate
|
||||
from chunk_driver.this_loop import Loop
|
||||
from do_epic.parking import Merged, parked_through
|
||||
from chunk_driver.project.model_choice import Models, overridden
|
||||
from do_epic.parking import parked_through
|
||||
from chunk_driver.project.premises import read_premises
|
||||
from git_cli.git_repo import record_chunk_base
|
||||
from forge.commands import Run, runner
|
||||
@@ -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`, and its worker goes on once you merged it. A parked chunk survives a reboot: run do-epic <EPIC-KEY> 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 uncommitted or untracked files, the worker goes on once a place is free. A parked chunk survives a reboot: run do-epic <EPIC-KEY> 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.
|
||||
@@ -265,6 +265,8 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
while True:
|
||||
if isinstance(news, Stop):
|
||||
return news
|
||||
if isinstance(news, Merged):
|
||||
return handed_on(key, epic, landed_in(repo, based))
|
||||
run = dataclasses.replace(run, cycle_number=run.cycle_number + 1)
|
||||
cycle = next_cycle(run, loop, repo is not None, epic, news)
|
||||
if isinstance(cycle, Stop):
|
||||
@@ -282,7 +284,7 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
news = parked_through(repo, loop, epic, told=news, finished=isinstance(concluded.verdict, Finished), based=based) if repo is not None else ""
|
||||
# A chunk that was parked has work again, whatever the judge ruled before its pull request passed the gate.
|
||||
if isinstance(concluded.verdict, Finished) and news == "":
|
||||
return handed_on(key, epic, Landed.ON_EPIC_BRANCH if based is not None else Landed.ON_DEFAULT_BRANCH if repo is not None else Landed.NOWHERE)
|
||||
return handed_on(key, epic, landed_in(repo, based))
|
||||
|
||||
|
||||
def epic_based(key: str, root: str, epic: EpicRun) -> str | None | Stop:
|
||||
@@ -352,6 +354,11 @@ class Landed(enum.Enum):
|
||||
ON_EPIC_BRANCH = enum.auto()
|
||||
|
||||
|
||||
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, 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
|
||||
|
||||
|
||||
class How(enum.Enum):
|
||||
"""How a finished chunk's issue moves when it doesn't move to a status the config names."""
|
||||
# do-epic neither moves nor awaits it.
|
||||
|
||||
+35
-5
@@ -7,18 +7,26 @@ 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")
|
||||
|
||||
|
||||
def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finished: bool, based: str | None) -> str | Stop:
|
||||
"""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. 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.
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Merged:
|
||||
"""What `parked_through` returns for a chunk whose pull request merged and whose worktree do-epic removed itself: the chunk is finished."""
|
||||
|
||||
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`).
|
||||
|
||||
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: 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.
|
||||
|
||||
A chunk parks in three steps: its file is written, its window is shown as parked, and the epic's next chunks start in the slot it frees. It resumes in the reverse order: `scheduler.resume` gives it a running slot, then its file is removed. So a window that ends in between finds the chunk parked when it starts again.
|
||||
"""
|
||||
@@ -34,6 +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):
|
||||
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)
|
||||
@@ -102,12 +115,17 @@ class Poll:
|
||||
return failed
|
||||
|
||||
|
||||
def resumed_news(poll: Poll, on: str, shown: str | None) -> str | Stop:
|
||||
"""Reads the gate of the parked chunk every POLL_SECONDS until its worker has something to do and a running slot is free, then removes its file: what to tell that worker. on is the gate the chunk's file says it is parked on, and shown what its window's name says it awaits, None where nothing yet. A gate that cannot be read leaves the chunk parked as it was."""
|
||||
def resumed_news(poll: Poll, on: str, shown: str | None) -> str | Stop | Merged:
|
||||
"""Reads the gate of the parked chunk every POLL_SECONDS until its worker has something to do and a running slot is free, then removes its file: what to tell that worker. on is the gate the chunk's file says it is parked on, and shown what its window's name says it awaits, None where nothing yet. A gate that cannot be read leaves the chunk parked as it was. A chunk whose pull request merged is Merged at once, without waiting for a slot (`merged_and_cleaned`)."""
|
||||
told = Told(poll, shown)
|
||||
while True:
|
||||
now = poll.gate()
|
||||
if isinstance(now, gates.Open):
|
||||
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)
|
||||
@@ -140,6 +158,18 @@ class Told:
|
||||
self.reason = reason
|
||||
|
||||
|
||||
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, 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 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()
|
||||
|
||||
|
||||
def unparked(poll: Poll, on: str, now: gates.Open) -> str | Stop:
|
||||
"""Removes the file of the chunk that was parked on the gate on: what to tell its worker, which now says why it resumes."""
|
||||
failed = parked.unpark(poll.folder, poll.key)
|
||||
|
||||
@@ -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"
|
||||
@@ -28,7 +29,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") -> 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,6 +40,8 @@ class Forge:
|
||||
"git rev-parse": HEAD + "\n",
|
||||
"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.
|
||||
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]),
|
||||
@@ -185,7 +188,10 @@ class GateOfAChunk(unittest.TestCase):
|
||||
for news, forge in cases.items():
|
||||
with self.subTest(news=news):
|
||||
self.assertEqual(forge.gate(), Open(news))
|
||||
self.assertEqual(Forge(pulls="").gate(), Unopened("no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already"))
|
||||
long_head = Forge(pulls="")
|
||||
long_head.answers["git rev-parse"] = "abc" * 13 + "\n"
|
||||
self.assertEqual(long_head.gate(), Unopened("no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already", "/code/billing-ABC-21"))
|
||||
self.assertEqual(Forge(pulls="").gate(), Unopened("no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already", "/code/billing-ABC-21"))
|
||||
|
||||
def test_a_read_that_fails_is_a_failure_and_says_nothing_of_the_gate(self):
|
||||
for command in ("git worktree", "git remote", "gh pr list", "gh pr view", "gh pr checks", "gh api graphql"):
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.main import Landed, landed_in
|
||||
|
||||
|
||||
class WhereTheWorkOfAFinishedChunkLanded(unittest.TestCase):
|
||||
def test_it_landed_on_the_epics_working_branch_where_the_chunk_has_one(self) -> None:
|
||||
self.assertEqual(landed_in("api", "ABC-12"), Landed.ON_EPIC_BRANCH)
|
||||
|
||||
def test_it_landed_on_the_default_branch_of_a_repo_without_one(self) -> None:
|
||||
self.assertEqual(landed_in("api", None), Landed.ON_DEFAULT_BRANCH)
|
||||
|
||||
def test_a_chunk_without_a_repo_landed_nowhere(self) -> None:
|
||||
self.assertEqual(landed_in(None, None), Landed.NOWHERE)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -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
|
||||
@@ -767,7 +768,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)
|
||||
@@ -921,6 +922,72 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval", "ABC-20 awaits a slot", "ABC-20"])
|
||||
self.assertEqual(len(prompts), 2)
|
||||
|
||||
def test_a_parked_chunk_whose_pull_request_merged_is_cleaned_and_finished_by_do_epic_though_no_slot_is_free(self) -> None:
|
||||
self.description = DESCRIPTION.replace("2", "1")
|
||||
self.forges = [awaiting(), awaiting(pulls="", merged=True)]
|
||||
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.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)
|
||||
|
||||
def test_where_the_parked_file_of_a_merged_chunk_cannot_be_removed_the_loop_stops(self) -> None:
|
||||
self.forges = [awaiting(), awaiting(pulls="", merged=True)]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=lambda seconds: self.file.parent.chmod(0o555)) # type: ignore[method-assign]
|
||||
self.addCleanup(lambda: self.file.parent.chmod(0o755))
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual((code, len(prompts)), (1, 1))
|
||||
self.assertIn("pull request merged: removed /code/api-ABC-20\n", out)
|
||||
self.assertIn("Permission denied", err)
|
||||
|
||||
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_where_the_teams_automation_moves_issues_a_merged_parked_chunk_waits_for_the_move_as_a_finished_one_does(self) -> None:
|
||||
(self.home / ".claude-projects" / "do-epic" / "config.toml").write_text(SETTINGS + 'jira-unblocking-statuses = ["Release Ready", "Shipped"]\njira-automation-moves-issues = true\n', encoding="utf-8")
|
||||
store = MemoryEpic("ABC-12", [*self.issues[:-1], issue("ABC-22", "do-epic-claude", blockers=("ABC-20",))])
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
self.forges = [awaiting(), awaiting(pulls="", merged=True)]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
slept: list[float] = []
|
||||
|
||||
def sleep(seconds: float) -> None:
|
||||
slept.append(seconds)
|
||||
if len(slept) == 3:
|
||||
store.change("ABC-20", status="Release Ready")
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=sleep) # type: ignore[method-assign]
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual((code, len(prompts)), (0, 1), err)
|
||||
self.assertEqual([(each.status, each.done) for each in store.issues if each.key == "ABC-20"], [("Release Ready", False)])
|
||||
self.assertIn("ABC-20 is To Do: it waits for the team's automation to move it to Release Ready or Shipped", out)
|
||||
self.assertIn("the chunk finished; started ABC-22\n", out)
|
||||
|
||||
def test_a_parked_chunk_whose_worktree_chunk_pr_keeps_goes_to_a_worker_as_before(self) -> None:
|
||||
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)
|
||||
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:
|
||||
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8")
|
||||
self.forges = [awaiting(pulls="", merged=True)]
|
||||
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.assertIn("the chunk finished; ", out)
|
||||
|
||||
def test_a_chunk_parks_and_resumes_though_the_next_chunk_cannot_start(self) -> None:
|
||||
self.forges = [awaiting(), awaiting(decision="APPROVED")]
|
||||
worker = self.worker()
|
||||
@@ -1132,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)
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
import types
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic import chunk_prompt
|
||||
from do_epic.parking import CHUNK_PR
|
||||
from do_epic import chunk_prompt, parked
|
||||
from failure import Failure
|
||||
from do_epic.parking import news_after
|
||||
from loop_effects.doubles import FakeEffects
|
||||
from do_epic.parking import Merged, merged_and_cleaned, news_after, Poll
|
||||
from do_epic.gates import Open, Unmergeable, Unopened
|
||||
from agent_cycle.stop import Stop
|
||||
|
||||
UNOPENED = Unopened("no pull request is open")
|
||||
UNOPENED = Unopened("no pull request is open", "/code/api-ABC-20")
|
||||
UNCLEANED = f"{chunk_prompt.DRIVER} keeps the chunk open while its worktree stands: no pull request is open."
|
||||
UNMERGEABLE = Unmergeable("pull request #7 conflicts with its base branch")
|
||||
UNLEVELLED = f"{chunk_prompt.DRIVER} keeps the chunk open while its pull request doesn't merge into its base: pull request #7 conflicts with its base branch."
|
||||
@@ -40,5 +48,61 @@ class TheNewsOfAChunkThatIsNotParked(unittest.TestCase):
|
||||
self.assertEqual(news_after(UNMERGEABLE, finished=True, by_human=True, told=UNLEVELLED), UNLEVELLED)
|
||||
|
||||
|
||||
class TheCleanupOfAChunkWhosePullRequestIsNoLongerOpen(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
made = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(made.cleanup)
|
||||
self.folder = pathlib.Path(made.name)
|
||||
parked.park(self.folder, parked.Parked("ABC-20", "/code/api-ABC-20", "7", "session", "your merge"))
|
||||
self.ran: list[tuple[str, list[str]]] = []
|
||||
self.clean: str | Failure = ""
|
||||
# What `git worktree list` says once chunk-pr clean ran.
|
||||
self.listed = "worktree /code/api\nbranch refs/heads/main\n"
|
||||
effects = FakeEffects().effects()
|
||||
self.poll = Poll("ABC-20", "api", True, self.folder, types.SimpleNamespace(root="/code/api"), types.SimpleNamespace(effects=effects, forge_at=self.forge_at)) # type: ignore[arg-type]
|
||||
|
||||
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 run
|
||||
|
||||
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(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), (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"])
|
||||
|
||||
def test_a_clean_that_failed_after_removing_the_worktree_finishes_the_chunk_and_says_why(self) -> None:
|
||||
self.clean = Failure("chunk-pr clean: its main checkout has uncommitted files")
|
||||
done, out = self.cleaned()
|
||||
self.assertEqual(done, Merged())
|
||||
self.assertIn(" pull request merged: removed /code/api-ABC-20, but chunk-pr clean: its main checkout has uncommitted files\n", out)
|
||||
|
||||
def test_a_parked_file_that_cannot_be_removed_stops_the_loop(self) -> None:
|
||||
self.folder.joinpath(parked.FOLDER).chmod(0o555)
|
||||
self.addCleanup(lambda: self.folder.joinpath(parked.FOLDER).chmod(0o755))
|
||||
done, _ = self.cleaned()
|
||||
self.assertEqual(done, Stop(1, f"cannot remove {parked.file_of(self.folder, 'ABC-20')}: Permission denied"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -514,7 +514,7 @@ def benched(bench: Bench, planned: Planner) -> list[str] | Failure:
|
||||
def baseline_failure(bench: Bench) -> Failure | None:
|
||||
"""Why a side's tests don't pass without a task; None where they pass at both sides."""
|
||||
for side, tree in bench.trees.items():
|
||||
ran = tests_in_copy(bench.containers, tree, bench.folder)
|
||||
ran = tests_in_copy(bench.containers, tree, bench.folder, bench.git)
|
||||
if isinstance(ran, Failure) or ran.code:
|
||||
return ran if isinstance(ran, Failure) else failed(f"The tests fail at the {side} without {bench.asked.kind.without}: the test command", ran)
|
||||
return None
|
||||
@@ -630,7 +630,7 @@ def planted_tree(bench: Bench, side: Side, tree: pathlib.Path, path: str, change
|
||||
(tree / path).write_bytes(changed)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not plant the bug in {tree}: {failure}")
|
||||
ran = tests_in_copy(bench.containers, str(tree), bench.folder)
|
||||
ran = tests_in_copy(bench.containers, str(tree), bench.folder, bench.git)
|
||||
# Tests that never end under the bug have no message.
|
||||
if isinstance(ran, TimedOut):
|
||||
return None
|
||||
|
||||
@@ -103,14 +103,15 @@ def committed(git: Git, tree: str) -> Failure | None:
|
||||
return None
|
||||
|
||||
|
||||
def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path) -> Ran | Failure:
|
||||
"""The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree."""
|
||||
def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path, git: Git) -> Ran | Failure:
|
||||
"""The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree. The copy gets a repository
|
||||
of its own with one commit first, since a project's tests may call git and a tree from `git archive` holds none."""
|
||||
copy = folder / "tested"
|
||||
copied = on_disk(f"copy {tree} to test it", lambda: shutil.copytree(tree, copy, symlinks=True))
|
||||
if isinstance(copied, Failure):
|
||||
return copied
|
||||
try:
|
||||
return ran_tests(containers, str(copy))
|
||||
return committed(git, str(copy)) or ran_tests(containers, str(copy))
|
||||
finally:
|
||||
shutil.rmtree(copy, ignore_errors=True)
|
||||
|
||||
|
||||
@@ -298,6 +298,11 @@ class BenchTest(unittest.TestCase):
|
||||
self.assertEqual(log, "task-bench Import\n")
|
||||
self.assertEqual(subprocess.run(["git", "status", "--porcelain"], cwd=tree, env=self.env, check=True, capture_output=True, text=True).stdout, "")
|
||||
|
||||
def test_tests_that_call_git_run_in_a_repository_at_each_side(self):
|
||||
# `git ls-files` fails in a tree that isn't a repository.
|
||||
found = self.bench(**{"--test": "git ls-files --error-unmatch calc.go >/dev/null && sh calc_test.go"})
|
||||
self.assertNotIsInstance(found, Failure, found)
|
||||
|
||||
def test_claude_runs_in_the_benchs_image_on_its_network_with_the_message_alone_and_the_token_by_name(self):
|
||||
self.bench(**{"--runs": "1"})
|
||||
calls = self.calls()
|
||||
@@ -589,7 +594,13 @@ class RunOutcomesTest(unittest.TestCase):
|
||||
|
||||
def test_a_tree_that_cannot_be_copied_for_its_tests_fails_the_bench_naming_it(self):
|
||||
gone = str(self.folder / "gone")
|
||||
self.assertFailsWith(main.tests_in_copy(self.containers(), gone, self.folder), f"could not copy {gone} to test it: ")
|
||||
self.assertFailsWith(main.tests_in_copy(self.containers(), gone, self.folder, self.bench().git), f"could not copy {gone} to test it: ")
|
||||
|
||||
def test_a_copy_that_cannot_be_committed_fails_the_bench_and_is_removed(self):
|
||||
tree = self.folder / "tree"
|
||||
tree.mkdir(exist_ok=True)
|
||||
self.assertFailsWith(main.tests_in_copy(self.containers(), str(tree), self.folder, lambda *args, **given: Failure("no git")), "no git")
|
||||
self.assertFalse((self.folder / "tested").exists())
|
||||
|
||||
def test_a_tree_whose_folder_cannot_be_made_fails_the_bench_naming_it(self):
|
||||
(self.folder / "file").write_text("")
|
||||
|
||||
Reference in New Issue
Block a user