Let do-epic --file take --blocked-by and --parent, so a change a repo ships as two pull requests gets an issue for each
CI / tests (pull_request) Failing after 3m45s
CI / tests (pull_request) Failing after 3m45s
This commit is contained in:
@@ -228,7 +228,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
|
||||
- `chunk_driver/` holds what the entry points share. An entry point is a tool that drives chunks through `agent_cycle`: `loop_claude` and `do_epic` are the two. They share how a cycle starts (`cycle_start.py`) and closes (`chunk_run.py`), the claim on a checkout before a chunk starts in it (`claims.py`), the prompts every worker gets (`prompts.py`), and a checkout's premises, records and saved models (`project/`). It imports neither entry point, and `repo_checks` fails any package that imports one of the two. `agent_cycle` is the layer below it, and `repo_checks` fails `agent_cycle` where it imports `chunk_driver`, tests included.
|
||||
- `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `command_patterns`, `reading_cost`, `routing_figures`, `rule_hook` and `run_heavy`.
|
||||
- `deploy_release` imports `release_plan`'s `release_standing`.
|
||||
- `do_epic/` holds `do-epic`, the tool that drives one Jira epic. `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `planning.py` settles, before the chunks start, where each open issue is worked and the order of the issues do-epic filed, through `split.py`, `repo_pick.py` and `ranking.py`. `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, posts comments, moves a finished chunk's issue to done, and closes the epic. `e2e/` holds `do-epic-e2e`.
|
||||
- `do_epic/` holds `do-epic`, the tool that drives one Jira epic. `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `planning.py` settles, before the chunks start, where each open issue is worked and the order of the issues do-epic filed, through `split.py`, `repo_pick.py` and `ranking.py`. `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, which takes `--blocked-by` to make the issue wait for another of the epic's and `--parent` to file it as a sub-task, so a change a repo ships as two pull requests gets an issue for each, and appends a decision to its description, with `--record-decision`. `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, posts comments, moves a finished chunk's issue to done, and closes the epic. `e2e/` holds `do-epic-e2e`.
|
||||
- `forge/` tells a GitHub origin from a Gitea one, names a repo beside an origin's and runs that forge's CLI (`commands.py`), finds a pull request and reads its checks, once or until they settle (`pulls.py`), and reads a pull request's review state (`reviews.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release`, `do_epic` and `larv_review`.
|
||||
- `git_cli/` runs git for every tool (`git_repo.py`), and reads the git calls in a shell command (`git_command.py`).
|
||||
- `judge_replay` imports `agent_cycle`'s judge and verdicts, and `chunk_driver`'s premises, records and `ANSWER_DESTINATIONS`.
|
||||
|
||||
@@ -91,6 +91,28 @@ class EpicStoreContract:
|
||||
self.assertEqual(store.file(task, "Count more.", "", ()), Failure(f"{task} is neither the epic {store.epic_key} nor one of its child issues, so nothing can be filed under it"))
|
||||
self.assertEqual(len(self.issues(store)), 2)
|
||||
|
||||
def test_files_an_issue_blocked_by_a_child_issue_or_a_sub_task_of_the_epic(self) -> None:
|
||||
store = self.new_store()
|
||||
child = self.filed(store, store.epic_key, "Pin the behaviour.")
|
||||
task = self.filed(store, child, "Pin it in the api.")
|
||||
second = store.file(store.epic_key, "Change the behaviour.", "", (), child)
|
||||
third = store.file(child, "Change it in the api.", "", (), task)
|
||||
assert isinstance(second, str) and isinstance(third, str), (second, third)
|
||||
read = {issue.key: issue for issue in self.issues(store)}
|
||||
self.assertEqual((read[second].blockers, read[third].blockers, read[third].parent), ((child,), (task,), child))
|
||||
|
||||
def test_refuses_to_file_blocked_by_an_issue_outside_the_epic(self) -> None:
|
||||
store = self.new_store()
|
||||
for blocker in ("ZZZ-1", "not a key"):
|
||||
with self.subTest(blocker=blocker):
|
||||
self.assertIsInstance(store.file(store.epic_key, "Count more.", "", (), blocker), Failure)
|
||||
self.assertEqual(self.issues(store), [])
|
||||
|
||||
def test_refuses_to_file_blocked_by_the_epic_itself(self) -> None:
|
||||
store = self.new_store()
|
||||
self.assertIsInstance(store.file(store.epic_key, "Count more.", "", (), store.epic_key), Failure)
|
||||
self.assertEqual(self.issues(store), [])
|
||||
|
||||
def test_refuses_to_file_under_an_issue_outside_the_epic(self) -> None:
|
||||
store = self.new_store()
|
||||
for parent in ("ZZZ-1", "not a key"):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""An epic held in memory, for do-epic's tests, held to contract.py like every backend."""
|
||||
import dataclasses
|
||||
|
||||
from do_epic.backend.protocol import EpicIssue, no_child, no_parent, no_words, unfit, unfit_label
|
||||
from do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_words, unfit, unfit_label
|
||||
from failure import Failure
|
||||
|
||||
|
||||
@@ -19,15 +19,17 @@ class MemoryEpic:
|
||||
return Failure(self.fails)
|
||||
return [issue for child in self.issues if child.parent == self.epic_key for issue in (child, *(task for task in self.issues if task.parent == child.key))]
|
||||
|
||||
def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...]) -> str | Failure:
|
||||
def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...], blocked_by: str | None = None) -> str | Failure:
|
||||
if self.fails:
|
||||
return Failure(self.fails)
|
||||
if refused := unfit(summary, labels):
|
||||
return refused
|
||||
if parent != self.epic_key and parent not in {issue.key for issue in self.issues if issue.parent == self.epic_key}:
|
||||
return no_parent(self.epic_key, parent)
|
||||
if blocked_by is not None and blocked_by not in {issue.key for issue in self.issues}:
|
||||
return no_blocker(self.epic_key, blocked_by)
|
||||
key = f"{self.epic_key.rpartition('-')[0]}-{len(self.issues) + 100}"
|
||||
self.issues.append(EpicIssue(key, summary, detail.strip(), tuple(sorted(labels)), None, "To Do", False, parent, by_loop=True))
|
||||
self.issues.append(EpicIssue(key, summary, detail.strip(), tuple(sorted(labels)), None, "To Do", False, parent, blockers=(blocked_by,) if blocked_by else (), by_loop=True))
|
||||
return key
|
||||
|
||||
def add_label(self, key: str, label: str) -> None | Failure:
|
||||
|
||||
@@ -7,9 +7,9 @@ from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
|
||||
from atlassian.client import basic_auth, Http, jira_json, ToAdf, ToMarkdown
|
||||
from atlassian.jira import DONE, entry_of, finishing_transition, ISSUE_KEY, MAX_PAGES, move_refusal, PERHAPS_FILED, PERHAPS_MOVED, project_of, rank_refusal, searched, SHAPE, status_category, unshaped
|
||||
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 do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_words, unfit, unfit_label
|
||||
from failure import Failure
|
||||
from plan_store.jira_epic import FILED_BY, ISSUE_TYPE, PROPERTY, scores
|
||||
from plan_store.jira_epic import BLOCKS, FILED_BY, ISSUE_TYPE, PROPERTY, scores
|
||||
|
||||
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.
|
||||
@@ -57,11 +57,11 @@ class JiraEpic:
|
||||
details = {each.issue.key: text.strip() for each, text in zip(described, texts)}
|
||||
return [dataclasses.replace(each.issue, detail=details.get(each.issue.key, "")) for each in found]
|
||||
|
||||
def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...]) -> str | Failure:
|
||||
def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...], blocked_by: str | None = None) -> str | Failure:
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
if refused := unfit(summary, labels) or self.not_a_parent(parent, authorization):
|
||||
if refused := unfit(summary, labels) or self.not_a_parent(parent, authorization) or (blocked_by and self.not_a_blocker(blocked_by, authorization)):
|
||||
return refused
|
||||
fields: dict[str, typing.Any] = {"project": {"key": project_of(parent)}, "parent": {"key": parent}, "summary": summary, "labels": list(labels)}
|
||||
# Marks the issue as the loop's, as plan_store marks the items it files.
|
||||
@@ -80,6 +80,11 @@ class JiraEpic:
|
||||
key = created.get("key") if isinstance(created, dict) else None
|
||||
if not isinstance(key, str) or not ISSUE_KEY.fullmatch(key):
|
||||
return Failure(f"Jira answered the new issue without an issue key; {PERHAPS_FILED.format(under=parent)}")
|
||||
if blocked_by:
|
||||
# Jira names the two ends by the link type's sides: the inward issue blocks the outward one, which then reads "is blocked by" it.
|
||||
linked = self.http("POST", f"{self.epic.site}/rest/api/3/issueLink", authorization, {"type": {"name": BLOCKS}, "inwardIssue": {"key": blocked_by}, "outwardIssue": {"key": key}})
|
||||
if isinstance(linked, Failure):
|
||||
return Failure(f"filed {key} under {parent}, but cannot link it as blocked by {blocked_by}: {linked.reason}; link it in Jira")
|
||||
return key
|
||||
|
||||
def add_label(self, key: str, label: str) -> None | Failure:
|
||||
@@ -184,6 +189,16 @@ class JiraEpic:
|
||||
above = self.parent_of(parent, authorization, "to file under it")
|
||||
return above if isinstance(above, Failure) else None if above == self.epic_key else no_parent(self.epic_key, parent)
|
||||
|
||||
def not_a_blocker(self, blocker: str, authorization: str) -> Failure | None:
|
||||
"""Why nothing can be filed blocked by blocker; None where it is a child issue of the epic or a sub-task of one."""
|
||||
above = self.parent_of(blocker, authorization, "to file blocked by it")
|
||||
if isinstance(above, Failure):
|
||||
return above
|
||||
if above == self.epic_key:
|
||||
return None
|
||||
grand = None if above is None else self.parent_of(above, authorization, "to file blocked by it")
|
||||
return grand if isinstance(grand, Failure) else None if grand == self.epic_key else no_blocker(self.epic_key, blocker)
|
||||
|
||||
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)
|
||||
|
||||
@@ -51,8 +51,8 @@ class EpicStore(typing.Protocol):
|
||||
def read(self) -> list[EpicIssue] | Failure:
|
||||
"""Each child issue, open or done, in the tracker's rank order, each followed by its sub-tasks in theirs."""
|
||||
|
||||
def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...]) -> str | Failure:
|
||||
"""Files an open issue under parent, marked as filed by the loop, and answers its key: a child issue where parent is the epic, a sub-task where parent is one of its child issues. detail is markdown, and may be empty."""
|
||||
def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...], blocked_by: str | None = None) -> str | Failure:
|
||||
"""Files an open issue under parent, marked as filed by the loop, and answers its key: a child issue where parent is the epic, a sub-task where parent is one of its child issues. detail is markdown, and may be empty. Where blocked_by names an issue, a child issue of the epic or a sub-task of one, the new issue is blocked by it; any other issue is refused before anything is filed. Where the issue is filed and cannot be linked, the Failure names its key."""
|
||||
|
||||
def add_label(self, key: str, label: str) -> None | Failure:
|
||||
"""Adds label to the epic's child issue named key, leaving its other labels as they are; adding one it already has leaves the labels as they are. A sub-task, or an issue outside the epic, is refused."""
|
||||
@@ -93,6 +93,11 @@ def no_parent(epic_key: str, parent: str) -> Failure:
|
||||
return Failure(f"{parent} is neither the epic {epic_key} nor one of its child issues, so nothing can be filed under it")
|
||||
|
||||
|
||||
def no_blocker(epic_key: str, blocker: str) -> Failure:
|
||||
"""What every backend says when asked to file an issue blocked by blocker, which is neither a child issue of the epic nor a sub-task of one."""
|
||||
return Failure(f"{blocker} is neither a child issue of the epic {epic_key} nor a sub-task of one, so nothing can be filed blocked by it")
|
||||
|
||||
|
||||
def no_child(epic_key: str, key: str, done_to_it: str) -> Failure:
|
||||
"""What every backend says when asked to change key, which is not one of the epic's child issues; done_to_it is the past participle of what was asked, such as "labelled"."""
|
||||
return Failure(f"{key} is not one of the child issues of the epic {epic_key}, so it cannot be {done_to_it}")
|
||||
|
||||
@@ -21,6 +21,7 @@ EPIC_URL = f"{SITE}/rest/api/3/issue/ABC-12?fields=summary"
|
||||
ISSUE_TYPES = f"{SITE}/rest/api/3/issue/createmeta/ABC/issuetypes"
|
||||
SEARCH = f"{SITE}/rest/api/3/search/jql"
|
||||
ISSUES = f"{SITE}/rest/api/3/issue"
|
||||
LINKS = f"{SITE}/rest/api/3/issueLink"
|
||||
RANK = f"{SITE}/rest/agile/1.0/issue/rank"
|
||||
TO_DO = {"name": "To Do", "statusCategory": {"key": "new"}}
|
||||
DONE = {"name": "Done", "statusCategory": {"key": "done"}}
|
||||
@@ -91,6 +92,11 @@ class FakeJira:
|
||||
return self.created(body)
|
||||
if method == "PUT" and url == RANK:
|
||||
return self.ranked(body)
|
||||
if method == "POST" and url == LINKS:
|
||||
assert isinstance(body, dict) and body["type"] == {"name": "Blocks"}, body
|
||||
links = next(issue for issue in self.issues if issue["key"] == body["outwardIssue"]["key"])["fields"]["issuelinks"] # type: ignore[index]
|
||||
links.append({"id": str(len(links) + 1), "type": {"inward": "is blocked by", "outward": "blocks"}, "inwardIssue": body["inwardIssue"]}) # type: ignore[index]
|
||||
return None
|
||||
if method == "POST" and (held := next((issue for issue in self.issues if url == f"{ISSUES}/{issue['key']}/comment"), None)):
|
||||
assert isinstance(body, dict)
|
||||
self.comments.setdefault(str(held["key"]), []).append(body["body"])
|
||||
@@ -304,6 +310,14 @@ class Jira(Case):
|
||||
self.jira.answers[("POST", ISSUES)] = answer
|
||||
self.assertEqual(self.new_store().file("ABC-12", "Count the runs.", "", ()), Failure(f"{reason}; unless Jira refused the request, the issue may exist: look under ABC-12 before filing it again"))
|
||||
|
||||
def test_a_link_jira_refuses_leaves_the_issue_filed_and_names_its_key(self) -> None:
|
||||
store = self.new_store()
|
||||
first = store.file("ABC-12", "Pin the behaviour.", "", ())
|
||||
assert isinstance(first, str)
|
||||
self.jira.answers[("POST", LINKS)] = Failure("Jira answered 403")
|
||||
self.assertEqual(store.file("ABC-12", "Change the behaviour.", "", (), first), Failure(f"filed ABC-101 under ABC-12, but cannot link it as blocked by {first}: Jira answered 403; link it in Jira"))
|
||||
self.assertEqual([issue["key"] for issue in self.jira.issues], [first, "ABC-101"])
|
||||
|
||||
def test_a_detail_the_codec_refuses_leaves_the_epic_as_it_was(self) -> None:
|
||||
store = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, lambda markdown: Failure("adf-codec refused it"))
|
||||
self.assertEqual(store.file("ABC-12", "Count the runs.", "Why.", ()), Failure("cannot convert the detail to a Jira description: adf-codec refused it"))
|
||||
|
||||
+32
-15
@@ -2,6 +2,7 @@
|
||||
|
||||
A finding about one of the epic's goals is filed in the epic, and one about a repo's goals by that repo's rules (docs/decisions.md → `do-epic: drives one Jira epic …` → "Findings"). A decision that governs the epic goes under the description's ## Decisions, where the judge of each later chunk reads it."""
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import fcntl
|
||||
import pathlib
|
||||
import typing
|
||||
@@ -16,16 +17,19 @@ 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`.
|
||||
FILE = "--file"
|
||||
LABEL = "--label"
|
||||
BLOCKED_BY = "--blocked-by"
|
||||
PARENT = "--parent"
|
||||
RECORD_DECISION = "--record-decision"
|
||||
# The labels that say where an issue is worked, as do-epic's scheduler reads them.
|
||||
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>]... [{BLOCKED_BY} <KEY>] [{PARENT} <KEY>] [<<'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 next `do-epic <EPIC-KEY>` you run picks where the issue is worked.
|
||||
A second {LABEL}, `{REVIEW_LABEL}`, marks the issue as a repo's release review, which the epic's finishing files.
|
||||
{BLOCKED_BY} makes the new issue blocked by that issue of the epic, or one of its sub-tasks, and {PARENT} files a sub-task under that child issue of the epic. A repo whose rules ask for a change to ship as more than one pull request gets an issue for each, the next one blocked by the one before.
|
||||
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."""
|
||||
|
||||
@@ -38,6 +42,7 @@ def instructions(epic: str, launcher: pathlib.Path, language: str) -> str:
|
||||
"Where filing fails and says the issue may exist, ask the human to look before you file it again. "
|
||||
"File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. "
|
||||
f"Record a decision that governs the epic, such as an answer the human typed, with `{launcher} {epic} {RECORD_DECISION} \"<title>\"` and its text on stdin. "
|
||||
f"Where the repo's rules ask for a change to ship as more than one pull request, file the next one as its own issue with `{launcher} {epic} {FILE} \"<summary>\" {BLOCKED_BY} <this issue's key>`, and `{PARENT} <its parent's key>` as well where this issue is a sub-task, then finish only this one. "
|
||||
f"Write the issue and the decision in {language}, the epic's language."
|
||||
)
|
||||
|
||||
@@ -51,35 +56,47 @@ def decisions_locked(folder: pathlib.Path) -> typing.Iterator[None]:
|
||||
yield
|
||||
|
||||
|
||||
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."""
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Write:
|
||||
"""What the words after the epic's key ask for: the flag, and its summary or title. A finding may also carry labels, the issue that blocks it and the child issue it is a sub-task of."""
|
||||
flag: str
|
||||
value: str
|
||||
labels: tuple[str, ...] = ()
|
||||
blocked_by: str | None = None
|
||||
parent: str | None = None
|
||||
|
||||
|
||||
def parsed(words: list[str]) -> Write | None:
|
||||
"""What the words after the epic's key ask for. None where they aren't spelt as USAGE has them. A word that opens with `--` is no summary, title, label or key."""
|
||||
if not words or words[0] not in (FILE, RECORD_DECISION):
|
||||
return None
|
||||
labels: list[str] = []
|
||||
taken: dict[str, list[str]] = {LABEL: [], BLOCKED_BY: [], PARENT: []}
|
||||
rest = words[1:]
|
||||
while words[0] == FILE and LABEL in rest:
|
||||
at = rest.index(LABEL)
|
||||
if at + 1 >= len(rest):
|
||||
return None
|
||||
labels.append(rest[at + 1])
|
||||
rest = rest[:at] + rest[at + 2:]
|
||||
if len(rest) != 1 or any(word.startswith("--") for word in (*rest, *labels)):
|
||||
for option in taken if words[0] == FILE else ():
|
||||
while option in rest:
|
||||
at = rest.index(option)
|
||||
if at + 1 >= len(rest):
|
||||
return None
|
||||
taken[option].append(rest[at + 1])
|
||||
rest = rest[:at] + rest[at + 2:]
|
||||
if len(rest) != 1 or len(taken[BLOCKED_BY]) > 1 or len(taken[PARENT]) > 1 or any(word.startswith("--") for word in (*rest, *sum(taken.values(), []))):
|
||||
return None
|
||||
return words[0], rest[0], tuple(labels)
|
||||
return Write(words[0], rest[0], tuple(taken[LABEL]), *(taken[option][0] if taken[option] else None for option in (BLOCKED_BY, PARENT)))
|
||||
|
||||
|
||||
def written(epic: str, flag: str, value: str, labels: tuple[str, ...], store: EpicStore, record: EpicRecord, stdin: typing.TextIO, folder: pathlib.Path) -> str | Failure:
|
||||
def written(epic: str, write: Write, 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)
|
||||
flag, value, labels = write.flag, write.value, write.labels
|
||||
if flag == FILE:
|
||||
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)
|
||||
key = store.file(write.parent or epic, value, text, labels, write.blocked_by)
|
||||
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 any(of_label(label) for label in labels) else f" It has no label that says where it is worked, so the next `do-epic {epic}` picks one: {LABELS}.")
|
||||
return f"Filed {key} {f'under {write.parent} in ' if write.parent else 'in '}the epic {epic}." + (f" It is blocked by {write.blocked_by}." if write.blocked_by else "") + ("" if any(of_label(label) for label in labels) else f" It has no label that says where it is worked, so the next `do-epic {epic}` picks one: {LABELS}.")
|
||||
try:
|
||||
with decisions_locked(folder):
|
||||
added = record.append_decision(value, text)
|
||||
|
||||
+2
-2
@@ -143,13 +143,13 @@ 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, tuple[str, ...]] | None, paths: Paths, backend: Backend, stdin: typing.TextIO) -> Stop:
|
||||
def epic_written(key: str, writes: findings.Write | 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)
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -90,6 +90,23 @@ class FilingAFinding(FindingsTest):
|
||||
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 has no label that says where it is worked, so the next `do-epic ABC-12` picks one: `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_files_the_next_step_of_a_change_blocked_by_the_issue_before_it(self) -> None:
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--file", "Change it", "--label", "repo:api", "--blocked-by", "ABC-20"], "Detail.\n")
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((code, out, err), (0, f"Filed {filed.key} in the epic ABC-12. It is blocked by ABC-20.\n", ""))
|
||||
self.assertEqual((filed.parent, filed.blockers, filed.labels), ("ABC-12", ("ABC-20",), ("repo:api",)))
|
||||
|
||||
def test_files_a_sub_task_under_a_child_issue_of_the_epic(self) -> None:
|
||||
code, out, _, _ = self.run_with(["ABC-12", "--file", "--parent", "ABC-20", "Change it", "--label", "repo:api", "--blocked-by", "ABC-21"])
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((code, out, filed.parent, filed.blockers), (0, f"Filed {filed.key} under ABC-20 in the epic ABC-12. It is blocked by ABC-21.\n", "ABC-20", ("ABC-21",)))
|
||||
|
||||
def test_refuses_a_blocker_or_parent_outside_the_epic(self) -> None:
|
||||
for argv, reason in ((["--blocked-by", "ZZZ-1"], "ZZZ-1 is neither a child issue of the epic ABC-12 nor a sub-task of one, so nothing can be filed blocked by it"), (["--parent", "ZZZ-1"], "ZZZ-1 is neither the epic ABC-12 nor one of its child issues, so nothing can be filed under it")):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--file", "Retry", "--label", "repo:api", *argv])
|
||||
self.assertEqual((code, out, err, len(self.store.issues)), (1, "", f"cannot file the finding in the epic ABC-12: {reason}\n", 2))
|
||||
|
||||
def test_refuses_a_label_the_scheduler_doesnt_read(self) -> None:
|
||||
for label in ("api", "repo:", "repo:a b"):
|
||||
with self.subTest(label=label):
|
||||
@@ -114,7 +131,7 @@ class FilingAFinding(FindingsTest):
|
||||
self.assertIn("config.toml", err)
|
||||
|
||||
def test_prints_the_help_for_a_filing_spelt_wrong(self) -> None:
|
||||
for argv in (["ABC-12", "--file"], ["ABC-12", "--file", "a", "b"], ["ABC-12", "--file", "a", "--label"], ["ABC-12", "--file", "a", "--labels", "x"], ["--file", "ABC-12", "a"], ["ABC-12", "--file", "--label", "x"], ["ABC-12", "--file", "--lable"], ["ABC-12", "--file", "a", "--label", "--x"], ["--chunk", "ABC-20", "ABC-12", "--file", "a"]):
|
||||
for argv in (["ABC-12", "--file"], ["ABC-12", "--file", "a", "b"], ["ABC-12", "--file", "a", "--label"], ["ABC-12", "--file", "a", "--labels", "x"], ["--file", "ABC-12", "a"], ["ABC-12", "--file", "--label", "x"], ["ABC-12", "--file", "--lable"], ["ABC-12", "--file", "a", "--blocked-by"], ["ABC-12", "--file", "a", "--blocked-by", "ABC-100", "--blocked-by", "ABC-101"], ["ABC-12", "--file", "a", "--parent", "ABC-100", "--parent", "ABC-101"], ["ABC-12", "--file", "a", "--parent", "--label", "x"], ["ABC-12", "--record-decision", "a", "--blocked-by", "ABC-100"], ["ABC-12", "--file", "a", "--label", "--x"], ["--chunk", "ABC-20", "ABC-12", "--file", "a"]):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, err, _ = self.run_with(argv)
|
||||
self.assertEqual((code, out, err, len(self.store.issues)), (1, "", main.HELP + "\n", 2))
|
||||
|
||||
@@ -345,7 +345,9 @@ class TheFirstPrompt(unittest.TestCase):
|
||||
told = (
|
||||
f"File a finding about one of the epic's goals in the epic, with `/b/do-epic ABC-12 --file \"<summary>\" --label <label>` and its detail on stdin. The label is {labels}; leave it out where you cannot tell, and the next `do-epic` the human runs picks it. "
|
||||
"Where filing fails and says the issue may exist, ask the human to look before you file it again. File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. "
|
||||
"Record a decision that governs the epic, such as an answer the human typed, with `/b/do-epic ABC-12 --record-decision \"<title>\"` and its text on stdin. Write the issue and the decision in Swedish, the epic's language."
|
||||
"Record a decision that governs the epic, such as an answer the human typed, with `/b/do-epic ABC-12 --record-decision \"<title>\"` and its text on stdin. "
|
||||
"Where the repo's rules ask for a change to ship as more than one pull request, file the next one as its own issue with `/b/do-epic ABC-12 --file \"<summary>\" --blocked-by <this issue's key>`, and `--parent <its parent's key>` as well where this issue is a sub-task, then finish only this one. "
|
||||
"Write the issue and the decision in Swedish, the epic's language."
|
||||
)
|
||||
task = chunk_prompt.task(issue("ABC-20"), "ABC-12", "/code/api", pathlib.Path("/b/do-epic"), "Swedish", CONFIG)
|
||||
self.assertTrue(task.startswith(f"Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout /code/api, on the branch ABC-20. {told} "))
|
||||
|
||||
Reference in New Issue
Block a user