Merge remote-tracking branch 'origin/main' into item-501
CI / tests (pull_request) Has been cancelled

This commit is contained in:
2026-11-21 03:37:59 +01:00
20 changed files with 356 additions and 64 deletions
+22
View File
@@ -16,6 +16,9 @@ class EpicStoreContract:
assertIsNone: typing.Callable[..., None]
subTest: typing.Callable[..., typing.ContextManager[None]]
# The name of a transition the tracker offers an open issue, which leads to the done status "Done".
transition = "Done"
def new_store(self) -> EpicStore:
raise NotImplementedError
@@ -193,6 +196,25 @@ class EpicStoreContract:
self.assertIsInstance(store.move_issue("ZZZ-1", "Done"), Failure)
self.assertEqual([issue.status for issue in self.issues(store)], ["To Do"])
def test_moves_a_child_issue_or_a_sub_task_by_the_transition_named_and_answers_the_status_it_leads_to(self) -> None:
store = self.new_store()
child = self.filed(store, store.epic_key, "Count the runs.")
task = self.filed(store, child, "Count them in the api.")
self.assertEqual([store.move_issue_by(task, self.transition, ("Done",)), store.move_issue_by(child, self.transition, ("Done",))], ["Done", "Done"])
self.assertEqual({issue.key: (issue.status, issue.done) for issue in self.issues(store)}, {child: ("Done", True), task: ("Done", True)})
def test_leaves_an_issue_already_at_a_status_asked_for_where_it_is(self) -> None:
store = self.new_store()
child = self.filed(store, store.epic_key, "Count the runs.")
self.assertEqual(store.move_issue_by(child, self.transition, ("Done",)), "Done")
self.assertEqual(store.move_issue_by(child, "Release Ready", ("done",)), "Done")
def test_refuses_to_move_an_issue_outside_the_epic_by_a_transition(self) -> None:
store = self.new_store()
self.filed(store, store.epic_key, "Count the runs.")
self.assertIsInstance(store.move_issue_by("ZZZ-1", self.transition, ("Done",)), Failure)
self.assertEqual([issue.status for issue in self.issues(store)], ["To Do"])
def test_finishes_a_sub_task_of_a_child_issue_and_leaves_its_parent_open(self) -> None:
store = self.new_store()
child = self.filed(store, store.epic_key, "Count the runs.")
+13
View File
@@ -126,6 +126,19 @@ class MemoryEpic:
self.writes.append(f"move {key} to {status}")
return None
def move_issue_by(self, key: str, transition: str, to: tuple[str, ...]) -> str | Failure:
# The fake holds no workflow, so it cannot tell where a transition leads: each leads to the first status asked for.
if self.fails:
return Failure(self.fails)
issue = self.within(key)
if issue is None:
return no_child(self.epic_key, key, "moved")
if issue.status.casefold() in {name.casefold() for name in to}:
return issue.status
self.change(key, status=to[0], done=to[0].casefold() == "done")
self.writes.append(f"move {key} by {transition}")
return to[0]
def finish_issue(self, key: str) -> None | Failure:
if self.fails:
return Failure(self.fails)
+8 -1
View File
@@ -10,7 +10,7 @@ from project_config.settings import DEFAULT_ISSUE_TYPE, Epic, Finish, JIRA_FINDI
from atlassian.jira import DONE, entry_of, finishing_transition, ISSUE_KEY, issue_type_refusal, issue_types_of, MAX_PAGES, move_refusal, PERHAPS_FILED, PERHAPS_MOVED, project_of, rank_refusal, searched, SHAPE, status_category, unshaped
from do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_scores, no_words, unfit, unfit_label
from failure import Failure
from do_epic.backend.jira_status import moved_to
from do_epic.backend.jira_status import moved_by, moved_to
from plan.todo_table import MOVES
from do_epic.repo_pick import REVIEW_LABEL
from do_epic.backend.jira_start import Start, started
@@ -215,6 +215,13 @@ class JiraEpic:
within = self.within(key, authorization, "move", "moved")
return within if isinstance(within, Failure) else moved_to(self.epic.site, key, status, authorization, self.http)
def move_issue_by(self, key: str, transition: str, to: tuple[str, ...]) -> str | Failure:
authorization = basic_auth(self.env_file)
if isinstance(authorization, Failure):
return authorization
within = self.within(key, authorization, "move", "moved")
return within if isinstance(within, Failure) else moved_by(self.epic.site, key, transition, to, authorization, self.http)
def finish_issue(self, key: str) -> None | Failure:
authorization = basic_auth(self.env_file)
if isinstance(authorization, Failure):
+33 -4
View File
@@ -1,4 +1,4 @@
"""Moves a Jira issue to a status by name, for a team whose own automation doesn't see the move's cause, such as a pull request into an epic's working branch."""
"""Moves a Jira issue to a named status, or through a named transition, for a team whose own automation doesn't see the move's cause, such as a pull request into an epic's working branch."""
import typing
from failure import Failure
@@ -6,15 +6,22 @@ from atlassian.client import Http
from atlassian.jira import offers_of, unshaped
def moved_to(site: str, key: str, status: str, authorization: str, http: Http) -> Failure | None:
"""Moves the issue named key to the status named status, in upper or lower case, by the first transition to that status the issue's workflow offers. An issue already there stays as it is. Why Jira did not take the move; None where the issue has the status."""
def status_of(site: str, key: str, authorization: str, http: Http) -> str | Failure:
"""The name of the status the issue named key has now, read from the issue itself, since a search may lag behind a move."""
answered: typing.Any = http("GET", f"{site}/rest/api/3/issue/{key}?fields=status", authorization, None)
if isinstance(answered, Failure):
return Failure(f"cannot read {key} to move it: {answered.reason}")
try:
now = str(answered["fields"]["status"]["name"])
return str(answered["fields"]["status"]["name"])
except (KeyError, TypeError) as failure:
return Failure(unshaped(key, failure))
def moved_to(site: str, key: str, status: str, authorization: str, http: Http) -> Failure | None:
"""Moves the issue named key to the status named status, in upper or lower case, by the first transition to that status the issue's workflow offers. An issue already there stays as it is. Why Jira did not take the move; None where the issue has the status."""
now = status_of(site, key, authorization, http)
if isinstance(now, Failure):
return now
if now.casefold() == status.casefold():
return None
offered = http("GET", f"{site}/rest/api/3/issue/{key}/transitions", authorization, None)
@@ -29,3 +36,25 @@ def moved_to(site: str, key: str, status: str, authorization: str, http: Http) -
return Failure(f"{key} has no transition to the status {status!r} from its status {now!r}, " + (f"only {others}" if offers else "nor any other the account may make"))
moved = http("POST", f"{site}/rest/api/3/issue/{key}/transitions", authorization, {"transition": {"id": leading[0]}})
return Failure(f"cannot move {key} to {status!r}: {moved.reason}") if isinstance(moved, Failure) else None
def moved_by(site: str, key: str, transition: str, to: tuple[str, ...], authorization: str, http: Http) -> str | Failure:
"""Moves the issue named key by the transition named transition, where that transition leads to one of the statuses to. Names match in upper or lower case. An issue already at one of those statuses stays as it is. The name of the status the issue has afterwards; why the move was not made."""
accepted = {name.casefold() for name in to}
now = status_of(site, key, authorization, http)
if isinstance(now, Failure) or now.casefold() in accepted:
return now
offered = http("GET", f"{site}/rest/api/3/issue/{key}/transitions", authorization, None)
if isinstance(offered, Failure):
return Failure(f"cannot read {key}'s transitions: {offered.reason}")
offers = offers_of(offered, key)
if isinstance(offers, Failure):
return offers
named = [(id_, to) for id_, name, to, _ in offers if name.casefold() == transition.casefold()]
if not named:
others = " and ".join(f"{name!r} to {to!r}" for _, name, to, _ in offers)
return Failure(f"{key} has no transition {transition!r} from its status {now!r}, " + (f"only {others}" if offers else "nor any other the account may make"))
if named and named[0][1].casefold() not in accepted:
return Failure(f"the transition {transition!r} leads {key} to the status {named[0][1]!r}, not to {' or '.join(repr(name) for name in to)}")
moved = http("POST", f"{site}/rest/api/3/issue/{key}/transitions", authorization, {"transition": {"id": named[0][0]}})
return Failure(f"cannot move {key} by {transition!r}: {moved.reason}") if isinstance(moved, Failure) else named[0][1]
+3
View File
@@ -73,6 +73,9 @@ class EpicStore(typing.Protocol):
def move_issue(self, key: str, status: str) -> None | Failure:
"""Moves the epic's child issue named key, or a sub-task of one, to the status named status, in upper or lower case; one already there stays as it is. An issue outside the epic is refused. A Failure says why the move could not be made, such as a workflow that gives no way from the issue's status to that one."""
def move_issue_by(self, key: str, transition: str, to: tuple[str, ...]) -> str | Failure:
"""Moves the epic's child issue named key, or a sub-task of one, by the workflow transition named transition, where that transition leads to one of the statuses to. Names match in upper or lower case. An issue already at one of those statuses stays as it is. Answers the name of the status the issue has afterwards. An issue outside the epic is refused. A Failure says why the move was not made, such as a workflow that offers the issue no transition of that name from its status, or a transition that leads to another status."""
def finish_issue(self, key: str) -> None | Failure:
"""Moves the epic's child issue named key, or a sub-task of one, to a done status, so that read answers it as done; one already done stays as it is. An issue outside the epic is refused. A Failure says why the move could not be made: the issue's workflow gives no way to a done status, gives several the backend cannot choose between, or refuses the move."""
+50
View File
@@ -190,6 +190,8 @@ class Case(unittest.TestCase):
class JiraEpicContract(Case, EpicStoreContract):
transition = "Mark as done"
def assign(self, store: JiraEpic, key: str, name: str) -> None: # type: ignore[override]
self.jira.change(key, assignee={"accountId": "5b10a2844c20165700ede21g", "displayName": name})
@@ -407,6 +409,54 @@ class Jira(Case):
self.assertIsNone(store.move_issue(key, "Code Review"))
self.assertEqual(self.jira.transitioned, ["51"])
def test_moves_an_issue_by_the_transition_named_in_any_case_and_answers_the_status_it_leads_to(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
ready = {"name": "Release Ready", "statusCategory": {"key": "indeterminate"}}
self.jira.workflow = [{"id": "31", "name": "Mark as done", "to": DONE}, {"id": "61", "name": "Ready for release", "to": ready}]
self.assertEqual(store.move_issue_by(key, "ready for release", ("Teach & Learn", "RELEASE READY")), "Release Ready")
self.assertEqual((self.jira.transitioned, self.jira.issues[0]["fields"]["status"]), (["61"], ready)) # type: ignore[index]
def test_an_issue_already_at_a_status_the_transition_may_lead_to_stays_as_it_is(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
self.jira.issues[0]["fields"]["status"] = {"name": "Release Ready", "statusCategory": {"key": "indeterminate"}} # type: ignore[index]
self.assertEqual(store.move_issue_by(key, "Mark as done", ("Done", "release ready")), "Release Ready")
self.assertEqual(self.jira.transitioned, [])
def test_a_transition_that_leads_to_another_status_than_those_asked_for_is_not_made(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
self.assertEqual(store.move_issue_by(key, "Mark as done", ("Release Ready", "Teach & Learn")), Failure(f"the transition 'Mark as done' leads {key} to the status 'Done', not to 'Release Ready' or 'Teach & Learn'"))
self.assertEqual(self.jira.transitioned, [])
def test_a_transition_the_workflow_does_not_offer_fails_naming_what_it_offers(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
self.assertEqual(store.move_issue_by(key, "Release Ready", ("Release Ready",)), Failure(f"{key} has no transition 'Release Ready' from its status 'To Do', only 'Mark as done' to 'Done'"))
self.jira.workflow.append({"id": "11", "name": "Start", "to": {"name": "In Progress", "statusCategory": {"key": "indeterminate"}}})
self.assertEqual(store.move_issue_by(key, "Release Ready", ("Release Ready",)), Failure(f"{key} has no transition 'Release Ready' from its status 'To Do', only 'Mark as done' to 'Done' and 'Start' to 'In Progress'"))
self.jira.workflow = []
self.assertEqual(store.move_issue_by(key, "Release Ready", ("Release Ready",)), Failure(f"{key} has no transition 'Release Ready' from its status 'To Do', nor any other the account may make"))
self.assertEqual(self.jira.transitioned, [])
def test_a_move_by_a_transition_that_jira_refuses_or_cannot_be_read_fails_with_the_reason(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
self.jira.issues.append({"key": "ABC-61", "fields": {"summary": "Other.", "description": None, "labels": [], "assignee": None, "status": TO_DO, "parent": None, "issuelinks": []}})
self.assertEqual(store.move_issue_by("ABC-61", "Mark as done", ("Done",)), Failure("ABC-61 is not one of the child issues of the epic ABC-12, so it cannot be moved"))
transitions = f"{ISSUES}/{key}/transitions"
self.jira.answers = {("POST", transitions): Failure("Jira answered 400")}
self.assertEqual(store.move_issue_by(key, "Mark as done", ("Done",)), Failure(f"cannot move {key} by 'Mark as done': Jira answered 400"))
self.jira.answers = {("GET", transitions): Failure("Jira answered 503")}
self.assertEqual(store.move_issue_by(key, "Mark as done", ("Done",)), Failure(f"cannot read {key}'s transitions: Jira answered 503"))
self.jira.answers = {("GET", transitions): {"transitions": [{"id": "31"}]}}
self.assertEqual(store.move_issue_by(key, "Mark as done", ("Done",)), Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents"))
self.jira.answers = {("GET", f"{ISSUES}/{key}?fields=parent,status"): Failure("Jira answered 503")}
self.assertEqual(store.move_issue_by(key, "Mark as done", ("Done",)), Failure(f"cannot read {key} to move it: Jira answered 503"))
self.jira.answers = {("GET", f"{ISSUES}/{key}?fields=status"): Failure("Jira answered 502")}
self.assertEqual(store.move_issue_by(key, "Mark as done", ("Done",)), Failure(f"cannot read {key} to move it: Jira answered 502"))
def test_a_move_the_workflow_does_not_offer_fails_naming_what_it_offers(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
+9 -6
View File
@@ -55,9 +55,10 @@ AUTOMATION_MOVES = "jira-automation-moves-issues"
# Three readers, seated as those who write and read this config, picked `jira-pull-request-open-status` from four candidates, 2-1, and the merged status's name was spelt to pair with it. Each names a status, not a transition as `jira-start-transition` does: do-epic takes whichever transition leads there.
PULL_OPEN_STATUS = "jira-pull-request-open-status"
PULL_MERGED_STATUS = "jira-pull-request-merged-status"
SUB_TASKS_LANDED_TRANSITION = "jira-sub-tasks-landed-transition"
SUB_TASK_SUMMARY = "sub-task-summary"
ISSUE_TYPES = (JIRA_FINDING_TYPE, JIRA_REVIEW_TYPE)
OPTIONAL = (CLONE_FOLDER, LANGUAGE, *JIRA_FINISH, START_TRANSITION, SPRINT_BOARD, UNBLOCKING_STATUSES, AUTOMATION_MOVES, PULL_OPEN_STATUS, PULL_MERGED_STATUS, LABEL_REPOS, SUB_TASK_SUMMARY, *ISSUE_TYPES)
OPTIONAL = (CLONE_FOLDER, LANGUAGE, *JIRA_FINISH, START_TRANSITION, SPRINT_BOARD, UNBLOCKING_STATUSES, AUTOMATION_MOVES, PULL_OPEN_STATUS, PULL_MERGED_STATUS, SUB_TASKS_LANDED_TRANSITION, LABEL_REPOS, SUB_TASK_SUMMARY, *ISSUE_TYPES)
LISTED = f"The settings are {', '.join(SETTINGS)}, and optionally {listed(OPTIONAL, 'and')}."
@@ -86,6 +87,8 @@ class DoEpicConfig:
finding_type: str = DEFAULT_ISSUE_TYPE
review_type: str = DEFAULT_ISSUE_TYPE
start: Start = Start()
# The SUB_TASKS_LANDED_TRANSITION transition, which `parent_moves` moves a parent by; None where the config doesn't name it.
sub_tasks_landed_transition: str | None = None
def label_repo_faults(table: object) -> list[str]:
@@ -127,12 +130,12 @@ def start_faults(values: dict[str, object]) -> list[str]:
]
def pull_status_faults(values: dict[str, object]) -> list[str]:
"""What is wrong with the PULL_OPEN_STATUS and PULL_MERGED_STATUS settings in values."""
def jira_name_faults(values: dict[str, object]) -> list[str]:
"""What is wrong with the PULL_OPEN_STATUS, PULL_MERGED_STATUS and SUB_TASKS_LANDED_TRANSITION settings in values."""
merged, unblocking = name_of(values.get(PULL_MERGED_STATUS)), values.get(UNBLOCKING_STATUSES, [])
listed_statuses = [status.casefold() for status in unblocking if isinstance(status, str)] if isinstance(unblocking, list) else []
return [
*(f"`{name}` is {values[name]!r}, not the name Jira shows, such as \"{example}\"" for name, example in ((PULL_OPEN_STATUS, "Code Review"), (PULL_MERGED_STATUS, "Release Ready")) if name in values and not name_of(values[name])),
*(f"`{name}` is {values[name]!r}, not the name Jira shows, such as \"{example}\"" for name, example in ((PULL_OPEN_STATUS, "Code Review"), (PULL_MERGED_STATUS, "Release Ready"), (SUB_TASKS_LANDED_TRANSITION, "Release Ready")) if name in values and not name_of(values[name])),
*([f"`{PULL_MERGED_STATUS}` is {merged!r}, so `{UNBLOCKING_STATUSES}` must list it: an issue at any other status reads as open, and its chunk would start again"] if merged and merged.casefold() not in listed_statuses else []),
]
@@ -180,7 +183,7 @@ def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfi
*finish_faults(values),
*workflow_faults(values),
*start_faults(values),
*pull_status_faults(values),
*jira_name_faults(values),
*(summary_template_faults(values[SUB_TASK_SUMMARY]) if SUB_TASK_SUMMARY in values else []),
*label_repo_faults(values.get(LABEL_REPOS, {})),
*(f"`{name}` is {values[name]!r}, {fault}" for name, example in zip(ISSUE_TYPES, ("Feature", "Chore")) if name in values and (fault := type_fault(values[name], example))),
@@ -199,4 +202,4 @@ def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfi
finding_type, review_type = (str(values.get(name, DEFAULT_ISSUE_TYPE)) for name in ISSUE_TYPES)
board = values.get(SPRINT_BOARD)
assert board is None or isinstance(board, int)
return DoEpicConfig(folder, url, env_file, clone_folder, language, model, rule, finish_of(values), types.MappingProxyType(labels), tuple(statuses), values.get(AUTOMATION_MOVES) is True, name_of(values.get(PULL_OPEN_STATUS)), name_of(values.get(PULL_MERGED_STATUS)), template, finding_type, review_type, Start(name_of(values.get(START_TRANSITION)), board))
return DoEpicConfig(folder, url, env_file, clone_folder, language, model, rule, finish_of(values), types.MappingProxyType(labels), tuple(statuses), values.get(AUTOMATION_MOVES) is True, name_of(values.get(PULL_OPEN_STATUS)), name_of(values.get(PULL_MERGED_STATUS)), template, finding_type, review_type, Start(name_of(values.get(START_TRANSITION)), board), name_of(values.get(SUB_TASKS_LANDED_TRANSITION)))
+22 -7
View File
@@ -1,6 +1,6 @@
"""The do-epic command (docs/decisions.md → `do-epic: drives one Jira epic …`).
`do-epic <EPIC-KEY>` first plans the epic's open issues (`planning`): each that no label places is split by repo or gets its pick, and the scored issues do-epic filed are re-ranked. Then it 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. The window of a human's task runs no cycle: it waits until the task no longer holds up an issue (`human_tasks`), then does the same.
`do-epic <EPIC-KEY>` first plans the epic's open issues (`planning`): each that no label places is split by repo or gets its pick, and the scored issues do-epic filed are re-ranked. Then it moves each parent whose sub-tasks a person filed, where those sub-tasks have landed or are done (`parent_moves`). Then it 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. The window of a human's task runs no cycle: it waits until the task no longer holds up an issue (`human_tasks`), then does the same.
After each cycle of a chunk in a repo, the window reads what the chunk's pull request waits on (`gates`). While that is a gate only time or a person passes, the chunk is parked (`parked`): the window frees its running slot and polls the forge, and the chunk's next cycle starts once the worker has something to do and a slot is free. `do-epic <EPIC-KEY> --status` prints what each open issue does."""
import dataclasses
@@ -11,7 +11,7 @@ import typing
from chunk_driver.cycle_start import announced_route, cycle_of, project_routing, routing_on
from chunk_driver.claims import CHUNK_FLAG
from do_epic import chunk_prompt, dry_run, findings, finish, gates, human_tasks, parked, planning, scheduler, split, status
from do_epic import chunk_prompt, dry_run, findings, finish, gates, human_tasks, parent_moves, parked, planning, scheduler, split, status
from chunk_driver.chunk_run import ChunkRun, closed_cycle
from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo
from project_config.main import located as config_located
@@ -53,7 +53,7 @@ Before it starts chunks, do-epic <EPIC-KEY> plans each open issue that has none
`repo:<name>` for its repo, `do-epic-claude` for work of Claude's that changes no repo, `do-epic-human` for a task of yours.
A label that `[label-repos]` in config.toml maps to a repo counts as that repo's.
Where such an issue changes several repos, it files a sub-task per repo. Otherwise it gives the issue its label, as repo-rule.md says.
An issue under which a person filed a sub-task is not planned: its sub-tasks run, each needs a label of its own, and you close the issue in Jira.
An issue under which a person filed a sub-task is not planned: its sub-tasks run, each needs a label of its own, and do-epic moves the issue once they have landed or are done, as config.toml names how.
Where the rule leaves the label unclear, it asks you on the terminal. Answer with the label, or with Enter alone to leave the issue waiting.
Where two or more issues may start, it then scores each of them that holds no scores, and tells the issue's team the scores in a comment on the issue. It scores by the `Score = ...` line under the epic's ## Scoring, and moves the issues do-epic itself filed into that order on the board.
An open issue labelled `repo:<name>` or `do-epic-claude` runs as a chunk once no issue blocks it.
@@ -67,7 +67,7 @@ on once the checks pass, the approval comes or a reviewer comments, and a place
name says `awaits a slot`. In a repo whose config sets `merge = "human"`, a chunk never merges: once its pull
request is ready, with nothing else to wait on, the window's name says `awaits your merge`, and its worker goes on once you merged it. A parked chunk survives a reboot: run do-epic <EPIC-KEY> again to go on polling.
--status doesn't start any chunk. It prints a line per open issue: that its chunk runs or asks you a question, or why it waits, such as the gate a parked chunk awaits and since when.
--dry-run runs the planning and the scheduling against the epic as Jira holds it. It doesn't write anything to Jira, start a window or ask a question, and it doesn't start any issue in Jira as a real run's chunk does. It prints each label, sub-task, comment, score and rank move that planning would write, the order the issues would start in, each chunk that would start and why each other issue waits. A sub-task not yet filed shows a key such as ABC-new1. A question planning would ask is printed instead of asked. Planning's claude calls still run.
--dry-run runs the planning and the scheduling against the epic as Jira holds it. It doesn't write anything to Jira, start a window or ask a question, and it doesn't start any issue in Jira as a real run's chunk does. It prints each label, sub-task, comment, score and rank move that planning would write, each move of a parent issue whose sub-tasks a person filed, the order the issues would start in, each chunk that would start and why each other issue waits. A sub-task not yet filed shows a key such as ABC-new1. A question planning would ask is printed instead of asked. Planning's claude calls still run.
A repo that is missing isn't cloned. Planning then stops there, so its writes are only those made before it, and the issues of that repo wait, and a chunk of another repo may start in the place a real run gives them; a real run would clone it and go on.
{findings.HELP}
{finish.HELP}
@@ -195,7 +195,9 @@ def planned_and_started(epic: EpicRun, dry: bool = False) -> scheduler.Started |
read = epic.store.read()
if isinstance(read, Failure):
return Stop(1, read.reason)
issues, stopped = planning.planned(planned_epic(epic), read)
planned, stopped = planning.planned(planned_epic(epic), read)
# After the planning, which reads the epic again and would drop a move a search doesn't show yet.
issues = parents_moved(epic, planned)
if isinstance(stopped, Limited):
return Stop(1, f"the epic is not planned, so no chunk started: {stopped.said}")
if stopped is not None:
@@ -534,7 +536,7 @@ class Landed(enum.Enum):
def handed_on(key: str, epic: EpicRun, landed: Landed = Landed.NOWHERE) -> Stop:
"""The stop of a do-epic whose chunk finished. It first moves the chunk's issue to done (the epic's finishing has none), 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. Where the team's automation moves issues, others move two kinds of issue. The automation moves the issue of a chunk whose work landed on the default branch, from its pull request: the stop waits for that move (`moved_by_automation`). The human moves their own task: the stop doesn't move or await anything. A chunk without a repo has no pull request, so its issue moves to done as ever, and so does a split item, once Jira counts each of its sub-tasks done. The automation doesn't see a pull request that merged into an epic's working branch: the stop moves that chunk's issue to the status `jira-pull-request-merged-status` names. Where none is named, it moves the issue to done, or stops where the automation moves issues, since then nobody would move it. do-epic's window closes as it exits."""
"""The stop of a do-epic whose chunk finished. It first moves the chunk's issue to done (the epic's finishing has none), and its parent too where the parent's sub-tasks now let it move (`parents_settled`), so that no finished chunk starts again and what they block may start, then starts each chunk that may start now. Where the team's automation moves issues, others move two kinds of issue. The automation moves the issue of a chunk whose work landed on the default branch, from its pull request: the stop waits for that move (`moved_by_automation`). The human moves their own task: the stop doesn't move or await anything. A chunk without a repo has no pull request, so its issue moves to done as ever, and so does a split item, once Jira counts each of its sub-tasks done. The automation doesn't see a pull request that merged into an epic's working branch: the stop moves that chunk's issue to the status `jira-pull-request-merged-status` names. Where none is named, it moves the issue to done, or stops where the automation moves issues, since then nobody would move it. do-epic's window closes as it exits."""
automated = epic.config.automation_moves
# The epic's finishing has no issue to move: the epic is closed by `--close-epic`. Nor has a human's task where the human moves it: its window waited until it holds up no issue.
if key == epic.key or (landed is Landed.WITH_A_HUMAN and automated):
@@ -562,7 +564,7 @@ def handed_on(key: str, epic: EpicRun, landed: Landed = Landed.NOWHERE) -> Stop:
issues = issues if isinstance(issues, Failure) else [dataclasses.replace(each, done=True) if each.key == key else each for each in issues]
if isinstance(issues, Failure):
return Stop(1, f"the chunk finished, but the next could not start: {issues.reason}")
closed = split_items_closed(epic, issues)
closed = parents_settled(epic, issues)
if isinstance(closed, Stop):
return closed
started = chunks_started(epic, closed, key)
@@ -592,6 +594,19 @@ def moved_by_automation(key: str, epic: EpicRun) -> list[EpicIssue]:
epic.effects.sleep(POLL_SECONDS)
def parents_moved(epic: EpicRun, issues: list[EpicIssue]) -> list[EpicIssue]:
"""The issues as they read once `parent_moves.moved` has moved each parent whose sub-tasks a person filed; a search may not show those moves yet. A move that was not made is said, and the run goes on: the parent holds back only what it blocks."""
issues, refused = parent_moves.moved(epic.store, issues, epic.config.unblocking, epic.config.sub_tasks_landed_transition, epic.config.finish is not None)
for reason in refused:
say(reason, epic.effects, stdout=True)
return issues
def parents_settled(epic: EpicRun, issues: list[EpicIssue]) -> list[EpicIssue] | Stop:
"""The issues once each parent has moved as its sub-tasks let it: one whose sub-tasks a person filed (`parents_moved`), then one do-epic split (`split_items_closed`); the stop where a split item cannot move."""
return split_items_closed(epic, parents_moved(epic, issues))
def split_items_closed(epic: EpicRun, issues: list[EpicIssue]) -> list[EpicIssue] | Stop:
"""The issues, with each item split by repo whose sub-tasks are all done moved to done in the tracker and read as done; the stop where one cannot move. Its last sub-task to finish closes it, and one an earlier run left open closes with it."""
for item in issues:
+33
View File
@@ -0,0 +1,33 @@
"""Moves a parent issue whose sub-tasks a person filed, once those sub-tasks have landed or are done. Until the parent moves, every issue it blocks waits, and nobody else moves it: the team's automation sees a pull request only on the sub-task that carries it. `main.split_items_closed` closes an item that do-epic split itself."""
import dataclasses
from do_epic.backend.protocol import EpicIssue, EpicStore
from failure import Failure
from do_epic.split import SPLIT_LABEL
from do_epic.config import SUB_TASKS_LANDED_TRANSITION
from do_epic.scheduler import unblocks
def moved(store: EpicStore, issues: list[EpicIssue], unblocking: tuple[str, ...], landed_by: str | None, finishes: bool) -> tuple[list[EpicIssue], list[str]]:
"""The issues as they read once each parent has moved, and why each move that failed was not made. A parent that did not move holds back only itself, so the others still move.
A parent whose sub-tasks are all done moves to done, where finishes says the config names how. One whose sub-tasks have all landed, each done or at one of the unblocking statuses, moves by the transition landed_by names, where the config names one and it leads to one of those statuses. A parent that is done, or has landed itself, never moves back. One without a sub-task, or with one still open, stays as it is."""
refused: list[str] = []
for parent in issues:
tasks = [task for task in issues if task.parent == parent.key]
# A sub-task do-epic filed under an item it didn't mark is a split that failed halfway, which the next run completes.
if parent.done or SPLIT_LABEL in parent.labels or all(task.by_loop for task in tasks):
continue
if all(task.done for task in tasks):
done = store.finish_issue(parent.key) if finishes else None
if isinstance(done, Failure):
refused.append(f"{parent.key}'s sub-tasks are all done, but it did not move to done: {done.reason}; close it in Jira")
elif finishes:
issues = [dataclasses.replace(each, done=True) if each.key == parent.key else each for each in issues]
elif landed_by and not unblocks(parent.status, unblocking) and all(task.done or unblocks(task.status, unblocking) for task in tasks):
status = store.move_issue_by(parent.key, landed_by, unblocking)
if isinstance(status, Failure):
refused.append(f"{parent.key}'s sub-tasks have all landed, but it did not move by {landed_by!r}, the transition `{SUB_TASKS_LANDED_TRANSITION}` names: {status.reason}; move it in Jira")
else:
issues = [dataclasses.replace(each, status=status) if each.key == parent.key else each for each in issues]
return issues, refused
+1 -1
View File
@@ -113,7 +113,7 @@ def task_summary(repo: str, summary: str, team: LabelRepos, template: str | None
def finished(issues: list[EpicIssue], key: str) -> bool:
"""Whether the item named key is done. An item marked SPLIT_LABEL that has sub-tasks is done once each of them is, whatever its own status. Any other item is done by its own status, also one a person's sub-tasks split: do-epic filed those for every repo the item changes, and a person's may cover only a part of it. A key no issue has isn't done."""
"""Whether the item named key is done. An item marked SPLIT_LABEL that has sub-tasks is done once each of them is, whatever its own status. Any other item is done by its own status, also one under which a person filed sub-tasks: `parent_moves` moves that item to done once every sub-task is done. A key no issue has isn't done."""
item = next((issue for issue in issues if issue.key == key), None)
tasks = [issue for issue in issues if issue.parent == key]
if item is None:
+12
View File
@@ -128,6 +128,18 @@ class ConfigTest(unittest.TestCase):
self.write(SETTINGS + f'jira-start-transition = " "\njira-sprint-board = {board}\n')
self.assertIn(f"`jira-start-transition` is ' ', not the name Jira shows, such as \"In Progress\"; `jira-sprint-board` is {read}, not a board's ID, the whole number in the board's address, such as 6", self.failure())
def test_reads_the_transition_that_moves_a_parent_whose_sub_tasks_have_all_landed(self) -> None:
self.write(SETTINGS)
found = load(self.home)
assert isinstance(found, DoEpicConfig), found
self.assertIsNone(found.sub_tasks_landed_transition)
self.write(SETTINGS + 'jira-sub-tasks-landed-transition = "Release Ready"\n')
found = load(self.home)
assert isinstance(found, DoEpicConfig), found
self.assertEqual(found.sub_tasks_landed_transition, "Release Ready")
self.write(SETTINGS + 'jira-sub-tasks-landed-transition = 5\n')
self.assertIn("`jira-sub-tasks-landed-transition` is 5, not the name Jira shows, such as \"Release Ready\"", self.failure())
def test_reads_the_unblocking_statuses_and_that_the_teams_automation_moves_issues(self) -> None:
self.write(SETTINGS)
found = load(self.home)
+31
View File
@@ -513,6 +513,29 @@ class AChunksRun(DoEpicTest):
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_the_last_sub_task_a_person_filed_to_finish_moves_its_parent_to_done_and_starts_what_it_blocks(self) -> None:
(self.home / ".claude-projects" / "do-epic" / "config.toml").write_text(SETTINGS + 'jira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n', encoding="utf-8")
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], issue("ABC-21"), *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_parent_jira_will_not_move_is_said_and_the_next_chunk_still_starts(self) -> None:
(self.home / ".claude-projects" / "do-epic" / "config.toml").write_text(SETTINGS + 'jira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n', encoding="utf-8")
store = MemoryEpic("ABC-12", [self.issues[0], issue("ABC-21"), issue("ABC-23", "do-epic-claude", parent="ABC-21"), issue("ABC-22", "do-epic-claude")])
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, 0, err)
self.assertIn("ABC-21's sub-tasks are all done, but it did not move to done: no way to done; close it in Jira\n", out)
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")])
@@ -1285,6 +1308,14 @@ class TheDryRun(DoEpicTest):
changing = {"new-session", "new-window", "kill-window", "set-option", "rename-window"}
self.assertEqual([args for args in fake.tmux_calls if args[0] in changing], [])
def test_prints_each_move_of_a_parent_whose_sub_tasks_a_person_filed(self) -> None:
(self.home / ".claude-projects" / "do-epic" / "config.toml").write_text(SETTINGS + 'jira-unblocking-statuses = ["Release Ready"]\njira-sub-tasks-landed-transition = "Release Ready"\njira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n', encoding="utf-8")
self.issues = [issue("ABC-20", status="In Progress"), issue("ABC-30", "do-epic-claude", parent="ABC-20", status="Release Ready"), issue("ABC-21"), issue("ABC-31", "do-epic-claude", parent="ABC-21", done=True), issue("ABC-22", "do-epic-claude", blockers=("ABC-20",))]
code, out, err = self.run_main(["ABC-12", "--dry-run"], FakeEffects())
self.assertEqual((code, err), (0, ""))
self.assertIn("planning would write to Jira:\n- move ABC-20 by Release Ready\n- finish ABC-21\nwould start ABC-22\n", out.replace("<1790000000> ", ""))
self.assertEqual(self.stores[0].writes, [])
def test_prints_the_label_a_pick_would_give_an_issue(self) -> None:
self.issues = [issue("ABC-20")]
code, out, _ = self.run_main(["ABC-12", "--dry-run"], FakeEffects(claude=[structured({"parts": []}), structured({"pick": "claude"})]))
+91
View File
@@ -0,0 +1,91 @@
import dataclasses
import pathlib
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from do_epic.backend.protocol import EpicIssue
from failure import Failure
from do_epic.test_scheduler import issue
from do_epic.backend.fake import MemoryEpic
from do_epic.parent_moves import moved
UNBLOCKING = ("Release Ready", "Teach & Learn")
def family(*tasks: EpicIssue, parent: EpicIssue | None = None) -> list[EpicIssue]:
"""ABC-20, or parent in its place, followed by tasks as its sub-tasks."""
above = parent or issue("ABC-20", status="In Progress")
return [above, *(dataclasses.replace(task, parent=above.key) for task in tasks)]
class MovingAParentWhoseSubTasksAPersonFiled(unittest.TestCase):
def moves(self, issues: list[EpicIssue], landed_by: str | None = "Release Ready", finishes: bool = True) -> tuple[list[str], dict[str, tuple[str, bool]], list[str]]:
"""The writes moved made, each issue's status and whether it is done as moved answers them, and the reasons it gave."""
store = MemoryEpic("ABC-12", list(issues))
after, refused = moved(store, issues, UNBLOCKING, landed_by, finishes)
return store.writes, {each.key: (each.status, each.done) for each in after}, refused
def test_sub_tasks_that_have_all_landed_move_their_parent_by_the_landed_transition(self) -> None:
for tasks in ([issue("ABC-30", status="Release Ready"), issue("ABC-31", status="teach & learn")], [issue("ABC-30", status="Release Ready"), issue("ABC-31", done=True)]):
with self.subTest(tasks=tasks):
writes, after, refused = self.moves(family(*tasks))
self.assertEqual((writes, refused), (["move ABC-20 by Release Ready"], []))
self.assertEqual(after["ABC-20"], ("Release Ready", False))
def test_sub_tasks_that_are_all_done_finish_their_parent(self) -> None:
for status in ("In Progress", "Release Ready"):
with self.subTest(status=status):
writes, after, refused = self.moves(family(issue("ABC-30", done=True), issue("ABC-31", done=True), parent=issue("ABC-20", status=status)))
self.assertEqual((writes, refused), (["finish ABC-20"], []))
self.assertTrue(after["ABC-20"][1])
def test_a_parent_at_or_past_the_target_stays(self) -> None:
landed = [issue("ABC-30", status="Release Ready"), issue("ABC-31", done=True)]
for parent in (issue("ABC-20", status="Release Ready"), issue("ABC-20", status="teach & learn"), issue("ABC-20", done=True)):
with self.subTest(parent=parent):
self.assertEqual(self.moves(family(*landed, parent=parent))[0], [])
self.assertEqual(self.moves(family(issue("ABC-30", done=True), parent=issue("ABC-20", done=True)))[0], [])
def test_a_parent_with_no_sub_task_or_with_one_still_open_is_left_alone(self) -> None:
self.assertEqual(self.moves(family())[0], [])
self.assertEqual(self.moves(family(issue("ABC-30", done=True), issue("ABC-31", status="Release Ready"), issue("ABC-32", status="In Progress")))[0], [])
def test_without_a_landed_transition_only_the_move_to_done_happens_and_only_where_the_config_names_how(self) -> None:
landed = family(issue("ABC-30", status="Release Ready"))
done = family(issue("ABC-30", done=True))
self.assertEqual(self.moves(landed, landed_by=None)[0], [])
self.assertEqual(self.moves(done, landed_by=None)[0], ["finish ABC-20"])
self.assertEqual(self.moves(done, finishes=False), ([], {"ABC-20": ("In Progress", False), "ABC-30": ("Done", True)}, []))
def test_an_item_do_epic_split_or_half_split_is_left_to_its_own_closing(self) -> None:
done = dataclasses.replace(issue("ABC-30", done=True), by_loop=True)
self.assertEqual(self.moves(family(done, parent=issue("ABC-20", "split-by-repo")))[0], [])
self.assertEqual(self.moves(family(done))[0], [])
def test_a_parent_with_a_sub_task_a_person_filed_beside_one_do_epic_filed_moves(self) -> None:
ours = dataclasses.replace(issue("ABC-31", done=True), by_loop=True)
self.assertEqual(self.moves(family(issue("ABC-30", status="Release Ready"), ours))[0], ["move ABC-20 by Release Ready"])
self.assertEqual(self.moves(family(issue("ABC-30", done=True), ours))[0], ["finish ABC-20"])
def test_a_landed_transition_named_unlike_its_status_moves_the_parent_to_an_unblocking_status(self) -> None:
writes, after, refused = self.moves(family(issue("ABC-30", status="Teach & Learn")), landed_by="Mark ready")
self.assertEqual((writes, after["ABC-20"], refused), (["move ABC-20 by Mark ready"], ("Release Ready", False), []))
def test_a_move_jira_refuses_is_answered_with_its_reason_and_the_other_parents_still_move(self) -> None:
issues = [*family(issue("ABC-30", status="Release Ready")), *family(issue("ABC-31", done=True), parent=issue("ABC-21")), *family(issue("ABC-32", done=True), parent=issue("ABC-22"))]
store = MemoryEpic("ABC-12", list(issues))
finish = store.finish_issue
store.move_issue_by = lambda key, transition, to: Failure("ABC-20 has no transition 'Release Ready' from its status") # type: ignore[method-assign]
store.finish_issue = lambda key: Failure("Jira answered 400") if key == "ABC-21" else finish(key) # type: ignore[method-assign]
after, refused = moved(store, issues, UNBLOCKING, "Release Ready", True)
self.assertEqual(refused, [
"ABC-20's sub-tasks have all landed, but it did not move by 'Release Ready', the transition `jira-sub-tasks-landed-transition` names: ABC-20 has no transition 'Release Ready' from its status; move it in Jira",
"ABC-21's sub-tasks are all done, but it did not move to done: Jira answered 400; close it in Jira",
])
self.assertEqual({each.key: (each.status, each.done) for each in after if each.parent == "ABC-12"}, {"ABC-20": ("In Progress", False), "ABC-21": ("To Do", False), "ABC-22": ("To Do", True)})
if __name__ == "__main__":
unittest.main()