diff --git a/README.md b/README.md index e805670b..ad82a868 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ The last line prints each setting's path once the config is complete. - `jira-unblocking-statuses` lists the statuses at which an issue's work has landed though Jira doesn't count it done yet, such as `["Release Ready"]`, in upper or lower case. An issue in one of them takes no chunk and no longer blocks the issues it blocks, and `--status` names the statuses beside each blocker. A status Jira counts as done always does both. The release reviews, which are the epic's last chunk, still wait until Jira counts every issue done: run `do-epic ` then, to start them. - `jira-automation-moves-issues = true` keeps do-epic from moving the issue of a finished chunk in a repo: the automation moves it, and do-epic waits for that move before it starts what the issue blocks. An issue without a repo has no pull request, so do-epic still moves it, with `jira-finish-transition`. The setting needs `jira-unblocking-statuses`, which names the status the automation gives an issue whose pull request merged. - `config.toml` names the statuses do-epic itself gives an issue whose chunk merges into an epic's working branch, in a repo whose config sets `epic-branch`. A team's automation moves an issue only for a pull request into the default branch, so there do-epic makes both moves, whatever `jira-automation-moves-issues` says. `jira-pull-request-open-status`, such as `"Code Review"`, is the status of an issue whose chunk parks with its pull request open; a pull request that opens and merges within one run of the worker skips it, unless the workflow leads to the merged status only through it. `jira-pull-request-merged-status`, such as `"Release Ready"`, is the status once the pull request has merged into the working branch. `jira-unblocking-statuses` must list it, and an issue that has it counts as done when the release reviews and the finishing chunk fall due, since both come before a person merges the working branch. Without it, do-epic moves a finished chunk's issue to done. Where `jira-automation-moves-issues` is set, it stops instead and asks you to move the issue. -- `config.toml` names how do-epic moves a parent issue whose sub-tasks a person filed. Once every sub-task has landed, each done or in one of `jira-unblocking-statuses`, the parent moves by the transition `jira-sub-tasks-landed-transition` names, such as `"Release Ready"`; without the setting it stays. Once every sub-task is done, it moves to done by `jira-finish-transition`. do-epic makes these moves as each run plans and as each chunk finishes, and `--dry-run` prints them. A parent already there, or done, never moves back, and a move Jira refuses is said while the run goes on. +- `config.toml` names how do-epic moves a parent issue whose sub-tasks a person filed. Once every sub-task is done, the parent moves to done by `jira-finish-transition`; without that setting it stays. Before that, once each sub-task is done or in one of `jira-unblocking-statuses`, the parent moves by the transition `jira-sub-tasks-landed-transition` names, such as `"Release Ready"`; without that setting it stays. The transition must lead to one of `jira-unblocking-statuses`, or do-epic doesn't make it. do-epic makes these moves as each run plans and as each chunk finishes, and `--dry-run` prints them. A parent that is done, or already in one of `jira-unblocking-statuses`, never moves back. A move that is not made is said, and the run goes on. - `config.toml` also says how a starting chunk's issue shows on its team's board. A starting chunk always assigns its issue to the account do-epic works as, unless someone else holds it; that issue keeps its assignee, and moves and joins the sprint like any other. `jira-start-transition` names the workflow transition that then moves the issue, such as `"In Progress"`; an issue whose work has started already keeps its status. `jira-sprint-board` is the ID of the board whose active sprint the issue joins, such as `6`. Where a setting is left out, do-epic doesn't take its step. - `config.toml` may set `jira-finding-type`, the issue type do-epic files a finding as, and `jira-review-type`, the one it files a repo's release review as, such as `"Feature"` and `"Chore"`. Both are Task where left out. do-epic doesn't file anything where the Jira project lacks the type, and says which types it has. - `config.toml` may set `sub-task-summary`, which shapes the summary of each sub-task do-epic files for an issue that changes several repos, such as `sub-task-summary = "{label}: {Summary}"`. `{label}` is the team's label for the repo, else the repo's name, and `{Summary}` is the issue's summary with a capital first letter. It must hold `{Summary}`. Without it a summary is `[] `. @@ -241,7 +241,21 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `chunk_driver/` holds what the entry points share. An entry point is a tool that drives chunks through `agent_cycle`: `loop_claude` and `do_epic` are the two. They share how a cycle starts (`cycle_start.py`) and closes (`chunk_run.py`), the claim on a checkout before a chunk starts in it (`claims.py`), the prompts every worker gets (`prompts.py`), and a checkout's premises, records and saved models (`project/`). It imports neither entry point, and `repo_checks` fails any package that imports one of the two. `agent_cycle` is the layer below it, and `repo_checks` fails `agent_cycle` where it imports `chunk_driver`, tests included. - `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `command_patterns`, `reading_cost`, `routing_figures`, `rule_hook` and `run_heavy`. - `deploy_release` imports `release_plan`'s `release_standing`. -- `do_epic/` holds `do-epic`, the tool that drives one Jira epic. `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `planning.py` settles, before the chunks start, where each open issue is worked, its scores and the order the issues start in, through `split.py`, `repo_pick.py`, `issue_scores.py` and `ranking.py`. `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `parent_moves.py` moves a parent whose sub-tasks a person filed, once those have landed or are done. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, posts comments, moves a finished chunk's issue to done, and closes the epic. `e2e/` holds `do-epic-e2e`. +- `do_epic/` holds `do-epic`, the tool that drives one Jira epic: + - `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. + - `planning.py` settles, before the chunks start, where each open issue is worked, its scores and the order the issues start in, through `split.py`, `repo_pick.py`, `issue_scores.py` and `ranking.py`. + - `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. + - `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. + - `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. + - `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. + - `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. + - `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. + - `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. + - `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. + - `parent_moves.py` moves a parent whose sub-tasks a person filed, once those have landed or are done. + - `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. + - `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, posts comments, moves a finished chunk's issue to done, and closes the epic. + - `e2e/` holds `do-epic-e2e`. - `forge/` tells a GitHub origin from a Gitea one, names a repo beside an origin's and runs that forge's CLI (`commands.py`), finds a pull request, lists the ready ones and reads its checks, once or until they settle (`pulls.py`), and reads a pull request's review state (`reviews.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release`, `do_epic` and `larv_review`. - `git_cli/` runs git for every tool (`git_repo.py`), reads the git calls in a shell command (`git_command.py`), and keeps an epic's working branch level with the default branch (`epic_branch.py`). - `judge_replay` imports `agent_cycle`'s judge and verdicts, and `chunk_driver`'s premises, records and `ANSWER_DESTINATIONS`. diff --git a/bin/do_epic/backend/contract.py b/bin/do_epic/backend/contract.py index 195d26e6..3dcdf92a 100644 --- a/bin/do_epic/backend/contract.py +++ b/bin/do_epic/backend/contract.py @@ -200,13 +200,25 @@ class EpicStoreContract: 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), store.move_issue_by(child, self.transition)], ["Done", "Done"]) + 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_makes_no_move_by_a_transition_that_leads_to_another_status_than_those_asked_for(self) -> None: + store = self.new_store() + child = self.filed(store, store.epic_key, "Count the runs.") + self.assertIsInstance(store.move_issue_by(child, self.transition, ("Release Ready",)), Failure) + self.assertEqual([(issue.status, issue.done) for issue in self.issues(store)], [("To Do", False)]) + + 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), Failure) + 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: diff --git a/bin/do_epic/backend/fake.py b/bin/do_epic/backend/fake.py index 22a27b6b..fbd3a59f 100644 --- a/bin/do_epic/backend/fake.py +++ b/bin/do_epic/backend/fake.py @@ -126,12 +126,18 @@ class MemoryEpic: self.writes.append(f"move {key} to {status}") return None - def move_issue_by(self, key: str, transition: str) -> str | Failure: + def move_issue_by(self, key: str, transition: str, to: tuple[str, ...]) -> str | Failure: # The fake holds no workflow: a transition leads to the status of its own name. if self.fails: return Failure(self.fails) - if self.within(key) is None: + issue = self.within(key) + if issue is None: return no_child(self.epic_key, key, "moved") + accepted = {name.casefold() for name in to} + if issue.status.casefold() in accepted: + return issue.status + if transition.casefold() not in accepted: + return Failure(f"the transition {transition!r} leads {key} to the status {transition!r}, not to {' or '.join(repr(name) for name in to)}") self.change(key, status=transition, done=transition.casefold() == "done") self.writes.append(f"move {key} by {transition}") return transition diff --git a/bin/do_epic/backend/jira.py b/bin/do_epic/backend/jira.py index c045be2d..269580ce 100644 --- a/bin/do_epic/backend/jira.py +++ b/bin/do_epic/backend/jira.py @@ -215,12 +215,12 @@ 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) -> str | Failure: + 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, authorization, self.http) + 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) diff --git a/bin/do_epic/backend/jira_status.py b/bin/do_epic/backend/jira_status.py index 747d3261..bb2e50af 100644 --- a/bin/do_epic/backend/jira_status.py +++ b/bin/do_epic/backend/jira_status.py @@ -1,4 +1,4 @@ -"""Moves a Jira issue to a status by name, or by a transition 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) @@ -31,8 +38,12 @@ def moved_to(site: str, key: str, status: str, authorization: str, http: Http) - 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, authorization: str, http: Http) -> str | Failure: - """Moves the issue named key by the transition named transition, in upper or lower case. The name of the status the transition leads to; why Jira did not take the move.""" +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}") @@ -42,6 +53,8 @@ def moved_by(site: str, key: str, transition: str, authorization: str, http: Htt 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, " + (f"only {others}" if offers else "nor any other the account may make")) + 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] diff --git a/bin/do_epic/backend/protocol.py b/bin/do_epic/backend/protocol.py index 6bfc7f3c..367a006b 100644 --- a/bin/do_epic/backend/protocol.py +++ b/bin/do_epic/backend/protocol.py @@ -73,8 +73,8 @@ 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) -> str | Failure: - """Moves the epic's child issue named key, or a sub-task of one, by the workflow transition named transition, and answers the name of the status it leads to. An issue outside the epic is refused. A Failure says why the move could not be made, such as a workflow that offers the issue no transition of that name from its status.""" + 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.""" diff --git a/bin/do_epic/backend/test_jira.py b/bin/do_epic/backend/test_jira.py index c4e2695b..5da2d0ea 100644 --- a/bin/do_epic/backend/test_jira.py +++ b/bin/do_epic/backend/test_jira.py @@ -414,33 +414,48 @@ class Jira(Case): 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"), "Release 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"), Failure(f"{key} has no transition 'Release Ready' from its status, only 'Mark as done' to 'Done'")) + 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"), Failure(f"{key} has no transition 'Release Ready' from its status, only 'Mark as done' to 'Done' and 'Start' to 'In Progress'")) + 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"), Failure(f"{key} has no transition 'Release Ready' from its status, nor any other the account may make")) + 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"), Failure("ABC-61 is not one of the child issues of the epic ABC-12, so it cannot be moved")) + 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"), Failure(f"cannot move {key} by 'Mark as done': 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"), Failure(f"cannot read {key}'s transitions: 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"), Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents")) + 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"), Failure(f"cannot read {key} to move it: 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() diff --git a/bin/do_epic/config.py b/bin/do_epic/config.py index 607e8016..bd680d45 100644 --- a/bin/do_epic/config.py +++ b/bin/do_epic/config.py @@ -55,7 +55,6 @@ 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" -# Three readers, seated as those who write do-epic's config, picked this spelling, 2 to 1. SUB_TASKS_LANDED_TRANSITION = "jira-sub-tasks-landed-transition" SUB_TASK_SUMMARY = "sub-task-summary" ISSUE_TYPES = (JIRA_FINDING_TYPE, JIRA_REVIEW_TYPE) @@ -131,7 +130,7 @@ def start_faults(values: dict[str, object]) -> list[str]: ] -def pull_status_faults(values: dict[str, object]) -> list[str]: +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 [] @@ -184,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))), diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index 00adc61b..e46216ad 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -1,6 +1,6 @@ """The do-epic command (docs/decisions.md → `do-epic: drives one Jira epic …`). -`do-epic ` first moves each parent whose sub-tasks a person filed, where those have landed or are done (`parent_moves`). Then it 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 `: 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 ` 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 `: 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 --status` prints what each open issue does.""" import dataclasses @@ -53,7 +53,7 @@ Before it starts chunks, do-epic plans each open issue that has none `repo:` 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:` 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 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), parents_moved(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 parent too where that was the last of the parent's sub-tasks (`parents_moved`, `split_items_closed`), 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, parents_moved(epic, issues)) + closed = parents_settled(epic, issues) if isinstance(closed, Stop): return closed started = chunks_started(epic, closed, key) @@ -593,13 +595,18 @@ def moved_by_automation(key: str, epic: EpicRun) -> list[EpicIssue]: def parents_moved(epic: EpicRun, issues: list[EpicIssue]) -> list[EpicIssue]: - """The issues once `parent_moves.moved` has moved each parent whose sub-tasks a person filed, as a search may not show them yet. A move Jira refused is said, and the run goes on: the parent holds back only what it blocks.""" + """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: diff --git a/bin/do_epic/parent_moves.py b/bin/do_epic/parent_moves.py index 4dfaae49..c597d203 100644 --- a/bin/do_epic/parent_moves.py +++ b/bin/do_epic/parent_moves.py @@ -1,16 +1,17 @@ -"""Moves a parent issue whose sub-tasks a person filed, once those sub-tasks have landed or are done. Until it moves, such a parent blocks every issue it blocks, and nobody else moves it: the team's automation sees a pull request only on the sub-task that carries it. An item do-epic split closes in `main.split_items_closed`.""" +"""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 Jira refused was not made. A parent it could not move holds back only itself, so the others still move. + """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. 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.""" + 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] @@ -20,13 +21,13 @@ def moved(store: EpicStore, issues: list[EpicIssue], unblocking: tuple[str, ...] 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 could not move to done: {done.reason}; close it in Jira") + 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) + 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 could not move by {landed_by!r}: {status.reason}; move it in Jira") + 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 diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index 5b6e4982..cac4f295 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -533,7 +533,7 @@ class AChunksRun(DoEpicTest): 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 could not move to done: no way to done; close it in Jira\n", out) + 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: diff --git a/bin/do_epic/test_parent_moves.py b/bin/do_epic/test_parent_moves.py index 287934f6..d26fb53e 100644 --- a/bin/do_epic/test_parent_moves.py +++ b/bin/do_epic/test_parent_moves.py @@ -64,16 +64,26 @@ class MovingAParentWhoseSubTasksAPersonFiled(unittest.TestCase): 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_that_leads_to_no_unblocking_status_is_not_made(self) -> None: + writes, after, refused = self.moves(family(issue("ABC-30", status="Release Ready")), landed_by="Code Review") + self.assertEqual((writes, after["ABC-20"]), ([], ("In Progress", False))) + self.assertEqual(refused, ["ABC-20's sub-tasks have all landed, but it did not move by 'Code Review', the transition `jira-sub-tasks-landed-transition` names: the transition 'Code Review' leads ABC-20 to the status 'Code Review', not to 'Release Ready' or 'Teach & Learn'; move it in Jira"]) + 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: Failure("ABC-20 has no transition 'Release Ready' from its status") # type: ignore[method-assign] + 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 could not move by 'Release Ready': ABC-20 has no transition 'Release Ready' from its status; move it in Jira", - "ABC-21's sub-tasks are all done, but it could not move to done: Jira answered 400; close it in Jira", + "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)})