Answer product-owner round 1: 0 🔴, 1 🟡 (0 misread); stop loop-claude where every item left awaits a person's merge
CI / tests (pull_request) Successful in 3m23s
CI / tests (pull_request) Successful in 3m23s
This commit is contained in:
@@ -76,8 +76,11 @@ def room_of(windows: list[tmux.Listed], own: str | None, leaving: bool, limit: i
|
||||
return Room(running, stopped, restart, room - len(restart))
|
||||
|
||||
|
||||
def may_start(plan: NextChunk | NoItem, running: list[str], held: set[int], room: int) -> list[str]:
|
||||
"""The chunks to start now beside the running ones, whose chunks hold the items in held: the plan's next item and the items touch_predictions picks to run beside it, in the plan's order, up to room of them. Each leaves out an item in held, and one whose `Touches:` prediction overlaps a held item's, or where either has none. A plan without an item starts NO_ITEM, and only alone."""
|
||||
def may_start(plan: NextChunk | NoItem, running: list[str], held: set[int], room: int) -> list[str] | Failure:
|
||||
"""The chunks to start now beside the running ones, whose chunks hold the items in held: the plan's next item and the items touch_predictions picks to run beside it, in the plan's order, up to room of them. Each leaves out an item in held, and one whose `Touches:` prediction overlaps a held item's, or where either has none. A plan without an item starts NO_ITEM, and only alone. A plan whose NoItem names pull requests that await a person's merge starts none: where nothing runs, a Failure names them."""
|
||||
if isinstance(plan, NoItem) and plan.awaits_merge:
|
||||
# Where nothing runs, the loop stops on the pull requests plan.why names, rather than start a worker only to report them.
|
||||
return [] if running else Failure(plan.why)
|
||||
if isinstance(plan, NoItem):
|
||||
return [] if running or room < 1 else [NO_ITEM]
|
||||
beside = chunks_beside(plan.items, plan.first)
|
||||
@@ -122,6 +125,8 @@ def start_chunks(loop_run: LoopRun, leaving: bool, paths: Paths, env: typing.Map
|
||||
if refused := refusal(session, windows, loop_run.root, effects.tmux):
|
||||
return refused
|
||||
chunks = chunks_to_start(windows, loop_run, leaving, config.parallel_chunks, paths, effects)
|
||||
if isinstance(chunks, Failure):
|
||||
return chunks
|
||||
for chunk in chunks:
|
||||
started = tmux.start_chunk(tmux.Window(session, chunk, ""), loop_run.root, handed, [str(launcher), CHUNK_FLAG, chunk, loop_run.task], windows, True, effects.tmux)
|
||||
if isinstance(started, Failure):
|
||||
@@ -139,8 +144,8 @@ def refusal(session: str, windows: list[tmux.Listed], root: str, run: tmux.Tmux)
|
||||
return None
|
||||
|
||||
|
||||
def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool, limit: int, paths: Paths, effects: Effects) -> list[str]:
|
||||
"""The chunks to start beside windows, the session's: the stopped ones room_of restarts, then those of the plan that may_start picks. A plan that cannot be read starts NO_ITEM, as a plan without an item does."""
|
||||
def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool, limit: int, paths: Paths, effects: Effects) -> list[str] | Failure:
|
||||
"""The chunks to start beside windows, the session's: the stopped ones room_of restarts, then those of the plan that may_start picks. A plan that cannot be read starts NO_ITEM, as a plan without an item does. A Failure where no chunk runs or restarts and every item left waits on a person's merge: it names the pull requests."""
|
||||
room = room_of(windows, loop_run.chunk, leaving, limit)
|
||||
if not room.left:
|
||||
return room.restart
|
||||
@@ -150,7 +155,8 @@ def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool
|
||||
say(f"starting a chunk without a plan item, since the plan cannot be read: {plan.reason}", effects)
|
||||
plan = NoItem(plan.reason)
|
||||
held = held_items(room.running + room.stopped, project_key(loop_run.root, paths.home), paths.claude_code_transcripts)
|
||||
return room.restart + [chunk for chunk in may_start(plan, room.running + room.restart, held, room.left) if chunk not in room.stopped]
|
||||
picked = may_start(plan, room.running + room.restart, held, room.left)
|
||||
return picked if isinstance(picked, Failure) else room.restart + [chunk for chunk in picked if chunk not in room.stopped]
|
||||
|
||||
|
||||
def held_beside(chunk: str, root: str, paths: Paths, effects: Effects) -> list[int]:
|
||||
|
||||
@@ -9,7 +9,7 @@ import unittest
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
|
||||
|
||||
from chunk_driver.doubles import a_loop
|
||||
from loop_claude.loop import chunk_start
|
||||
from loop_claude.loop import chunk_start, chunk_windows
|
||||
from project_config.doubles import configured
|
||||
from release_plan.release_standing import DefaultPlan, LastCut, UNSEEN_RELEASES
|
||||
from failure import Failure
|
||||
@@ -92,11 +92,13 @@ class RouteSources(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = configured(self, pathlib.Path(root))
|
||||
(folder / "config.toml").write_text((folder / "config.toml").read_text() + 'merge = "human"\n')
|
||||
fake = FakeEffects(forge=[f"12\thttps://github.com/o/r/pull/12\t{head}\tfalse\tfalse\n"])
|
||||
fake = FakeEffects(forge=[f"12\thttps://github.com/o/r/pull/12\t{head}\tfalse\tfalse\n"] * 2)
|
||||
held = chunk_start.fetched_plan(a_loop(dataclasses.replace(fake.effects(), git=git), root=root, paths=paths.paths_from(folder.parents[1])))
|
||||
self.assertEqual([(item.id, item.awaits_merge) for item in held.plan.items], [(7, ""), (3, "#12 https://github.com/o/r/pull/12"), (1, "")])
|
||||
self.assertEqual(fake.made("forge")[0][:3], ["gh", "pr", "list"])
|
||||
self.assertEqual(fake.made("forge")[0][:4], [root, "gh", "pr", "list"])
|
||||
self.assertIsNone(chunk_start.plan_item(held, None, fake.effects()), "items 7 and 3 wait, so no item of the next release routes the chunk")
|
||||
window = chunk_windows.next_plan(root, folder.parents[1], dataclasses.replace(fake.effects(), git=git))
|
||||
self.assertEqual((window.awaits_merge, fake.made("forge")[1][:4]), (True, [root, "gh", "pr", "list"]), "a window starts by the same pick")
|
||||
|
||||
def test_reads_a_plan_outside_the_checkout_as_it_stands_and_stops_without_a_config(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
|
||||
@@ -61,6 +61,11 @@ class ChunkWindows(unittest.TestCase):
|
||||
windows = [tmux.Listed(f"item-{n}", "", False) for n in (1, 2, 3)]
|
||||
self.assertEqual(chunk_windows.room_of(windows, "item-1", False, 2).left, 0)
|
||||
|
||||
def test_stops_on_the_pull_requests_where_every_item_left_awaits_a_persons_merge_and_nothing_runs(self):
|
||||
awaited = next_chunk.NoItem("every item of release 1.0.0 waits. Pull request #7 awaits a person's merge.", True)
|
||||
self.assertEqual(chunk_windows.may_start(awaited, [], set(), 1), Failure(awaited.why))
|
||||
self.assertEqual(chunk_windows.may_start(awaited, ["item-5"], set(), 1), [], "a running or restarted chunk goes on, and no chunk without an item joins it")
|
||||
|
||||
def test_starts_no_item_that_overlaps_a_running_chunks_items(self):
|
||||
# Item 1 merged, so 2 is the plan's next item; it overlaps item 3, which still runs, at c.py.
|
||||
items = touch_plan((2, "1.0.0", "", "- `a.py`\n- `c.py`"), (3, "1.0.0", "", "- `c.py`"), (4, "1.0.0", "", "- `d.py`"))
|
||||
|
||||
Reference in New Issue
Block a user