Merge origin/main into item-412
This commit is contained in:
@@ -9,6 +9,7 @@ from failure import Failure
|
||||
class EpicStoreContract:
|
||||
assertEqual: typing.Callable[..., None]
|
||||
assertIsInstance: typing.Callable[..., None]
|
||||
assertIsNone: typing.Callable[..., None]
|
||||
subTest: typing.Callable[..., typing.ContextManager[None]]
|
||||
|
||||
def new_store(self) -> EpicStore:
|
||||
@@ -124,6 +125,29 @@ class EpicStoreContract:
|
||||
self.assertIsInstance(store.add_label("ZZZ-1", "repo:log"), Failure)
|
||||
self.assertEqual([issue.labels for issue in self.issues(store)], [(), ()])
|
||||
|
||||
def test_finishes_a_child_issue_so_it_reads_as_done_and_leaves_one_that_is_done_as_it_is(self) -> None:
|
||||
store = self.new_store()
|
||||
key = self.filed(store, store.epic_key, "Count the runs.")
|
||||
other = self.filed(store, store.epic_key, "Ship the later thing.")
|
||||
closed = self.filed(store, store.epic_key, "Close the old thing.")
|
||||
self.close(store, closed, "Done")
|
||||
self.assertEqual([store.finish_issue(key), store.finish_issue(closed)], [None, None])
|
||||
self.assertEqual({issue.key: issue.done for issue in self.issues(store)}, {key: True, other: False, closed: True})
|
||||
|
||||
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.")
|
||||
task = self.filed(store, child, "Count them in the api.")
|
||||
self.assertIsNone(store.finish_issue(task))
|
||||
self.assertEqual({issue.key: issue.done for issue in self.issues(store)}, {child: False, task: True})
|
||||
|
||||
def test_refuses_to_finish_an_issue_outside_the_epic(self) -> None:
|
||||
store = self.new_store()
|
||||
child = self.filed(store, store.epic_key, "Count the runs.")
|
||||
self.assertIsInstance(store.finish_issue("ZZZ-1"), Failure)
|
||||
self.assertIsInstance(store.finish_issue("not a key"), Failure)
|
||||
self.assertEqual([issue.done for issue in self.issues(store)], [False])
|
||||
|
||||
def test_posts_comments_on_a_child_issue_in_order(self) -> None:
|
||||
store = self.new_store()
|
||||
key = self.filed(store, store.epic_key, "Count the runs.")
|
||||
@@ -140,6 +164,14 @@ class EpicStoreContract:
|
||||
self.assertIsInstance(store.comment("ZZZ-1", "Hello."), Failure)
|
||||
self.assertEqual([self.comments_on(store, key) for key in (child, task)], [[], []])
|
||||
|
||||
def test_closes_the_epic_once_its_summary_is_posted_and_refuses_a_blank_one(self) -> None:
|
||||
store = self.new_store()
|
||||
self.assertEqual(store.closed(), False)
|
||||
self.assertIsInstance(store.close(" \n"), Failure)
|
||||
self.assertEqual((store.closed(), self.comments_on(store, "ABC-12")), (False, []))
|
||||
self.assertEqual(store.close("## Shipped\n\nThe import.\n"), None)
|
||||
self.assertEqual((store.closed(), self.comments_on(store, "ABC-12")), (True, ["## Shipped\n\nThe import."]))
|
||||
|
||||
def test_reads_an_issue_without_scores_or_blockers_as_one_with_none(self) -> None:
|
||||
store = self.new_store()
|
||||
key = self.filed(store, store.epic_key, "Count the runs.")
|
||||
|
||||
@@ -7,11 +7,12 @@ from failure import Failure
|
||||
|
||||
@dataclasses.dataclass
|
||||
class MemoryEpic:
|
||||
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every read, filing, label, comment and rank fails with it as the reason. comments holds each issue's comments, by key."""
|
||||
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every read, filing, label, comment, rank, issue finish and closing fails with it as the reason. comments holds each issue's comments, and the epic's, by key. done says whether the epic is closed."""
|
||||
epic_key: str
|
||||
issues: list[EpicIssue] = dataclasses.field(default_factory=list)
|
||||
comments: dict[str, list[str]] = dataclasses.field(default_factory=dict)
|
||||
fails: str | None = None
|
||||
done: bool = False
|
||||
|
||||
def read(self) -> list[EpicIssue] | Failure:
|
||||
if self.fails:
|
||||
@@ -60,6 +61,29 @@ class MemoryEpic:
|
||||
self.comments.setdefault(key, []).append(text.strip())
|
||||
return None
|
||||
|
||||
def closed(self) -> bool | Failure:
|
||||
return Failure(self.fails) if self.fails else self.done
|
||||
|
||||
def close(self, summary: str) -> None | Failure:
|
||||
if self.fails:
|
||||
return Failure(self.fails)
|
||||
if refused := no_words(summary):
|
||||
return refused
|
||||
self.comments.setdefault(self.epic_key, []).append(summary.strip())
|
||||
self.done = True
|
||||
return None
|
||||
|
||||
def finish_issue(self, key: str) -> None | Failure:
|
||||
if self.fails:
|
||||
return Failure(self.fails)
|
||||
children = {issue.key for issue in self.issues if issue.parent == self.epic_key}
|
||||
child = next((issue for issue in self.issues if issue.key == key and (issue.parent == self.epic_key or issue.parent in children)), None)
|
||||
if child is None:
|
||||
return no_child(self.epic_key, key, "finished")
|
||||
if not child.done:
|
||||
self.change(key, status="Done", done=True)
|
||||
return None
|
||||
|
||||
def change(self, key: str, **fields: object) -> None:
|
||||
"""Changes the issue named key as a person would in the tracker, such as assignee="Ada Lovelace"."""
|
||||
self.issues = [dataclasses.replace(issue, **fields) if issue.key == key else issue for issue in self.issues] # type: ignore[arg-type]
|
||||
|
||||
@@ -5,14 +5,15 @@ import typing
|
||||
|
||||
from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
|
||||
from atlassian.client import basic_auth, Http, jira_json, ToAdf, ToMarkdown
|
||||
from plan_store.jira_epic import blocked_by_links, FILED_BY, ISSUE_KEY, ISSUE_TYPE, project_of, PROPERTY, rank_refusal, scores, searched
|
||||
from project_config.settings import Epic
|
||||
from plan_store.jira_epic import blocked_by_links, DONE, FILED_BY, finishing_transition, ISSUE_KEY, ISSUE_TYPE, move_refusal, PERHAPS_MOVED, project_of, PROPERTY, rank_refusal, scores, searched
|
||||
from project_config.settings import Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
|
||||
from do_epic.backend.protocol import EpicIssue, no_child, no_parent, no_words, unfit, unfit_label
|
||||
from failure import Failure
|
||||
|
||||
FIELDS = ["summary", "description", "labels", "assignee", "status", "parent", "issuelinks"]
|
||||
# How many child issues one search for sub-tasks names, which keeps its JQL well inside the length Jira takes.
|
||||
PARENTS_PER_SEARCH = 50
|
||||
NO_FINISH = "do-epic's settings name no transition to {to} by: set `{transition}` and `{status}` in ~/.claude-projects/do-epic/config.toml, to the names Jira shows, such as \"Mark as done\" and \"Done\""
|
||||
PERHAPS_FILED = "unless Jira refused the request, the issue may exist: look under {parent} before filing it again"
|
||||
|
||||
|
||||
@@ -25,12 +26,13 @@ class Found:
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class JiraEpic:
|
||||
"""The issues of a Jira epic, read and filed with the credentials env_file holds."""
|
||||
"""The issues of a Jira epic, read and filed with the credentials env_file holds. finish says how the epic itself closes; None where the machine's settings don't say."""
|
||||
epic: Epic
|
||||
env_file: pathlib.Path
|
||||
http: Http = jira_json
|
||||
to_markdown: ToMarkdown = adfs_to_markdown
|
||||
to_adf: ToAdf = markdown_to_adf
|
||||
finish: Finish | None = None
|
||||
|
||||
@property
|
||||
def epic_key(self) -> str:
|
||||
@@ -116,6 +118,64 @@ class JiraEpic:
|
||||
posted = self.http("POST", f"{self.epic.site}/rest/api/3/issue/{key}/comment", authorization, {"body": body})
|
||||
return Failure(f"cannot comment on {key}: {posted.reason}") if isinstance(posted, Failure) else None
|
||||
|
||||
def closed(self) -> bool | Failure:
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
answered = self.http("GET", f"{self.epic.site}/rest/api/3/issue/{self.epic_key}?fields=status", authorization, None)
|
||||
if isinstance(answered, Failure):
|
||||
return Failure(f"cannot read {self.epic_key}'s status: {answered.reason}")
|
||||
try:
|
||||
category = answered["fields"]["status"]["statusCategory"]["key"] # type: ignore[index]
|
||||
except (KeyError, TypeError) as failure:
|
||||
return Failure(f"{self.epic_key}'s status is not in the shape Jira Cloud's REST API version 3 documents: {failure!r}")
|
||||
return bool(category == "done")
|
||||
|
||||
def close(self, summary: str) -> None | Failure:
|
||||
if self.finish is None:
|
||||
return Failure(NO_FINISH.format(to="close an epic", transition=JIRA_FINISH_TRANSITION, status=JIRA_FINISH_STATUS))
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
if refused := no_words(summary):
|
||||
return refused
|
||||
body = self.to_adf(summary)
|
||||
if isinstance(body, Failure):
|
||||
return Failure(f"cannot convert the summary to a Jira comment: {body.reason}")
|
||||
# The transition is read before the comment is posted, so an epic that cannot move gets no summary.
|
||||
transition = finishing_transition(self.epic.site, self.epic_key, self.finish, authorization, self.http)
|
||||
if isinstance(transition, Failure):
|
||||
return transition
|
||||
posted = self.http("POST", f"{self.epic.site}/rest/api/3/issue/{self.epic_key}/comment", authorization, {"body": body})
|
||||
if isinstance(posted, Failure):
|
||||
return Failure(f"cannot comment on {self.epic_key}: {posted.reason}")
|
||||
refused_move = move_refusal(self.epic.site, self.epic_key, transition, self.finish, authorization, self.http)
|
||||
return Failure(f"posted the summary on {self.epic_key}, but {refused_move}; close the epic in Jira rather than posting the summary again") if refused_move else None
|
||||
|
||||
def finish_issue(self, key: str) -> None | Failure:
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
placed = self.placed(key, authorization, "to finish it")
|
||||
if isinstance(placed, Failure):
|
||||
return placed
|
||||
above, done = placed
|
||||
# A sub-task is no child of the epic but its parent is, so a sub-task's parent is read too.
|
||||
grand = self.parent_of(above, authorization, "to finish its sub-task") if above not in (None, self.epic_key) else None
|
||||
if isinstance(grand, Failure):
|
||||
return grand
|
||||
if above is None or (above != self.epic_key and grand != self.epic_key):
|
||||
return no_child(self.epic_key, key, "finished")
|
||||
if done:
|
||||
return None
|
||||
if self.finish is None:
|
||||
return Failure(NO_FINISH.format(to="finish an issue", transition=JIRA_FINISH_TRANSITION, status=JIRA_FINISH_STATUS))
|
||||
transition = finishing_transition(self.epic.site, key, self.finish, authorization, self.http)
|
||||
if isinstance(transition, Failure):
|
||||
return transition
|
||||
refused = move_refusal(self.epic.site, key, transition, self.finish, authorization, self.http)
|
||||
return Failure(f"{refused}; {PERHAPS_MOVED.format(key=key)}") if refused else None
|
||||
|
||||
def not_a_parent(self, parent: str, authorization: str) -> Failure | None:
|
||||
"""Why nothing can be filed under parent; None where it is the epic or one of its child issues."""
|
||||
if parent == self.epic_key:
|
||||
@@ -125,15 +185,22 @@ class JiraEpic:
|
||||
|
||||
def parent_of(self, key: str, authorization: str, why: str) -> str | None | Failure:
|
||||
"""The key of key's parent issue; None where key isn't an issue key or has no parent. A failed read says "cannot read <key> <why>"."""
|
||||
placed = self.placed(key, authorization, why)
|
||||
return placed if isinstance(placed, Failure) else placed[0]
|
||||
|
||||
def placed(self, key: str, authorization: str, why: str) -> tuple[str | None, bool] | Failure:
|
||||
"""The key of key's parent issue, None where key isn't an issue key or has no parent, and whether key's own status is a done one. A failed read says "cannot read <key> <why>"."""
|
||||
if not ISSUE_KEY.fullmatch(key):
|
||||
return None
|
||||
return None, False
|
||||
# A search may not show an issue filed a moment ago, so the issue is asked for by its key.
|
||||
answered = self.http("GET", f"{self.epic.site}/rest/api/3/issue/{key}?fields=parent", authorization, None)
|
||||
answered = self.http("GET", f"{self.epic.site}/rest/api/3/issue/{key}?fields=parent,status", authorization, None)
|
||||
if isinstance(answered, Failure):
|
||||
return Failure(f"cannot read {key} {why}: {answered.reason}")
|
||||
fields = answered.get("fields") if isinstance(answered, dict) else None
|
||||
above = fields.get("parent") if isinstance(fields, dict) else None
|
||||
return above.get("key") if isinstance(above, dict) and isinstance(above.get("key"), str) else None
|
||||
status = fields.get("status") if isinstance(fields, dict) else None
|
||||
category = status.get("statusCategory") if isinstance(status, dict) else None
|
||||
return (above.get("key") if isinstance(above, dict) and isinstance(above.get("key"), str) else None), isinstance(category, dict) and category.get("key") == DONE
|
||||
|
||||
def found(self, authorization: str) -> list[Found] | Failure:
|
||||
"""Each child issue, each followed by its sub-tasks."""
|
||||
|
||||
@@ -63,6 +63,16 @@ class EpicStore(typing.Protocol):
|
||||
def comment(self, key: str, text: str) -> None | Failure:
|
||||
"""Posts text, markdown, as a comment on the epic's child issue named key, for the people who work the epic to read. A sub-task, an issue outside the epic, or an empty or blank text is refused."""
|
||||
|
||||
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."""
|
||||
|
||||
|
||||
def closed(self) -> bool | Failure:
|
||||
"""Whether the epic itself is in a status the tracker counts as done."""
|
||||
|
||||
def close(self, summary: str) -> None | Failure:
|
||||
"""Posts summary, markdown, as a comment on the epic, then moves the epic to a status the tracker counts as done. Before anything is posted, it refuses a blank summary, and an epic the tracker cannot move to such a status. Where the move fails after the comment is posted, the Failure says so."""
|
||||
|
||||
|
||||
def unfit(summary: str, labels: tuple[str, ...]) -> Failure | None:
|
||||
"""Why no tracker can file an issue with this summary and these labels; None where a tracker can file it."""
|
||||
|
||||
@@ -51,5 +51,19 @@ class Ranking(unittest.TestCase):
|
||||
self.assertEqual(store.rank(str(child), "ZZZ-1"), Failure(f"ZZZ-1 is not one of the child issues of the epic ABC-12, so {child} is not ranked"))
|
||||
|
||||
|
||||
class Finishing(unittest.TestCase):
|
||||
def test_finishes_an_issue_to_the_status_done(self) -> None:
|
||||
store = MemoryEpic("ABC-12")
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.assertIsNone(store.finish_issue(str(key)))
|
||||
self.assertEqual([(issue.status, issue.done) for issue in store.issues], [("Done", True)])
|
||||
|
||||
def test_refuses_to_finish_an_issue_outside_the_epic_saying_so(self) -> None:
|
||||
self.assertEqual(MemoryEpic("ABC-12").finish_issue("ZZZ-1"), Failure("ZZZ-1 is not one of the child issues of the epic ABC-12, so it cannot be finished"))
|
||||
|
||||
def test_fails_to_finish_with_the_reason_given(self) -> None:
|
||||
self.assertEqual(MemoryEpic("ABC-12", fails="Jira is down").finish_issue("ABC-100"), Failure("Jira is down"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -9,7 +9,7 @@ import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
|
||||
|
||||
from project_config.settings import Epic
|
||||
from project_config.settings import Epic, Finish
|
||||
from do_epic.backend.contract import EpicStoreContract
|
||||
from failure import Failure
|
||||
from plan_store import jira_epic
|
||||
@@ -25,6 +25,10 @@ SEARCH = f"{SITE}/rest/api/3/search/jql"
|
||||
ISSUES = f"{SITE}/rest/api/3/issue"
|
||||
RANK = f"{SITE}/rest/agile/1.0/issue/rank"
|
||||
TO_DO = {"name": "To Do", "statusCategory": {"key": "new"}}
|
||||
DONE = {"name": "Done", "statusCategory": {"key": "done"}}
|
||||
TRANSITIONS = f"{ISSUES}/ABC-12/transitions"
|
||||
EPIC_COMMENT = f"{ISSUES}/ABC-12/comment"
|
||||
EPIC_STATUS = f"{ISSUES}/ABC-12?fields=status"
|
||||
TYPES = {"issueTypes": [{"id": "10001", "name": "Task", "subtask": False}, {"id": "10003", "name": "Subtask", "subtask": True}]}
|
||||
|
||||
|
||||
@@ -44,6 +48,12 @@ class FakeJira:
|
||||
answers: dict[tuple[str, str], object] = dataclasses.field(default_factory=dict)
|
||||
calls: list[tuple[str, str]] = dataclasses.field(default_factory=list)
|
||||
comments: dict[str, list[object]] = dataclasses.field(default_factory=dict)
|
||||
# The ID of each transition made.
|
||||
transitioned: list[str] = dataclasses.field(default_factory=list)
|
||||
# The transitions Jira offers an issue that isn't done.
|
||||
workflow: list[dict[str, object]] = dataclasses.field(default_factory=lambda: [{"id": "31", "name": "Mark as done", "to": DONE}])
|
||||
# The epic's own status, which the transition "Mark as done" moves to DONE.
|
||||
epic_status: dict[str, object] = dataclasses.field(default_factory=lambda: dict(TO_DO))
|
||||
|
||||
def __call__(self, method: str, url: str, authorization: str, body: object) -> object:
|
||||
self.calls.append((method, url))
|
||||
@@ -53,12 +63,32 @@ class FakeJira:
|
||||
return self.answers[method, url]
|
||||
if method == "GET" and url == EPIC_URL:
|
||||
return {"key": "ABC-12"}
|
||||
if method == "GET" and url == EPIC_STATUS:
|
||||
return {"key": "ABC-12", "fields": {"status": self.epic_status}}
|
||||
if method == "GET" and url == TRANSITIONS:
|
||||
return {"transitions": [] if self.epic_status == DONE else [{"id": "31", "name": "Mark as done", "to": DONE}, {"id": "21", "name": "Start", "to": {"name": "In Progress", "statusCategory": {"key": "indeterminate"}}}]}
|
||||
if method == "POST" and url == TRANSITIONS:
|
||||
assert body == {"transition": {"id": "31"}}, body
|
||||
self.epic_status = DONE
|
||||
return None
|
||||
if method == "POST" and url == EPIC_COMMENT:
|
||||
assert isinstance(body, dict)
|
||||
self.comments.setdefault("ABC-12", []).append(body["body"])
|
||||
return {"id": "1"}
|
||||
if method == "GET" and url == ISSUE_TYPES:
|
||||
return TYPES
|
||||
if method == "POST" and url == SEARCH:
|
||||
return self.page(body)
|
||||
if method == "GET" and (held := next((issue for issue in self.issues if url == f"{ISSUES}/{issue['key']}?fields=parent"), None)):
|
||||
return {"key": held["key"], "fields": {"parent": held["fields"]["parent"]}} # type: ignore[index]
|
||||
if method == "GET" and (held := next((issue for issue in self.issues if url.startswith(f"{ISSUES}/{issue['key']}?fields=")), None)):
|
||||
asked = url.partition("?fields=")[2].split(",")
|
||||
return {"key": held["key"], "fields": {name: held["fields"][name] for name in asked}} # type: ignore[index]
|
||||
if method == "GET" and (held := next((issue for issue in self.issues if url == f"{ISSUES}/{issue['key']}/transitions"), None)):
|
||||
return {"transitions": [] if held["fields"]["status"] == DONE else self.workflow} # type: ignore[index]
|
||||
if method == "POST" and (held := next((issue for issue in self.issues if url == f"{ISSUES}/{issue['key']}/transitions"), None)):
|
||||
assert isinstance(body, dict)
|
||||
held["fields"]["status"] = DONE # type: ignore[index]
|
||||
self.transitioned.append(body["transition"]["id"])
|
||||
return None
|
||||
if method == "POST" and url == ISSUES:
|
||||
return self.created(body)
|
||||
if method == "PUT" and url == RANK:
|
||||
@@ -127,7 +157,7 @@ class Case(unittest.TestCase):
|
||||
self.jira = FakeJira()
|
||||
|
||||
def new_store(self) -> JiraEpic:
|
||||
return JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf)
|
||||
return JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Mark as done", "Done"))
|
||||
|
||||
|
||||
class JiraEpicContract(Case, EpicStoreContract):
|
||||
@@ -153,6 +183,111 @@ class JiraEpicContract(Case, EpicStoreContract):
|
||||
|
||||
|
||||
class Jira(Case):
|
||||
def test_closes_the_epic_by_the_transition_the_settings_name_after_the_summary(self) -> None:
|
||||
self.assertEqual(self.new_store().close("Shipped."), None)
|
||||
self.assertEqual(self.jira.calls[-3:], [("GET", TRANSITIONS), ("POST", EPIC_COMMENT), ("POST", TRANSITIONS)])
|
||||
|
||||
def test_posts_no_summary_on_an_epic_it_cannot_close(self) -> None:
|
||||
unnamed = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf)
|
||||
wrong_status = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Start", "Done"))
|
||||
no_such = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Close", "Done"))
|
||||
unconverted = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, lambda markdown: Failure("adf-codec refused it"), Finish("Mark as done", "Done"))
|
||||
for store, reason in (
|
||||
(unnamed, "do-epic's settings name no transition to close an epic by: set `jira-finish-transition` and `jira-finish-status` in ~/.claude-projects/do-epic/config.toml, to the names Jira shows, such as \"Mark as done\" and \"Done\""),
|
||||
(wrong_status, "ABC-12's transition 'Start' leads to the status 'In Progress', not to 'Done', which `jira-finish-status` names"),
|
||||
(unconverted, "cannot convert the summary to a Jira comment: adf-codec refused it"),
|
||||
):
|
||||
self.assertEqual(store.close("Shipped."), Failure(reason))
|
||||
refused = no_such.close("Shipped.")
|
||||
assert isinstance(refused, Failure)
|
||||
self.assertIn("ABC-12 has no transition 'Close' from its status", refused.reason)
|
||||
self.jira.answers[("GET", TRANSITIONS)] = Failure("Jira answered 503")
|
||||
self.assertEqual(self.new_store().close("Shipped."), Failure("cannot read ABC-12's transitions: Jira answered 503"))
|
||||
self.assertEqual((self.jira.comments, self.jira.epic_status), ({}, TO_DO))
|
||||
|
||||
def test_says_what_was_posted_where_the_comment_or_the_move_fails(self) -> None:
|
||||
self.jira.answers[("POST", EPIC_COMMENT)] = Failure("Jira answered 503")
|
||||
self.assertEqual(self.new_store().close("Shipped."), Failure("cannot comment on ABC-12: Jira answered 503"))
|
||||
self.assertEqual(self.jira.epic_status, TO_DO)
|
||||
del self.jira.answers[("POST", EPIC_COMMENT)]
|
||||
self.jira.answers[("POST", TRANSITIONS)] = Failure("Jira answered 503")
|
||||
self.assertEqual(self.new_store().close("Shipped."), Failure("posted the summary on ABC-12, but cannot move ABC-12 by 'Mark as done': Jira answered 503; close the epic in Jira rather than posting the summary again"))
|
||||
|
||||
def test_says_why_the_epics_status_cannot_be_read(self) -> None:
|
||||
for answer, reason in ((Failure("Jira answered 503"), "cannot read ABC-12's status: Jira answered 503"), ({"fields": {}}, "ABC-12's status is not in the shape Jira Cloud's REST API version 3 documents: KeyError('status')"), (["ABC-12"], "ABC-12's status is not in the shape Jira Cloud's REST API version 3 documents: TypeError('list indices must be integers or slices, not str')")):
|
||||
self.jira.answers[("GET", EPIC_STATUS)] = answer
|
||||
self.assertEqual(self.new_store().closed(), Failure(reason))
|
||||
|
||||
def test_finishes_an_issue_by_the_transition_the_settings_name(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.workflow = [{"id": "11", "name": "Start", "to": {"name": "In Progress", "statusCategory": {"key": "indeterminate"}}}, {"id": "31", "name": "Mark as done", "to": DONE}]
|
||||
self.assertIsNone(store.finish_issue(key))
|
||||
self.assertEqual(self.jira.calls[-1], ("POST", f"{ISSUES}/{key}/transitions"))
|
||||
self.assertEqual((self.jira.transitioned, self.jira.issues[0]["fields"]["status"]), (["31"], DONE)) # type: ignore[index]
|
||||
|
||||
def test_finishes_by_the_named_transition_where_several_lead_to_a_done_status(self) -> None:
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.workflow = [{"id": "31", "name": "Resolve", "to": DONE}, {"id": "41", "name": "Close", "to": {"name": "Closed", "statusCategory": {"key": "done"}}}]
|
||||
self.assertIsNone(JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Close", "Closed")).finish_issue(key))
|
||||
self.assertEqual(self.jira.transitioned, ["41"])
|
||||
|
||||
def test_leaves_an_issue_that_is_done_without_asking_for_its_transitions(self) -> None:
|
||||
store = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf)
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.change(key, status=DONE)
|
||||
self.assertIsNone(store.finish_issue(key))
|
||||
self.assertNotIn(("GET", f"{ISSUES}/{key}/transitions"), self.jira.calls)
|
||||
|
||||
def test_a_finish_names_why_no_move_finishes_the_issue(self) -> None:
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
unnamed = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf)
|
||||
wrong_status = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Mark as done", "Closed"))
|
||||
no_such = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Close", "Done"))
|
||||
self.assertEqual(unnamed.finish_issue(key), Failure("do-epic's settings name no transition to finish an issue by: set `jira-finish-transition` and `jira-finish-status` in ~/.claude-projects/do-epic/config.toml, to the names Jira shows, such as \"Mark as done\" and \"Done\""))
|
||||
self.assertEqual(wrong_status.finish_issue(key), Failure(f"{key}'s transition 'Mark as done' leads to the status 'Done', not to 'Closed', which `jira-finish-status` names"))
|
||||
refused = no_such.finish_issue(key)
|
||||
assert isinstance(refused, Failure)
|
||||
self.assertIn(f"{key} has no transition 'Close' from its status", refused.reason)
|
||||
self.assertEqual((self.jira.transitioned, self.jira.issues[0]["fields"]["status"]), ([], TO_DO)) # type: ignore[index]
|
||||
|
||||
def test_refuses_to_finish_a_sub_task_of_an_issue_that_is_no_child_of_the_epic_or_an_issue_without_a_parent(self) -> None:
|
||||
store = self.new_store()
|
||||
for key, parent in (("ABC-50", "ABC-60"), ("ABC-60", "ABC-61"), ("ABC-61", None)):
|
||||
fields = {"summary": "Other.", "description": None, "labels": [], "assignee": None, "status": TO_DO, "parent": {"key": parent} if parent else None, "issuelinks": []}
|
||||
self.jira.issues.append({"key": key, "fields": fields})
|
||||
for key in ("ABC-50", "ABC-61"):
|
||||
with self.subTest(key=key):
|
||||
self.assertEqual(store.finish_issue(key), Failure(f"{key} is not one of the child issues of the epic ABC-12, so it cannot be finished"))
|
||||
self.assertNotIn("POST", [method for method, _ in self.jira.calls])
|
||||
|
||||
def test_a_finish_jira_refuses_says_so_and_that_the_issue_may_have_moved(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.answers[("POST", f"{ISSUES}/{key}/transitions")] = Failure("Jira answered 400: Resolution is required")
|
||||
self.assertEqual(store.finish_issue(key), Failure(f"cannot move {key} by 'Mark as done': Jira answered 400: Resolution is required; unless Jira refused the request, the issue may have moved: look at {key} before finishing the item again"))
|
||||
|
||||
def test_a_finish_whose_transitions_jira_cannot_give_or_gives_in_another_shape_fails(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
url = ("GET", f"{ISSUES}/{key}/transitions")
|
||||
self.jira.answers[url] = Failure("Jira answered 503")
|
||||
self.assertEqual(store.finish_issue(key), Failure(f"cannot read {key}'s transitions: Jira answered 503"))
|
||||
for answer in ({"transitions": [{"id": 31}]}, ["Mark as done"], {"transitions": 5}):
|
||||
with self.subTest(answer=answer):
|
||||
self.jira.answers[url] = answer
|
||||
self.assertEqual(store.finish_issue(key), Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents"))
|
||||
|
||||
def test_a_finish_whose_issue_or_parent_jira_cannot_read_says_which(self) -> None:
|
||||
store = self.new_store()
|
||||
child = store.file("ABC-12", "Count the runs.", "", ())
|
||||
task = store.file(child, "Count them in the api.", "", ())
|
||||
self.jira.answers[("GET", f"{ISSUES}/{task}?fields=parent,status")] = Failure("Jira answered 503")
|
||||
self.assertEqual(store.finish_issue(task), Failure(f"cannot read {task} to finish it: Jira answered 503"))
|
||||
del self.jira.answers[("GET", f"{ISSUES}/{task}?fields=parent,status")]
|
||||
self.jira.answers[("GET", f"{ISSUES}/{child}?fields=parent,status")] = Failure("Jira answered 503")
|
||||
self.assertEqual(store.finish_issue(task), Failure(f"cannot read {child} to finish its sub-task: Jira answered 503"))
|
||||
|
||||
def test_reads_the_sub_tasks_of_more_children_than_one_search_names(self) -> None:
|
||||
store = self.new_store()
|
||||
children = [store.file("ABC-12", f"Item {n}.", "", ()) for n in range(60)]
|
||||
@@ -223,11 +358,11 @@ class Jira(Case):
|
||||
self.assertEqual(store.read(), Failure("the search for ABC-12's child issues did not end within 1 pages"))
|
||||
|
||||
def test_refuses_to_file_under_another_epics_child_or_an_issue_it_cannot_read(self) -> None:
|
||||
self.jira.issues.append({"key": "ABC-5", "fields": {"parent": {"key": "ABC-1"}}})
|
||||
self.jira.issues.append({"key": "ABC-5", "fields": {"parent": {"key": "ABC-1"}, "status": TO_DO}})
|
||||
store = self.new_store()
|
||||
self.assertEqual(store.file("ABC-5", "Count more.", "", ()), Failure("ABC-5 is neither the epic ABC-12 nor one of its child issues, so nothing can be filed under it"))
|
||||
self.assertEqual(store.file("ABC-77", "Count more.", "", ()), Failure(f"cannot read ABC-77 to file under it: Jira answered 404 for GET {ISSUES}/ABC-77?fields=parent"))
|
||||
self.jira.answers[("GET", f"{ISSUES}/ABC-78?fields=parent")] = ["ABC-12"]
|
||||
self.assertEqual(store.file("ABC-77", "Count more.", "", ()), Failure(f"cannot read ABC-77 to file under it: Jira answered 404 for GET {ISSUES}/ABC-77?fields=parent,status"))
|
||||
self.jira.answers[("GET", f"{ISSUES}/ABC-78?fields=parent,status")] = ["ABC-12"]
|
||||
self.assertEqual(store.file("ABC-78", "Count more.", "", ()), Failure("ABC-78 is neither the epic ABC-12 nor one of its child issues, so nothing can be filed under it"))
|
||||
self.assertEqual([call for call in self.jira.calls if call[0] == "POST" and call[1] == ISSUES], [])
|
||||
|
||||
@@ -252,14 +387,14 @@ class Jira(Case):
|
||||
def test_an_issue_jira_cannot_read_is_not_commented_on(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.answers[("GET", f"{ISSUES}/{key}?fields=parent")] = Failure("Jira answered 500")
|
||||
self.jira.answers[("GET", f"{ISSUES}/{key}?fields=parent,status")] = Failure("Jira answered 500")
|
||||
self.assertEqual(store.comment(str(key), "Hello."), Failure(f"cannot read {key} to comment on it: Jira answered 500"))
|
||||
self.assertNotIn(("POST", f"{ISSUES}/{key}/comment"), self.jira.calls)
|
||||
|
||||
def test_an_issue_jira_cannot_read_is_not_labelled(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.answers[("GET", f"{ISSUES}/{key}?fields=parent")] = Failure("Jira answered 500")
|
||||
self.jira.answers[("GET", f"{ISSUES}/{key}?fields=parent,status")] = Failure("Jira answered 500")
|
||||
self.assertEqual(store.add_label(str(key), "repo:log"), Failure(f"cannot read {key} to label it: Jira answered 500"))
|
||||
self.assertNotIn(("PUT", f"{ISSUES}/{key}"), self.jira.calls)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""What a do-epic cycle's worker is told: its task, from the issue, and its first prompt. The resumed prompt and the rung sentences are the ones loop-claude's cycles use, naming do-epic; a chunk that was parked is first told why it resumes."""
|
||||
"""What a do-epic cycle's worker is told: its task, from the issue, and its first prompt. The resumed prompt and the rung sentences are the ones loop-claude's cycles use, naming do-epic; a chunk that was parked is first told why it resumes, and one whose task follows the epic's state is told that task as it resumes."""
|
||||
import dataclasses
|
||||
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
@@ -48,3 +48,8 @@ def unparked(news: str) -> WorkerPrompts:
|
||||
"""The prompts of the first cycle after a parked chunk resumes: WORKER's, with each prompt that starts a worker opening with news, which says what the chunk waited on and what changed. The fresh prompt opens with it too, since a chunk the judge ruled finished before it parked has no session left to resume."""
|
||||
opening = f"{news} {FEEDBACK}\n\n"
|
||||
return dataclasses.replace(WORKER, fresh=lambda *task: opening + WORKER.fresh(*task), resumed=lambda *evidence: opening + WORKER.resumed(*evidence))
|
||||
|
||||
|
||||
def restating(task: str) -> WorkerPrompts:
|
||||
"""WORKER for a chunk whose task follows the epic's state, as its finishing's does: the prompt that resumes its worker states task, which may not be the one its session began with."""
|
||||
return dataclasses.replace(WORKER, resumed=lambda *evidence: f"{WORKER.resumed(*evidence)}\n\nThe task follows the epic's state, so it may have changed since you began. It is now:\n\n{task}")
|
||||
|
||||
@@ -13,13 +13,15 @@ One pair per machine, the same for every epic (docs/decisions.md → `do-epic: d
|
||||
- `repoless-model` is the model that works an epic item with no repo: a model on the routing ladder, `model_routing/routing-ladder.json`.
|
||||
- `clone-folder` is the folder a missing repo is cloned into: a path that starts with / or ~/. `~/code` where left out.
|
||||
- `language` is the default language of Jira text, by its English name. English where left out.
|
||||
- `jira-finish-transition` and `jira-finish-status` name the workflow transition that moves a finished chunk's issue and closes a finished epic, such as "Mark as done", and the status it leads to, such as "Done". A project's config names a plan item's the same way. Set both or neither; without them do-epic moves no issue to done and closes no epic.
|
||||
- `repo-rule.md` is prose that says how to tell an item's repo, and mustn't be blank."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
from project_config.settings import anywhere, CONFIG, DO_EPIC, ENV_FILE, LANGUAGE, language_fault, lies_in, parsed, PROJECTS, SITE
|
||||
from project_config.settings import anywhere, CONFIG, DO_EPIC, ENV_FILE, Finish, finish_faults, finish_of, JIRA_FINISH, LANGUAGE, language_fault, lies_in, parsed, PROJECTS, SITE
|
||||
from failure import Failure
|
||||
from text_files.markdown_text import listed
|
||||
from model_routing.ladder_file import read_ladder, SHIPPED
|
||||
|
||||
REPO_RULE = "repo-rule.md"
|
||||
@@ -28,8 +30,8 @@ JIRA_URL = "jira-url"
|
||||
REPOLESS_MODEL = "repoless-model"
|
||||
CLONE_FOLDER = "clone-folder"
|
||||
SETTINGS = (JIRA_URL, ENV_FILE, REPOLESS_MODEL)
|
||||
OPTIONAL = (CLONE_FOLDER, LANGUAGE)
|
||||
LISTED = f"The settings are {', '.join(SETTINGS)}, and optionally {' and '.join(OPTIONAL)}."
|
||||
OPTIONAL = (CLONE_FOLDER, LANGUAGE, *JIRA_FINISH)
|
||||
LISTED = f"The settings are {', '.join(SETTINGS)}, and optionally {listed(OPTIONAL, 'and')}."
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -42,6 +44,8 @@ class DoEpicConfig:
|
||||
language: str
|
||||
repoless_model: str
|
||||
repo_rule: str
|
||||
# How a finished epic closes; None where the config doesn't say.
|
||||
finish: Finish | None = None
|
||||
|
||||
|
||||
def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfig | Failure:
|
||||
@@ -73,10 +77,11 @@ def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfi
|
||||
*([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, inside a folder of ~/{PROJECTS} or the clone folder, which hold git checkouts"] if env_file and lies_in(env_file, *config_folders, *([clone_folder] if clone_folder else [])) else []),
|
||||
*([f"`{LANGUAGE}` is {language!r}, {fault}"] if LANGUAGE in values and (fault := language_fault(language)) else []),
|
||||
*([f"`{REPOLESS_MODEL}` is {model!r}, not a model on the routing ladder: {', '.join(models)}"] if REPOLESS_MODEL in values and model not in models else []),
|
||||
*finish_faults(values),
|
||||
*([rule.reason] if isinstance(rule, Failure) else [f"`{REPO_RULE}` is blank"] if not rule.strip() else []),
|
||||
]
|
||||
if faults:
|
||||
return Failure(f"{folder}: {'; '.join(faults)}. {LISTED}")
|
||||
# Without a fault, each value above is present and of the type asserted here.
|
||||
assert clone_folder and env_file and isinstance(url, str) and isinstance(model, str) and isinstance(language, str) and isinstance(rule, str)
|
||||
return DoEpicConfig(folder, url, env_file, clone_folder, language, model, rule)
|
||||
return DoEpicConfig(folder, url, env_file, clone_folder, language, model, rule, finish_of(values))
|
||||
|
||||
+19
-14
@@ -6,10 +6,11 @@ import fcntl
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
from do_epic.repo_pick import CLAUDE_LABEL, HUMAN_LABEL, of_label, REPO_PREFIX
|
||||
from do_epic.repo_pick import CLAUDE_LABEL, HUMAN_LABEL, of_label, REPO_PREFIX, REVIEW_LABEL
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from do_epic.backend.protocol import EpicStore
|
||||
from failure import Failure
|
||||
from text_files.markdown_text import listed
|
||||
from text_files.piped_text import piped
|
||||
|
||||
# Three readers, seated as the human and as a chunk's worker, picked each spelling from four: `<EPIC-KEY> --file` over `--file <EPIC-KEY>`, `add` and `--finding`, and `--record-decision` over `--decision` and `--decide`.
|
||||
@@ -20,10 +21,11 @@ RECORD_DECISION = "--record-decision"
|
||||
LABELS = f"`{REPO_PREFIX}<name>` for the repo that works it, `{CLAUDE_LABEL}` for work of Claude's that changes no repo, or `{HUMAN_LABEL}` for a task of the human's"
|
||||
# Under the epic's folder, the file a do-epic holds locked while it appends a decision.
|
||||
DECISIONS_LOCK = "decisions.lock"
|
||||
USAGE = f"""do-epic <EPIC-KEY> {FILE} <summary> [{LABEL} <label>] [<<'EOF' detail EOF]
|
||||
USAGE = f"""do-epic <EPIC-KEY> {FILE} <summary> [{LABEL} <label>]... [<<'EOF' detail EOF]
|
||||
do-epic <EPIC-KEY> {RECORD_DECISION} <title> <<'EOF' entry EOF"""
|
||||
HELP = f"""{FILE} files a finding about one of the epic's goals as an open issue of the epic, with the markdown piped in as its description.
|
||||
{LABEL} is {LABELS}; without one the issue waits until someone labels it.
|
||||
A second {LABEL}, `{REVIEW_LABEL}`, marks the issue as a repo's release review, which the epic's finishing files.
|
||||
A finding about a repo's own goals goes into that repo's plan instead.
|
||||
{RECORD_DECISION} appends a decision that governs the epic to its description's ## Decisions, under the title, with the markdown piped in as its text."""
|
||||
|
||||
@@ -49,32 +51,35 @@ def decisions_locked(folder: pathlib.Path) -> typing.Iterator[None]:
|
||||
yield
|
||||
|
||||
|
||||
def parsed(words: list[str]) -> tuple[str, str, str | None] | None:
|
||||
"""What the words after the epic's key ask for: the flag, the summary or title, and the label, None without one. None where they aren't spelt as USAGE has them. A word that opens with `--` is no summary, title or label."""
|
||||
def parsed(words: list[str]) -> tuple[str, str, tuple[str, ...]] | None:
|
||||
"""What the words after the epic's key ask for: the flag, the summary or title, and each label. None where they aren't spelt as USAGE has them. A word that opens with `--` is no summary, title or label."""
|
||||
if not words or words[0] not in (FILE, RECORD_DECISION):
|
||||
return None
|
||||
label: str | None = None
|
||||
labels: list[str] = []
|
||||
rest = words[1:]
|
||||
if words[0] == FILE and LABEL in rest:
|
||||
while words[0] == FILE and LABEL in rest:
|
||||
at = rest.index(LABEL)
|
||||
if at + 1 >= len(rest):
|
||||
return None
|
||||
label, rest = rest[at + 1], rest[:at] + rest[at + 2:]
|
||||
if len(rest) != 1 or any(word.startswith("--") for word in (*rest, label or "")):
|
||||
labels.append(rest[at + 1])
|
||||
rest = rest[:at] + rest[at + 2:]
|
||||
if len(rest) != 1 or any(word.startswith("--") for word in (*rest, *labels)):
|
||||
return None
|
||||
return words[0], rest[0], label
|
||||
return words[0], rest[0], tuple(labels)
|
||||
|
||||
|
||||
def written(epic: str, flag: str, value: str, label: str | None, store: EpicStore, record: EpicRecord, stdin: typing.TextIO, folder: pathlib.Path) -> str | Failure:
|
||||
def written(epic: str, flag: str, value: str, labels: tuple[str, ...], store: EpicStore, record: EpicRecord, stdin: typing.TextIO, folder: pathlib.Path) -> str | Failure:
|
||||
"""Files the finding or records the decision, as flag says, and answers the line to print. folder is the epic's, where the lock for its decisions lies."""
|
||||
text = piped(stdin)
|
||||
if flag == FILE:
|
||||
if label and of_label(label) is None:
|
||||
return Failure(f"cannot file the finding in the epic {epic}: do-epic doesn't read the label {label!r}; write {LABELS}")
|
||||
key = store.file(epic, value, text, (label,) if label else ())
|
||||
if unread := [label for label in labels if of_label(label) is None and label != REVIEW_LABEL]:
|
||||
return Failure(f"cannot file the finding in the epic {epic}: do-epic doesn't read the label {unread[0]!r}; write {LABELS}")
|
||||
if len(picks := [label for label in labels if of_label(label)]) > 1:
|
||||
return Failure(f"cannot file the finding in the epic {epic}: {listed(picks, 'and')} each say who works it; write one of them")
|
||||
key = store.file(epic, value, text, labels)
|
||||
if isinstance(key, Failure):
|
||||
return Failure(f"cannot file the finding in the epic {epic}: {key.reason}")
|
||||
return f"Filed {key} in the epic {epic}." + ("" if label else f" It waits until someone labels it: {LABELS}.")
|
||||
return f"Filed {key} in the epic {epic}." + ("" if any(of_label(label) for label in labels) else f" It waits until someone labels it: {LABELS}.")
|
||||
try:
|
||||
with decisions_locked(folder):
|
||||
added = record.append_decision(value, text)
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
"""How an epic ends (docs/decisions.md → `do-epic: drives one Jira epic …` → "Finishing").
|
||||
|
||||
Once the epic holds issues and none is open, its finishing chunk runs, in a window named for the epic's key. It has no issue: `task` is its task, which follows the epic's state.
|
||||
|
||||
1. While a repo the epic changed lacks a release review, the chunk files one issue per such repo, labelled REVIEW_LABEL, and ends. Each such issue runs as any issue's chunk does, and so does each issue its review files.
|
||||
2. With each repo reviewed, the human confirms each goal. For a goal they don't confirm, the chunk files the set of items they approve, and ends.
|
||||
3. With every goal confirmed, `do-epic <EPIC-KEY> --close-epic` posts the summary on the epic and closes it.
|
||||
|
||||
The chunk starts again each time the epic holds no open issue, until the epic is closed. A repo is reviewed once per epic, as a release is: the issues filed after its review don't bring another."""
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
from do_epic.chunk_prompt import DRIVER
|
||||
from do_epic.backend.protocol import EpicIssue, EpicStore
|
||||
from failure import Failure
|
||||
from do_epic import findings
|
||||
from do_epic.split import finished
|
||||
from text_files.markdown_text import listed
|
||||
from text_files.piped_text import piped
|
||||
from do_epic.repo_pick import recorded, Repo, REPO_PREFIX, REVIEW_LABEL
|
||||
|
||||
# Not `--close`, which reads as closing the run or one issue: three readers, seated as the human, as a chunk's worker and as one of the client's team, picked this one from four, 2-1 over it.
|
||||
CLOSE = "--close-epic"
|
||||
USAGE = f"do-epic <EPIC-KEY> {CLOSE} <<'EOF' summary EOF"
|
||||
HELP = f"""Once every issue is done, the epic's finishing chunk runs, in a window named for the epic.
|
||||
It files a release review of each repo the epic changed, as an issue labelled `{REVIEW_LABEL}`, then asks you to confirm each goal.
|
||||
{CLOSE} posts the markdown piped in on the epic as its summary, then closes the epic. It refuses while an issue is open or a repo lacks its review.
|
||||
It closes the epic by the transition `jira-finish-transition` names, to the status `jira-finish-status` names."""
|
||||
|
||||
|
||||
def due(issues: list[EpicIssue]) -> bool:
|
||||
"""Whether the epic's finishing comes next: it holds an issue, and none is open."""
|
||||
return bool(issues) and not still_open(issues)
|
||||
|
||||
|
||||
def still_open(issues: list[EpicIssue]) -> list[str]:
|
||||
"""The key of each issue that isn't done; an item split by repo is done once its sub-tasks are."""
|
||||
return [issue.key for issue in issues if not finished(issues, issue.key)]
|
||||
|
||||
|
||||
def repo_of(issue: EpicIssue) -> str | None:
|
||||
"""The name of the repo the issue's labels record; None where they record none."""
|
||||
pick = recorded(issue)
|
||||
return pick.name if isinstance(pick, Repo) else None
|
||||
|
||||
|
||||
def unreviewed(issues: list[EpicIssue]) -> list[str]:
|
||||
"""The repos the epic changed that have no release review, sorted. The epic changed a repo where a done issue names it, and a repo has its review once an issue labelled REVIEW_LABEL names it, open or done."""
|
||||
reviewed = {repo_of(issue) for issue in issues if REVIEW_LABEL in issue.labels}
|
||||
changed = {repo_of(issue) for issue in issues if issue.done and REVIEW_LABEL not in issue.labels}
|
||||
return sorted(repo for repo in changed - reviewed if repo is not None)
|
||||
|
||||
|
||||
def task(epic: str, issues: list[EpicIssue], launcher: pathlib.Path, language: str) -> str:
|
||||
"""The finishing chunk's task, for the epic with the key epic as issues has it. launcher is the do-epic that runs the chunk, and language the one the epic's Jira text is in."""
|
||||
opening = f"Finish the epic {epic}, which holds no open issue, as one chunk that changes no repo: work in the folder you start in."
|
||||
if lacking := unreviewed(issues):
|
||||
return (
|
||||
f"{opening} Each repo the epic changed takes a release review first, and {listed(lacking, 'and')} {'has' if len(lacking) == 1 else 'have'} none. "
|
||||
f"File one issue per such repo, with `{launcher} {epic} {findings.FILE} \"<summary>\" {findings.LABEL} {REPO_PREFIX}<name> {findings.LABEL} {REVIEW_LABEL}` and its detail on stdin, both in {language}, the epic's language. "
|
||||
f"The detail asks for a release review of the whole repo, as the epic's issues left it: the one `~/.claude/skills/larv-review/SKILL.md` → \"Release review\" describes. The epic's key stands in place of the release there, so the review's branch opens with an empty commit titled `Release review of {epic}`. "
|
||||
"Where filing fails and says the issue may exist, ask the human to look before you file it again. "
|
||||
f"The chunk is finished once each issue is filed: {DRIVER} works them, and starts this chunk again once the epic holds no open issue."
|
||||
)
|
||||
return (
|
||||
f"{opening} Each repo it changed has had its release review. Three steps remain, in this order.\n\n"
|
||||
"1. Ask the human to confirm each goal under the description's ## Goals: that an achieve goal is achieved, and that no defect stands against a maintain goal. Ask one goal per question, each with the evidence of what shipped. "
|
||||
"A goal is met only where the human confirms it: never take one as met from the evidence alone. Don't ask again about a goal a decision in the description records as confirmed.\n"
|
||||
"2. For a goal the human doesn't confirm, propose a set of items that would meet it, and ask the human to approve the set. File each item they approve. "
|
||||
f"Then the chunk is finished: {DRIVER} works the items, and starts this chunk again once the epic holds no open issue.\n"
|
||||
f"3. Once the human has confirmed every goal, write a summary in {language}, the epic's language, for the people who work the epic: what shipped in each repo, and each goal's evidence. "
|
||||
f"Post it and close the epic with `{launcher} {epic} {CLOSE}`, the summary on stdin. That is the chunk's very last step, and the chunk is finished once it succeeds.\n\n"
|
||||
f"{findings.instructions(epic, launcher, language)} Record each goal's confirmation as such a decision.\n\n"
|
||||
"The epic's issues, each done:\n\n" + "\n".join(f"- {issue.key}{f' ({repo})' if (repo := repo_of(issue)) else ''}: {issue.summary}" for issue in issues)
|
||||
)
|
||||
|
||||
|
||||
def closed(epic: str, store: EpicStore, stdin: typing.TextIO) -> str | Failure:
|
||||
"""Posts the summary piped in on the epic with the key epic and closes it, and answers the line to print; a Failure, with nothing posted, while the epic isn't ready to close."""
|
||||
# Whether the human confirmed each goal isn't checked here: a decision that records it is the worker's own text, so only the task and the judge, who reads the human's answers, can hold the worker to it.
|
||||
issues = store.read()
|
||||
if isinstance(issues, Failure):
|
||||
return Failure(f"cannot close the epic {epic}: {issues.reason}")
|
||||
already = store.closed()
|
||||
if already:
|
||||
return Failure(f"cannot close the epic {epic}: {already.reason if isinstance(already, Failure) else 'it is closed already'}")
|
||||
if waiting := still_open(issues):
|
||||
return Failure(f"cannot close the epic {epic}: {listed(waiting, 'and')} {'is' if len(waiting) == 1 else 'are'} open")
|
||||
if lacking := unreviewed(issues):
|
||||
return Failure(f"cannot close the epic {epic}: no issue labelled {REVIEW_LABEL} reviews {listed(lacking, 'or')}")
|
||||
done = store.close(piped(stdin))
|
||||
return Failure(f"cannot close the epic {epic}: {done.reason}") if isinstance(done, Failure) else f"Posted the summary on the epic {epic} and closed it."
|
||||
+81
-30
@@ -9,7 +9,7 @@ import sys
|
||||
import typing
|
||||
|
||||
from loop_claude.loop.chunk_start import archived_route, routed
|
||||
from do_epic import chunk_prompt, findings, gates, parked, scheduler, status
|
||||
from do_epic import chunk_prompt, findings, finish, gates, parked, scheduler, split, status
|
||||
from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo
|
||||
from loop_claude.loop.close import closed_cycle
|
||||
from loop_claude.project.records import CONSEQUENCE, read_records
|
||||
@@ -42,6 +42,7 @@ from agent_cycle import tmux
|
||||
|
||||
HELP = f"""usage: do-epic <EPIC-KEY> [--status]
|
||||
{findings.USAGE}
|
||||
{finish.USAGE}
|
||||
|
||||
Runs the chunks of one Jira epic, such as ABC-12, each in its own window of the tmux session epic-<EPIC-KEY>.
|
||||
An open issue of the epic runs as a chunk once it has a label and no issue blocks it.
|
||||
@@ -54,6 +55,7 @@ on once the checks pass, the approval comes or a reviewer comments, and a place
|
||||
name says `awaits a slot`. 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.
|
||||
{findings.HELP}
|
||||
{finish.HELP}
|
||||
The Jira site and its credentials are set in ~/.claude-projects/do-epic/config.toml."""
|
||||
# Under the home folder, where a chunk's cycles are archived, a folder per epic. It is not loop-claude's archive, since that archive's readers, such as judge-replay and the routing figures, read loop-claude's prompts.
|
||||
ARCHIVE = ".claude/do-epic-transcripts"
|
||||
@@ -68,7 +70,7 @@ Backend = typing.Callable[[DoEpicConfig, str], tuple[EpicStore, EpicRecord]]
|
||||
|
||||
def jira_backend(config: DoEpicConfig, key: str) -> tuple[EpicStore, EpicRecord]:
|
||||
epic = Epic(config.jira_url, key)
|
||||
return JiraEpic(epic, config.env_file), EpicRecord(EpicDescription(epic, config.env_file))
|
||||
return JiraEpic(epic, config.env_file, finish=config.finish), EpicRecord(EpicDescription(epic, config.env_file))
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -112,9 +114,10 @@ def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher:
|
||||
words = words[:1] if status_asked else words
|
||||
# What the words after the epic's key write into the epic, where they are a filing or a decision.
|
||||
writes = findings.parsed(words[1:]) if chunk is None else None
|
||||
if (len(words) != 1 and not writes) or not ISSUE_KEY.fullmatch(words[0]) or (chunk is not None and not ISSUE_KEY.fullmatch(chunk)):
|
||||
closes = chunk is None and words[1:] == [finish.CLOSE]
|
||||
if (len(words) != 1 and not writes and not closes) or not ISSUE_KEY.fullmatch(words[0]) or (chunk is not None and not ISSUE_KEY.fullmatch(chunk)):
|
||||
return Stop(0 if words in (["-h"], ["--help"]) else 1, HELP)
|
||||
if writes:
|
||||
if writes or closes:
|
||||
return epic_written(words[0], writes, paths, backend, stdin)
|
||||
# Before anything starts: a clone, a claude session or a tmux window.
|
||||
if reason := tmux.unusable(effects.tmux, chunk_prompt.DRIVER):
|
||||
@@ -136,23 +139,27 @@ def status_printed(epic: EpicRun) -> Stop:
|
||||
return Stop(1, lines.reason) if isinstance(lines, Failure) else Stop(0, "\n".join(lines) or f"the epic {epic.key} has no open issue")
|
||||
|
||||
|
||||
def epic_written(key: str, writes: tuple[str, str, str | None], paths: Paths, backend: Backend, stdin: typing.TextIO) -> Stop:
|
||||
"""Files a finding in the epic, or records a decision in its description. It needs no tmux, so a chunk's worker may run it anywhere."""
|
||||
def epic_written(key: str, writes: tuple[str, str, tuple[str, ...]] | None, paths: Paths, backend: Backend, stdin: typing.TextIO) -> Stop:
|
||||
"""Files a finding in the epic or records a decision in its description, as writes says; closes the epic where writes is None. It needs no tmux, so a chunk's worker may run it anywhere."""
|
||||
config = load(paths.home)
|
||||
if isinstance(config, Failure):
|
||||
return Stop(1, config.reason)
|
||||
done = findings.written(key, *writes, *backend(config, key), stdin, paths.home / scheduler.STATE / key)
|
||||
store, record = backend(config, key)
|
||||
done = findings.written(key, *writes, store, record, stdin, paths.home / scheduler.STATE / key) if writes else finish.closed(key, store, stdin)
|
||||
return Stop(1, done.reason) if isinstance(done, Failure) else Stop(0, done)
|
||||
|
||||
|
||||
def windows_opened(epic: EpicRun) -> Stop:
|
||||
"""What the do-epic the human runs does: starts each chunk that may start now, says why each other open issue waits, then puts the epic's session on the terminal until the human detaches."""
|
||||
started = chunks_started(epic, None)
|
||||
issues = epic.store.read()
|
||||
started = issues if isinstance(issues, Failure) else chunks_started(epic, issues, None)
|
||||
if isinstance(started, Failure):
|
||||
return Stop(1, started.reason)
|
||||
say(f"started {', '.join(started.started)} in the tmux session {epic.session}" if started.started else "started no chunk", epic.effects, stdout=True)
|
||||
for wait in started.waits:
|
||||
say(f"{wait.issue} waits: {wait.reason}", epic.effects, stdout=True)
|
||||
if started.closed:
|
||||
say(f"the epic {epic.key} is closed", epic.effects, stdout=True)
|
||||
if not tmux.listed(epic.session, epic.effects.tmux):
|
||||
return Stop(0, "")
|
||||
if not epic.effects.on_terminal():
|
||||
@@ -162,13 +169,16 @@ def windows_opened(epic: EpicRun) -> Stop:
|
||||
return Stop(1, f"`tmux {' '.join(shown)}` failed; the chunks go on in the tmux session") if epic.effects.tmux_on_terminal(shown) else Stop(0, "")
|
||||
|
||||
|
||||
def chunks_started(epic: EpicRun, own: str | None) -> scheduler.Started | Failure:
|
||||
"""scheduler.start_chunks on the epic's issues and cap, read afresh; own is the issue of the chunk that asks."""
|
||||
issues = epic.store.read()
|
||||
if isinstance(issues, Failure):
|
||||
return issues
|
||||
def chunks_started(epic: EpicRun, issues: list[EpicIssue], own: str | None) -> scheduler.Started | Failure:
|
||||
"""scheduler.start_chunks on the epic's issues, as read, and its cap, read afresh; own is the issue of the chunk that asks. Where no issue is open, the chunk to start is the epic's finishing, unless the epic is closed."""
|
||||
closed = finish.due(issues) and epic.store.closed()
|
||||
if isinstance(closed, Failure):
|
||||
return closed
|
||||
scheduled = scheduled_epic(epic)
|
||||
return scheduled if isinstance(scheduled, Failure) else scheduler.start_chunks(scheduled, issues, own, epic.effects.tmux)
|
||||
if isinstance(scheduled, Failure):
|
||||
return scheduled
|
||||
started = scheduler.start_chunks(scheduled, issues, finish.due(issues) and not closed, own, epic.effects.tmux)
|
||||
return started if isinstance(started, Failure) else dataclasses.replace(started, closed=closed)
|
||||
|
||||
|
||||
def scheduled_epic(epic: EpicRun) -> scheduler.Epic | Failure:
|
||||
@@ -218,10 +228,7 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
pane = epic.env.get("TMUX_PANE")
|
||||
if not pane:
|
||||
return Stop(1, f"{scheduler.CHUNK_FLAG} is how do-epic starts itself in a tmux window; run do-epic <EPIC-KEY>")
|
||||
issue = issue_read(key, epic)
|
||||
if isinstance(issue, Stop):
|
||||
return issue
|
||||
place = chunk_root(issue, epic)
|
||||
place = chunk_root(key, epic)
|
||||
if isinstance(place, Stop):
|
||||
return place
|
||||
root, repo = place
|
||||
@@ -292,7 +299,8 @@ def parked_through(repo: str, loop: Loop, epic: EpicRun, starts: bool) -> str |
|
||||
shown = awaits
|
||||
if on is None:
|
||||
# Once the window shows as parked, so the chunks that start count it as running nowhere.
|
||||
started = chunks_started(epic, key)
|
||||
issues = epic.store.read()
|
||||
started = issues if isinstance(issues, Failure) else chunks_started(epic, issues, key)
|
||||
say(f"could not start the next chunk: {started.reason}" if isinstance(started, Failure) else f"started {', '.join(started.started) or 'no other'}", epic.effects, stdout=True)
|
||||
on = now.on if isinstance(now, gates.Gate) else on
|
||||
if stays is not None and stays != said:
|
||||
@@ -322,9 +330,12 @@ def issue_read(key: str, epic: EpicRun) -> EpicIssue | Stop:
|
||||
return found[0] if found else Stop(1, f"{key} is no issue of the epic {epic.key}")
|
||||
|
||||
|
||||
def chunk_root(issue: EpicIssue, epic: EpicRun) -> tuple[str, str | None] | Stop:
|
||||
"""The folder the issue's chunk works in, and the name of the repo whose checkout it is: None for the epic's folder, which holds work without a repo. The chunk keeps both to its end, whatever the issue's labels become. The stop where the labels make the issue no chunk."""
|
||||
pick = recorded(issue)
|
||||
def chunk_root(key: str, epic: EpicRun) -> tuple[str, str | None] | Stop:
|
||||
"""The folder the chunk called key works in, and the name of the repo whose checkout it is: None for the epic's folder, which holds work without a repo, as the epic's finishing is. The chunk keeps both to its end, whatever its issue's labels become. The stop where the labels make the issue no chunk."""
|
||||
issue = None if key == epic.key else issue_read(key, epic)
|
||||
if isinstance(issue, Stop):
|
||||
return issue
|
||||
pick = recorded(issue) if issue else ClaudeWork()
|
||||
if isinstance(pick, Failure):
|
||||
return Stop(1, pick.reason)
|
||||
if isinstance(pick, ClaudeWork):
|
||||
@@ -332,25 +343,45 @@ def chunk_root(issue: EpicIssue, epic: EpicRun) -> tuple[str, str | None] | Stop
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
return str(folder), None
|
||||
if not isinstance(pick, Repo):
|
||||
return Stop(1, f"{issue.key} is no chunk: {'it is a human\'s task' if isinstance(pick, HumanTask) else 'no label names its repo'}")
|
||||
return Stop(1, f"{key} is no chunk: {'it is a human\'s task' if isinstance(pick, HumanTask) else 'no label names its repo'}")
|
||||
found = locate(pick.name, [], epic.config, epic.paths.home, epic.effects.git)
|
||||
return Stop(1, found.reason) if isinstance(found, Failure) else (str(real(found.checkout)), pick.name)
|
||||
|
||||
|
||||
def handed_on(key: str, epic: EpicRun) -> Stop:
|
||||
"""The stop of a do-epic whose chunk finished, once it has started each chunk that may start now. Its window closes as it exits."""
|
||||
started = chunks_started(epic, key)
|
||||
"""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. Its window closes as it exits."""
|
||||
# The epic's finishing has no issue to move: the epic is closed by `--close-epic`.
|
||||
moved = None if key == epic.key else epic.store.finish_issue(key)
|
||||
if isinstance(moved, Failure):
|
||||
return Stop(1, f"the chunk finished, but its issue could not move to done: {moved.reason}; once it is done in Jira, run `do-epic {epic.key}` to start the chunks it blocks")
|
||||
issues = epic.store.read()
|
||||
if isinstance(issues, Failure):
|
||||
return Stop(1, f"the chunk finished, but the next could not start: {issues.reason}")
|
||||
# A search may not show the move yet, so the issue counts as done here whatever the read says.
|
||||
issues = [dataclasses.replace(each, done=True) if each.key == key else each for each in issues]
|
||||
closed = split_items_closed(epic, issues)
|
||||
if isinstance(closed, Stop):
|
||||
return closed
|
||||
started = chunks_started(epic, closed, key)
|
||||
if isinstance(started, Failure):
|
||||
return Stop(1, f"the chunk finished, but the next could not start: {started.reason}")
|
||||
say(f"the chunk finished; started {', '.join(started.started) or 'no other'}", epic.effects, stdout=True)
|
||||
return Stop(0, "")
|
||||
|
||||
|
||||
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:
|
||||
if split.SPLIT_LABEL in item.labels and not item.done and split.finished(issues, item.key):
|
||||
moved = epic.store.finish_issue(item.key)
|
||||
if isinstance(moved, Failure):
|
||||
return Stop(1, f"the chunk finished, but its split item {item.key} could not move to done: {moved.reason}; once it is done in Jira, run `do-epic {epic.key}` to start the chunks it blocks")
|
||||
issues = [dataclasses.replace(each, done=True) if each.key == item.key else each for each in issues]
|
||||
return issues
|
||||
|
||||
|
||||
def next_cycle(loop_run: LoopRun, loop: Loop, in_repo: bool, epic: EpicRun, news: str = "") -> Cycle | Stop:
|
||||
"""The cycle loop_run runs next, from the issue, the premises, the records, the models and the routing ladder read afresh; the stop where one of them cannot be read. news is what `parked_through` tells the worker of a chunk that was parked, and opens its prompt. A chunk in a repo routes on that repo's model and ladder, and one without a repo on the machine setting `repoless-model` and the shipped ladder."""
|
||||
issue = issue_read(loop.window.name, epic)
|
||||
if isinstance(issue, Stop):
|
||||
return issue
|
||||
premises = premises_read(loop.root if in_repo else None, epic)
|
||||
if isinstance(premises, Failure):
|
||||
return Stop(1, premises.reason)
|
||||
@@ -360,6 +391,10 @@ def next_cycle(loop_run: LoopRun, loop: Loop, in_repo: bool, epic: EpicRun, news
|
||||
records = records_read(loop.root if in_repo else None, epic)
|
||||
if isinstance(records, Failure):
|
||||
return Stop(1, records.reason)
|
||||
work = chunk_work(loop.window.name, loop.root if in_repo else None, language or epic.config.language, epic)
|
||||
if isinstance(work, Stop):
|
||||
return work
|
||||
task, routing = work
|
||||
models = get_or_ask_models(project_key(loop.root, epic.paths.home), epic.paths, epic.env, chunk_prompt.DRIVER, epic.effects) if in_repo else repoless_models(epic)
|
||||
if isinstance(models, Stop):
|
||||
return models
|
||||
@@ -371,9 +406,25 @@ def next_cycle(loop_run: LoopRun, loop: Loop, in_repo: bool, epic: EpicRun, news
|
||||
return Stop(1, ladder.reason)
|
||||
archive_folder = epic.paths.home / ARCHIVE / epic.key
|
||||
project = ladder.project_rung(models.worker)
|
||||
route = routed(loop_run.route, project, models.worker, lambda: archived_route(archive_folder, loop), lambda: RoutingIssue(issue) if "L" in issue.scores else None)
|
||||
route = routed(loop_run.route, project, models.worker, lambda: archived_route(archive_folder, loop), lambda: routing)
|
||||
say(f"\n=== cycle {loop_run.cycle_number}, worker on {route.rung} ===", epic.effects, stdout=True)
|
||||
return Cycle(config=setup_version(epic.paths.claude_dir, epic.effects.git), effects=epic.effects, facts="", judge=judge_rung(ladder, models.judge), premises=premises, project=project, project_archive=archive_folder, records=records, root=loop.root, route=route, session=loop.session, task=chunk_prompt.task(issue, epic.key, loop.root if in_repo else None, epic.launcher, language or epic.config.language), prompts=chunk_prompt.unparked(news) if news else chunk_prompt.WORKER, taken_in=lambda entries: TakenIn(), unfinished_evidence=loop_run.unfinished_evidence, window=loop.window)
|
||||
return Cycle(config=setup_version(epic.paths.claude_dir, epic.effects.git), effects=epic.effects, facts="", judge=judge_rung(ladder, models.judge), premises=premises, project=project, project_archive=archive_folder, records=records, root=loop.root, route=route, session=loop.session, task=task, prompts=chunk_prompt.unparked(news) if news else chunk_prompt.restating(task) if loop_run.chunk == epic.key else chunk_prompt.WORKER, taken_in=lambda entries: TakenIn(), unfinished_evidence=loop_run.unfinished_evidence, window=loop.window)
|
||||
|
||||
|
||||
def chunk_work(key: str, checkout: str | None, language: str, epic: EpicRun) -> tuple[str, RoutingIssue | None] | Stop:
|
||||
"""The task of the chunk called key, and the issue that routes it, or None where that issue has no scores: both from the epic's issues, read afresh. The epic's finishing has no issue, and it ends here once the epic holds an open issue again, since working that issue comes first."""
|
||||
if key != epic.key:
|
||||
issue = issue_read(key, epic)
|
||||
if isinstance(issue, Stop):
|
||||
return issue
|
||||
return chunk_prompt.task(issue, epic.key, checkout, epic.launcher, language), RoutingIssue(issue) if "L" in issue.scores else None
|
||||
issues = epic.store.read()
|
||||
if isinstance(issues, Failure):
|
||||
return Stop(1, issues.reason)
|
||||
if not finish.due(issues):
|
||||
say(f"the epic {epic.key} holds an open issue again, so its finishing chunk ends until none is open", epic.effects, stdout=True)
|
||||
return handed_on(key, epic)
|
||||
return finish.task(epic.key, issues, epic.launcher, language), None
|
||||
|
||||
|
||||
def repoless_models(epic: EpicRun) -> Models:
|
||||
|
||||
@@ -15,6 +15,8 @@ from claude_code.entries import structured_output
|
||||
REPO_PREFIX = "repo:"
|
||||
CLAUDE_LABEL = "do-epic-claude"
|
||||
HUMAN_LABEL = "do-epic-human"
|
||||
# Marks the issue that asks for a repo's release review, beside the label that names the repo (finish.py). Not `release-review`, which could pass for the team's own release process: three readers, seated as the human, as a chunk's worker and as one of the client's team, picked this one 3-0 from four.
|
||||
REVIEW_LABEL = "do-epic-release-review"
|
||||
# A repo's name is a folder name and part of a clone address, so claude's answer or a label a person typed must not hold a slash, a colon or a leading dot.
|
||||
REPO_NAME = re.compile(r"\w[\w.-]*")
|
||||
|
||||
|
||||
@@ -40,9 +40,11 @@ class Waits:
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Started:
|
||||
# The issues whose chunks started.
|
||||
# The issues whose chunks started, and the epic's key where its finishing did.
|
||||
started: list[str]
|
||||
waits: list[Waits]
|
||||
# Whether the epic is closed, so that not even its finishing starts.
|
||||
closed: bool = False
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -108,10 +110,12 @@ def refusal(repo: str, room: RepoRoom) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def start_chunks(epic: Epic, issues: list[EpicIssue], own: str | None, run: tmux.Tmux) -> Started | Failure:
|
||||
"""Starts a do-epic in a new window for each of the epic's chunks that may start now. own is the issue of the chunk that asks, which has finished or parked: it counts as running nowhere, and no stopped chunk starts again. Where own is None, the human's `do-epic <EPIC-KEY>` asks, and each stopped chunk starts again. A parked chunk waits in its window; one without a live window, as after a reboot, starts again as a stopped chunk does, whatever the limits, since it goes on parked. A Failure says why a window could not start; those before it run."""
|
||||
def start_chunks(epic: Epic, issues: list[EpicIssue], finishing: bool, own: str | None, run: tmux.Tmux) -> Started | Failure:
|
||||
"""Starts a do-epic in a new window for each of the epic's chunks that may start now. Where finishing is set, no issue is open, and the one chunk to start is the epic's finishing (finish.py), in a window named for the epic's key. own is the key of the chunk that asks, which has finished or parked: it counts as running nowhere, and no stopped chunk starts again. Where own is None, the human's `do-epic <EPIC-KEY>` asks, and each stopped chunk starts again. A parked chunk waits in its window; one without a live window, as after a reboot, starts again as a stopped chunk does, whatever the limits, since it goes on parked. A Failure says why a window could not start; those before it run."""
|
||||
session = tmux.session_name(tmux.EPIC, epic.key)
|
||||
found, waits = chunks(issues)
|
||||
if finishing:
|
||||
found.append(Chunk(epic.key, None))
|
||||
started: list[str] = []
|
||||
parked = parked_chunks(epic.folder)
|
||||
if isinstance(parked, Failure):
|
||||
@@ -145,7 +149,9 @@ def start_chunks(epic: Epic, issues: list[EpicIssue], own: str | None, run: tmux
|
||||
taken += chunk.issue not in parked
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot lock {failure.filename or epic.folder / LOCK}: {failure.strerror}")
|
||||
return Started(started, sorted(waits, key=lambda wait: [issue.key for issue in issues].index(wait.issue)))
|
||||
# The epic's finishing is no issue: its wait is listed after every issue's.
|
||||
order = [*(issue.key for issue in issues), epic.key]
|
||||
return Started(started, sorted(waits, key=lambda wait: order.index(wait.issue)))
|
||||
|
||||
|
||||
def start_chunk(epic: Epic, chunk: Chunk, own: str | None, windows: list[tmux.Listed], run: tmux.Tmux) -> list[tmux.Listed] | str | Failure:
|
||||
|
||||
@@ -7,6 +7,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.config import DoEpicConfig, load
|
||||
from failure import Failure
|
||||
from project_config.settings import Finish
|
||||
|
||||
SETTINGS = """jira-url = "https://acme.atlassian.net"
|
||||
env-file = "~/jira.env"
|
||||
@@ -43,6 +44,14 @@ class ConfigTest(unittest.TestCase):
|
||||
assert isinstance(found, DoEpicConfig), found
|
||||
self.assertEqual((found.clone_folder, found.language), (pathlib.Path("/srv/repos"), "Brazilian Portuguese"))
|
||||
|
||||
def test_reads_how_a_finished_epic_closes_and_wants_both_names_or_neither(self) -> None:
|
||||
self.write(SETTINGS + 'jira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n')
|
||||
found = load(self.home)
|
||||
assert isinstance(found, DoEpicConfig), found
|
||||
self.assertEqual(found.finish, Finish("Mark as done", "Done"))
|
||||
self.write(SETTINGS + 'jira-finish-status = " "\n')
|
||||
self.assertIn('`jira-finish-status` is \' \', not the name Jira shows, such as "Done"; `jira-finish-status` is set, so `jira-finish-transition` must be too', self.failure())
|
||||
|
||||
def test_refuses_while_the_config_is_missing(self) -> None:
|
||||
self.write(None)
|
||||
self.assertIn(f"cannot read {self.folder / 'config.toml'}", self.failure())
|
||||
|
||||
@@ -83,6 +83,13 @@ class FilingAFinding(FindingsTest):
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((code, out, filed.labels, filed.detail), (0, f"Filed {filed.key} in the epic ABC-12.\n", (label,), ""))
|
||||
|
||||
def test_a_release_review_takes_its_label_beside_its_repo(self) -> None:
|
||||
code, out, _, _ = self.run_with(["ABC-12", "--file", "Review api", "--label", "repo:api", "--label", "do-epic-release-review"])
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((code, out, filed.labels), (0, f"Filed {filed.key} in the epic ABC-12.\n", ("do-epic-release-review", "repo:api")))
|
||||
code, out, _, _ = self.run_with(["ABC-12", "--file", "Review api", "--label", "do-epic-release-review"])
|
||||
self.assertEqual((code, out), (0, f"Filed {self.store.issues[-1].key} in the epic ABC-12. It waits until someone labels it: `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's.\n"))
|
||||
|
||||
def test_refuses_a_label_the_scheduler_doesnt_read(self) -> None:
|
||||
for label in ("api", "repo:", "repo:a b"):
|
||||
with self.subTest(label=label):
|
||||
@@ -90,6 +97,11 @@ class FilingAFinding(FindingsTest):
|
||||
self.assertEqual((code, out, len(self.store.issues)), (1, "", 2))
|
||||
self.assertEqual(err, f"cannot file the finding in the epic ABC-12: do-epic doesn't read the label {label!r}; write `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's\n")
|
||||
|
||||
def test_refuses_two_labels_that_each_say_who_works_the_issue(self) -> None:
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--file", "Retry", "--label", "repo:api", "--label", "repo:web"])
|
||||
self.assertEqual((code, out, len(self.store.issues)), (1, "", 2))
|
||||
self.assertEqual(err, "cannot file the finding in the epic ABC-12: repo:api and repo:web each say who works it; write one of them\n")
|
||||
|
||||
def test_says_why_an_issue_was_not_filed(self) -> None:
|
||||
self.store.fails = "Jira answered 401"
|
||||
code, _, err, _ = self.run_with(["ABC-12", "--file", "Retry"])
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
import contextlib
|
||||
import io
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.test_main import Description, DESCRIPTION, DoEpicTest, MODELS, UNREAD
|
||||
from do_epic.config import DoEpicConfig, load
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from failure import Failure
|
||||
from loop_claude.test_loop_claude import FakeEffects, judged, Worker
|
||||
from do_epic import findings, finish, main, scheduler
|
||||
from project_config.settings import Finish
|
||||
from do_epic.test_scheduler import issue
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from loop_state.paths import paths_from
|
||||
from claude_code.session import session_named
|
||||
|
||||
LAUNCHER = pathlib.Path("/b/do-epic")
|
||||
REVIEWED = [issue("ABC-20", "repo:api", done=True), issue("ABC-21", "do-epic-claude", done=True), issue("ABC-30", "repo:api", "do-epic-release-review", done=True)]
|
||||
|
||||
|
||||
class WhenTheFinishingIsDue(DoEpicTest):
|
||||
def test_is_due_once_the_epic_holds_issues_and_none_is_open(self) -> None:
|
||||
self.assertIs(finish.due([]), False)
|
||||
self.assertIs(finish.due([issue("ABC-20", done=True), issue("ABC-21")]), False)
|
||||
self.assertIs(finish.due([issue("ABC-20", done=True), issue("ABC-21", done=True)]), True)
|
||||
|
||||
def test_an_item_split_by_repo_is_done_once_its_sub_tasks_are(self) -> None:
|
||||
split = [issue("ABC-20", "split-by-repo"), issue("ABC-40", "repo:api", done=True, parent="ABC-20")]
|
||||
self.assertIs(finish.due(split), True)
|
||||
self.assertIs(finish.due([*split, issue("ABC-41", "repo:web", parent="ABC-20")]), False)
|
||||
|
||||
def test_a_repo_lacks_its_review_while_a_done_issue_names_it_and_no_review_does(self) -> None:
|
||||
done = [issue("ABC-20", "repo:web", done=True), issue("ABC-21", "repo:api", done=True), issue("ABC-22", "do-epic-claude", done=True), issue("ABC-23", "repo:docs")]
|
||||
self.assertEqual(finish.unreviewed(done), ["api", "web"])
|
||||
self.assertEqual(finish.unreviewed([*done, issue("ABC-30", "repo:api", "do-epic-release-review")]), ["web"])
|
||||
self.assertEqual(finish.unreviewed([issue("ABC-30", "repo:api", "do-epic-release-review", done=True)]), [], "a review alone changes no repo")
|
||||
|
||||
|
||||
class TheFinishingChunksTask(DoEpicTest):
|
||||
def test_first_asks_for_one_review_issue_per_repo_that_lacks_one(self) -> None:
|
||||
task = finish.task("ABC-12", [issue("ABC-20", "repo:api", done=True), issue("ABC-21", "repo:web", done=True)], LAUNCHER, "Swedish")
|
||||
self.assertIn("Finish the epic ABC-12", task)
|
||||
self.assertIn("first, and api and web have none. ", task)
|
||||
self.assertIn("first, and api has none. ", finish.task("ABC-12", [issue("ABC-20", "repo:api", done=True)], LAUNCHER, "Swedish"))
|
||||
self.assertIn('`/b/do-epic ABC-12 --file "<summary>" --label repo:<name> --label do-epic-release-review`', task)
|
||||
self.assertIn("`Release review of ABC-12`", task)
|
||||
self.assertIn("in Swedish", task)
|
||||
self.assertNotIn("--close-epic", task)
|
||||
|
||||
def test_then_has_the_human_confirm_each_goal_before_the_summary_and_the_closing(self) -> None:
|
||||
task = finish.task("ABC-12", REVIEWED, LAUNCHER, "Swedish")
|
||||
self.assertIn("Finish the epic ABC-12", task)
|
||||
self.assertIn("A goal is met only where the human confirms it", task)
|
||||
self.assertIn("ask the human to approve the set", task)
|
||||
self.assertIn("`/b/do-epic ABC-12 --close-epic`", task)
|
||||
self.assertIn("in Swedish", task)
|
||||
self.assertIn(findings.instructions("ABC-12", LAUNCHER, "Swedish"), task)
|
||||
self.assertIn("- ABC-20 (api): Do ABC-20\n- ABC-21: Do ABC-21\n- ABC-30 (api): Do ABC-30", task)
|
||||
self.assertNotIn("do-epic-release-review`", task)
|
||||
|
||||
|
||||
class ClosingTheEpic(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.issues = list(REVIEWED)
|
||||
self.store = MemoryEpic("ABC-12", self.issues)
|
||||
|
||||
def backend(self, config: object, key: str) -> tuple[MemoryEpic, EpicRecord]:
|
||||
self.assertIsInstance(config, DoEpicConfig)
|
||||
self.store.issues = list(self.issues)
|
||||
return self.store, EpicRecord(Description(self.description)) # type: ignore[arg-type]
|
||||
|
||||
def close(self, summary: str = "## Shipped\n\napi: the import.\n") -> tuple[int, str, str]:
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
code = main.main(["ABC-12", "--close-epic"], {}, paths_from(self.home), LAUNCHER, FakeEffects().effects(), self.backend, io.StringIO(summary))
|
||||
return code, out.getvalue(), err.getvalue()
|
||||
|
||||
def test_posts_the_summary_on_the_epic_and_closes_it(self) -> None:
|
||||
code, out, err = self.close()
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("Posted the summary on the epic ABC-12 and closed it.\n", out)
|
||||
self.assertEqual(self.store.comments, {"ABC-12": ["## Shipped\n\napi: the import."]})
|
||||
self.assertIs(self.store.done, True)
|
||||
|
||||
def test_refuses_an_epic_that_is_closed_already(self) -> None:
|
||||
self.store.done = True
|
||||
code, _, err = self.close()
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("cannot close the epic ABC-12: it is closed already\n", err)
|
||||
self.assertEqual(self.store.comments, {})
|
||||
|
||||
def test_says_why_it_cannot_tell_whether_the_epic_is_closed(self) -> None:
|
||||
class Unreadable(MemoryEpic):
|
||||
def closed(self) -> Failure:
|
||||
return Failure("Jira answered 503")
|
||||
|
||||
self.assertEqual(finish.closed("ABC-12", Unreadable("ABC-12", list(REVIEWED)), io.StringIO("Shipped.")), Failure("cannot close the epic ABC-12: Jira answered 503"))
|
||||
|
||||
def test_the_jira_backend_closes_an_epic_by_the_transition_the_settings_name(self) -> None:
|
||||
with open(self.home / ".claude-projects/do-epic/config.toml", "a", encoding="utf-8") as settings:
|
||||
settings.write('jira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n')
|
||||
config = load(self.home)
|
||||
assert isinstance(config, DoEpicConfig), config
|
||||
store, _ = main.jira_backend(config, "ABC-12")
|
||||
self.assertEqual(store.finish, Finish("Mark as done", "Done")) # type: ignore[attr-defined]
|
||||
|
||||
def test_refuses_while_an_issue_is_open(self) -> None:
|
||||
self.issues.append(issue("ABC-31", "repo:api"))
|
||||
code, _, err = self.close()
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("cannot close the epic ABC-12: ABC-31 is open\n", err)
|
||||
self.assertEqual((self.store.comments, self.store.done), ({}, False))
|
||||
self.issues.append(issue("ABC-32", "repo:api"))
|
||||
self.assertIn("cannot close the epic ABC-12: ABC-31 and ABC-32 are open\n", self.close()[2])
|
||||
|
||||
def test_refuses_while_a_repo_the_epic_changed_lacks_its_release_review(self) -> None:
|
||||
self.issues.append(issue("ABC-31", "repo:web", done=True))
|
||||
code, _, err = self.close()
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("cannot close the epic ABC-12: no issue labelled do-epic-release-review reviews web\n", err)
|
||||
self.assertEqual((self.store.comments, self.store.done), ({}, False))
|
||||
self.issues.append(issue("ABC-32", "repo:docs", done=True))
|
||||
self.assertIn("reviews docs or web\n", self.close()[2])
|
||||
|
||||
def test_refuses_a_blank_summary_and_says_why_the_tracker_refused(self) -> None:
|
||||
code, _, err = self.close(" \n")
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("cannot close the epic ABC-12: ", err)
|
||||
self.assertIs(self.store.done, False)
|
||||
self.store.fails = "Jira answered 401"
|
||||
code, _, err = self.close()
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("cannot close the epic ABC-12: Jira answered 401\n", err)
|
||||
self.assertEqual((self.store.closed(), self.store.close("Shipped.")), (Failure("Jira answered 401"), Failure("Jira answered 401")))
|
||||
|
||||
def test_prints_the_help_for_a_closing_spelt_wrong(self) -> None:
|
||||
for argv in (["ABC-12", "--close-epic", "now"], ["--close-epic", "ABC-12"], ["--close-epic"]):
|
||||
code, out, err = self.run_main(argv, FakeEffects())
|
||||
self.assertEqual((code, out), (1, ""), argv)
|
||||
self.assertIn("usage: do-epic <EPIC-KEY> [--status]\n", err)
|
||||
self.assertIn("do-epic <EPIC-KEY> --close-epic <<'EOF' summary EOF", err)
|
||||
|
||||
|
||||
class TheFinishingChunk(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.store = MemoryEpic("ABC-12", [])
|
||||
|
||||
def backend(self, config: object, key: str) -> tuple[MemoryEpic, EpicRecord]:
|
||||
self.store.issues = list(self.issues)
|
||||
return self.store, EpicRecord(Description(self.description)) # type: ignore[arg-type]
|
||||
|
||||
def started(self, fake: FakeEffects) -> list[str]:
|
||||
"""The name of each window do-epic started."""
|
||||
return [args[args.index("-n") + 1] for args in fake.tmux_calls if args[0] in ("new-session", "new-window")]
|
||||
|
||||
def test_starts_in_a_window_named_for_the_epic_once_no_issue_is_open(self) -> None:
|
||||
self.issues = [issue("ABC-20", "do-epic-claude", done=True)]
|
||||
fake = FakeEffects(on_terminal=False)
|
||||
code, out, err = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("started ABC-12 in the tmux session epic-ABC-12\n", out)
|
||||
self.assertEqual(self.started(fake), ["ABC-12"])
|
||||
self.assertIn(["/b/do-epic", "--chunk", "ABC-12", "ABC-12"], [args[-4:] for args in fake.tmux_calls])
|
||||
|
||||
def test_doesnt_start_while_an_issue_is_open_or_in_an_epic_without_issues(self) -> None:
|
||||
for issues in ([issue("ABC-20", "do-epic-claude", done=True), issue("ABC-21")], []):
|
||||
self.issues = issues
|
||||
fake = FakeEffects(on_terminal=False)
|
||||
code, out, _ = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual((code, self.started(fake)), (0, []))
|
||||
self.assertIn("started no chunk\n", out)
|
||||
|
||||
def test_doesnt_start_in_an_epic_that_is_closed(self) -> None:
|
||||
self.issues = [issue("ABC-20", "do-epic-claude", done=True)]
|
||||
self.store.done = True
|
||||
fake = FakeEffects(on_terminal=False)
|
||||
code, out, _ = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual((code, self.started(fake)), (0, []))
|
||||
self.assertIn("started no chunk\n", out)
|
||||
self.assertIn("the epic ABC-12 is closed\n", out)
|
||||
|
||||
def test_its_worker_is_handed_the_finishing_task_and_runs_until_the_judge_rules_it_finished(self) -> None:
|
||||
self.issues = list(REVIEWED)
|
||||
worker = Worker(paths_from(self.home).claude_code_transcripts.parent)
|
||||
fake = FakeEffects(streams=[worker], claude=[judged("finished")], git=UNREAD, windows="ABC-12\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-12", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("the chunk finished; started no other\n", out)
|
||||
streamed = " ".join([what for seam, what in fake.calls if seam == "stream_claude"][0])
|
||||
self.assertIn("Finish the epic ABC-12", streamed)
|
||||
self.assertIn("`/b/do-epic ABC-12 --close-epic`", streamed)
|
||||
self.assertIn("From the epic ABC-12's description:\n## Goals\nShip the import.", streamed)
|
||||
self.assertIn("write a summary in English, the epic's language", streamed)
|
||||
self.assertTrue((self.home / ".local/state/do-epic/ABC-12").is_dir())
|
||||
|
||||
def test_a_worker_that_resumes_is_told_the_task_as_the_epic_now_stands(self) -> None:
|
||||
self.issues = list(REVIEWED)
|
||||
transcripts = paths_from(self.home).claude_code_transcripts
|
||||
worker = Worker(transcripts.parent)
|
||||
session = session_named("A ABC-12 do-epic ABC-12", transcripts)
|
||||
(transcripts / "-fake").mkdir(parents=True)
|
||||
(transcripts / "-fake" / f"{session.id}.jsonl").write_text("{}\n", encoding="utf-8")
|
||||
fake = FakeEffects(streams=[worker], claude=[judged("finished")], git=UNREAD, windows="ABC-12\t0\t@9\n")
|
||||
code, _, err = self.run_main(["--chunk", "ABC-12", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
args = [what for seam, what in fake.calls if seam == "stream_claude"][0]
|
||||
self.assertIn("--resume", args)
|
||||
self.assertIn("so it may have changed since you began. It is now:\n\nFinish the epic ABC-12", " ".join(args))
|
||||
self.assertIn("`/b/do-epic ABC-12 --close-epic`", " ".join(args))
|
||||
|
||||
def test_stops_where_the_epics_issues_cannot_be_read_or_its_lock_cannot_be_taken(self) -> None:
|
||||
self.issues = [issue("ABC-20", "do-epic-claude", done=True)]
|
||||
(self.home / ".local/state/do-epic/ABC-12" / scheduler.LOCK).mkdir(parents=True)
|
||||
code, _, err = self.run_main(["ABC-12"], FakeEffects(on_terminal=False))
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("cannot lock ", err)
|
||||
self.store.fails = "Jira answered 503"
|
||||
code, _, err = self.run_main(["--chunk", "ABC-12", "ABC-12"], FakeEffects(windows="ABC-12\t0\t@9\n"), MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("Jira answered 503\n", err)
|
||||
|
||||
def test_ends_before_a_cycle_where_the_epic_holds_an_open_issue_again_and_starts_its_chunk(self) -> None:
|
||||
self.issues = [*REVIEWED, issue("ABC-31", "do-epic-claude")]
|
||||
self.description = DESCRIPTION.replace("chunks:** 2", "chunks:** 1")
|
||||
fake = FakeEffects(windows="ABC-12\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-12", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("the epic ABC-12 holds an open issue again, so its finishing chunk ends until none is open\n", out)
|
||||
self.assertIn("the chunk finished; started ABC-31\n", out)
|
||||
self.assertEqual([seam for seam, _ in fake.calls if seam == "stream_claude"], [])
|
||||
+101
-2
@@ -13,6 +13,8 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic import chunk_prompt, main
|
||||
from project_config.test_project_config import configured
|
||||
from do_epic.config import DoEpicConfig
|
||||
from project_config.settings import Epic, Finish
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from agent_cycle import escalation_mark, judge, tmux
|
||||
@@ -84,6 +86,14 @@ class DoEpicTest(unittest.TestCase):
|
||||
return code, out.getvalue(), err.getvalue()
|
||||
|
||||
|
||||
class TheJiraBackend(unittest.TestCase):
|
||||
def test_reads_the_epic_with_the_credentials_and_the_finish_the_config_names(self) -> None:
|
||||
config = DoEpicConfig(pathlib.Path("/c"), "https://acme.atlassian.net", pathlib.Path("/h/jira.env"), pathlib.Path("/h/code"), "English", "claude-opus-5-5", "rule", Finish("Mark as done", "Done"))
|
||||
store, record = main.jira_backend(config, "ABC-12")
|
||||
self.assertEqual((store.epic, store.env_file, store.finish), (Epic("https://acme.atlassian.net", "ABC-12"), pathlib.Path("/h/jira.env"), Finish("Mark as done", "Done"))) # type: ignore[attr-defined]
|
||||
self.assertEqual((record.description.epic, record.description.env_file), (store.epic, store.env_file)) # type: ignore[attr-defined]
|
||||
|
||||
|
||||
class TheLauncher(unittest.TestCase):
|
||||
def test_the_repo_ships_a_do_epic_that_prints_its_help(self) -> None:
|
||||
launcher = pathlib.Path(__file__).resolve().parents[1] / "do-epic"
|
||||
@@ -143,7 +153,7 @@ class ACycleOfAChunkWithoutARepo(DoEpicTest):
|
||||
assert not isinstance(config, Failure)
|
||||
store, record = self.backend(config, "ABC-12")
|
||||
epic = main.EpicRun("ABC-12", config, store, record, paths, env or {}, pathlib.Path("/b/do-epic"), fake.effects())
|
||||
place = main.chunk_root(self.issues[1], epic)
|
||||
place = main.chunk_root("ABC-21", epic)
|
||||
assert isinstance(place, tuple)
|
||||
root, repo = place
|
||||
loop = Loop(root=root, session=main.session_named("A ABC-12 do-epic ABC-21", paths.claude_code_transcripts), window=tmux.Window("epic-ABC-12", "ABC-21", "%1"), paths=paths, env=env or {}, launcher=pathlib.Path("/b/do-epic"), effects=fake.effects())
|
||||
@@ -207,6 +217,14 @@ class TheHumansRun(DoEpicTest):
|
||||
code, _, err = self.run_main(["ABC-12"], fake, {"TMUX": "/tmp/tmux"})
|
||||
self.assertEqual((code, err.split(" ", 1)[1]), (1, "`tmux switch-client -t =epic-ABC-12` failed; the chunks go on in the tmux session\n"))
|
||||
|
||||
def test_stops_with_the_reason_where_the_epics_issues_cannot_be_read(self) -> None:
|
||||
store = MemoryEpic("ABC-12", fails="Jira answered 503")
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
code, out, err = self.run_main(["ABC-12"], FakeEffects(on_terminal=False))
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("Jira answered 503\n", err)
|
||||
self.assertNotIn("started", out)
|
||||
|
||||
def test_off_a_terminal_it_says_how_to_see_the_chunks(self) -> None:
|
||||
code, out, err = self.run_main(["ABC-12"], FakeEffects(on_terminal=False, windows="ABC-21\t0\t@9\n"))
|
||||
self.assertEqual((code, err), (0, ""))
|
||||
@@ -320,6 +338,67 @@ class AChunksRun(DoEpicTest):
|
||||
self.assertEqual(code, 2, out)
|
||||
self.assertIn("the judge ruled it unfinished 6 cycles running; finish the chunk yourself, or rerun do-epic to give it 6 more cycles", err + out)
|
||||
|
||||
def test_a_finished_chunk_moves_its_issue_to_done_before_the_chunk_it_blocks_starts(self) -> None:
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], self.issues[1], issue("ABC-22", "do-epic-claude", blockers=("ABC-21",))])
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows="ABC-21\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual({each.key: each.done for each in store.issues}, {"ABC-20": False, "ABC-21": True, "ABC-22": False})
|
||||
self.assertIn("the chunk finished; started ABC-22\n", out)
|
||||
|
||||
def test_a_finished_chunk_counts_as_done_though_the_search_still_shows_its_issue_open(self) -> None:
|
||||
issues = [self.issues[0], self.issues[1], issue("ABC-22", "do-epic-claude", blockers=("ABC-21",))]
|
||||
store = MemoryEpic("ABC-12", issues)
|
||||
store.read = lambda: list(issues) # type: ignore[method-assign]
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows="ABC-21\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("the chunk finished; started ABC-22\n", out)
|
||||
|
||||
def test_the_last_sub_task_of_a_split_item_to_finish_moves_the_item_to_done_and_starts_what_it_blocks(self) -> None:
|
||||
parent = issue("ABC-21", "split-by-repo")
|
||||
tasks = [issue("ABC-23", "do-epic-claude", parent="ABC-21"), issue("ABC-24", "do-epic-claude", parent="ABC-21", done=True)]
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], parent, *tasks, issue("ABC-22", "do-epic-claude", blockers=("ABC-21",))])
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows="ABC-23\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-23", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual({each.key: each.done for each in store.issues}, {"ABC-20": False, "ABC-21": True, "ABC-23": True, "ABC-24": True, "ABC-22": False})
|
||||
self.assertIn("the chunk finished; started ABC-22\n", out)
|
||||
|
||||
def test_a_sub_task_that_leaves_another_open_leaves_its_split_item_open(self) -> None:
|
||||
parent = issue("ABC-21", "split-by-repo")
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], parent, issue("ABC-23", "do-epic-claude", parent="ABC-21"), issue("ABC-24", "do-epic-claude", parent="ABC-21")])
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows="ABC-23\t0\t@9\n")
|
||||
code, _, err = self.run_main(["--chunk", "ABC-23", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual({each.key: each.done for each in store.issues if each.key in ("ABC-21", "ABC-23", "ABC-24")}, {"ABC-21": False, "ABC-23": True, "ABC-24": False})
|
||||
|
||||
def test_a_split_item_that_jira_will_not_move_to_done_stops_with_the_reason(self) -> None:
|
||||
parent = issue("ABC-21", "split-by-repo")
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], parent, issue("ABC-23", "do-epic-claude", parent="ABC-21")])
|
||||
finish = store.finish_issue
|
||||
store.finish_issue = lambda key: Failure("no way to done") if key == "ABC-21" else finish(key) # type: ignore[method-assign]
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows="ABC-23\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-23", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("the chunk finished, but its split item ABC-21 could not move to done: no way to done; once it is done in Jira, run `do-epic ABC-12` to start the chunks it blocks\n", err)
|
||||
self.assertNotIn("started", out)
|
||||
|
||||
def test_a_chunk_whose_issue_jira_will_not_move_to_done_stops_with_the_reason_and_starts_no_other(self) -> None:
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
store.finish_issue = lambda key: Failure("ABC-21's status has no transition to a done status") # type: ignore[method-assign]
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
code, out, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("the chunk finished, but its issue could not move to done: ABC-21's status has no transition to a done status; once it is done in Jira, run `do-epic ABC-12` to start the chunks it blocks\n", err)
|
||||
self.assertNotIn("started", out)
|
||||
|
||||
def test_a_finished_chunk_says_why_the_next_could_not_start(self) -> None:
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
reads = iter([self.issues, self.issues, Failure("Jira answered 503")])
|
||||
@@ -345,7 +424,7 @@ class AChunksRun(DoEpicTest):
|
||||
self.assertIn("Ship the import.", prompt)
|
||||
self.assertIn("The repo's goals, which rank after the epic's and after code health, are from", prompt)
|
||||
self.assertIn("Serve the API.", prompt)
|
||||
self.assertIn("the chunk finished; started no other\n", out)
|
||||
self.assertIn("the chunk finished; started ABC-12\n", out)
|
||||
judge_prompt = [what[1] for seam, what in fake.calls if seam == "claude"][0]
|
||||
self.assertIn("The records: the epic's scoring and decisions, then the repo's working rules and decisions, then the human's rules for every project:\nFrom the epic ABC-12's description, ## Decisions:\nKeep the v1 endpoints.\n\nFrom AGENTS.md:\nSquash every merge.", judge_prompt)
|
||||
self.assertIn("writing it into the epic's description under ## Decisions, the repo's goals file's Goals or Audience, AGENTS.md, docs/decisions.md, the repo's plan or a comment", judge_prompt)
|
||||
@@ -565,6 +644,26 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
self.assertFalse(self.file.exists())
|
||||
self.assertEqual(len(prompts), 2)
|
||||
|
||||
def test_a_chunk_parks_and_resumes_though_the_epics_issues_cannot_be_read(self) -> None:
|
||||
self.forges = [awaiting(), awaiting(decision="APPROVED")]
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
read = store.read
|
||||
unreadable = [False]
|
||||
worker = self.worker()
|
||||
|
||||
def unreadable_after(*args: object) -> object:
|
||||
unreadable[0] = True
|
||||
return worker(*args) # type: ignore[arg-type]
|
||||
store.read = lambda: Failure("Jira answered 502") if unreadable[0] else read() # type: ignore[method-assign]
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
fake = FakeEffects(streams=[unreadable_after, self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=lambda seconds: unreadable.__setitem__(0, False)) # type: ignore[method-assign]
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("parked: pull request #7 awaits an approval\ncould not start the next chunk: Jira answered 502\n", out)
|
||||
self.assertFalse(self.file.exists())
|
||||
self.assertEqual(len(prompts), 2)
|
||||
|
||||
def test_a_forge_that_cannot_be_read_parks_no_chunk_and_unparks_none(self) -> None:
|
||||
self.forges = [awaiting(fails="gh pr checks")]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
|
||||
@@ -131,7 +131,7 @@ class StartingAnEpicsChunks(unittest.TestCase):
|
||||
return Epic("ABC-12", cap, locate, self.home, pathlib.Path("/bin/do-epic"), {"LOOP_CLAUDE_X": "1", "OTHER": "2"})
|
||||
|
||||
def start(self, epic: Epic, issues: list[EpicIssue], run: Tmux, own: str | None = None) -> Started:
|
||||
found = start_chunks(epic, issues, own, run)
|
||||
found = start_chunks(epic, issues, False, own, run)
|
||||
assert not isinstance(found, Failure), found
|
||||
return found
|
||||
|
||||
@@ -189,7 +189,7 @@ class StartingAnEpicsChunks(unittest.TestCase):
|
||||
self.parked("ABC-20")
|
||||
file_of(self.home / ".local/state/do-epic/ABC-12", "ABC-20").write_text("{")
|
||||
run = Tmux()
|
||||
found = start_chunks(self.epic(2, api=2), [issue("ABC-21", "repo:api")], None, run)
|
||||
found = start_chunks(self.epic(2, api=2), [issue("ABC-21", "repo:api")], False, None, run)
|
||||
assert isinstance(found, Failure)
|
||||
self.assertIn("cannot read the parked chunk in ", found.reason)
|
||||
self.assertEqual(run.started(), [])
|
||||
@@ -286,7 +286,7 @@ class StartingAnEpicsChunks(unittest.TestCase):
|
||||
def test_says_which_lock_it_could_not_take(self) -> None:
|
||||
(self.home / ".local/state/do-epic").mkdir(parents=True)
|
||||
(self.home / ".local/state/do-epic/ABC-12").write_text("", encoding="utf-8")
|
||||
found = start_chunks(self.epic(1, api=1), [issue("ABC-20", "repo:api")], None, Tmux())
|
||||
found = start_chunks(self.epic(1, api=1), [issue("ABC-20", "repo:api")], False, None, Tmux())
|
||||
assert isinstance(found, Failure)
|
||||
self.assertRegex(found.reason, f"^cannot lock {self.home}/.local/state/do-epic/ABC-12: \\w")
|
||||
|
||||
|
||||
@@ -272,15 +272,11 @@ class JiraPlan:
|
||||
if isinstance(raw, Failure):
|
||||
return raw
|
||||
key = f"{project_of(self.epic.key)}-{id_}"
|
||||
url = f"{self.epic.site}/rest/api/3/issue/{key}/transitions"
|
||||
offered = self.http("GET", url, authorization, None)
|
||||
if isinstance(offered, Failure):
|
||||
return Failure(f"cannot read {key}'s transitions: {offered.reason}")
|
||||
transition = transition_of(offered, key, self.finish_by)
|
||||
transition = finishing_transition(self.epic.site, key, self.finish_by, authorization, self.http)
|
||||
if isinstance(transition, Failure):
|
||||
return transition
|
||||
moved = self.http("POST", url, authorization, {"transition": {"id": transition}})
|
||||
return Failure(f"cannot move {key} by {self.finish_by.transition!r}: {moved.reason}; {PERHAPS_MOVED.format(key=key)}") if isinstance(moved, Failure) else Written(id_)
|
||||
refused = move_refusal(self.epic.site, key, transition, self.finish_by, authorization, self.http)
|
||||
return Failure(f"{refused}; {PERHAPS_MOVED.format(key=key)}") if refused else Written(id_)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -409,6 +405,20 @@ def offer_of(raw: object) -> tuple[str, str, str, str] | None:
|
||||
return (id_, name, status, key) if isinstance(id_, str) and isinstance(name, str) and isinstance(status, str) and isinstance(key, str) else None
|
||||
|
||||
|
||||
def finishing_transition(site: str, key: str, finish: Finish, authorization: str, http: Http) -> str | Failure:
|
||||
"""The ID of the transition finish names, as Jira offers it now for the issue named key, which is a plan item or an epic; or why none of those offered finishes it."""
|
||||
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}")
|
||||
return transition_of(offered, key, finish)
|
||||
|
||||
|
||||
def move_refusal(site: str, key: str, transition: str, finish: Finish, authorization: str, http: Http) -> str | None:
|
||||
"""Moves the issue named key by the transition with the ID transition, which finishing_transition answered for finish. Why Jira did not take the move; None where it did."""
|
||||
moved = http("POST", f"{site}/rest/api/3/issue/{key}/transitions", authorization, {"transition": {"id": transition}})
|
||||
return f"cannot move {key} by {finish.transition!r}: {moved.reason}" if isinstance(moved, Failure) else None
|
||||
|
||||
|
||||
def transition_of(offered: object, key: str, finish: Finish) -> str | Failure:
|
||||
"""The ID of the transition finish names, among those Jira offered for the issue named key, which are the ones its present status has; or why none of them finishes the item."""
|
||||
raw = offered.get("transitions") if isinstance(offered, dict) else None
|
||||
|
||||
@@ -204,7 +204,6 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
||||
env_file = anywhere(values.get(ENV_FILE), home)
|
||||
misplaced = ENV_FILE in values and (env_file is None or lies_in(env_file, top, main, file.parent))
|
||||
scalars = {scalar: scalar.read(values[scalar.name]) for scalar in SCALARS if scalar.name in values}
|
||||
finish = [name for setting in JIRA_FINISH if (name := name_of(values.get(setting)))]
|
||||
formula, bar = values.get(JIRA_SCORE_FORMULA), values.get(JIRA_SCORE_BAR)
|
||||
scoring = JiraScoring(formula, bar_value) if isinstance(formula, str) and (bar_value := bar_of(bar)) is not None else None
|
||||
faults = [
|
||||
@@ -225,8 +224,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
||||
*(f"`{name}` names a Confluence page, so `plan` must name a Jira epic" for name in RANKED if name in pages and not epics["plan"]),
|
||||
*(f"`{name}` is set, so `plan` must name a Jira epic" for name in JIRA_PLAN_ONLY if name in values and not epics["plan"]),
|
||||
*(f"`plan` names a Jira epic, so `{name}` must be set, as `project-config --help` shows" for name in JIRA_SCORE if epics["plan"] and name not in values),
|
||||
*(f"`{name}` is {values[name]!r}, not the name Jira shows, such as \"{example}\"" for name, example in zip(JIRA_FINISH, ("Mark as done", "Done")) if name in values and not name_of(values[name])),
|
||||
*(f"`{name}` is set, so `{other}` must be too" for name, other in (JIRA_FINISH, JIRA_FINISH[::-1]) if name in values and other not in values),
|
||||
*finish_faults(values),
|
||||
*([f"`{JIRA_SCORE_FORMULA}` is {formula!r}: {fault}"] if JIRA_SCORE_FORMULA in values and (fault := formula_fault(formula)) else []),
|
||||
*([f"`{JIRA_SCORE_BAR}` is {bar!r}, not a bare number, such as `{JIRA_SCORE_BAR} = 1`"] if JIRA_SCORE_BAR in values and bar_of(bar) is None else []),
|
||||
]
|
||||
@@ -234,7 +232,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
||||
return Failure(f"{file}: {'; '.join(faults)}. The settings are {', '.join(SETTINGS)}, and optionally {', '.join(OPTIONAL[:-1])} and {OPTIONAL[-1]}.")
|
||||
# faults names a formula or bar a plan in Jira lacks or misspells.
|
||||
assert scoring is not None or not epics["plan"]
|
||||
defaulted = ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path}, env_file, epic=epics["plan"], goals_epic=epics["goals-and-audience"], jira_finish=Finish(*finish) if finish else None, jira_scoring=scoring, pages=pages, coding_conventions=conventions or ())
|
||||
defaulted = ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path}, env_file, epic=epics["plan"], goals_epic=epics["goals-and-audience"], jira_finish=finish_of(values), jira_scoring=scoring, pages=pages, coding_conventions=conventions or ())
|
||||
return dataclasses.replace(defaulted, **{scalar.field: read for scalar, read in scalars.items()})
|
||||
|
||||
|
||||
@@ -294,6 +292,20 @@ def bar_of(value: object) -> float | None:
|
||||
return float(value)
|
||||
|
||||
|
||||
def finish_faults(values: dict[str, object]) -> list[str]:
|
||||
"""What is wrong with the two JIRA_FINISH settings in values, which are set together or not at all."""
|
||||
return [
|
||||
*(f"`{name}` is {values[name]!r}, not the name Jira shows, such as \"{example}\"" for name, example in zip(JIRA_FINISH, ("Mark as done", "Done")) if name in values and not name_of(values[name])),
|
||||
*(f"`{name}` is set, so `{other}` must be too" for name, other in (JIRA_FINISH, JIRA_FINISH[::-1]) if name in values and other not in values),
|
||||
]
|
||||
|
||||
|
||||
def finish_of(values: dict[str, object]) -> Finish | None:
|
||||
"""The Finish the two JIRA_FINISH settings in values name; None where they don't name both."""
|
||||
names = [name for setting in JIRA_FINISH if (name := name_of(values.get(setting)))]
|
||||
return Finish(*names) if len(names) == 2 else None
|
||||
|
||||
|
||||
def name_of(value: object) -> str | None:
|
||||
"""The name value holds, of a Jira transition or status; None where it holds none."""
|
||||
return value if isinstance(value, str) and value.strip() else None
|
||||
|
||||
@@ -123,7 +123,7 @@ def heading_commit(release: Release, ref: str, changelog: stores.RecordStore, cw
|
||||
|
||||
|
||||
def release_reviewed(tag: str | None, ref: str, cwd: str, titles: templates.Titles, after: Release | None = None, run: Git = git) -> bool | Failure:
|
||||
"""Whether ref holds a commit titled as a release review opens, `Release review of <release>`: after tag, or anywhere where tag is None.
|
||||
"""Whether ref holds a commit titled as a release review opens, `Release review of <release>`: after tag, or anywhere where tag is None. A title that names no version, such as an epic's `Release review of ABC-12` (do_epic/finish.py), reviews no release.
|
||||
|
||||
titles holds the project's title templates, and each commit title is read as the summary they give. after is the version a branch with no tag counts as cut, or None. Where it is given, a title counts only where its release is later than after.
|
||||
"""
|
||||
@@ -132,7 +132,7 @@ def release_reviewed(tag: str | None, ref: str, cwd: str, titles: templates.Titl
|
||||
return log
|
||||
summaries = [titles.summary(line) for line in log.splitlines()]
|
||||
reviews = [summary.removeprefix("Release review of ") for summary in summaries if summary.startswith("Release review of ")]
|
||||
return any(after is None or ((named := parsed(review)) is not None and named > after) for review in reviews)
|
||||
return any((named := parsed(review)) is not None and (after is None or named > after) for review in reviews)
|
||||
|
||||
|
||||
def todos_since(tag: str | None | Failure, ref: str, plan: str | None, cwd: str, run: Git = git) -> list[str] | Failure:
|
||||
|
||||
@@ -209,6 +209,8 @@ class ChunkItem(unittest.TestCase):
|
||||
self.addCleanup(subprocess.run, ["rm", "-rf", repo])
|
||||
run = lambda *args: subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], capture_output=True, check=True, cwd=repo, env=isolated_env(), text=True)
|
||||
run("init", "-q", "-b", "main")
|
||||
run("commit", "-q", "--allow-empty", "-m", "Release review of ABC-12")
|
||||
self.assertIs(release_standing.release_reviewed(None, "main", repo, BARE), False, "an epic's review reviews no release")
|
||||
run("commit", "-q", "--allow-empty", "-m", "Release review of 0.1.0")
|
||||
run("tag", "v0.1.0")
|
||||
run("commit", "-q", "--allow-empty", "-m", "Ship item 4")
|
||||
@@ -217,6 +219,8 @@ class ChunkItem(unittest.TestCase):
|
||||
run("commit", "-q", "--allow-empty", "-m", "Answer architecture round 1: 0 🔴, 1 🟡 (0 misread); split loader")
|
||||
self.assertIs(release_standing.release_reviewed("v0.1.0", "main", repo, BARE), True)
|
||||
self.assertIs(release_standing.release_reviewed(None, "main", repo, BARE), True)
|
||||
run("commit", "-q", "--allow-empty", "-m", "Release review of ABC-12")
|
||||
self.assertIs(release_standing.release_reviewed("v0.1.0", "main", repo, BARE), True)
|
||||
self.assertIsInstance(release_standing.release_reviewed("v9.9.9", "main", repo, BARE), Failure)
|
||||
self.assertEqual(release_standing.default_plan(repo, "main", plan_in(repo), changelog_of(repo), BARE).cut.reviewed, True)
|
||||
run("tag", "v0.2.0")
|
||||
|
||||
Reference in New Issue
Block a user