This commit is contained in:
+118
-18
@@ -13,6 +13,8 @@ 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.config import DoEpicConfig
|
||||
from project_config.settings import Epic, Finish
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from agent_cycle import escalation_mark, judge, tmux
|
||||
@@ -77,6 +79,12 @@ class DoEpicTest(unittest.TestCase):
|
||||
self.issues = [issue("ABC-20", "repo:api")]
|
||||
return folder
|
||||
|
||||
def epic_run(self, fake: FakeEffects, env: dict[str, str] | None = None) -> main.EpicRun:
|
||||
config = main.load(self.home)
|
||||
assert not isinstance(config, Failure)
|
||||
store, record = self.backend(config, "ABC-12")
|
||||
return main.EpicRun("ABC-12", config, store, record, paths_from(self.home), env or {}, pathlib.Path("/b/do-epic"), fake.effects())
|
||||
|
||||
def run_main(self, argv: list[str], fake: FakeEffects, env: dict[str, str] | None = None) -> tuple[int, str, str]:
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
@@ -84,6 +92,14 @@ class DoEpicTest(unittest.TestCase):
|
||||
return code, out.getvalue(), err.getvalue()
|
||||
|
||||
|
||||
class TheJiraBackend(unittest.TestCase):
|
||||
def test_reads_the_epic_with_the_credentials_and_the_finish_the_config_names(self) -> None:
|
||||
config = DoEpicConfig(pathlib.Path("/c"), "https://acme.atlassian.net", pathlib.Path("/h/jira.env"), pathlib.Path("/h/code"), "English", "claude-opus-5-5", "rule", Finish("Mark as done", "Done"))
|
||||
store, record = main.jira_backend(config, "ABC-12")
|
||||
self.assertEqual((store.epic, store.env_file, store.finish), (Epic("https://acme.atlassian.net", "ABC-12"), pathlib.Path("/h/jira.env"), Finish("Mark as done", "Done"))) # type: ignore[attr-defined]
|
||||
self.assertEqual((record.description.epic, record.description.env_file), (store.epic, store.env_file)) # type: ignore[attr-defined]
|
||||
|
||||
|
||||
class TheLauncher(unittest.TestCase):
|
||||
def test_the_repo_ships_a_do_epic_that_prints_its_help(self) -> None:
|
||||
launcher = pathlib.Path(__file__).resolve().parents[1] / "do-epic"
|
||||
@@ -139,10 +155,7 @@ class ACycleOfAChunkWithoutARepo(DoEpicTest):
|
||||
def cycle(self, env: dict[str, str] | None = None) -> main.Cycle:
|
||||
fake = FakeEffects(git=[Failure("no git"), Failure("no git")])
|
||||
paths = paths_from(self.home)
|
||||
config = main.load(self.home)
|
||||
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())
|
||||
epic = self.epic_run(fake, env)
|
||||
place = main.chunk_root("ABC-21", self.issues[1], epic)
|
||||
assert isinstance(place, tuple)
|
||||
root, repo = place
|
||||
@@ -207,6 +220,14 @@ class TheHumansRun(DoEpicTest):
|
||||
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_stops_with_the_reason_where_the_epics_issues_cannot_be_read(self) -> None:
|
||||
store = MemoryEpic("ABC-12", fails="Jira answered 503")
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
code, out, err = self.run_main(["ABC-12"], FakeEffects(on_terminal=False))
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("Jira answered 503\n", err)
|
||||
self.assertNotIn("started", out)
|
||||
|
||||
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, ""))
|
||||
@@ -320,6 +341,67 @@ class AChunksRun(DoEpicTest):
|
||||
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_moves_its_issue_to_done_before_the_chunk_it_blocks_starts(self) -> None:
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], self.issues[1], issue("ABC-22", "do-epic-claude", blockers=("ABC-21",))])
|
||||
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, 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.assertEqual({each.key: each.done for each in store.issues}, {"ABC-20": False, "ABC-21": True, "ABC-22": False})
|
||||
self.assertIn("the chunk finished; started ABC-22\n", out)
|
||||
|
||||
def test_a_finished_chunk_counts_as_done_though_the_search_still_shows_its_issue_open(self) -> None:
|
||||
issues = [self.issues[0], self.issues[1], issue("ABC-22", "do-epic-claude", blockers=("ABC-21",))]
|
||||
store = MemoryEpic("ABC-12", issues)
|
||||
store.read = lambda: list(issues) # 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, 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("the chunk finished; started ABC-22\n", out)
|
||||
|
||||
def test_the_last_sub_task_of_a_split_item_to_finish_moves_the_item_to_done_and_starts_what_it_blocks(self) -> None:
|
||||
parent = issue("ABC-21", "split-by-repo")
|
||||
tasks = [issue("ABC-23", "do-epic-claude", parent="ABC-21"), issue("ABC-24", "do-epic-claude", parent="ABC-21", done=True)]
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], parent, *tasks, issue("ABC-22", "do-epic-claude", blockers=("ABC-21",))])
|
||||
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, windows="ABC-23\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-23", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual({each.key: each.done for each in store.issues}, {"ABC-20": False, "ABC-21": True, "ABC-23": True, "ABC-24": True, "ABC-22": False})
|
||||
self.assertIn("the chunk finished; started ABC-22\n", out)
|
||||
|
||||
def test_a_sub_task_that_leaves_another_open_leaves_its_split_item_open(self) -> None:
|
||||
parent = issue("ABC-21", "split-by-repo")
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], parent, issue("ABC-23", "do-epic-claude", parent="ABC-21"), issue("ABC-24", "do-epic-claude", parent="ABC-21")])
|
||||
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, windows="ABC-23\t0\t@9\n")
|
||||
code, _, err = self.run_main(["--chunk", "ABC-23", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual({each.key: each.done for each in store.issues if each.key in ("ABC-21", "ABC-23", "ABC-24")}, {"ABC-21": False, "ABC-23": True, "ABC-24": False})
|
||||
|
||||
def test_a_split_item_that_jira_will_not_move_to_done_stops_with_the_reason(self) -> None:
|
||||
parent = issue("ABC-21", "split-by-repo")
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], parent, issue("ABC-23", "do-epic-claude", parent="ABC-21")])
|
||||
finish = store.finish_issue
|
||||
store.finish_issue = lambda key: Failure("no way to done") if key == "ABC-21" else finish(key) # 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, windows="ABC-23\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-23", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("the chunk finished, but its split item ABC-21 could not move to done: no way to done; once it is done in Jira, run `do-epic ABC-12` to start the chunks it blocks\n", err)
|
||||
self.assertNotIn("started", out)
|
||||
|
||||
def test_a_chunk_whose_issue_jira_will_not_move_to_done_stops_with_the_reason_and_starts_no_other(self) -> None:
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
store.finish_issue = lambda key: Failure("ABC-21's status has no transition to a done status") # 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, out, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("the chunk finished, but its issue could not move to done: ABC-21's status has no transition to a done status; once it is done in Jira, run `do-epic ABC-12` to start the chunks it blocks\n", err)
|
||||
self.assertNotIn("started", 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")])
|
||||
@@ -330,6 +412,12 @@ class AChunksRun(DoEpicTest):
|
||||
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_folder_no_project_config_names_stops_with_gits_reason(self) -> None:
|
||||
stopped = main.chunk_work("ABC-21", str(self.home), "English", self.epic_run(FakeEffects()))
|
||||
assert isinstance(stopped, main.Stop)
|
||||
self.assertEqual(stopped.code, 1)
|
||||
self.assertIn("rev-parse", stopped.reason) # git's reason, since no project config can be found without a checkout
|
||||
|
||||
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)
|
||||
@@ -345,7 +433,9 @@ class AChunksRun(DoEpicTest):
|
||||
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)
|
||||
self.assertIn("the chunk finished; started no other\n", out)
|
||||
self.assertIn("without `--finish`", prompt)
|
||||
self.assertIn("add one bullet to `## Unreleased` in `CHANGELOG.md`", prompt)
|
||||
self.assertIn("the chunk finished; started ABC-12\n", out)
|
||||
judge_prompt = [what[1] for seam, what in fake.calls if seam == "claude"][0]
|
||||
self.assertIn("The records: the epic's scoring and decisions, then the repo's working rules and decisions, then the human's rules for every project:\nFrom the epic ABC-12's description, ## Decisions:\nKeep the v1 endpoints.\n\nFrom AGENTS.md:\nSquash every merge.", judge_prompt)
|
||||
self.assertIn("writing it into the epic's description under ## Decisions, the repo's goals file's Goals or Audience, AGENTS.md, docs/decisions.md, the repo's plan or a comment", judge_prompt)
|
||||
@@ -563,6 +653,26 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
self.assertFalse(self.file.exists())
|
||||
self.assertEqual(len(prompts), 2)
|
||||
|
||||
def test_a_chunk_parks_and_resumes_though_the_epics_issues_cannot_be_read(self) -> None:
|
||||
self.forges = [awaiting(), awaiting(decision="APPROVED")]
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
read = store.read
|
||||
unreadable = [False]
|
||||
worker = self.worker()
|
||||
|
||||
def unreadable_after(*args: object) -> object:
|
||||
unreadable[0] = True
|
||||
return worker(*args) # type: ignore[arg-type]
|
||||
store.read = lambda: Failure("Jira answered 502") if unreadable[0] else read() # type: ignore[method-assign]
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[unreadable_after, self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=lambda seconds: unreadable.__setitem__(0, False)) # type: ignore[method-assign]
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("parked: pull request #7 awaits an approval\ncould not start the next chunk: Jira answered 502\n", out)
|
||||
self.assertFalse(self.file.exists())
|
||||
self.assertEqual(len(prompts), 2)
|
||||
|
||||
def test_a_forge_that_cannot_be_read_parks_no_chunk_and_unparks_none(self) -> None:
|
||||
self.forges = [awaiting(fails="gh pr checks")]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
@@ -606,23 +716,13 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
|
||||
class TheStatus(DoEpicTest):
|
||||
def test_prints_what_each_open_issue_does_and_starts_nothing(self) -> None:
|
||||
self.issues = [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api"), issue("ABC-22", "repo:api"), issue("ABC-23", "repo:api", blockers=("ABC-20",)), issue("ABC-24", "repo:api"), issue("ABC-25", "repo:api", done=True), issue("ABC-26", "repo:api"), issue("ABC-27")]
|
||||
folder = self.home / ".local/state/do-epic/ABC-12"
|
||||
parked.park(folder, parked.Parked("ABC-20", "/code/api-ABC-20", "7", "s", "an approval"))
|
||||
parked.park(folder, parked.Parked("ABC-26", "/code/api-ABC-26", "9", "s", "its checks"))
|
||||
parked.park(folder, parked.Parked("ABC-28", "/code/api-ABC-28", "11", "s", "an approval"))
|
||||
self.issues.insert(7, issue("ABC-28", "repo:api"))
|
||||
fake = FakeEffects(windows="ABC-20 awaits an approval\t0\t@1\nABC-21 ?\t0\t@2\nABC-22\t1\t@3\nABC-28 awaits a slot\t0\t@4\n")
|
||||
self.issues = [issue("ABC-21", "repo:api"), issue("ABC-24", "repo:api"), issue("ABC-27")]
|
||||
fake = FakeEffects(windows="ABC-21 ?\t0\t@2\n")
|
||||
code, out, err = self.run_main(["ABC-12", "--status"], fake)
|
||||
self.assertEqual((code, err), (0, ""))
|
||||
self.assertEqual(out.replace("<1790000000> ", "").splitlines(), [
|
||||
"ABC-20 waits: it is parked: its pull request #7 awaits an approval",
|
||||
"ABC-21 runs",
|
||||
"ABC-22 waits: its window stopped; run `do-epic ABC-12` to start it again",
|
||||
"ABC-23 waits: ABC-20 blocks it",
|
||||
"ABC-21 asks you: answer its question in the tmux window epic-ABC-12:ABC-21",
|
||||
"ABC-24 waits: it has not started; `do-epic ABC-12` starts it once the epic and its repo have room",
|
||||
"ABC-26 waits: it is parked: its pull request #9 awaits its checks, and its window stopped; run `do-epic ABC-12` to start it again",
|
||||
"ABC-28 waits: it is parked: its worker has work again on pull request #11 and awaits a slot",
|
||||
"ABC-27 waits: no label names its repo",
|
||||
])
|
||||
self.assertEqual({args[0] for args in fake.tmux_calls}, {"-V", "list-windows"})
|
||||
|
||||
Reference in New Issue
Block a user