Answer stability round 1: 0 🔴, 6 🟡 (1 misread); name a checkout by its real path, pick a chunk's repo once, test the step line, the repo's model and ladder, and a clone
This commit is contained in:
@@ -14,7 +14,6 @@ def task(issue: EpicIssue, epic: str, checkout: str | None) -> str:
|
||||
return f"Work the Jira issue {issue.key} of the epic {epic} as one chunk, {where}. Its summary: {issue.summary}" + (f"\n\nIts description:\n\n{issue.detail}" if issue.detail else "")
|
||||
|
||||
|
||||
# Where code health is stated.
|
||||
CODE_HEALTH = '~/.claude/CLAUDE.md → "Shared goal"'
|
||||
|
||||
|
||||
@@ -22,7 +21,7 @@ def fresh(task: str, premises: str, route: Route, project: ProjectRung | None, f
|
||||
"""A chunk's first prompt. facts is empty: do-epic runs no preflight."""
|
||||
routed = f"{DRIVER} runs you on {route.rung}, routed by the issue's L of {route.likelihood}. Where a sentence below names item {route.item}, it means the issue." if route.item else ""
|
||||
opening = " ".join(filter(None, [routed, *prompts.rung_sentences(DRIVER, route, project)]))
|
||||
return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one. {prompts.READING_RULE}\n\n{opening and f'{opening}{chr(10)}{chr(10)}'}The issue sets the chunk's scope. The goals below choose between ways to deliver that scope, and never widen it: the epic's first, then code health ({CODE_HEALTH}), then the repo's.\n\nFrom {premises}"
|
||||
return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one. {prompts.READING_RULE}\n\n{opening and f'{opening}{chr(10)}{chr(10)}'}The issue sets the chunk's scope. The goals below choose between ways to deliver that scope, and never widen it. The epic's goals rank first, then code health ({CODE_HEALTH}), then the repo's.\n\nFrom {premises}"
|
||||
|
||||
|
||||
# The worker names no plan items: the chunk's one item is its issue.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""A Jira epic's description as the record of do-epic, the tool that will drive one epic.
|
||||
"""A Jira epic's description as the record of do-epic, the tool that drives one epic.
|
||||
|
||||
The description holds a language line, a line that caps the chunks running at once, and the sections Goals, Audience, Scoring (the formula and the bar) and Decisions. They are read and written one at a time through `EpicDescription`, and a write leaves every other line of the markdown as it was. Goals and Audience change only where the human approved in an interrupt, which `write_section` takes as `approved`; `EpicDescription` refuses the change otherwise."""
|
||||
import dataclasses
|
||||
@@ -16,6 +16,8 @@ LANGUAGE_LINE = re.compile(r"^\*\*Language:\*\* (.*?)\s*$")
|
||||
# The line that caps how many of the epic's chunks run at once. Three readers, seated as the human who writes an epic's description, picked this spelling from four candidates, 2-1 over `**Parallel chunks:**`, which reads as a count of what runs now.
|
||||
CAP = "**Max parallel chunks:**"
|
||||
CAP_LINE = re.compile(rf"^{re.escape(CAP)}(.*?)\s*$")
|
||||
# A line that opens with CAP's words in another spelling. It is refused, since the epic would otherwise run on the cap of 1 without a word.
|
||||
NEAR_CAP_LINE = re.compile(r"^[\s*_>#-]*max parallel chunks", re.IGNORECASE)
|
||||
|
||||
|
||||
def read_section(text: str, name: str) -> str | Failure:
|
||||
@@ -70,6 +72,8 @@ def parallel_chunks_in(text: str) -> int | Failure:
|
||||
if re.fullmatch(r"[1-9][0-9]*", value):
|
||||
return int(value)
|
||||
return Failure(f"the epic's description caps its chunks with `{CAP} {value}`, which is not a whole number of 1 or more, such as `{CAP} 2`")
|
||||
if not fenced and NEAR_CAP_LINE.match(line):
|
||||
return Failure(f"the epic's description holds the line `{line.strip()}`, which do-epic doesn't read as the epic's cap: write it as a line of its own, spelt `{CAP} 2`")
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
+27
-19
@@ -1,12 +1,13 @@
|
||||
"""The do-epic command (docs/decisions.md → `do-epic: drives one Jira epic …`).
|
||||
|
||||
`do-epic <EPIC-KEY>` starts each of the epic's chunks that may start now, each in a window of the epic's tmux session, as `scheduler` picks them, and puts that session on the terminal. Each window runs `do-epic --chunk <ISSUE-KEY> <EPIC-KEY>`: the cycles of one issue's chunk, which loop-claude's cycles share (`agent_cycle`), until the judge rules it finished. Then it starts the chunks that may start now, and its window closes."""
|
||||
`do-epic <EPIC-KEY>` starts each of the epic's chunks that may start now, each in a window of the epic's tmux session, as `scheduler` picks them, and puts that session on the terminal. Each window runs `do-epic --chunk <ISSUE-KEY> <EPIC-KEY>`: the cycles of one issue's chunk, run by the code that runs loop-claude's (`agent_cycle`), until the judge rules it finished. Then it starts the chunks that may start now, and its window closes."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
from loop_claude.loop.chunk_start import archived_route, routed
|
||||
from do_epic import chunk_prompt, scheduler
|
||||
from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo
|
||||
from loop_claude.loop.close import closed_cycle
|
||||
from agent_cycle.run import Cycle, run_cycle
|
||||
from do_epic.config import DoEpicConfig, load
|
||||
@@ -29,7 +30,6 @@ from transcript_archive.project_key import project_key
|
||||
from model_routing.ladder_file import project_ladder_file, read_ladder, SHIPPED
|
||||
from loop_claude.project.premises import read_premises
|
||||
from loop_claude.project.records import read_records
|
||||
from do_epic.repo_pick import recorded, Repo
|
||||
from claude_code.session import session_named
|
||||
from loop_claude.loop.main import setup_version
|
||||
from agent_cycle.stop import Stop
|
||||
@@ -39,11 +39,12 @@ from agent_cycle import tmux
|
||||
HELP = f"""usage: do-epic <EPIC-KEY>
|
||||
|
||||
Runs the chunks of one Jira epic, such as ABC-12, each in its own window of the tmux session epic-<EPIC-KEY>.
|
||||
An open issue of the epic is a chunk once a label names its repo, or names it work without a repo, and nothing blocks it.
|
||||
An open issue of the epic runs as a chunk once it has a label and no issue blocks it.
|
||||
The label names the issue's repo, or says the work changes no repo.
|
||||
As many run at once as the epic's description allows with a line such as `**Max parallel chunks:** 2`, one where it has none.
|
||||
A repo takes as many chunks as its `parallel-chunks`, and none while loop-claude runs chunks in it.
|
||||
The Jira site and its credentials are set in ~/.claude-projects/do-epic/config.toml."""
|
||||
# Under the home folder, where a chunk's cycles are archived, a folder per epic. Apart from loop-claude's archive, whose readers, such as judge-replay and the routing figures, read loop-claude's prompts.
|
||||
# Under the home folder, where a chunk's cycles are archived, a folder per epic. It is not loop-claude's archive, since that archive's readers, such as judge-replay and the routing figures, read loop-claude's prompts.
|
||||
ARCHIVE = ".claude/do-epic-transcripts"
|
||||
|
||||
# The store of an epic's issues and its record, for the epic with this key.
|
||||
@@ -108,7 +109,7 @@ def windows_opened(epic: EpicRun) -> Stop:
|
||||
started = chunks_started(epic, None)
|
||||
if isinstance(started, Failure):
|
||||
return Stop(1, started.reason)
|
||||
say(f"started {', '.join(started.started)} in the tmux session {epic.session}" if started.started else f"started no chunk in the tmux session {epic.session}", epic.effects, stdout=True)
|
||||
say(f"started {', '.join(started.started)} in the tmux session {epic.session}" if started.started else "started no chunk", epic.effects, stdout=True)
|
||||
for wait in started.waits:
|
||||
say(f"{wait.issue} waits: {wait.reason}", epic.effects, stdout=True)
|
||||
if not tmux.listed(epic.session, epic.effects.tmux):
|
||||
@@ -136,7 +137,7 @@ def chunks_started(epic: EpicRun, own: str | None) -> scheduler.Started | Failur
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
seen.append(found.checkout)
|
||||
return found.checkout, found.config.parallel_chunks
|
||||
return real(found.checkout), found.config.parallel_chunks
|
||||
|
||||
return scheduler.start_chunks(scheduler.Epic(epic.key, cap, located, epic.paths.home, epic.launcher, epic.env), issues, own, epic.effects.tmux)
|
||||
|
||||
@@ -148,7 +149,7 @@ class RoutingIssue:
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
"""The number in the issue's key. A Route keeps a number, and one chunk's archive holds one issue, so the project's letters aren't needed to tell it."""
|
||||
"""The number in the issue's key. A Route keeps a number, and one chunk's archive holds one issue, so the number tells the issue without its project's letters."""
|
||||
return int(self.issue.key.rpartition("-")[2])
|
||||
|
||||
@property
|
||||
@@ -160,6 +161,11 @@ class RoutingIssue:
|
||||
return self.issue.scores.get("E", 0) + self.issue.scores.get("I", 0)
|
||||
|
||||
|
||||
def real(checkout: pathlib.Path) -> pathlib.Path:
|
||||
"""The checkout as loop-claude names it, which is as git does: through no symlink or `..`. Each keys the checkout's lock and its chunks by that path, so a project config that spells it another way hides neither from the other."""
|
||||
return checkout.resolve()
|
||||
|
||||
|
||||
def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
"""Runs the cycles of the chunk of the issue called key until one stops the loop, or the judge rules the chunk finished."""
|
||||
pane = epic.env.get("TMUX_PANE")
|
||||
@@ -168,15 +174,16 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
issue = issue_read(key, epic)
|
||||
if isinstance(issue, Stop):
|
||||
return issue
|
||||
root = chunk_root(issue, epic)
|
||||
if isinstance(root, Stop):
|
||||
return root
|
||||
place = chunk_root(issue, epic)
|
||||
if isinstance(place, Stop):
|
||||
return place
|
||||
root, in_repo = place
|
||||
session = session_named(f"A {epic.key} do-epic {key}", epic.paths.claude_code_transcripts)
|
||||
loop = Loop(root=root, session=session, window=tmux.Window(epic.session, key, pane), paths=epic.paths, env=epic.env, launcher=epic.launcher, effects=epic.effects)
|
||||
loop_run = LoopRun(0, root, "", "", chunk=key)
|
||||
while True:
|
||||
loop_run = dataclasses.replace(loop_run, cycle_number=loop_run.cycle_number + 1)
|
||||
cycle = next_cycle(loop_run, loop, epic)
|
||||
cycle = next_cycle(loop_run, loop, in_repo, epic)
|
||||
if isinstance(cycle, Stop):
|
||||
return cycle
|
||||
loop_run = dataclasses.replace(loop_run, task=cycle.task)
|
||||
@@ -200,17 +207,19 @@ def issue_read(key: str, epic: EpicRun) -> EpicIssue | Stop:
|
||||
return found[0] if found else Stop(1, f"{key} is no issue of the epic {epic.key}")
|
||||
|
||||
|
||||
def chunk_root(issue: EpicIssue, epic: EpicRun) -> str | Stop:
|
||||
"""The folder the issue's chunk works in: its repo's checkout, or the epic's folder for work without a repo."""
|
||||
def chunk_root(issue: EpicIssue, epic: EpicRun) -> tuple[str, bool] | Stop:
|
||||
"""The folder the issue's chunk works in, and whether it is a repo's checkout: the epic's folder holds work without a repo. The chunk keeps both to its end, whatever the issue's labels become. The stop where the labels make the issue no chunk."""
|
||||
pick = recorded(issue)
|
||||
if isinstance(pick, Failure):
|
||||
return Stop(1, pick.reason)
|
||||
if not isinstance(pick, Repo):
|
||||
if isinstance(pick, ClaudeWork):
|
||||
folder = epic.paths.home / scheduler.STATE / epic.key
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
return str(folder)
|
||||
return str(folder), False
|
||||
if not isinstance(pick, Repo):
|
||||
return Stop(1, f"{issue.key} is no chunk: {'it is a human\'s task' if isinstance(pick, HumanTask) else 'no label names its repo'}")
|
||||
found = locate(pick.name, [], epic.config, epic.paths.home, epic.effects.git)
|
||||
return Stop(1, found.reason) if isinstance(found, Failure) else str(found.checkout)
|
||||
return Stop(1, found.reason) if isinstance(found, Failure) else (str(real(found.checkout)), True)
|
||||
|
||||
|
||||
def handed_on(key: str, epic: EpicRun) -> Stop:
|
||||
@@ -222,12 +231,11 @@ def handed_on(key: str, epic: EpicRun) -> Stop:
|
||||
return Stop(0, "")
|
||||
|
||||
|
||||
def next_cycle(loop_run: LoopRun, loop: Loop, epic: EpicRun) -> Cycle | Stop:
|
||||
"""The cycle loop_run runs next, from the issue, the premises, the records, the models and the routing ladder read afresh; the stop where one of them cannot be read. A chunk in a repo routes on that repo's model and ladder, and one without a repo on the machine setting's model, `repoless-model`, and the shipped ladder."""
|
||||
def next_cycle(loop_run: LoopRun, loop: Loop, in_repo: bool, epic: EpicRun) -> Cycle | Stop:
|
||||
"""The cycle loop_run runs next, from the issue, the premises, the records, the models and the routing ladder read afresh; the stop where one of them cannot be read. A chunk in a repo routes on that repo's model and ladder, and one without a repo on the machine setting `repoless-model` and the shipped ladder."""
|
||||
issue = issue_read(loop.window.name, epic)
|
||||
if isinstance(issue, Stop):
|
||||
return issue
|
||||
in_repo = isinstance(recorded(issue), Repo)
|
||||
premises = premises_read(loop.root if in_repo else None, epic)
|
||||
if isinstance(premises, Failure):
|
||||
return Stop(1, premises.reason)
|
||||
|
||||
@@ -73,7 +73,7 @@ class Epic:
|
||||
|
||||
|
||||
def chunks(issues: list[EpicIssue]) -> tuple[list[Chunk], list[Waits]]:
|
||||
"""The open issues to work as chunks, in the tracker's rank order, and those that wait. An item split by repo is worked through its sub-tasks, and what blocks it blocks them. A blocker outside the epic blocks, since its state is unknown."""
|
||||
"""The open issues to work as chunks, in the tracker's rank order, and those that wait. An item split by repo is worked through its sub-tasks, and what blocks it blocks them. A blocker outside the epic blocks until the human removes the link, since its state is unknown."""
|
||||
by_key = {issue.key: issue for issue in issues}
|
||||
found: list[Chunk] = []
|
||||
waits: list[Waits] = []
|
||||
@@ -83,6 +83,7 @@ def chunks(issues: list[EpicIssue]) -> tuple[list[Chunk], list[Waits]]:
|
||||
pick = recorded(issue)
|
||||
parent = by_key.get(issue.parent)
|
||||
blocking = [key for key in (*issue.blockers, *(parent.blockers if parent else ())) if key not in by_key or not by_key[key].done]
|
||||
outside = [key for key in blocking if key not in by_key]
|
||||
if isinstance(pick, Failure):
|
||||
waits.append(Waits(issue.key, pick.reason))
|
||||
elif pick is None:
|
||||
@@ -90,7 +91,7 @@ def chunks(issues: list[EpicIssue]) -> tuple[list[Chunk], list[Waits]]:
|
||||
elif isinstance(pick, HumanTask):
|
||||
waits.append(Waits(issue.key, "it is a human's task"))
|
||||
elif blocking:
|
||||
waits.append(Waits(issue.key, f"{' and '.join(blocking)} block{'s' if len(blocking) == 1 else ''} it"))
|
||||
waits.append(Waits(issue.key, f"{' and '.join(blocking)} block{'s' if len(blocking) == 1 else ''} it" + (f"; do-epic cannot see {' and '.join(outside)}, outside the epic, finish: remove such a link in Jira once its issue is done" if outside else "")))
|
||||
else:
|
||||
found.append(Chunk(issue.key, pick.name if isinstance(pick, Repo) else None))
|
||||
return found, waits
|
||||
@@ -106,7 +107,7 @@ def refusal(repo: str, room: RepoRoom) -> str | None:
|
||||
|
||||
|
||||
def start_chunks(epic: Epic, issues: list[EpicIssue], own: str | None, run: tmux.Tmux) -> Started | Failure:
|
||||
"""Starts a do-epic in a new window for each of the epic's chunks that may start now. own is the issue of the chunk that asks, which has finished: it counts as running nowhere, and no stopped chunk starts again. None is the human's `do-epic <EPIC-KEY>`, which restarts each stopped chunk. A Failure says why a window could not start; those before it run."""
|
||||
"""Starts a do-epic in a new window for each of the epic's chunks that may start now. own is the issue of the chunk that asks, which has finished: it counts as running nowhere, and no stopped chunk starts again. Where own is None, the human's `do-epic <EPIC-KEY>` asks, and each stopped chunk starts again. A Failure says why a window could not start; those before it run."""
|
||||
session = tmux.session_name(tmux.EPIC, epic.key)
|
||||
found, waits = chunks(issues)
|
||||
started: list[str] = []
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import io
|
||||
import json
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -118,11 +120,12 @@ class ACycleOfAChunkWithoutARepo(DoEpicTest):
|
||||
assert not isinstance(config, Failure)
|
||||
store, record = self.backend(config, "ABC-12")
|
||||
epic = main.EpicRun("ABC-12", config, store, record, paths, env or {}, pathlib.Path("/b/do-epic"), fake.effects())
|
||||
root = main.chunk_root(self.issues[1], epic)
|
||||
assert isinstance(root, str)
|
||||
place = main.chunk_root(self.issues[1], epic)
|
||||
assert isinstance(place, tuple)
|
||||
root, in_repo = place
|
||||
loop = Loop(root=root, session=main.session_named("A ABC-12 do-epic ABC-21", paths.claude_code_transcripts), window=tmux.Window("epic-ABC-12", "ABC-21", "%1"), paths=paths, env=env or {}, launcher=pathlib.Path("/b/do-epic"), effects=fake.effects())
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
found = main.next_cycle(LoopRun(1, root, "", "", chunk="ABC-21"), loop, epic)
|
||||
found = main.next_cycle(LoopRun(1, root, "", "", chunk="ABC-21"), loop, in_repo, epic)
|
||||
assert isinstance(found, main.Cycle), found
|
||||
return found
|
||||
|
||||
@@ -175,7 +178,7 @@ class TheHumansRun(DoEpicTest):
|
||||
fake = FakeEffects()
|
||||
code, out, _ = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual(code, 0)
|
||||
self.assertIn("started no chunk in the tmux session epic-ABC-12\n", out)
|
||||
self.assertIn("started no chunk\n", out)
|
||||
self.assertNotIn("attach-session", [args[0] for args in fake.tmux_calls])
|
||||
|
||||
def test_stops_without_its_settings_or_on_a_cap_it_cannot_read(self) -> None:
|
||||
@@ -207,6 +210,31 @@ class TheHumansRun(DoEpicTest):
|
||||
self.assertIn("started ABC-20, ABC-22 in the tmux session epic-ABC-12\n", out)
|
||||
self.assertEqual([args[args.index("-c") + 1] for args in fake.tmux_calls if args[0] in ("new-session", "new-window")], [str(self.home / "code/api"), str(self.home / "code/web")])
|
||||
|
||||
def test_clones_a_missing_repo_from_the_host_of_the_repos_located_before_it(self) -> None:
|
||||
for name in ("api", "web"):
|
||||
configured(self, self.home / "code" / name, home=self.home)
|
||||
shutil.rmtree(self.home / "code/web")
|
||||
self.issues = [issue("ABC-20", "repo:api"), issue("ABC-22", "repo:web")]
|
||||
fake = FakeEffects(on_terminal=False, git=["git@host.example:team/api.git", ""])
|
||||
code, out, err = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("started ABC-20, ABC-22 in the tmux session epic-ABC-12\n", out)
|
||||
clones = [what for seam, what in fake.calls if seam == "git" and "clone" in what]
|
||||
self.assertEqual([what[what.index("--") + 1:] for what in clones], [["git@host.example:team/web", str(self.home / "code/web")]])
|
||||
|
||||
def test_names_a_checkout_as_loop_claude_does_whatever_way_its_config_spells_it(self) -> None:
|
||||
real = self.home / "code" / "api"
|
||||
real.mkdir(parents=True)
|
||||
(self.home / "work").mkdir()
|
||||
(self.home / "work/api").symlink_to(real)
|
||||
configured(self, self.home / "work/api", home=self.home)
|
||||
self.issues = [issue("ABC-20", "repo:api")]
|
||||
fake = FakeEffects(on_terminal=False)
|
||||
code, _, err = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual([args[args.index("-c") + 1] for args in fake.tmux_calls if args[0] == "new-session"], [str(real)])
|
||||
self.assertEqual([args[-2:] for args in fake.tmux_calls if "@chunk-root" in args], [["@chunk-root", str(real)]])
|
||||
|
||||
|
||||
class AChunksRun(DoEpicTest):
|
||||
def worker(self) -> Worker:
|
||||
@@ -231,7 +259,7 @@ class AChunksRun(DoEpicTest):
|
||||
self.assertNotIn("Work the Jira issue", " ".join(streamed[1]))
|
||||
|
||||
def test_every_text_of_a_run_names_do_epic_as_what_drives_it(self) -> None:
|
||||
fake = FakeEffects(streams=[self.worker()] * 3, claude=[judged("unfinished"), judged("interrupt"), judged("finished")], inputs=["Use B."], git=UNREAD)
|
||||
fake = FakeEffects(streams=[self.worker()] * 3, claude=[judged("unfinished", escalation="working"), judged("interrupt"), judged("finished")], inputs=["Use B."], git=UNREAD)
|
||||
code, _, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
prompts = [" ".join(what) for seam, what in fake.calls if seam == "stream_claude"]
|
||||
@@ -244,8 +272,10 @@ class AChunksRun(DoEpicTest):
|
||||
self.assertIn("The human answered your question at do-epic's terminal:\nUse B.", prompts[2])
|
||||
for text in judged_with:
|
||||
self.assertIn("what do-epic told it on [loop] lines, latest last:\n", text)
|
||||
self.assertIn(escalation_mark.asks_higher_rung(chunk_prompt.DRIVER), text)
|
||||
self.assertIn("asking do-epic for a higher rung", text)
|
||||
self.assertIn("do-epic in ", fake.dms[0])
|
||||
self.assertNotIn("\n\n[step] ", judged_with[0])
|
||||
self.assertIn("\n\n[step] do-epic stepped the worker up a rung here", judged_with[1])
|
||||
|
||||
def test_stops_for_the_human_after_six_unfinished_cycles_naming_do_epic(self) -> None:
|
||||
fake = FakeEffects(streams=[self.worker()] * 6, claude=[judged("unfinished")] * 6, git=UNREAD)
|
||||
@@ -280,6 +310,64 @@ class AChunksRun(DoEpicTest):
|
||||
self.assertIn("the chunk finished; started no other\n", out)
|
||||
self.assertIn("Squash every merge.", [what[1] for seam, what in fake.calls if seam == "claude"][0])
|
||||
|
||||
def repo_chunk(self) -> pathlib.Path:
|
||||
"""Makes ABC-20 the one issue, a chunk in the repo api whose checkout holds its premises; the folder of the repo's config."""
|
||||
checkout = self.home / "code" / "api"
|
||||
folder = configured(self, checkout, home=self.home)
|
||||
(checkout / "README.md").write_text("## Goals\nServe the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
|
||||
self.issues = [issue("ABC-20", "repo:api")]
|
||||
return folder
|
||||
|
||||
def test_a_chunk_in_a_repo_routes_on_the_repos_model(self) -> None:
|
||||
folder = self.repo_chunk()
|
||||
models = self.home / ".claude/loop-claude-models.json"
|
||||
models.parent.mkdir(parents=True, exist_ok=True)
|
||||
models.write_text(json.dumps({folder.name: "claude-fable-5-2", "other": "claude-opus-5-5"}), encoding="utf-8")
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, {"TMUX_PANE": "%1"})
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("=== cycle 1, worker on claude-fable-5-2 at low effort ===\n", out)
|
||||
|
||||
def test_a_chunk_in_a_repo_stops_where_the_repos_ladder_or_records_cannot_be_read(self) -> None:
|
||||
folder = self.repo_chunk()
|
||||
(folder / "routing-ladder.json").write_text("[", encoding="utf-8")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], FakeEffects(git=UNREAD), MODELS)
|
||||
self.assertEqual((code, out), (1, ""))
|
||||
self.assertIn(f"{folder / 'routing-ladder.json'}", err.strip().splitlines()[-1])
|
||||
(folder / "routing-ladder.json").unlink()
|
||||
(self.home / "code/api/docs/decisions.md").mkdir(parents=True)
|
||||
fake = FakeEffects(git=UNREAD)
|
||||
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual((code, out), (1, ""))
|
||||
self.assertIn("decisions.md", err.strip().splitlines()[-1])
|
||||
self.assertIn("decisions.md", fake.dms[0])
|
||||
|
||||
def test_an_issue_that_is_a_humans_or_names_no_repo_is_no_chunk(self) -> None:
|
||||
for labels, why in ((("do-epic-human",), "it is a human's task"), ((), "no label names its repo")):
|
||||
with self.subTest(labels):
|
||||
self.issues = [issue("ABC-20", *labels)]
|
||||
fake = FakeEffects(git=UNREAD)
|
||||
code, _, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn(f"ABC-20 is no chunk: {why}\n", err)
|
||||
self.assertEqual([seam for seam, _ in fake.calls if seam == "stream_claude"], [])
|
||||
|
||||
def test_a_chunk_stays_in_its_repo_when_its_labels_change_under_it(self) -> None:
|
||||
self.repo_chunk()
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
|
||||
class Relabelling(Worker):
|
||||
def __call__(inner, *args: object, **kwargs: object) -> object:
|
||||
store.issues[:] = [issue("ABC-20", "do-epic-claude")]
|
||||
return super().__call__(*args, **kwargs)
|
||||
|
||||
worker = Relabelling(paths_from(self.home).claude_code_transcripts.parent)
|
||||
fake = FakeEffects(streams=[worker, self.worker()], claude=[judged("unfinished"), judged("finished")], git=UNREAD)
|
||||
code, _, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("Serve the API.", [what[1] for seam, what in fake.calls if seam == "claude"][1])
|
||||
|
||||
def test_a_chunk_in_a_repo_without_premises_stops(self) -> None:
|
||||
configured(self, self.home / "code" / "api", home=self.home)
|
||||
self.issues = [issue("ABC-20", "repo:api")]
|
||||
@@ -329,7 +417,7 @@ class WhatAWorkerJudgeAndHumanRead(DoEpicTest):
|
||||
self.assertNotIn("Chunk items:", texts[1])
|
||||
# The worker's prompt and the judge's rules word the request for a higher rung alike, from one place.
|
||||
for text in (texts[0], texts[3]):
|
||||
self.assertIn(escalation_mark.asks_higher_rung(chunk_prompt.DRIVER), text)
|
||||
self.assertIn("asking do-epic for a higher rung", text)
|
||||
self.assertEqual(escalation_mark.asks_higher_rung(chunk_prompt.DRIVER), "asking do-epic for a higher rung")
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,13 @@ class TheCapLine(unittest.TestCase):
|
||||
self.assertEqual(parallel_chunks_in("## Goals\nShip.\n"), 1)
|
||||
self.assertEqual(parallel_chunks_in("```\n**Max parallel chunks:** 3\n```\n"), 1)
|
||||
|
||||
def test_refuses_a_line_that_nearly_spells_the_cap(self) -> None:
|
||||
for line in ("**Max parallel chunks**: 2", "Max parallel chunks: 2", "**max parallel chunks:** 2", "- **Max parallel chunks:** 2"):
|
||||
found = parallel_chunks_in(f"## Goals\nShip.\n{line}\n")
|
||||
assert isinstance(found, Failure), line
|
||||
self.assertEqual(found.reason, f"the epic's description holds the line `{line}`, which do-epic doesn't read as the epic's cap: write it as a line of its own, spelt `**Max parallel chunks:** 2`")
|
||||
self.assertEqual(parallel_chunks_in("We raise the max parallel chunks later.\n```\nMax parallel chunks: 2\n```\n"), 1)
|
||||
|
||||
def test_refuses_a_cap_that_is_no_whole_number_of_1_or_more(self) -> None:
|
||||
for value in ("0", "many", "2.5", "-1", ""):
|
||||
found = parallel_chunks_in(f"**Max parallel chunks:** {value}\n")
|
||||
@@ -57,7 +64,7 @@ class WhichIssuesAreChunks(unittest.TestCase):
|
||||
Waits("ABC-20", "no label names its repo"),
|
||||
Waits("ABC-21", "it is a human's task"),
|
||||
Waits("ABC-22", "ABC-22 is labelled with 2 picks: repo:api, repo:web; remove all but the right one"),
|
||||
Waits("ABC-23", "ABC-20 and XYZ-1 block it"),
|
||||
Waits("ABC-23", "ABC-20 and XYZ-1 block it; do-epic cannot see XYZ-1, outside the epic, finish: remove such a link in Jira once its issue is done"),
|
||||
]))
|
||||
|
||||
def test_what_blocks_a_split_item_blocks_its_sub_tasks(self) -> None:
|
||||
@@ -193,7 +200,7 @@ class TheFirstPrompt(unittest.TestCase):
|
||||
self.assertEqual(chunk_prompt.task(issue("ABC-20"), "ABC-12", "/code/api"), "Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout /code/api, on the branch ABC-20. Its summary: Do ABC-20")
|
||||
|
||||
def test_opens_with_the_task_then_the_rung_then_the_premises(self) -> None:
|
||||
rest = f"The issue sets the chunk's scope. The goals below choose between ways to deliver that scope, and never widen it: the epic's first, then code health ({chunk_prompt.CODE_HEALTH}), then the repo's.\n\nFrom P"
|
||||
rest = f"The issue sets the chunk's scope. The goals below choose between ways to deliver that scope, and never widen it. The epic's goals rank first, then code health ({chunk_prompt.CODE_HEALTH}), then the repo's.\n\nFrom P"
|
||||
start = f"T\n\nContinue any open draft PR or worktree for the chunk before creating a new one. {prompts.READING_RULE}\n\n"
|
||||
self.assertEqual(chunk_prompt.fresh("T", "P", Route(Rung("off-the-ladder")), None, ""), start + rest)
|
||||
routed = chunk_prompt.fresh("T", "P", Route(Rung("off-the-ladder"), 21, 3, 5), None, "")
|
||||
|
||||
Reference in New Issue
Block a user