Stop a chunk whose epic lacks Goals or Audience, and test do-epic's run end to end
This commit is contained in:
+143
-1
@@ -9,11 +9,12 @@ import unittest
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic import chunk_prompt, main
|
||||
from project_config.test_project_config import configured
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from agent_cycle import escalation_mark, judge, tmux
|
||||
from failure import Failure
|
||||
from loop_claude.test_loop_claude import FakeEffects
|
||||
from loop_claude.test_loop_claude import FakeEffects, judged, Worker
|
||||
from do_epic.test_scheduler import issue
|
||||
from loop_claude.loop.this_loop import Loop
|
||||
from loop_claude.loop.reload import LoopRun
|
||||
@@ -140,6 +141,147 @@ class ACycleOfAChunkWithoutARepo(DoEpicTest):
|
||||
self.assertEqual(cycle.route, Route(cycle.project.rung))
|
||||
|
||||
|
||||
UNREAD = [Failure("no git")] * 20
|
||||
MODELS = {"LOOP_CLAUDE_JUDGE_MODEL": "claude-opus-5-5", "LOOP_CLAUDE_WORKER_MODEL": "claude-opus-5-5", "TMUX_PANE": "%1"}
|
||||
|
||||
|
||||
class TheHumansRun(DoEpicTest):
|
||||
def test_shows_the_session_on_a_terminal_and_says_when_tmux_cannot(self) -> None:
|
||||
fake = FakeEffects(windows="ABC-21\t0\t@9\n")
|
||||
self.assertEqual(self.run_main(["ABC-12"], fake)[0], 0)
|
||||
self.assertEqual(fake.tmux_calls[-1], ["attach-session", "-t", "=epic-ABC-12"])
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, tmux_on_terminal=lambda args: 1) # type: ignore[method-assign]
|
||||
code, _, err = self.run_main(["ABC-12"], fake, {"TMUX": "/tmp/tmux"})
|
||||
self.assertEqual((code, err.split(" ", 1)[1]), (1, "`tmux switch-client -t =epic-ABC-12` failed; the chunks go on in the tmux session\n"))
|
||||
|
||||
def test_off_a_terminal_it_says_how_to_see_the_chunks(self) -> None:
|
||||
code, out, err = self.run_main(["ABC-12"], FakeEffects(on_terminal=False, windows="ABC-21\t0\t@9\n"))
|
||||
self.assertEqual((code, err), (0, ""))
|
||||
self.assertIn("not on a terminal; see the chunks with `tmux attach -t =epic-ABC-12`\n", out)
|
||||
|
||||
def test_with_no_window_in_the_session_it_shows_none(self) -> None:
|
||||
self.issues = self.issues[:1]
|
||||
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.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:
|
||||
self.description = "**Max parallel chunks:** many\n"
|
||||
code, _, err = self.run_main(["ABC-12"], FakeEffects())
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("`**Max parallel chunks:** many`, which is not a whole number of 1 or more", err)
|
||||
(self.home / ".claude-projects/do-epic/config.toml").unlink()
|
||||
code, out, err = self.run_main(["ABC-12"], FakeEffects())
|
||||
self.assertEqual((code, out), (1, ""))
|
||||
self.assertIn("config.toml", err)
|
||||
|
||||
def test_an_interrupt_from_the_keyboard_ends_it_quietly_and_a_crash_is_sent_on(self) -> None:
|
||||
fake = FakeEffects()
|
||||
fake.tmux = lambda args: (_ for _ in ()).throw(KeyboardInterrupt()) # type: ignore[method-assign]
|
||||
self.assertEqual(self.run_main(["ABC-12"], fake), (130, "", ""))
|
||||
fake.tmux = lambda args: (_ for _ in ()).throw(ValueError("boom")) # type: ignore[method-assign]
|
||||
with self.assertRaises(ValueError):
|
||||
self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual(fake.dms, ["do-epic ABC-12 crashed: ValueError('boom')"])
|
||||
|
||||
def test_starts_each_chunk_in_its_repos_checkout(self) -> None:
|
||||
for name in ("api", "web"):
|
||||
configured(self, self.home / "code" / name, home=self.home)
|
||||
self.issues = [issue("ABC-20", "repo:api"), issue("ABC-22", "repo:web")]
|
||||
fake = FakeEffects(on_terminal=False)
|
||||
code, out, _ = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual(code, 0)
|
||||
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")])
|
||||
|
||||
|
||||
class AChunksRun(DoEpicTest):
|
||||
def worker(self) -> Worker:
|
||||
return Worker(paths_from(self.home).claude_code_transcripts.parent)
|
||||
|
||||
def test_runs_cycles_until_the_judge_rules_it_finished_then_starts_the_next_chunk(self) -> None:
|
||||
self.issues.append(issue("ABC-22", "do-epic-claude"))
|
||||
self.description = DESCRIPTION.replace("2", "1")
|
||||
fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("unfinished"), judged("finished")], git=UNREAD, windows="ABC-21\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("=== cycle 1, worker on claude-", out)
|
||||
self.assertIn("=== cycle 2, worker on claude-", out)
|
||||
self.assertNotIn("=== cycle 3", out)
|
||||
self.assertIn("the chunk finished; started ABC-22\n", out)
|
||||
self.assertEqual(fake.dms, [])
|
||||
archive = self.home / ".claude/do-epic-transcripts/ABC-12"
|
||||
self.assertTrue(any(archive.iterdir()))
|
||||
self.assertFalse((self.home / ".claude/loop-claude-transcripts").exists())
|
||||
streamed = [what for seam, what in fake.calls if seam == "stream_claude"]
|
||||
self.assertIn("Work the Jira issue ABC-21 of the epic ABC-12 as one chunk", " ".join(streamed[0]))
|
||||
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)
|
||||
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"]
|
||||
judged_with = [" ".join(what[0]) + (what[1] or "") for seam, what in fake.calls if seam == "claude"]
|
||||
self.assertEqual((len(prompts), len(judged_with)), (3, 3))
|
||||
for text in (*prompts, *judged_with, *fake.dms, *[str(what) for seam, what in fake.calls if seam == "input"]):
|
||||
self.assertNotIn("loop-claude", text)
|
||||
self.assertNotIn("None", text)
|
||||
self.assertIn(" do-epic runs you on claude-", prompts[1])
|
||||
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("do-epic in ", fake.dms[0])
|
||||
|
||||
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)
|
||||
code, out, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 2, out)
|
||||
self.assertIn("the judge ruled it unfinished 6 cycles running; finish the chunk yourself, or rerun do-epic to give it 6 more cycles", err + out)
|
||||
|
||||
def test_a_finished_chunk_says_why_the_next_could_not_start(self) -> None:
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
reads = iter([self.issues, self.issues, Failure("Jira answered 503")])
|
||||
store.read = lambda: next(reads) # type: ignore[method-assign]
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
code, _, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("the chunk finished, but the next could not start: Jira answered 503\n", err)
|
||||
|
||||
def test_a_chunk_in_a_repo_works_in_its_checkout_on_the_repos_premises_and_records(self) -> None:
|
||||
checkout = self.home / "code" / "api"
|
||||
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 = [dataclasses.replace(issue("ABC-20", "repo:api"), scores={"L": 2, "E": 1, "I": 1})]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
prompt = " ".join([what for seam, what in fake.calls if seam == "stream_claude"][0])
|
||||
self.assertIn(f"Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout {checkout}, on the branch ABC-20.", prompt)
|
||||
self.assertIn("Ship the import.", prompt)
|
||||
self.assertIn("The repo's goals, which rank after the epic's and after code health, are from", prompt)
|
||||
self.assertIn("Serve the API.", prompt)
|
||||
|
||||
def test_a_chunk_whose_repo_or_premises_cannot_be_read_stops(self) -> None:
|
||||
self.issues = [issue("ABC-20", "repo:api"), issue("ABC-23", "repo:api", "repo:web")]
|
||||
code, _, err = self.run_main(["--chunk", "ABC-23", "ABC-12"], FakeEffects(), MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("ABC-23 is labelled with 2 picks", err)
|
||||
self.issues = [self.issues[0]]
|
||||
code, _, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], FakeEffects(git=UNREAD), MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("api", err)
|
||||
self.issues = [issue("ABC-21", "do-epic-claude")]
|
||||
self.description = "## Goals\nShip.\n"
|
||||
code, _, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], FakeEffects(git=UNREAD), MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("the epic ABC-12's description has no text under a `## Audience` heading - no premises.\n", err)
|
||||
|
||||
|
||||
class WhatAWorkerJudgeAndHumanRead(DoEpicTest):
|
||||
def test_every_prompt_names_do_epic_and_never_loop_claude(self) -> None:
|
||||
cycle = ACycleOfAChunkWithoutARepo.cycle(self) # type: ignore[arg-type]
|
||||
|
||||
Reference in New Issue
Block a user