Answer product-owner round 2: 1 🔴, 1 🟡 (0 misread); take a workflow's one done transition whatever the config names, move a split item to done with its last sub-task, count the finished chunk as done in the next start, and read a parent and status together
This commit is contained in:
@@ -154,15 +154,15 @@ class JiraEpic:
|
||||
|
||||
def parent_of(self, key: str, authorization: str, why: str) -> str | None | Failure:
|
||||
"""The key of key's parent issue; None where key isn't an issue key or has no parent. A failed read says "cannot read <key> <why>"."""
|
||||
placed = self.placed(key, authorization, why, "parent")
|
||||
placed = self.placed(key, authorization, why)
|
||||
return placed if isinstance(placed, Failure) else placed[0]
|
||||
|
||||
def placed(self, key: str, authorization: str, why: str, asked: str = "parent,status") -> tuple[str | None, bool] | Failure:
|
||||
"""The key of key's parent issue, None where key isn't an issue key or has no parent, and whether key's own status is a done one; asked names the fields to read, and leaving out `status` makes key read as not done. A failed read says "cannot read <key> <why>"."""
|
||||
def placed(self, key: str, authorization: str, why: str) -> tuple[str | None, bool] | Failure:
|
||||
"""The key of key's parent issue, None where key isn't an issue key or has no parent, and whether key's own status is a done one. A failed read says "cannot read <key> <why>"."""
|
||||
if not ISSUE_KEY.fullmatch(key):
|
||||
return None, False
|
||||
# A search may not show an issue filed a moment ago, so the issue is asked for by its key.
|
||||
answered = self.http("GET", f"{self.epic.site}/rest/api/3/issue/{key}?fields={asked}", authorization, None)
|
||||
answered = self.http("GET", f"{self.epic.site}/rest/api/3/issue/{key}?fields=parent,status", authorization, None)
|
||||
if isinstance(answered, Failure):
|
||||
return Failure(f"cannot read {key} {why}: {answered.reason}")
|
||||
fields = answered.get("fields") if isinstance(answered, dict) else None
|
||||
@@ -217,7 +217,7 @@ def done_transition(offered: object, key: str, named: str | None) -> str | Failu
|
||||
if not isinstance(raw, list) or len(found) != len(raw):
|
||||
return Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents")
|
||||
closing = [(id_, name, status) for id_, name, status, category in found if category == DONE]
|
||||
chosen = [move for move in closing if named is None or move[1] == named]
|
||||
chosen = closing if len(closing) == 1 else [move for move in closing if move[1] == named]
|
||||
if len(chosen) == 1:
|
||||
return chosen[0][0]
|
||||
listed = " and ".join(f"{name!r} to {status!r}" for _, name, status in closing)
|
||||
|
||||
@@ -207,6 +207,12 @@ class Jira(Case):
|
||||
self.assertEqual(self.jira.calls[-1], ("POST", f"{ISSUES}/{key}/transitions"))
|
||||
self.assertEqual(self.jira.transitioned, ["41"])
|
||||
|
||||
def test_finishes_by_the_one_transition_to_a_done_status_whatever_name_the_config_gives(self) -> None:
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.workflow = [{"id": "31", "name": "Resolve", "to": DONE}]
|
||||
self.assertIsNone(JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, "Close").finish(key))
|
||||
self.assertEqual(self.jira.transitioned, ["31"])
|
||||
|
||||
def test_refuses_to_finish_a_sub_task_of_an_issue_that_is_no_child_of_the_epic_or_an_issue_without_a_parent(self) -> None:
|
||||
store = self.new_store()
|
||||
for key, parent in (("ABC-50", "ABC-60"), ("ABC-60", "ABC-61"), ("ABC-61", None)):
|
||||
@@ -241,7 +247,7 @@ class Jira(Case):
|
||||
self.jira.answers[("GET", f"{ISSUES}/{task}?fields=parent,status")] = Failure("Jira answered 503")
|
||||
self.assertEqual(store.finish(task), Failure(f"cannot read {task} to finish it: Jira answered 503"))
|
||||
del self.jira.answers[("GET", f"{ISSUES}/{task}?fields=parent,status")]
|
||||
self.jira.answers[("GET", f"{ISSUES}/{child}?fields=parent")] = Failure("Jira answered 503")
|
||||
self.jira.answers[("GET", f"{ISSUES}/{child}?fields=parent,status")] = Failure("Jira answered 503")
|
||||
self.assertEqual(store.finish(task), Failure(f"cannot read {child} to finish its sub-task: Jira answered 503"))
|
||||
|
||||
def test_reads_the_sub_tasks_of_more_children_than_one_search_names(self) -> None:
|
||||
@@ -314,11 +320,11 @@ class Jira(Case):
|
||||
self.assertEqual(store.read(), Failure("the search for ABC-12's child issues did not end within 1 pages"))
|
||||
|
||||
def test_refuses_to_file_under_another_epics_child_or_an_issue_it_cannot_read(self) -> None:
|
||||
self.jira.issues.append({"key": "ABC-5", "fields": {"parent": {"key": "ABC-1"}}})
|
||||
self.jira.issues.append({"key": "ABC-5", "fields": {"parent": {"key": "ABC-1"}, "status": TO_DO}})
|
||||
store = self.new_store()
|
||||
self.assertEqual(store.file("ABC-5", "Count more.", "", ()), Failure("ABC-5 is neither the epic ABC-12 nor one of its child issues, so nothing can be filed under it"))
|
||||
self.assertEqual(store.file("ABC-77", "Count more.", "", ()), Failure(f"cannot read ABC-77 to file under it: Jira answered 404 for GET {ISSUES}/ABC-77?fields=parent"))
|
||||
self.jira.answers[("GET", f"{ISSUES}/ABC-78?fields=parent")] = ["ABC-12"]
|
||||
self.assertEqual(store.file("ABC-77", "Count more.", "", ()), Failure(f"cannot read ABC-77 to file under it: Jira answered 404 for GET {ISSUES}/ABC-77?fields=parent,status"))
|
||||
self.jira.answers[("GET", f"{ISSUES}/ABC-78?fields=parent,status")] = ["ABC-12"]
|
||||
self.assertEqual(store.file("ABC-78", "Count more.", "", ()), Failure("ABC-78 is neither the epic ABC-12 nor one of its child issues, so nothing can be filed under it"))
|
||||
self.assertEqual([call for call in self.jira.calls if call[0] == "POST" and call[1] == ISSUES], [])
|
||||
|
||||
@@ -343,14 +349,14 @@ class Jira(Case):
|
||||
def test_an_issue_jira_cannot_read_is_not_commented_on(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.answers[("GET", f"{ISSUES}/{key}?fields=parent")] = Failure("Jira answered 500")
|
||||
self.jira.answers[("GET", f"{ISSUES}/{key}?fields=parent,status")] = Failure("Jira answered 500")
|
||||
self.assertEqual(store.comment(str(key), "Hello."), Failure(f"cannot read {key} to comment on it: Jira answered 500"))
|
||||
self.assertNotIn(("POST", f"{ISSUES}/{key}/comment"), self.jira.calls)
|
||||
|
||||
def test_an_issue_jira_cannot_read_is_not_labelled(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.answers[("GET", f"{ISSUES}/{key}?fields=parent")] = Failure("Jira answered 500")
|
||||
self.jira.answers[("GET", f"{ISSUES}/{key}?fields=parent,status")] = Failure("Jira answered 500")
|
||||
self.assertEqual(store.add_label(str(key), "repo:log"), Failure(f"cannot read {key} to label it: Jira answered 500"))
|
||||
self.assertNotIn(("PUT", f"{ISSUES}/{key}"), self.jira.calls)
|
||||
|
||||
|
||||
+18
-9
@@ -6,7 +6,7 @@ import pathlib
|
||||
import typing
|
||||
|
||||
from loop_claude.loop.chunk_start import archived_route, routed
|
||||
from do_epic import chunk_prompt, scheduler
|
||||
from do_epic import chunk_prompt, scheduler, split
|
||||
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
|
||||
@@ -106,7 +106,8 @@ def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher:
|
||||
|
||||
def windows_opened(epic: EpicRun) -> Stop:
|
||||
"""What the do-epic the human runs does: starts each chunk that may start now, says why each other open issue waits, then puts the epic's session on the terminal until the human detaches."""
|
||||
started = chunks_started(epic, None)
|
||||
issues = epic.store.read()
|
||||
started = issues if isinstance(issues, Failure) else chunks_started(epic, issues, 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 "started no chunk", epic.effects, stdout=True)
|
||||
@@ -121,11 +122,8 @@ def windows_opened(epic: EpicRun) -> Stop:
|
||||
return Stop(1, f"`tmux {' '.join(shown)}` failed; the chunks go on in the tmux session") if epic.effects.tmux_on_terminal(shown) else Stop(0, "")
|
||||
|
||||
|
||||
def chunks_started(epic: EpicRun, own: str | None) -> scheduler.Started | Failure:
|
||||
"""scheduler.start_chunks on the epic's issues and cap, read afresh; own is the issue of the chunk that asks."""
|
||||
issues = epic.store.read()
|
||||
if isinstance(issues, Failure):
|
||||
return issues
|
||||
def chunks_started(epic: EpicRun, issues: list[EpicIssue], own: str | None) -> scheduler.Started | Failure:
|
||||
"""scheduler.start_chunks on the epic's issues, as read, and its cap; own is the issue of the chunk that asks."""
|
||||
cap = epic.record.parallel_chunks()
|
||||
if isinstance(cap, Failure):
|
||||
return cap
|
||||
@@ -223,11 +221,22 @@ def chunk_root(issue: EpicIssue, epic: EpicRun) -> tuple[str, bool] | Stop:
|
||||
|
||||
|
||||
def handed_on(key: str, epic: EpicRun) -> Stop:
|
||||
"""The stop of a do-epic whose chunk finished. It first moves the chunk's issue to done, so that no finished chunk starts again and what the issue blocks may start, then starts each chunk that may start now. Its window closes as it exits."""
|
||||
"""The stop of a do-epic whose chunk finished. It first moves the chunk's issue to done, and its split item too where that was the last of the item's sub-tasks, so that no finished chunk starts again and what they block may start, then starts each chunk that may start now. Its window closes as it exits."""
|
||||
moved = epic.store.finish(key)
|
||||
if isinstance(moved, Failure):
|
||||
return Stop(1, f"the chunk finished, but its issue could not move to done: {moved.reason}; once it is done in Jira, run `do-epic {epic.key}` to start the chunks it blocks")
|
||||
started = chunks_started(epic, key)
|
||||
issues = epic.store.read()
|
||||
if isinstance(issues, Failure):
|
||||
return Stop(1, f"the chunk finished, but the next could not start: {issues.reason}")
|
||||
# A search may not show the move yet, so the issue counts as done here whatever the read says.
|
||||
issues = [dataclasses.replace(each, done=True) if each.key == key else each for each in issues]
|
||||
above = next((each.parent for each in issues if each.key == key), "")
|
||||
if not any(each.key == above and each.done for each in issues) and split.finished(issues, above):
|
||||
moved = epic.store.finish(above)
|
||||
if isinstance(moved, Failure):
|
||||
return Stop(1, f"the chunk finished, but its split item {above} could not move to done: {moved.reason}; once it is done in Jira, run `do-epic {epic.key}` to start the chunks it blocks")
|
||||
issues = [dataclasses.replace(each, done=True) if each.key == above else each for each in issues]
|
||||
started = chunks_started(epic, issues, key)
|
||||
if isinstance(started, Failure):
|
||||
return Stop(1, f"the chunk finished, but the next could not start: {started.reason}")
|
||||
say(f"the chunk finished; started {', '.join(started.started) or 'no other'}", epic.effects, stdout=True)
|
||||
|
||||
@@ -302,6 +302,48 @@ class AChunksRun(DoEpicTest):
|
||||
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
|
||||
store.finish = 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 = lambda key: Failure("ABC-21's status has no transition to a done status") # type: ignore[method-assign]
|
||||
|
||||
Reference in New Issue
Block a user