Keep a parked chunk out of the epic's and its repo's running slots
This commit is contained in:
@@ -6,7 +6,8 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.scheduler import Chunk, CHUNK_FLAG, chunks, Epic, refusal, RepoRoom, start_chunks, Started, Waits
|
||||
from do_epic.scheduler import Chunk, CHUNK_FLAG, chunks, Epic, refusal, RepoRoom, resume, start_chunks, Started, Waits
|
||||
from do_epic.parked import file_of, park, Parked
|
||||
from do_epic import chunk_prompt
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from failure import Failure
|
||||
@@ -102,6 +103,12 @@ class Tmux:
|
||||
session = args[args.index("-s") + 1] if args[0] == "new-session" else args[args.index("-t") + 1].removeprefix("=").removesuffix(":")
|
||||
self.windows.append((session, args[args.index("-n") + 1], False, args[args.index("-c") + 1]))
|
||||
out = f"@{len(self.windows) - 1}\n"
|
||||
elif args[0] == "rename-window":
|
||||
at = int(args[2].removeprefix("%"))
|
||||
self.windows[at] = (self.windows[at][0], args[3], *self.windows[at][2:])
|
||||
elif args[0] == "set-option" and tmux.ROOT in args:
|
||||
at = int(args[args.index("-t") + 1].removeprefix("%").removeprefix("@"))
|
||||
self.windows[at] = (*self.windows[at][:3], "" if "-u" in args else args[-1])
|
||||
elif args[0] == "kill-window":
|
||||
self.windows[int(args[2].removeprefix("@"))] = ("", "", True, "")
|
||||
return subprocess.CompletedProcess(args, 0, out, "")
|
||||
@@ -137,6 +144,77 @@ class StartingAnEpicsChunks(unittest.TestCase):
|
||||
self.assertIn("LOOP_CLAUDE_X=1", run.calls[[args[0] for args in run.calls].index("new-session")])
|
||||
self.assertNotIn("OTHER=2", run.calls[[args[0] for args in run.calls].index("new-session")])
|
||||
|
||||
def parked(self, issue_key: str, on: str = "an approval") -> None:
|
||||
self.assertIsNone(park(self.home / ".local/state/do-epic/ABC-12", Parked(issue_key, f"/code/api-{issue_key}", "7", "0c0f", on)))
|
||||
|
||||
def test_a_parked_chunk_waits_in_its_window_and_takes_no_slot_of_the_epic_or_its_repo(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 awaits an approval", False, ""))
|
||||
found = self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api"), issue("ABC-22", "repo:api", blockers=("ABC-20",))], run)
|
||||
self.assertEqual(found, Started(["ABC-21"], [Waits("ABC-20", "it is parked: its pull request #7 awaits an approval"), Waits("ABC-22", "ABC-20 blocks it")]))
|
||||
|
||||
def test_a_parked_chunk_without_a_window_starts_again_whatever_the_limits_in_the_epics_folder(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
for windows in ((), (("epic-ABC-12", "ABC-20 awaits an approval", True, ""),)):
|
||||
with self.subTest(windows=windows):
|
||||
run = Tmux(*windows, ("epic-ABC-12", "ABC-21", False, str(self.home / "code/api")))
|
||||
found = self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], run)
|
||||
self.assertEqual(found, Started(["ABC-20"], []))
|
||||
self.assertEqual(run.windows[-1], ("epic-ABC-12", "ABC-20", False, str(self.home / ".local/state/do-epic/ABC-12")))
|
||||
self.assertEqual([name for _, name, dead, _ in run.windows if dead], [""] * len(windows))
|
||||
|
||||
def test_a_parked_chunk_that_starts_again_leaves_the_epics_cap_to_the_others(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
found = self.start(self.epic(1, api=2), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], Tmux())
|
||||
self.assertEqual(found, Started(["ABC-20", "ABC-21"], []))
|
||||
|
||||
def test_a_chunk_that_hands_on_starts_no_parked_chunk_whose_window_stopped(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
found = self.start(self.epic(2, api=2), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], Tmux(), own="ABC-21")
|
||||
self.assertEqual(found, Started([], [Waits("ABC-20", "its window stopped; run `do-epic ABC-12` to start it again")]))
|
||||
|
||||
def test_a_chunk_that_parks_frees_its_slot_for_the_next(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 awaits an approval", False, ""))
|
||||
found = self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], run, own="ABC-20")
|
||||
self.assertEqual(found, Started(["ABC-21"], []))
|
||||
|
||||
def test_stops_on_a_parked_chunk_it_cannot_read_and_starts_none(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
file_of(self.home / ".local/state/do-epic/ABC-12", "ABC-20").write_text("{")
|
||||
run = Tmux()
|
||||
found = start_chunks(self.epic(2, api=2), [issue("ABC-21", "repo:api")], None, run)
|
||||
assert isinstance(found, Failure)
|
||||
self.assertIn("cannot read the parked chunk in ", found.reason)
|
||||
self.assertEqual(run.started(), [])
|
||||
|
||||
def test_hands_each_chunk_the_variable_that_makes_its_merge_park(self) -> None:
|
||||
run = Tmux()
|
||||
self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api")], run)
|
||||
self.assertIn("CHUNK_PR_PARKS=1", run.calls[[args[0] for args in run.calls].index("new-session")])
|
||||
|
||||
def resumed(self, epic: Epic, run: Tmux) -> str | None:
|
||||
"""resume for the parked chunk in the first window, which changes the repo api."""
|
||||
return resume(epic, "api", tmux.Window("epic-ABC-12", "ABC-20", "%0"), run)
|
||||
|
||||
def test_a_parked_chunk_resumes_into_a_free_slot_and_counts_in_its_repo_again(self) -> None:
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 awaits an approval", False, ""), ("epic-ABC-12", "ABC-21 awaits its checks", False, ""))
|
||||
self.assertIsNone(self.resumed(self.epic(1, api=1), run))
|
||||
self.assertEqual(run.windows[0], ("epic-ABC-12", "ABC-20", False, str(self.home / "code/api")))
|
||||
|
||||
def test_a_parked_chunk_stays_parked_while_the_epic_or_its_repo_is_full(self) -> None:
|
||||
parked = ("epic-ABC-12", "ABC-20 awaits an approval", False, "")
|
||||
cases = {
|
||||
"the epic runs as many chunks as its `**Max parallel chunks:**` line allows: 1": (self.epic(1, api=2), Tmux(parked, ("epic-ABC-12", "ABC-21", False, str(self.home / "code/web")))),
|
||||
"api runs as many chunks as its `parallel-chunks` allows: 1": (self.epic(2, api=1), Tmux(parked, ("epic-XYZ-1", "XYZ-5", False, str(self.home / "code/api")))),
|
||||
"loop-claude runs chunks in api": (self.epic(2, api=1), Tmux(parked, ("loop-api", "item-3", False, str(self.home / "code/api")), owners={"loop-api": str(self.home / "code/api")})),
|
||||
"no project config names api": (self.epic(2), Tmux(parked)),
|
||||
}
|
||||
for reason, (epic, run) in cases.items():
|
||||
with self.subTest(reason=reason):
|
||||
self.assertEqual(self.resumed(epic, run), reason)
|
||||
self.assertEqual(run.windows[0], parked)
|
||||
|
||||
def test_a_running_chunk_counts_and_is_not_started_twice(self) -> None:
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 ?", False, str(self.home / "code/api")))
|
||||
found = self.start(self.epic(2, api=2), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api"), issue("ABC-22", "repo:api")], run)
|
||||
|
||||
Reference in New Issue
Block a user