Merge origin/main into item-441
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- do-epic finishes an epic: once none of its issues is open, a finishing chunk files a release review of each repo the epic changed, as an issue labelled `do-epic-release-review`, and asks you to confirm each goal. `do-epic <EPIC-KEY> --close-epic` then posts the summary piped in as a comment on the epic and closes it in Jira, by the transition `jira-finish-transition` names, to the status `jira-finish-status` names.
|
||||
- do-epic parks a chunk whose pull request waits on its checks, an approval or a new review: the chunk frees its place for the next one, its tmux window says what it awaits, and its worker goes on when the gate opens or a reviewer comments, even after a reboot. `do-epic <EPIC-KEY> --status` prints what each open issue does.
|
||||
- A chunk that `do-epic` runs files a finding about an epic goal as an issue of the epic, with `do-epic <EPIC-KEY> --file`, and records a decision in the epic's description, with `--record-decision`; its judge reads the epic's Scoring and Decisions before the repo's records.
|
||||
- Added `do-epic <EPIC-KEY>`: it runs the chunks of one Jira epic, each in its own window of the tmux session `epic-<EPIC-KEY>`. As many run at once as the line `**Max parallel chunks:** 2` in the epic's description allows, one without it; a repo takes as many as its `parallel-chunks`, and none while loop-claude runs chunks in it. loop-claude in turn starts no chunk in a checkout where do-epic runs one.
|
||||
- Refuse in rule-hook a Bash or Monitor command that waits forever: a sleeping loop with no time or count cap, and a `pgrep -f` or `pkill -f` whose pattern its own command line matches.
|
||||
- A project's config may list its team's convention files in `coding-conventions`, which larv-review's reviewer agents read beside the principles and the standards, the team's rule winning where they conflict. larv-review opens the pull request after its own review where a push to the branch starts CI, and files an item to add a mutation tool where `mutate-changes` covers none of a language. The technical principles gain rules for tests on a shared environment, "Never mock a service your own team runs" and "Don't loosen a type when refactoring"; stability-reviewer checks a change that stores a value differently; and every finding of an outside reviewer now changes the setup, a deterministic tool first.
|
||||
|
||||
@@ -216,8 +216,8 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
|
||||
- `branch_chunks/` cuts a default branch into chunks and finds, for each, the items it shipped and the later chunks that fixed its code, for `score_outcomes` and `routing_figures`. It imports `reading_cost`'s record path.
|
||||
- `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`. `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. Beside it, `chunk_prompt.py` words what a chunk's worker reads. `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, and moves a finished chunk's issue to done.
|
||||
- `forge/` tells a GitHub origin from a Gitea one, names a repo beside an origin's and runs that forge's CLI (`commands.py`), and finds a pull request and waits for its checks (`pulls.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release`, `do_epic` and `larv_review`.
|
||||
- `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`. `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.
|
||||
- `forge/` tells a GitHub origin from a Gitea one, names a repo beside an origin's and runs that forge's CLI (`commands.py`), and finds a pull request and reads its checks, once or until they settle (`pulls.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 `loop_claude`'s premises, records and `ANSWER_DESTINATIONS`.
|
||||
- `loop_claude` runs `chunk-preflight` as a process of its own.
|
||||
@@ -237,7 +237,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
|
||||
- `routing_figures/` measures loop-claude's archive, and each of its projects' default branches, for loop-claude's routing calls.
|
||||
- `rung_replay/` holds what `judge_replay` and `review_replay` share: the parallel replay runner, the argument reader, the candidate rungs and the exits, and `judge_replay`'s rung search. It reads `agent_cycle`'s retry count and `loop_claude`'s models file, and finds that file through `loop_state`'s paths. Its `archive.py` keeps each replay's runs and its report in a `replays/` folder of loop-claude's archive.
|
||||
- `test_env.py` serves the tests.
|
||||
- `text_files/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, stamps times in UTC, replaces a file in one step, private where it is new, and gzips a file beside its plain name, by which it reads it afterwards.
|
||||
- `text_files/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, reads the text piped into a command, stamps times in UTC, replaces a file in one step, private where it is new, and gzips a file beside its plain name, by which it reads it afterwards.
|
||||
- `transcript_archive/` stores loop-claude's transcripts. Its `project_key.py` names each project's archive folder, loop-claude session and models-file entry.
|
||||
|
||||
## Test
|
||||
|
||||
@@ -141,6 +141,8 @@ class Brief(typing.NamedTuple):
|
||||
task: str
|
||||
premises: str
|
||||
records: str
|
||||
# What the records are, in their order, as WorkerPrompts.records_named has it.
|
||||
records_named: str
|
||||
# Where the worker may record an answer the human typed, as the entry point names it.
|
||||
answer_destinations: str
|
||||
entries: list[Entry]
|
||||
@@ -290,7 +292,7 @@ def judge_prompt(brief: Brief) -> tuple[str, Grounds]:
|
||||
"""The prompt, and what the judge's quotes are checked against."""
|
||||
head = (
|
||||
f"From the goals file, {brief.premises}\n\n"
|
||||
f"The records: the project's working rules and decisions, then the human's rules for every project:\n{brief.records or 'none'}\n\n"
|
||||
f"The records: {brief.records_named}:\n{brief.records or 'none'}\n\n"
|
||||
f"{TASK_HEADING}{brief.task}\n\n"
|
||||
f"{transcript_heading(brief.driver)}"
|
||||
)
|
||||
|
||||
@@ -156,6 +156,7 @@ def rule(cycle: Cycle, transcript_path: str, quoted_answers: int) -> Ruled | Sto
|
||||
task=cycle.task,
|
||||
premises=cycle.premises,
|
||||
records=cycle.records,
|
||||
records_named=cycle.prompts.records_named,
|
||||
answer_destinations=cycle.prompts.answer_destinations,
|
||||
entries=entries,
|
||||
escalated_at=cycle.route.escalated_at,
|
||||
|
||||
+28
-3
@@ -14,6 +14,8 @@ NEEDED = (3, 2)
|
||||
# What a window's name ends in while its chunk waits for the human. tmux's status bar shows the name, and `!` after it once the bell rang.
|
||||
WAITS = " ?"
|
||||
BELL = "\a"
|
||||
# What follows a window's name while its chunk is parked, before what its pull request waits on, as in `ABC-34 awaits an approval`. A parked chunk takes no running slot (docs/decisions.md → `do-epic: drives one Jira epic …`, "Long gates").
|
||||
PARKED = " awaits "
|
||||
# What a session's name opens with: LOOP for a project's chunks under loop-claude, EPIC for an epic's chunks under do-epic.
|
||||
LOOP = "loop"
|
||||
EPIC = "epic"
|
||||
@@ -41,12 +43,18 @@ class Window:
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Listed:
|
||||
"""A window of the project's session, as tmux lists it."""
|
||||
# Without WAITS.
|
||||
# Without WAITS, and without PARKED and what follows it.
|
||||
name: str
|
||||
# tmux's ID of the window, such as `@3`.
|
||||
id: str
|
||||
# Whether its loop has exited: `remain-on-exit failed` keeps the window of a loop that failed, so its last lines stay readable.
|
||||
dead: bool
|
||||
# What its name says its parked chunk awaits, as the words after PARKED; empty for a chunk that isn't parked.
|
||||
awaits: str = ""
|
||||
|
||||
@property
|
||||
def parked(self) -> bool:
|
||||
return bool(self.awaits)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -76,14 +84,20 @@ def listed(session: str, run: Tmux) -> list[Listed]:
|
||||
"""The windows of session; none where tmux lists none, as while the session doesn't exist or no tmux server runs."""
|
||||
done = run(["list-windows", "-t", f"={session}", "-F", "#{window_name}\t#{pane_dead}\t#{window_id}"])
|
||||
rows = [line.split("\t") for line in done.stdout.splitlines()] if done.returncode == 0 else []
|
||||
return [Listed(row[0].removesuffix(WAITS), row[2], row[1] == "1") for row in rows if len(row) == 3]
|
||||
return [as_listed(row[0], row[2], row[1]) for row in rows if len(row) == 3]
|
||||
|
||||
|
||||
def as_listed(shown: str, id: str, pane_dead: str) -> Listed:
|
||||
"""The window tmux shows under the name shown, with the ID id and `#{pane_dead}` as pane_dead."""
|
||||
name, _, awaits = shown.removesuffix(WAITS).partition(PARKED)
|
||||
return Listed(name, id, pane_dead == "1", awaits)
|
||||
|
||||
|
||||
def everywhere(run: Tmux) -> list[Placed]:
|
||||
"""The windows of every session; none where no tmux server runs."""
|
||||
done = run(["list-windows", "-a", "-F", f"#{{session_name}}\t#{{window_name}}\t#{{pane_dead}}\t#{{window_id}}\t#{{{ROOT}}}"])
|
||||
rows = [line.split("\t") for line in done.stdout.splitlines()] if done.returncode == 0 else []
|
||||
return [Placed(row[0], Listed(row[1].removesuffix(WAITS), row[3], row[2] == "1"), row[4]) for row in rows if len(row) == 5]
|
||||
return [Placed(row[0], as_listed(row[1], row[3], row[2]), row[4]) for row in rows if len(row) == 5]
|
||||
|
||||
|
||||
def start_window(window: Window, cwd: str, env: typing.Mapping[str, str], command: list[str], first: bool, owned: bool, run: Tmux) -> Failure | None:
|
||||
@@ -131,6 +145,17 @@ def mark(window: Window, waits: bool, run: Tmux) -> None:
|
||||
run(["rename-window", "-t", window.pane, window.name + (WAITS if waits else "")])
|
||||
|
||||
|
||||
def park(window: Window, on: str, run: Tmux) -> None:
|
||||
"""Shows window's chunk as parked. on is what the chunk awaits, such as `an approval` or `a slot`: the name says so, and no checkout counts a window so named as a running chunk."""
|
||||
run(["rename-window", "-t", window.pane, window.name + PARKED + on])
|
||||
|
||||
|
||||
def unpark(window: Window, root: str, run: Tmux) -> None:
|
||||
"""Shows window's chunk as running again, in the folder root. The window may name another folder: one started again for a parked chunk starts in the epic's folder."""
|
||||
run(["rename-window", "-t", window.pane, window.name])
|
||||
run(["set-option", "-w", "-t", window.pane, ROOT, root])
|
||||
|
||||
|
||||
def show(session: str, inside: bool) -> list[str]:
|
||||
"""The tmux arguments that put session on the human's terminal: inside tmux the client switches to it, and outside a new client attaches."""
|
||||
return ["switch-client" if inside else "attach-session", "-t", f"={session}"]
|
||||
|
||||
@@ -45,6 +45,8 @@ class WorkerPrompts:
|
||||
quote_sources: str
|
||||
# Where the worker may record an answer the human typed.
|
||||
answer_destinations: str
|
||||
# What the records the judge reads are, in the order it reads them.
|
||||
records_named: str
|
||||
|
||||
def answered(self, question: str, answer: str, route: Route, project: ProjectRung | None, stepped: bool) -> str:
|
||||
"""stepped is whether the answer's ruling stepped the worker up."""
|
||||
|
||||
+24
-10
@@ -10,6 +10,8 @@ from forge.commands import Forge, Run
|
||||
# A human answers in hours, so merge polls once a minute and gives up after 90 minutes. That leaves half an hour for the queue and the checks inside the 2 hours a background command may run; a run that needs more is killed before the give-up message prints, and its next run goes on from what it pushed.
|
||||
POLL_SECONDS = 60
|
||||
WAIT_SECONDS = 90 * 60
|
||||
# The environment variable do-epic sets to 1 for its chunks' workers. With it, merge doesn't wait for an approval: do-epic parks the chunk and polls the forge itself, so the chunk holds no running slot meanwhile (docs/decisions.md → `do-epic: drives one Jira epic …`, "Long gates").
|
||||
PARKS = "CHUNK_PR_PARKS"
|
||||
|
||||
|
||||
def awaited(forge: Forge, wait_for_approval: bool) -> bool | Failure:
|
||||
@@ -58,17 +60,29 @@ def approved(number: str, run: Run, sleep: typing.Callable[[float], None] = time
|
||||
return Failure(f"pull request {number} wasn't approved within {WAIT_SECONDS // 60} minutes; run chunk-pr merge again once it is")
|
||||
|
||||
|
||||
def left_to_park(number: str, run: Run) -> Failure:
|
||||
"""Why a merge under PARKS ends at once where pull request number passed its checks and awaits an approval, in place of waiting as `approved` does: a reviewer's comment waits for an answer, which the worker gives first, or else do-epic parks the chunk, so the worker ends its run."""
|
||||
return unanswered(number, run) or Failure(f"pull request {number} passed its checks and awaits an approval; end your run now, since do-epic parks the chunk and resumes this session once it is approved or a reviewer comments")
|
||||
|
||||
|
||||
def unanswered(number: str, run: Run) -> Failure | None:
|
||||
"""A Failure naming the files where a reviewer's comment waits for an answer on pull request number: a review thread nobody resolved, whose last comment someone other than the pull request's author wrote. So a thread the worker answered, as that author, waits for the reviewer again. None where no thread waits."""
|
||||
read = run(["gh", "api", "graphql", "-f", f"query={THREADS}", "-F", "owner={owner}", "-F", "repo={repo}", "-F", f"number={number}"])
|
||||
try:
|
||||
pull = read if isinstance(read, Failure) else json.loads(read)["data"]["repository"]["pullRequest"]
|
||||
if isinstance(pull, Failure):
|
||||
return pull
|
||||
author = pull["author"]["login"]
|
||||
waiting = sorted({thread["path"] for thread in pull["reviewThreads"]["nodes"] if not thread["isResolved"] and any(comment["author"]["login"] != author for comment in thread["comments"]["nodes"])})
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return Failure(f"gh api graphql printed no review threads: {str(read).strip()[:200]}")
|
||||
"""A Failure naming the files where a reviewer's comment waits for an answer on pull request number, as `waiting_threads` finds them, or saying why they cannot be read. None where no thread waits."""
|
||||
waiting = waiting_threads(number, run)
|
||||
if isinstance(waiting, Failure):
|
||||
return waiting
|
||||
if not waiting:
|
||||
return None
|
||||
return Failure(f"a reviewer's comment on pull request {number} waits for an answer, in {', '.join(waiting)}; answer it in its thread, push any fix, and run chunk-pr merge again")
|
||||
|
||||
|
||||
def waiting_threads(number: str, run: Run) -> list[str] | Failure:
|
||||
"""The files where a reviewer's comment waits for an answer on pull request number, read once: those of each review thread nobody resolved, whose last comment someone other than the pull request's author wrote. So a thread the worker answered, as that author, waits for the reviewer again."""
|
||||
read = run(["gh", "api", "graphql", "-f", f"query={THREADS}", "-F", "owner={owner}", "-F", "repo={repo}", "-F", f"number={number}"])
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
try:
|
||||
pull = json.loads(read)["data"]["repository"]["pullRequest"]
|
||||
author = pull["author"]["login"]
|
||||
return sorted({thread["path"] for thread in pull["reviewThreads"]["nodes"] if not thread["isResolved"] and any(comment["author"]["login"] != author for comment in thread["comments"]["nodes"])})
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return Failure(f"gh api graphql printed no review threads: {read.strip()[:200]}")
|
||||
|
||||
+11
-8
@@ -45,7 +45,8 @@ merge merges the pull request in its turn: the chunks of one project on this
|
||||
Where the project's config sets `wait-for-approval = true` (`project-config --help`), it
|
||||
merges only once GitHub reports the pull request approved as its branch protection
|
||||
requires. It waits for that outside its turn, so other chunks merge meanwhile, and takes
|
||||
a new turn once approved.
|
||||
a new turn once approved. In a chunk do-epic runs, which sets CHUNK_PR_PARKS=1, it
|
||||
fails at once instead of waiting: do-epic parks the chunk until the approval comes.
|
||||
It stops, without merging, and says what to do before running it again:
|
||||
- on a merge conflict in step 1, naming the conflicted files, with the merge in progress;
|
||||
- where `larv-review scoring-run-owed` exits 1 after step 3, because the chunk owes a
|
||||
@@ -85,7 +86,7 @@ import sys
|
||||
import time
|
||||
import typing
|
||||
|
||||
from chunk_pr.approval import approval, approved, awaited, unanswered
|
||||
from chunk_pr.approval import approval, approved, awaited, left_to_park, PARKS, unanswered
|
||||
from forge.pulls import checks_passed, merged_pull, open_pull, required_checks
|
||||
from failure import Failure
|
||||
from forge.commands import Forge, forge_of, gitea, Run, runner
|
||||
@@ -119,7 +120,7 @@ def main(argv: list[str]) -> int:
|
||||
if argv[:1] in (["-h"], ["--help"]):
|
||||
print(__doc__.strip())
|
||||
return 0
|
||||
done = step(argv, runner(os.getcwd()), functools.cache(lambda: located(os.getcwd(), pathlib.Path.home())))
|
||||
done = step(argv, runner(os.getcwd()), functools.cache(lambda: located(os.getcwd(), pathlib.Path.home())), os.environ.get(PARKS) == "1")
|
||||
if isinstance(done, Failure):
|
||||
print(f"chunk-pr: {done.reason}", file=sys.stderr)
|
||||
return 1
|
||||
@@ -127,8 +128,8 @@ def main(argv: list[str]) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def step(argv: list[str], run: Run, config: Config) -> str | Failure:
|
||||
"""Run the step argv names: the line to print, or a Failure. A malformed argv doesn't run anything."""
|
||||
def step(argv: list[str], run: Run, config: Config, parks: bool = False) -> str | Failure:
|
||||
"""Run the step argv names: the line to print, or a Failure. A malformed argv doesn't run anything. parks is whether a merge fails at once where it would wait for an approval (`merged`)."""
|
||||
match argv:
|
||||
case ["open", title, *body] if len(body) <= 1 and not title.startswith("-"):
|
||||
return Failure("give a title of one line") if not one_line(title) else misfit(title, run, config) or opened(title, body[0] if body else "", run)
|
||||
@@ -138,7 +139,7 @@ def step(argv: list[str], run: Run, config: Config) -> str | Failure:
|
||||
return Failure("give a title of one line") if title and not one_line(title[0]) else (misfit(title[0], run, config) if title else None) or marked_ready(run, title[0] if title else None)
|
||||
case ["merge", *given]:
|
||||
finishes = finishes_of(given)
|
||||
return Failure(USAGE) if finishes is None else merged(run, config, finishes=finishes)
|
||||
return Failure(USAGE) if finishes is None else merged(run, config, finishes=finishes, parks=parks)
|
||||
case ["clean"]:
|
||||
return cleaned(run)
|
||||
return Failure(USAGE)
|
||||
@@ -304,8 +305,8 @@ def finishes_of(given: list[str]) -> list[list[str]] | None:
|
||||
return finishes
|
||||
|
||||
|
||||
def merged(run: Run, config: Config, sleep: typing.Callable[[float], None] = time.sleep, finishes: typing.Sequence[list[str]] = ()) -> str | Failure:
|
||||
"""Merge the branch's pull request in the project's merge queue. Each pass of the loop is one turn in the queue; a pull request that still wants its approval leaves the queue while it waits, so the next chunk merges meanwhile, and takes a new turn once approved."""
|
||||
def merged(run: Run, config: Config, sleep: typing.Callable[[float], None] = time.sleep, finishes: typing.Sequence[list[str]] = (), parks: bool = False) -> str | Failure:
|
||||
"""Merge the branch's pull request in the project's merge queue. Each pass of the loop is one turn in the queue; a pull request that still wants its approval leaves the queue while it waits, so the next chunk merges meanwhile, and takes a new turn once approved. Where parks, it doesn't wait for the approval: it fails at once, as `left_to_park` says."""
|
||||
found = pull(run)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
@@ -336,6 +337,8 @@ def merged(run: Run, config: Config, sleep: typing.Callable[[float], None] = tim
|
||||
taken = untaken or merge_turn(pull_request, finishes, loaded, run, sleep)
|
||||
if not isinstance(taken, AwaitsApproval):
|
||||
return taken if isinstance(taken, Failure) else taken + absent
|
||||
if parks:
|
||||
return left_to_park(number, run)
|
||||
# Out of the queue, so the project's other chunks merge while this one waits.
|
||||
waited = approved(number, run, sleep)
|
||||
if isinstance(waited, Failure):
|
||||
|
||||
@@ -377,6 +377,26 @@ class Merge(unittest.TestCase):
|
||||
self.assertEqual(merged(checkout, checkout.config, slept.append), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(slept, [60])
|
||||
|
||||
def test_a_merge_that_parks_returns_at_once_while_the_branch_protection_still_wants_a_review(self):
|
||||
checkout = self.requiring_approval(GITHUB, "REVIEW_REQUIRED")
|
||||
failed = merged(checkout, checkout.config, self.fail, parks=True)
|
||||
self.assertEqual(failed.reason, "pull request 12 passed its checks and awaits an approval; end your run now, since do-epic parks the chunk and resumes this session once it is approved or a reviewer comments")
|
||||
self.assertEqual(checkout.ran.count(GH_DECISION), 1)
|
||||
self.assertEqual(step(["merge"], self.requiring_approval(GITHUB, "REVIEW_REQUIRED"), checkout.config, parks=True), failed)
|
||||
|
||||
def test_a_merge_that_parks_reports_a_reviewers_unanswered_comment_before_the_approval_it_awaits(self):
|
||||
checkout = self.requiring_approval(GITHUB, "REVIEW_REQUIRED")
|
||||
checkout.threads = [MergeQueue.thread("bin/asked.py", "reviewer")]
|
||||
failed = merged(checkout, checkout.config, self.fail, parks=True)
|
||||
self.assertEqual(failed.reason, "a reviewer's comment on pull request 12 waits for an answer, in bin/asked.py; answer it in its thread, push any fix, and run chunk-pr merge again")
|
||||
checkout = self.requiring_approval(GITHUB, "REVIEW_REQUIRED")
|
||||
checkout.answers[tuple(GH_THREADS)] = Failure("gh api graphql failed")
|
||||
self.assertEqual(merged(checkout, checkout.config, self.fail, parks=True), Failure("gh api graphql failed"))
|
||||
|
||||
def test_a_merge_that_parks_merges_an_approved_pull_request(self):
|
||||
checkout = self.requiring_approval()
|
||||
self.assertEqual(merged(checkout, checkout.config, self.fail, parks=True), "Merged pull request #12 (merge).")
|
||||
|
||||
def test_an_approval_that_never_comes_leaves_it_unmerged_after_90_minutes(self):
|
||||
checkout = self.requiring_approval(GITHUB, "REVIEW_REQUIRED")
|
||||
slept: list[float] = []
|
||||
|
||||
@@ -131,21 +131,21 @@ class EpicStoreContract:
|
||||
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(key), store.finish(closed)], [None, None])
|
||||
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(task))
|
||||
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("ZZZ-1"), Failure)
|
||||
self.assertIsInstance(store.finish("not a key"), Failure)
|
||||
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:
|
||||
@@ -164,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, rank and finish 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,7 +61,19 @@ class MemoryEpic:
|
||||
self.comments.setdefault(key, []).append(text.strip())
|
||||
return None
|
||||
|
||||
def finish(self, key: str) -> None | Failure:
|
||||
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}
|
||||
|
||||
+45
-33
@@ -5,15 +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, DONE, FILED_BY, ISSUE_KEY, ISSUE_TYPE, offer_of, project_of, PROPERTY, rank_refusal, scores, searched
|
||||
from project_config.settings import Epic, JIRA_FINISH_TRANSITION
|
||||
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
|
||||
PERHAPS_MOVED = "unless Jira refused the request, {key} may be done: read it in Jira before moving it again"
|
||||
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"
|
||||
|
||||
|
||||
@@ -26,14 +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
|
||||
# The name of the transition to finish an issue by, where its status offers several to a done status.
|
||||
finish_by: str | None = None
|
||||
finish: Finish | None = None
|
||||
|
||||
@property
|
||||
def epic_key(self) -> str:
|
||||
@@ -119,7 +118,41 @@ 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 finish(self, key: str) -> None | Failure:
|
||||
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
|
||||
@@ -135,15 +168,13 @@ class JiraEpic:
|
||||
return no_child(self.epic_key, key, "finished")
|
||||
if done:
|
||||
return None
|
||||
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 = done_transition(offered, key, self.finish_by)
|
||||
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
|
||||
moved = self.http("POST", url, authorization, {"transition": {"id": transition}})
|
||||
return Failure(f"cannot move {key} to done: {moved.reason}; {PERHAPS_MOVED.format(key=key)}") if isinstance(moved, Failure) else None
|
||||
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."""
|
||||
@@ -210,25 +241,6 @@ class JiraEpic:
|
||||
return Failure(f"{project} has no sub-task issue type; turn sub-tasks on in Jira") if found is None else {"id": found}
|
||||
|
||||
|
||||
def done_transition(offered: object, key: str, named: str | None) -> str | Failure:
|
||||
"""The ID of the transition that finishes the issue named key, among those Jira offered, which are the ones its status has and the account may make. It is the one that leads to a done status, or where there are several, the one called named; or why Jira offered no such move. Which of several finishes an issue is the team's workflow, so none is picked without a name."""
|
||||
raw = offered.get("transitions") if isinstance(offered, dict) else None
|
||||
found = [offer for each in raw if (offer := offer_of(each))] if isinstance(raw, list) else []
|
||||
if not isinstance(raw, list) or len(found) != len(raw):
|
||||
return Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents")
|
||||
closing = [(id_, name, status) for id_, name, status, category in found if category == DONE]
|
||||
chosen = closing if len(closing) == 1 else [move for move in closing if move[1] == named]
|
||||
if len(chosen) == 1:
|
||||
return chosen[0][0]
|
||||
listed = " and ".join(f"{name!r} to {status!r}" for _, name, status in closing)
|
||||
if closing and not named:
|
||||
return Failure(f"{key}'s status has more than one transition to a done status, {listed}: name the one to use in `{JIRA_FINISH_TRANSITION}`, in ~/.claude-projects/do-epic/config.toml")
|
||||
if closing:
|
||||
return Failure(f"{key}'s status has no transition called {named!r} to a done status, only {listed}: correct `{JIRA_FINISH_TRANSITION}`, in ~/.claude-projects/do-epic/config.toml")
|
||||
others = " and ".join(f"{name!r} to {status!r}" for _, name, status, _ in found)
|
||||
return Failure(f"{key}'s status has no transition to a done status" + (f", only {others}" if others else "") + ": Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues")
|
||||
|
||||
|
||||
def found_of(raw: object) -> Found | Failure:
|
||||
"""The issue in one entry of a search's answer, or which issue is not in the shape Jira documents."""
|
||||
key = raw.get("key") if isinstance(raw, dict) else None
|
||||
|
||||
@@ -63,10 +63,17 @@ 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(self, key: str) -> None | Failure:
|
||||
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."""
|
||||
if not summary.strip() or "\n" in summary:
|
||||
|
||||
@@ -55,14 +55,14 @@ 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(str(key)))
|
||||
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("ZZZ-1"), Failure("ZZZ-1 is not one of the child issues of the epic ABC-12, so it cannot be finished"))
|
||||
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("ABC-100"), Failure("Jira is down"))
|
||||
self.assertEqual(MemoryEpic("ABC-12", fails="Jira is down").finish_issue("ABC-100"), Failure("Jira is down"))
|
||||
|
||||
|
||||
if __name__ == "__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
|
||||
@@ -24,8 +24,11 @@ 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"
|
||||
RANK = f"{SITE}/rest/agile/1.0/issue/rank"
|
||||
DONE = {"name": "Done", "statusCategory": {"key": "done"}}
|
||||
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}]}
|
||||
|
||||
|
||||
@@ -49,6 +52,8 @@ class FakeJira:
|
||||
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))
|
||||
@@ -58,6 +63,18 @@ 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:
|
||||
@@ -140,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):
|
||||
@@ -166,52 +183,73 @@ class JiraEpicContract(Case, EpicStoreContract):
|
||||
|
||||
|
||||
class Jira(Case):
|
||||
def test_finishes_an_issue_by_the_one_transition_that_leads_to_a_done_status(self) -> None:
|
||||
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(key))
|
||||
self.assertIsNone(store.finish_issue(key))
|
||||
self.assertEqual(self.jira.calls[-1], ("POST", f"{ISSUES}/{key}/transitions"))
|
||||
self.assertEqual(self.jira.issues[0]["fields"]["status"], DONE) # type: ignore[index]
|
||||
self.assertEqual((self.jira.transitioned, self.jira.issues[0]["fields"]["status"]), (["31"], DONE)) # type: ignore[index]
|
||||
|
||||
def test_leaves_an_issue_that_is_done_without_asking_for_its_transitions(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.change(key, status=DONE)
|
||||
self.assertIsNone(store.finish(key))
|
||||
self.assertNotIn(("GET", f"{ISSUES}/{key}/transitions"), self.jira.calls)
|
||||
|
||||
def test_a_finish_names_why_no_move_closes_the_issue(self) -> None:
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
closed = {"name": "Closed", "statusCategory": {"key": "done"}}
|
||||
start = {"id": "11", "name": "Start", "to": {"name": "In Progress", "statusCategory": {"key": "indeterminate"}}}
|
||||
both = [{"id": "31", "name": "Mark as done", "to": DONE}, {"id": "41", "name": "Close", "to": closed}]
|
||||
config = " in `jira-finish-transition`, in ~/.claude-projects/do-epic/config.toml"
|
||||
for workflow, named, reason in (
|
||||
([start, {"id": "12", "name": "Pause", "to": {"name": "On Hold", "statusCategory": {"key": "indeterminate"}}}], None, f"{key}'s status has no transition to a done status, only 'Start' to 'In Progress' and 'Pause' to 'On Hold': Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues"),
|
||||
([start], None, f"{key}'s status has no transition to a done status, only 'Start' to 'In Progress': Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues"),
|
||||
([], None, f"{key}'s status has no transition to a done status: Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues"),
|
||||
(both, None, f"{key}'s status has more than one transition to a done status, 'Mark as done' to 'Done' and 'Close' to 'Closed': name the one to use{config}"),
|
||||
(both, "Resolve", f"{key}'s status has no transition called 'Resolve' to a done status, only 'Mark as done' to 'Done' and 'Close' to 'Closed': correct `jira-finish-transition`, in ~/.claude-projects/do-epic/config.toml"),
|
||||
([start], "Close", f"{key}'s status has no transition to a done status, only 'Start' to 'In Progress': Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues"),
|
||||
):
|
||||
with self.subTest(workflow=workflow, named=named):
|
||||
self.jira.workflow = workflow # type: ignore[assignment]
|
||||
self.assertEqual(JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, named).finish(key), Failure(reason))
|
||||
self.assertEqual(self.jira.issues[0]["fields"]["status"], TO_DO) # type: ignore[index]
|
||||
|
||||
def test_finishes_by_the_transition_the_config_names_where_several_lead_to_a_done_status(self) -> None:
|
||||
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, "Close").finish(key))
|
||||
self.assertEqual(self.jira.calls[-1], ("POST", f"{ISSUES}/{key}/transitions"))
|
||||
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_finishes_by_the_one_transition_to_a_done_status_whatever_name_the_config_gives(self) -> None:
|
||||
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.workflow = [{"id": "31", "name": "Resolve", "to": DONE}]
|
||||
self.assertIsNone(JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, "Close").finish(key))
|
||||
self.assertEqual(self.jira.transitioned, ["31"])
|
||||
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()
|
||||
@@ -220,35 +258,35 @@ class Jira(Case):
|
||||
self.jira.issues.append({"key": key, "fields": fields})
|
||||
for key in ("ABC-50", "ABC-61"):
|
||||
with self.subTest(key=key):
|
||||
self.assertEqual(store.finish(key), Failure(f"{key} is not one of the child issues of the epic ABC-12, so it cannot be finished"))
|
||||
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(key), Failure(f"cannot move {key} to done: Jira answered 400: Resolution is required; unless Jira refused the request, {key} may be done: read it in Jira before moving it again"))
|
||||
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(key), Failure(f"cannot read {key}'s transitions: 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(key), Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents"))
|
||||
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(task), Failure(f"cannot read {task} to finish it: 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(task), Failure(f"cannot read {child} to finish its sub-task: 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()
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
"""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."""
|
||||
"""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
|
||||
from do_epic import findings
|
||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
|
||||
from text_files.markdown_text import listed
|
||||
import pathlib
|
||||
from model_routing.ladder import ProjectRung
|
||||
from loop_claude.cycle import prompts
|
||||
from model_routing.route import Route
|
||||
from agent_cycle.worker_prompts import WorkerPrompts
|
||||
|
||||
# The entry point's name as the worker, the judge and the human read it.
|
||||
DRIVER = "do-epic"
|
||||
|
||||
|
||||
def task(issue: EpicIssue, epic: str, checkout: str | None) -> str:
|
||||
"""The task of the chunk that works issue, of the epic with the key epic: in checkout, or without a repo where it is None."""
|
||||
def task(issue: EpicIssue, epic: str, checkout: str | None, launcher: pathlib.Path, language: str) -> str:
|
||||
"""The task of the chunk that works issue, of the epic with the key epic: in checkout, or without a repo where it is None. launcher is the do-epic that runs the chunk, and language the one the epic's Jira text is in."""
|
||||
where = f"in the checkout {checkout}, on the branch {issue.key}" if checkout else "which changes no repo: work in the folder you start in"
|
||||
return f"Work the Jira issue {issue.key} of the epic {epic} as one chunk, {where}. Its summary: {issue.summary}" + (f"\n\nIts description:\n\n{issue.detail}" if issue.detail else "")
|
||||
return f"Work the Jira issue {issue.key} of the epic {epic} as one chunk, {where}. {findings.instructions(epic, launcher, language)} Its summary: {issue.summary}" + (f"\n\nIts description:\n\n{issue.detail}" if issue.detail else "")
|
||||
|
||||
|
||||
CODE_HEALTH = '~/.claude/CLAUDE.md → "Shared goal"'
|
||||
@@ -25,4 +32,24 @@ def fresh(task: str, premises: str, route: Route, project: ProjectRung | None, f
|
||||
|
||||
|
||||
# The worker names no plan items: the chunk's one item is its issue.
|
||||
WORKER = prompts.worker_prompts(DRIVER, fresh, "")
|
||||
# The epic's records come first, as its goals do; a chunk without a repo is handed only those and the human's rules, so the names that mention a repo's then name nothing it reads.
|
||||
NAMES = prompts.RecordNames(
|
||||
quote_sources=listed(("the epic's description", "the repo's goals file's Goals and Audience", *RECORD_FILES, *HUMAN_RULE_NAMES), "or"),
|
||||
answer_destinations="the epic's description under ## Decisions, the repo's goals file's Goals or Audience, " + ", ".join(RECORD_FILES) + ", the repo's plan or a comment",
|
||||
records_named="the epic's scoring and decisions, then the repo's working rules and decisions, then the human's rules for every project",
|
||||
)
|
||||
WORKER = prompts.worker_prompts(DRIVER, fresh, "", NAMES)
|
||||
|
||||
# What a worker does with a reviewer's feedback, as the decision asks (docs/decisions.md → `do-epic: drives one Jira epic …`, "Long gates").
|
||||
FEEDBACK = 'Where a reviewer left feedback, fix what is reasonable and push the fix, answer each other comment in its thread, and change the setup so our review would have caught the finding (~/.claude/CLAUDE.md → "Working loop", "Change the setup for each finding an outside reviewer raises on a PR, deterministic tools first"). Then merge the pull request as before.'
|
||||
|
||||
|
||||
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}")
|
||||
|
||||
+9
-10
@@ -7,21 +7,21 @@ One pair per machine, the same for every epic (docs/decisions.md → `do-epic: d
|
||||
repoless-model = "claude-opus-5-5"
|
||||
clone-folder = "~/code"
|
||||
language = "Swedish"
|
||||
jira-finish-transition = "Mark as done"
|
||||
|
||||
- `jira-url` is the Jira site's address: https, a host, and no path.
|
||||
- `env-file` is the file of Jira credentials: a path that starts with / or ~/, outside every folder of `~/.claude-projects` and outside the clone folder, which hold git checkouts. `~/.claude-projects/<key>.env` is fine.
|
||||
- `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` is the name Jira shows of the transition that moves a finished chunk's issue to done. It is needed only where an issue's status offers more than one transition to a done status, such as Resolve and Close. Left out, do-epic takes the one transition that leads to a done status.
|
||||
- `jira-finish-transition` and `jira-finish-status` name the workflow transition that 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 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, JIRA_FINISH_TRANSITION, LANGUAGE, language_fault, lies_in, name_of, 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"
|
||||
@@ -30,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, JIRA_FINISH_TRANSITION)
|
||||
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)
|
||||
@@ -44,8 +44,8 @@ class DoEpicConfig:
|
||||
language: str
|
||||
repoless_model: str
|
||||
repo_rule: str
|
||||
# The name of the transition that finishes an issue where its status offers several to a done status; None where the config names none.
|
||||
finish_transition: str | None = None
|
||||
# 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:
|
||||
@@ -67,7 +67,6 @@ def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfi
|
||||
clone_folder = anywhere(values.get(CLONE_FOLDER, "~/code"), home)
|
||||
env_file = anywhere(values.get(ENV_FILE), home)
|
||||
language = values.get(LANGUAGE, "English")
|
||||
finish = values.get(JIRA_FINISH_TRANSITION)
|
||||
url, model = values.get(JIRA_URL), values.get(REPOLESS_MODEL)
|
||||
faults = [
|
||||
*(f"`{name}` is missing" for name in SETTINGS if name not in values),
|
||||
@@ -77,12 +76,12 @@ def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfi
|
||||
*([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, not a path that starts with / or ~/"] if ENV_FILE in values and env_file is None else []),
|
||||
*([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"`{JIRA_FINISH_TRANSITION}` is {finish!r}, not the name Jira shows, such as \"Mark as done\""] if JIRA_FINISH_TRANSITION in values and not name_of(finish) 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, name_of(finish))
|
||||
return DoEpicConfig(folder, url, env_file, clone_folder, language, model, rule, finish_of(values))
|
||||
|
||||
@@ -89,6 +89,19 @@ def with_language(text: str, language: str) -> str | Failure:
|
||||
return line + "\n" + "\n" * bool(text.strip()) + text
|
||||
|
||||
|
||||
def decision_titled(decisions: str, title: str) -> str | None:
|
||||
"""The entry under the ### title heading of decisions, a ## Decisions section's body; None where it has no such heading."""
|
||||
found: list[str] | None = None
|
||||
for line, fenced in fenced_lines(decisions):
|
||||
if not fenced and line.startswith("### "):
|
||||
if found is not None:
|
||||
break
|
||||
found = [] if line[4:].strip() == title else None
|
||||
elif found is not None:
|
||||
found.append(line)
|
||||
return None if found is None else "\n".join(found).strip()
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class EpicRecord:
|
||||
"""One epic's record, kept in its description."""
|
||||
@@ -110,6 +123,28 @@ class EpicRecord:
|
||||
"""Writes body as the ## name section. approved says the human approved the change in an interrupt, which Goals and Audience need."""
|
||||
return self.written(lambda text: with_section(text, name, body), frozenset({name}) if approved else frozenset())
|
||||
|
||||
def append_decision(self, title: str, entry: str) -> bool | Failure:
|
||||
"""Adds entry under a ### title heading at the end of ## Decisions, leaving the decisions before it as they are. False where the section already holds that entry under that title, so recording a decision twice keeps one; a Failure where it holds another entry under it, so one title names one decision."""
|
||||
title, entry = title.strip(), entry.strip()
|
||||
if not title or "\n" in title:
|
||||
return Failure("the title must be one line of text")
|
||||
if not entry:
|
||||
return Failure("pipe the decision's text in")
|
||||
held = self.description.held()
|
||||
if isinstance(held, Failure):
|
||||
return held
|
||||
before = read_section(held.text, "Decisions")
|
||||
if isinstance(before, Failure):
|
||||
return before
|
||||
same = decision_titled(before, title)
|
||||
if same is not None:
|
||||
return False if same == entry else Failure(f"## Decisions already holds another decision titled {title!r}: give this one a title of its own")
|
||||
text = with_section(held.text, "Decisions", f"{before}\n\n### {title}\n\n{entry}".strip())
|
||||
if isinstance(text, Failure):
|
||||
return text
|
||||
wrote = dataclasses.replace(self.description, approved=frozenset()).write(text, held.version)
|
||||
return wrote if isinstance(wrote, Failure) else True
|
||||
|
||||
def write_language(self, language: str) -> Held | Failure:
|
||||
return self.written(lambda text: with_language(text, language), frozenset())
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
"""What a chunk's worker writes into its epic: a finding, filed as an issue, and a decision, appended to the description.
|
||||
|
||||
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 fcntl
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
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`.
|
||||
FILE = "--file"
|
||||
LABEL = "--label"
|
||||
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]
|
||||
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."""
|
||||
|
||||
|
||||
def instructions(epic: str, launcher: pathlib.Path, language: str) -> str:
|
||||
"""What a chunk's first prompt says about filing a finding and recording a decision in the epic with the key epic. launcher is the do-epic that runs the chunk, and language the one the epic's Jira text is in."""
|
||||
return (
|
||||
f"File a finding about one of the epic's goals in the epic, with `{launcher} {epic} {FILE} \"<summary>\" {LABEL} <label>` and its detail on stdin. "
|
||||
f"The label is {LABELS}; leave it out where you cannot tell, and the issue waits for the human. "
|
||||
"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"Write the issue and the decision in {language}, the epic's language."
|
||||
)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def decisions_locked(folder: pathlib.Path) -> typing.Iterator[None]:
|
||||
"""Holds the epic's DECISIONS_LOCK, in its folder, so two chunks that record a decision at once write one after the other. Raises OSError where the file cannot be made or locked."""
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
with open(folder / DECISIONS_LOCK, "w") as lock:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||
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."""
|
||||
if not words or words[0] not in (FILE, RECORD_DECISION):
|
||||
return None
|
||||
labels: list[str] = []
|
||||
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)):
|
||||
return None
|
||||
return words[0], rest[0], tuple(labels)
|
||||
|
||||
|
||||
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 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 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)
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot record the decision in the epic {epic}'s description: cannot lock {failure.filename or folder / DECISIONS_LOCK}: {failure.strerror}")
|
||||
if isinstance(added, Failure):
|
||||
return Failure(f"cannot record the decision in the epic {epic}'s description: {added.reason}")
|
||||
return f"Recorded the decision in the epic {epic}'s description." if added else f"The epic {epic}'s description already holds that decision."
|
||||
@@ -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."
|
||||
@@ -0,0 +1,131 @@
|
||||
"""What the pull request of a do-epic chunk waits on, read once from its forge (docs/decisions.md → `do-epic: drives one Jira epic …`, "Long gates").
|
||||
|
||||
A gate is something only time or a person passes: checks that still run, an approval a reviewer has yet to give, or the new review of a reviewer whose requested changes the worker answered. While a chunk's pull request waits on one, its worker doesn't have anything to do, so do-epic parks the chunk (`parked`). Anything else is news the worker acts on."""
|
||||
import dataclasses
|
||||
import json
|
||||
import typing
|
||||
|
||||
from forge.pulls import CheckFailed, checks_now, open_pull, Pending, required_checks
|
||||
from failure import Failure
|
||||
from forge.commands import forge_of, gitea, Run
|
||||
from chunk_pr.approval import waiting_threads
|
||||
|
||||
# What a pull request waits on, as the words after "awaits".
|
||||
CHECKS = "its checks"
|
||||
APPROVAL = "an approval"
|
||||
NEW_REVIEW = "a new review"
|
||||
# What `review_decision` returns in place of GitHub's `CHANGES_REQUESTED` once the worker answered those changes: GitHub keeps its decision until the reviewer reviews again.
|
||||
ANSWERED = "CHANGES_ANSWERED"
|
||||
# What the title of a draft opens with on Gitea, in any case: Gitea's default `WORK_IN_PROGRESS_PREFIXES`.
|
||||
GITEA_DRAFT = ("WIP:", "[WIP]")
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Gate:
|
||||
"""The gate a chunk's open pull request waits on."""
|
||||
# The chunk's worktree, where the pull request's branch is checked out.
|
||||
worktree: str
|
||||
# The pull request's number.
|
||||
pull: str
|
||||
# CHECKS, APPROVAL or NEW_REVIEW.
|
||||
on: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Open:
|
||||
"""A chunk that waits on no gate, so its worker goes on."""
|
||||
# Why, as a sentence without its full stop, for the worker of a chunk that was parked.
|
||||
news: str
|
||||
|
||||
|
||||
def gate(branch: str, checkout: str, at: typing.Callable[[str], Run]) -> Gate | Open | Failure:
|
||||
"""What the chunk on branch waits on, in a worktree of checkout; at gives the runner of commands in a folder. A Failure where git or the forge cannot be read, which doesn't say anything about the gate.
|
||||
|
||||
A draft never waits on a gate: its worker still works on it. On Gitea only the checks are a gate, since chunk-pr reads approvals on GitHub only (`chunk_pr.approval.awaited`). Changes a reviewer requested are news until the worker answered them (`answered`); from then on the pull request awaits a new review.
|
||||
"""
|
||||
worktree = worktree_of(branch, at(checkout))
|
||||
if not isinstance(worktree, str):
|
||||
return worktree or Open(f"no worktree of {checkout} has the branch {branch} checked out")
|
||||
run = at(worktree)
|
||||
read = [run(["git", *args]) for args in (["remote", "get-url", "origin"], ["rev-parse", "HEAD"], ["symbolic-ref", "--short", "refs/remotes/origin/HEAD"])]
|
||||
failed = next((answer for answer in read if isinstance(answer, Failure)), None)
|
||||
if failed is not None:
|
||||
return failed
|
||||
origin, head, base = (str(answer).strip() for answer in read)
|
||||
forge = forge_of(origin)
|
||||
pull = open_pull(forge, branch, head, run)
|
||||
if not isinstance(pull, str):
|
||||
return pull or Open(f"no pull request from origin's {branch} is open at {head[:12]}; it may be merged or closed already")
|
||||
decision = review_decision(pull, head, run) if forge == "gh" else gitea_decision(pull, run)
|
||||
if not isinstance(decision, str):
|
||||
return decision or Open(f"pull request #{pull} is a draft")
|
||||
required = required_checks(forge, base.removeprefix("origin/"), run)
|
||||
checks = required if isinstance(required, Failure) else checks_now(forge, pull, head, required, run)
|
||||
if isinstance(checks, CheckFailed):
|
||||
return Open(f"{checks.reason}; fix it and push")
|
||||
if isinstance(checks, Failure):
|
||||
return checks
|
||||
if isinstance(checks, Pending):
|
||||
return Gate(worktree, pull, CHECKS)
|
||||
if decision == "CHANGES_REQUESTED":
|
||||
return Open(f"a reviewer requested changes on pull request #{pull}")
|
||||
waiting = waiting_threads(pull, run) if forge == "gh" else []
|
||||
if isinstance(waiting, Failure):
|
||||
return waiting
|
||||
if waiting:
|
||||
return Open(f"a reviewer's comment on pull request #{pull} waits for an answer, in {', '.join(waiting)}")
|
||||
if decision in (ANSWERED, "REVIEW_REQUIRED"):
|
||||
return Gate(worktree, pull, NEW_REVIEW if decision == ANSWERED else APPROVAL)
|
||||
return Open(f"pull request #{pull} passed its checks" + (" and is approved" if decision == "APPROVED" else ""))
|
||||
|
||||
|
||||
def worktree_of(branch: str, run: Run) -> str | None | Failure:
|
||||
"""The worktree, of the checkout run works in, that has branch checked out; None where none has."""
|
||||
listed = run(["git", "worktree", "list", "--porcelain"])
|
||||
if isinstance(listed, Failure):
|
||||
return listed
|
||||
for block in listed.split("\n\n"):
|
||||
lines = block.splitlines()
|
||||
if f"branch refs/heads/{branch}" in lines and lines[0].startswith("worktree "):
|
||||
return lines[0].removeprefix("worktree ")
|
||||
return None
|
||||
|
||||
|
||||
def review_decision(pull: str, head: str, run: Run) -> str | None | Failure:
|
||||
"""GitHub's review decision on the pull request, whose head commit is head, read once: `APPROVED`, `REVIEW_REQUIRED`, `CHANGES_REQUESTED`, or empty where its branch protection asks for no review. ANSWERED in place of `CHANGES_REQUESTED` once the worker answered those changes. None where it is a draft."""
|
||||
viewed = run(["gh", "pr", "view", pull, "--json", "isDraft,reviewDecision,author,reviews,comments"])
|
||||
if isinstance(viewed, Failure):
|
||||
return viewed
|
||||
try:
|
||||
parsed = json.loads(viewed)
|
||||
if parsed["isDraft"]:
|
||||
return None
|
||||
decision = str(parsed["reviewDecision"] or "")
|
||||
return ANSWERED if decision == "CHANGES_REQUESTED" and answered(parsed, head) else decision
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return Failure(f"gh pr view printed no review decision: {viewed.strip()[:200]}")
|
||||
|
||||
|
||||
def answered(pull: dict[str, typing.Any], head: str) -> bool:
|
||||
"""Whether the worker answered the newest review that requested changes on pull, as `gh pr view --json author,reviews,comments` prints it, whose head commit is head: the head is no longer the commit that review was made on, or the pull request's author commented or replied in a thread after it. GitHub lists a reply in a thread as a review of its own. False where it lists no review that requested changes. Raises KeyError or TypeError where pull has another shape.
|
||||
|
||||
The review names its commit, so no clock tells whether the worker pushed: a commit's date says when it was made, never when it was pushed.
|
||||
"""
|
||||
asked = max((review for review in pull["reviews"] if review["state"] == "CHANGES_REQUESTED"), key=lambda review: review["submittedAt"], default=None)
|
||||
if asked is None:
|
||||
return False
|
||||
author = pull["author"]["login"]
|
||||
# A review the author has yet to submit has no time, and answers nobody.
|
||||
said = [review["submittedAt"] or "" for review in pull["reviews"] if review["author"]["login"] == author] + [comment["createdAt"] for comment in pull["comments"] if comment["author"]["login"] == author]
|
||||
return asked["commit"]["oid"] != head or any(at > asked["submittedAt"] for at in said)
|
||||
|
||||
|
||||
def gitea_decision(pull: str, run: Run) -> str | None | Failure:
|
||||
"""What stands in for `review_decision` on Gitea, read once: empty, since no review is a gate there, and None where the pull request is a draft, which Gitea tells by its title (GITEA_DRAFT)."""
|
||||
viewed = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{pull}")
|
||||
if isinstance(viewed, Failure):
|
||||
return viewed
|
||||
try:
|
||||
return None if viewed["title"].upper().startswith(GITEA_DRAFT) else ""
|
||||
except (KeyError, TypeError, AttributeError):
|
||||
return Failure(f"tea api printed no title of pull request {pull}: {str(viewed)[:200]}")
|
||||
+197
-38
@@ -1,14 +1,18 @@
|
||||
"""The do-epic command (docs/decisions.md → `do-epic: drives one Jira epic …`).
|
||||
|
||||
`do-epic <EPIC-KEY>` starts each of the epic's chunks that may start now, each in a window of the epic's tmux session, as `scheduler` picks them, and puts that session on the terminal. Each window runs `do-epic --chunk <ISSUE-KEY> <EPIC-KEY>`: the cycles of one issue's chunk, run by the code that runs loop-claude's (`agent_cycle`), until the judge rules it finished. Then it starts the chunks that may start now, and its window closes."""
|
||||
`do-epic <EPIC-KEY>` starts each of the epic's chunks that may start now, each in a window of the epic's tmux session, as `scheduler` picks them, and puts that session on the terminal. Each window runs `do-epic --chunk <ISSUE-KEY> <EPIC-KEY>`: the cycles of one issue's chunk, run by the code that runs loop-claude's (`agent_cycle`), until the judge rules it finished. Then it starts the chunks that may start now, and its window closes.
|
||||
|
||||
After each cycle of a chunk in a repo, the window reads what the chunk's pull request waits on (`gates`). While that is a gate only time or a person passes, the chunk is parked (`parked`): the window frees its running slot and polls the forge, and the chunk's next cycle starts once the worker has something to do and a slot is free. `do-epic <EPIC-KEY> --status` prints what each open issue does."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from loop_claude.loop.chunk_start import archived_route, routed
|
||||
from do_epic import chunk_prompt, scheduler, split
|
||||
from do_epic import chunk_prompt, findings, finish, gates, parked, scheduler, split
|
||||
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
|
||||
from agent_cycle.run import Cycle, run_cycle
|
||||
from do_epic.config import DoEpicConfig, load
|
||||
from loop_effects.effects import Effects, say
|
||||
@@ -29,23 +33,36 @@ from loop_state.paths import Paths
|
||||
from transcript_archive.project_key import project_key
|
||||
from model_routing.ladder_file import project_ladder_file, read_ladder, SHIPPED
|
||||
from loop_claude.project.premises import read_premises
|
||||
from loop_claude.project.records import read_records
|
||||
from forge.commands import Run, runner
|
||||
from claude_code.session import session_named
|
||||
from loop_claude.loop.main import setup_version
|
||||
from agent_cycle.stop import Stop
|
||||
from agent_cycle.direct_message import tell
|
||||
from agent_cycle import tmux
|
||||
|
||||
HELP = f"""usage: do-epic <EPIC-KEY>
|
||||
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.
|
||||
The label names the issue's repo, or says the work changes no repo.
|
||||
As many run at once as the epic's description allows with a line such as `**Max parallel chunks:** 2`, one where it has none.
|
||||
A repo takes as many chunks as its `parallel-chunks`, and none while loop-claude runs chunks in it.
|
||||
A chunk whose worker ends its run while its pull request waits on its checks, an approval or a new review
|
||||
is parked: it frees its place for the next chunk, and its window's name says what it awaits. Its worker goes
|
||||
on once the checks pass, the approval comes or a reviewer comments, and a place is free; until one is, the
|
||||
name says `awaits a slot`. A parked chunk survives a reboot: run do-epic <EPIC-KEY> again to go on polling.
|
||||
--status starts no chunk: it prints each open issue with whether its chunk runs, or why it waits.
|
||||
{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"
|
||||
# The flag that prints what each open issue does.
|
||||
STATUS_FLAG = "--status"
|
||||
# How often a parked chunk reads its pull request's gate: a reviewer answers in hours, and each read is three or four calls to the forge.
|
||||
POLL_SECONDS = 60
|
||||
|
||||
# The store of an epic's issues and its record, for the epic with this key.
|
||||
Backend = typing.Callable[[DoEpicConfig, str], tuple[EpicStore, EpicRecord]]
|
||||
@@ -53,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, finish_by=config.finish_transition), 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)
|
||||
@@ -67,15 +84,17 @@ class EpicRun:
|
||||
env: typing.Mapping[str, str]
|
||||
launcher: pathlib.Path
|
||||
effects: Effects
|
||||
# The runner of git's and the forge's commands in a folder.
|
||||
forge_at: typing.Callable[[str], Run] = runner
|
||||
|
||||
@property
|
||||
def session(self) -> str:
|
||||
return tmux.session_name(tmux.EPIC, self.key)
|
||||
|
||||
|
||||
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend = jira_backend) -> int:
|
||||
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend = jira_backend, stdin: typing.TextIO = sys.stdin, forge_at: typing.Callable[[str], Run] = runner) -> int:
|
||||
try:
|
||||
stop = run(argv, env, paths, launcher, effects, backend)
|
||||
stop = run(argv, env, paths, launcher, effects, backend, stdin, forge_at)
|
||||
except KeyboardInterrupt:
|
||||
stop = Stop(130, "")
|
||||
except Exception as crash:
|
||||
@@ -89,10 +108,17 @@ def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher:
|
||||
return stop.code
|
||||
|
||||
|
||||
def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend) -> Stop:
|
||||
def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend, stdin: typing.TextIO, forge_at: typing.Callable[[str], Run]) -> Stop:
|
||||
chunk, words = (argv[1], argv[2:]) if len(argv) >= 2 and argv[0] == scheduler.CHUNK_FLAG else (None, argv)
|
||||
if len(words) != 1 or not ISSUE_KEY.fullmatch(words[0]) or (chunk is not None and not ISSUE_KEY.fullmatch(chunk)):
|
||||
status = chunk is None and words[1:] == [STATUS_FLAG]
|
||||
words = words[:1] if status 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
|
||||
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 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):
|
||||
return Stop(1, reason)
|
||||
@@ -100,10 +126,29 @@ def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher:
|
||||
if isinstance(config, Failure):
|
||||
return Stop(1, config.reason)
|
||||
store, record = backend(config, words[0])
|
||||
epic = EpicRun(words[0], config, store, record, paths, env, launcher, effects)
|
||||
epic = EpicRun(words[0], config, store, record, paths, env, launcher, effects, forge_at)
|
||||
if status:
|
||||
return status_printed(epic)
|
||||
return windows_opened(epic) if chunk is None else chunk_run(chunk, epic)
|
||||
|
||||
|
||||
def status_printed(epic: EpicRun) -> Stop:
|
||||
"""What `do-epic <EPIC-KEY> --status` does: prints a line per open issue, and doesn't start anything."""
|
||||
issues = epic.store.read()
|
||||
lines = issues if isinstance(issues, Failure) else scheduler.status(epic.key, epic.paths.home, issues, epic.effects.tmux)
|
||||
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:
|
||||
"""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)
|
||||
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."""
|
||||
issues = epic.store.read()
|
||||
@@ -113,6 +158,8 @@ def windows_opened(epic: EpicRun) -> Stop:
|
||||
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():
|
||||
@@ -123,7 +170,19 @@ def windows_opened(epic: EpicRun) -> Stop:
|
||||
|
||||
|
||||
def chunks_started(epic: EpicRun, issues: list[EpicIssue], own: str | None) -> scheduler.Started | Failure:
|
||||
"""scheduler.start_chunks on the epic's issues, as read, and its cap; own is the issue of the chunk that asks."""
|
||||
"""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)
|
||||
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:
|
||||
"""The epic as scheduler limits its chunks: with its cap, read afresh, and each repo's checkout."""
|
||||
cap = epic.record.parallel_chunks()
|
||||
if isinstance(cap, Failure):
|
||||
return cap
|
||||
@@ -137,7 +196,7 @@ def chunks_started(epic: EpicRun, issues: list[EpicIssue], own: str | None) -> s
|
||||
seen.append(found.checkout)
|
||||
return real(found.checkout), found.config.parallel_chunks
|
||||
|
||||
return scheduler.start_chunks(scheduler.Epic(epic.key, cap, located, epic.paths.home, epic.launcher, epic.env), issues, own, epic.effects.tmux)
|
||||
return scheduler.Epic(epic.key, cap, located, epic.paths.home, epic.launcher, epic.env)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -165,23 +224,24 @@ def real(checkout: pathlib.Path) -> pathlib.Path:
|
||||
|
||||
|
||||
def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
"""Runs the cycles of the chunk of the issue called key until one stops the loop, or the judge rules the chunk finished."""
|
||||
"""Runs the cycles of the chunk of the issue called key until one stops the loop, or the judge rules the chunk finished. A chunk in a repo parks after each cycle that leaves its pull request waiting on a gate, and before its first where it was parked when its window last ended, as at a reboot."""
|
||||
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, in_repo = place
|
||||
root, repo = place
|
||||
session = session_named(f"A {epic.key} do-epic {key}", epic.paths.claude_code_transcripts)
|
||||
loop = Loop(root=root, session=session, window=tmux.Window(epic.session, key, pane), paths=epic.paths, env=epic.env, launcher=epic.launcher, effects=epic.effects)
|
||||
loop_run = LoopRun(0, root, "", "", chunk=key)
|
||||
# What a chunk that was parked is told as it resumes; empty for a chunk that wasn't.
|
||||
news = parked_through(repo, loop, epic, starts=True) if repo is not None else ""
|
||||
while True:
|
||||
if isinstance(news, Stop):
|
||||
return news
|
||||
loop_run = dataclasses.replace(loop_run, cycle_number=loop_run.cycle_number + 1)
|
||||
cycle = next_cycle(loop_run, loop, in_repo, epic)
|
||||
cycle = next_cycle(loop_run, loop, repo is not None, epic, news)
|
||||
if isinstance(cycle, Stop):
|
||||
return cycle
|
||||
loop_run = dataclasses.replace(loop_run, task=cycle.task)
|
||||
@@ -192,10 +252,75 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
if isinstance(closed, Stop):
|
||||
return closed
|
||||
loop_run = closed
|
||||
if isinstance(concluded.verdict, Finished):
|
||||
news = parked_through(repo, loop, epic, starts=False) if repo is not None else ""
|
||||
# A chunk that was parked has work again, whatever the judge ruled before its pull request passed the gate.
|
||||
if isinstance(concluded.verdict, Finished) and news == "":
|
||||
return handed_on(key, epic)
|
||||
|
||||
|
||||
def parked_through(repo: str, loop: Loop, epic: EpicRun, starts: bool) -> str | Stop:
|
||||
"""Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. starts says the window just started, where the chunk is parked only if its file says so: the forge isn't read for a chunk that starts afresh.
|
||||
|
||||
A chunk parks in three steps: its file is written, its window is shown as parked, and the epic's next chunks start in the slot it frees. It resumes in the reverse order: `scheduler.resume` gives it a running slot, then its file is removed. So a window that ends in between finds the chunk parked when it starts again.
|
||||
"""
|
||||
key, folder = loop.window.name, epic.paths.home / scheduler.STATE / epic.key
|
||||
recorded_as = parked.parked_chunks(folder)
|
||||
if isinstance(recorded_as, Failure):
|
||||
return Stop(1, recorded_as.reason)
|
||||
if starts and key not in recorded_as:
|
||||
return ""
|
||||
# What the chunk is parked on; None while it isn't parked.
|
||||
on = recorded_as[key].on if key in recorded_as else None
|
||||
# What the window's name says the chunk awaits, and the last reason said for staying parked.
|
||||
shown = said = None
|
||||
while True:
|
||||
now = gates.gate(key, loop.root, epic.forge_at)
|
||||
if on is None and not isinstance(now, gates.Gate):
|
||||
if isinstance(now, Failure):
|
||||
say(f"cannot tell whether the chunk's pull request waits on a gate, so the chunk isn't parked: {now.reason}", epic.effects, stdout=True)
|
||||
return ""
|
||||
stays = None
|
||||
if isinstance(now, gates.Gate) and now.on != on:
|
||||
failed = parked.park(folder, parked.Parked(key, now.worktree, now.pull, str(loop.session.id), now.on))
|
||||
if failed is not None:
|
||||
return Stop(1, failed.reason)
|
||||
say(f"parked: pull request #{now.pull} awaits {now.on}", epic.effects, stdout=True)
|
||||
elif isinstance(now, Failure):
|
||||
stays = f"cannot read the gate: {now.reason}"
|
||||
elif isinstance(now, gates.Open):
|
||||
full = resumed(repo, loop, epic)
|
||||
if full is None:
|
||||
failed = parked.unpark(folder, key)
|
||||
return Stop(1, failed.reason) if failed is not None else f"{DRIVER_PARKED} its pull request awaited {on}. It resumes now: {now.news}."
|
||||
stays = f"{now.news}, but the chunk stays parked: {full}"
|
||||
awaits = parked.SLOT if isinstance(now, gates.Open) else now.on if isinstance(now, gates.Gate) else shown or on
|
||||
if awaits != shown:
|
||||
tmux.park(loop.window, str(awaits), epic.effects.tmux)
|
||||
shown = awaits
|
||||
if on is None:
|
||||
# Once the window shows as parked, so the chunks that start count it as running nowhere.
|
||||
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:
|
||||
say(f"{stays}; trying again every {POLL_SECONDS} seconds", epic.effects, stdout=True)
|
||||
said = stays
|
||||
epic.effects.sleep(POLL_SECONDS)
|
||||
|
||||
|
||||
# How the news for a chunk that was parked opens.
|
||||
DRIVER_PARKED = f"{chunk_prompt.DRIVER} parked the chunk while"
|
||||
|
||||
|
||||
def resumed(repo: str, loop: Loop, epic: EpicRun) -> str | None:
|
||||
"""scheduler.resume for the parked chunk in loop's window, whose work is in the repo called repo, on the epic's cap and repos read afresh: None once it holds a running slot, else why it stays parked."""
|
||||
scheduled = scheduled_epic(epic)
|
||||
if isinstance(scheduled, Failure):
|
||||
return scheduled.reason
|
||||
return scheduler.resume(scheduled, repo, loop.window, epic.effects.tmux)
|
||||
|
||||
|
||||
def issue_read(key: str, epic: EpicRun) -> EpicIssue | Stop:
|
||||
"""The epic's issue called key, read afresh."""
|
||||
issues = epic.store.read()
|
||||
@@ -205,24 +330,28 @@ 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, bool] | Stop:
|
||||
"""The folder the issue's chunk works in, and whether it is a repo's checkout: the epic's folder 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):
|
||||
folder = epic.paths.home / scheduler.STATE / epic.key
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
return str(folder), False
|
||||
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)), True)
|
||||
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. It first moves the chunk's issue to done, and its split item too where that was the last of the item's sub-tasks, so that no finished chunk starts again and what they block may start, then starts each chunk that may start now. Its window closes as it exits."""
|
||||
moved = epic.store.finish(key)
|
||||
"""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()
|
||||
@@ -244,25 +373,28 @@ def split_items_closed(epic: EpicRun, issues: list[EpicIssue]) -> list[EpicIssue
|
||||
"""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(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) -> 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. 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
|
||||
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."""
|
||||
premises = premises_read(loop.root if in_repo else None, epic)
|
||||
if isinstance(premises, Failure):
|
||||
return Stop(1, premises.reason)
|
||||
# The epic's records join the repo's with todo.md item 413; until then a chunk without a repo has none.
|
||||
records = read_records(loop.root, epic.paths.home, epic.paths.claude_dir) if in_repo else ""
|
||||
language = epic.record.language()
|
||||
if isinstance(language, Failure):
|
||||
return Stop(1, language.reason)
|
||||
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
|
||||
@@ -274,9 +406,25 @@ def next_cycle(loop_run: LoopRun, loop: Loop, in_repo: bool, epic: EpicRun) -> C
|
||||
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), prompts=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:
|
||||
@@ -284,6 +432,17 @@ def repoless_models(epic: EpicRun) -> Models:
|
||||
return Models(epic.env.get("LOOP_CLAUDE_JUDGE_MODEL") or epic.config.repoless_model, epic.env.get("LOOP_CLAUDE_WORKER_MODEL") or epic.config.repoless_model)
|
||||
|
||||
|
||||
def records_read(root: str | None, epic: EpicRun) -> str | Failure:
|
||||
"""The epic's Scoring and Decisions, from its description, then the records of the repo checked out at root, where the chunk has one, then the human's rules."""
|
||||
sections: list[tuple[str, str]] = []
|
||||
for name in ("Scoring", "Decisions"):
|
||||
body = epic.record.section(name)
|
||||
if isinstance(body, Failure):
|
||||
return Failure(f"the epic {epic.key}'s description: {body.reason} - {CONSEQUENCE}.")
|
||||
sections.append((f"the epic {epic.key}'s description, ## {name}", body))
|
||||
return read_records(root, epic.paths.home, epic.paths.claude_dir, tuple(sections))
|
||||
|
||||
|
||||
def premises_read(root: str | None, epic: EpicRun) -> str | Failure:
|
||||
"""The epic's Goals and Audience, from its description, then those of the repo checked out at root, where the chunk has one. A Failure where the epic lacks either: no chunk runs without premises."""
|
||||
bodies: list[str] = []
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
"""The parked chunks of an epic: each keeps its worktree, pull request and session while that pull request waits on a long gate, in a file that survives a reboot (docs/decisions.md → `do-epic: drives one Jira epic …`, "Long gates").
|
||||
|
||||
A chunk is parked from the moment its file is written until the file is removed, whatever its window does: `scheduler` starts a window again for a parked chunk that has none, and that window goes on polling."""
|
||||
import dataclasses
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
|
||||
from failure import Failure
|
||||
|
||||
# Under the epic's folder, the folder that holds one file per parked chunk, named for its issue.
|
||||
FOLDER = "parked"
|
||||
# What a parked chunk awaits, in its window's name, once its worker has something to do but no running slot is free.
|
||||
SLOT = "a slot"
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Parked:
|
||||
"""A parked chunk."""
|
||||
# The key of the issue it works.
|
||||
issue: str
|
||||
worktree: str
|
||||
# Its pull request's number.
|
||||
pull: str
|
||||
# The ID of its worker's claude session, which `claude --resume` takes.
|
||||
session: str
|
||||
# What its pull request waits on, as the words after "awaits" (`gates.CHECKS`, `gates.APPROVAL`, `gates.NEW_REVIEW`).
|
||||
on: str
|
||||
|
||||
def waits(self, shown: str) -> str:
|
||||
"""Why the chunk doesn't run, for the human. shown is what the name of its live window says it awaits, which is newer than the file's `on`; empty where no window lives."""
|
||||
if shown == SLOT:
|
||||
return f"it is parked: its worker has work again on pull request #{self.pull} and awaits {SLOT}"
|
||||
return f"it is parked: its pull request #{self.pull} awaits {shown or self.on}"
|
||||
|
||||
|
||||
def file_of(folder: pathlib.Path, issue: str) -> pathlib.Path:
|
||||
return folder / FOLDER / f"{issue}.json"
|
||||
|
||||
|
||||
def park(folder: pathlib.Path, chunk: Parked) -> Failure | None:
|
||||
"""Records chunk as parked under the epic's folder, in place of what was recorded for its issue. The file is whole or absent, whenever the machine stops."""
|
||||
file = file_of(folder, chunk.issue)
|
||||
partial = file.with_suffix(".partial")
|
||||
try:
|
||||
file.parent.mkdir(parents=True, exist_ok=True)
|
||||
partial.write_text(json.dumps(dataclasses.asdict(chunk), indent="\t") + "\n", encoding="utf-8")
|
||||
os.replace(partial, file)
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot record the parked chunk in {file}: {failure.strerror}")
|
||||
return None
|
||||
|
||||
|
||||
def unpark(folder: pathlib.Path, issue: str) -> Failure | None:
|
||||
"""Records that the issue's chunk is parked no longer."""
|
||||
try:
|
||||
file_of(folder, issue).unlink(missing_ok=True)
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot remove {file_of(folder, issue)}: {failure.strerror}")
|
||||
return None
|
||||
|
||||
|
||||
def parked_chunks(folder: pathlib.Path) -> dict[str, Parked] | Failure:
|
||||
"""The epic's parked chunks, by issue. A Failure where a file cannot be read as one, since a chunk taken as not parked would start a second time."""
|
||||
found: dict[str, Parked] = {}
|
||||
for file in sorted((folder / FOLDER).glob("*.json")):
|
||||
try:
|
||||
fields = json.loads(file.read_text(encoding="utf-8"))
|
||||
chunk = Parked(**fields)
|
||||
except (OSError, ValueError, TypeError) as failure:
|
||||
return Failure(f"cannot read the parked chunk in {file}: {failure}; fix or remove the file")
|
||||
if chunk.issue != file.stem or not all(isinstance(value, str) for value in fields.values()):
|
||||
return Failure(f"cannot read the parked chunk in {file}: its fields are not those of {file.stem}'s chunk; fix or remove the file")
|
||||
found[chunk.issue] = chunk
|
||||
return found
|
||||
@@ -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.-]*")
|
||||
|
||||
|
||||
+68
-13
@@ -1,6 +1,6 @@
|
||||
"""Which of an epic's issues run as chunks now, each in its own window of the epic's tmux session (docs/decisions.md → `do-epic: drives one Jira epic …`).
|
||||
|
||||
Three limits hold a chunk back: the epic's cap of chunks at once, its repo's `parallel-chunks`, counted across every epic, and a loop-claude that runs chunks in its repo. do-epic checks a repo and starts a chunk in it while holding the lock loop-claude holds when it starts one (`chunk_windows.starting`), so the two never start chunks in one checkout together."""
|
||||
Three limits hold a chunk back: the epic's cap of chunks at once, its repo's `parallel-chunks`, counted across every epic, and a loop-claude that runs chunks in its repo. A parked chunk (`parked`) counts toward none of them: its window only polls the forge, and `resume` gives it a running slot under the same limits once its worker has something to do. do-epic checks a repo and starts a chunk in it while holding the lock loop-claude holds when it starts one (`chunk_windows.starting`), so the two never start chunks in one checkout together."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import typing
|
||||
@@ -11,6 +11,8 @@ from do_epic.backend.protocol import EpicIssue
|
||||
from failure import Failure
|
||||
from do_epic.repo_pick import HumanTask, recorded, Repo
|
||||
from project_config.settings import PARALLEL_CHUNKS
|
||||
from do_epic.parked import parked_chunks
|
||||
from chunk_pr.approval import PARKS
|
||||
from transcript_archive.project_key import project_key
|
||||
from do_epic.split import SPLIT_LABEL
|
||||
from agent_cycle import tmux
|
||||
@@ -38,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)
|
||||
@@ -106,25 +110,35 @@ 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: 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 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):
|
||||
return parked
|
||||
try:
|
||||
with starting(epic.folder):
|
||||
windows = tmux.listed(session, run)
|
||||
running = {window.name for window in windows if not window.dead} - {own}
|
||||
stopped = {window.name for window in windows if window.dead} - running
|
||||
live = {window.name: window for window in windows if not window.dead and window.name != own}
|
||||
running = {window.name for window in windows if not window.dead and not window.parked} - {own}
|
||||
stopped = {window.name for window in windows if window.dead} - set(live)
|
||||
# The windows this call started that take a running slot.
|
||||
taken = 0
|
||||
for chunk in found:
|
||||
if chunk.issue in running or chunk.issue == own:
|
||||
continue
|
||||
if own and chunk.issue in stopped:
|
||||
if chunk.issue in parked and chunk.issue in live:
|
||||
waits.append(Waits(chunk.issue, parked[chunk.issue].waits(live[chunk.issue].awaits)))
|
||||
elif own and (chunk.issue in stopped or chunk.issue in parked):
|
||||
waits.append(Waits(chunk.issue, f"its window stopped; run `do-epic {epic.key}` to start it again"))
|
||||
elif len(running) + len(started) >= epic.cap:
|
||||
elif chunk.issue not in parked and len(running) + taken >= epic.cap:
|
||||
waits.append(Waits(chunk.issue, f"the epic runs as many chunks as its `{CAP}` line allows: {epic.cap}"))
|
||||
else:
|
||||
now = start_chunk(epic, chunk, own, windows, run)
|
||||
now = start_chunk(epic, chunk if chunk.issue not in parked else Chunk(chunk.issue, None), own, windows, run)
|
||||
if isinstance(now, Failure):
|
||||
return now
|
||||
if isinstance(now, str):
|
||||
@@ -132,15 +146,18 @@ def start_chunks(epic: Epic, issues: list[EpicIssue], own: str | None, run: tmux
|
||||
else:
|
||||
windows = now
|
||||
started.append(chunk.issue)
|
||||
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:
|
||||
"""Starts chunk's window beside windows, the epic's session's, and returns the session's windows afterwards; the reason where its repo takes no chunk now, and a Failure where tmux started none. It holds the repo's lock from the check to the start. Raises OSError where that lock cannot be taken."""
|
||||
"""Starts chunk's window beside windows, the epic's session's, and returns the session's windows afterwards; the reason where its repo takes no chunk now, and a Failure where tmux started none. It holds the repo's lock from the check to the start. Raises OSError where that lock cannot be taken. A chunk without a repo starts in the epic's folder. So does a parked chunk, since it takes no room in its repo."""
|
||||
session = tmux.session_name(tmux.EPIC, epic.key)
|
||||
handed = {name: value for name, value in epic.env.items() if name.startswith(HANDED)}
|
||||
handed = {**{name: value for name, value in epic.env.items() if name.startswith(HANDED)}, PARKS: "1"}
|
||||
command = [str(epic.launcher), CHUNK_FLAG, chunk.issue, epic.key]
|
||||
if chunk.repo is None:
|
||||
return tmux.start_chunk(tmux.Window(session, chunk.issue, ""), str(epic.folder), handed, command, windows, False, run)
|
||||
@@ -155,8 +172,46 @@ def start_chunk(epic: Epic, chunk: Chunk, own: str | None, windows: list[tmux.Li
|
||||
|
||||
|
||||
def room_in(checkout: str, limit: int, leaving: tuple[str, str | None], home: pathlib.Path, run: tmux.Tmux) -> RepoRoom:
|
||||
"""The room in a repo's checkout under its limit. leaving is the session and name of a window whose chunk finished, which no longer counts."""
|
||||
"""The room in a repo's checkout under its limit. leaving is the session and name of the window that asks, which doesn't count: its chunk finished or is parked."""
|
||||
theirs = [placed for placed in epic_chunks(checkout, run) if (placed.session, placed.window.name) != leaving]
|
||||
loop_session = tmux.session_name(tmux.LOOP, project_key(checkout, home))
|
||||
loops = any(not window.dead for window in tmux.listed(loop_session, run)) and tmux.owner(loop_session, run) == checkout
|
||||
return RepoRoom(limit, len(theirs), loops)
|
||||
|
||||
|
||||
def resume(epic: Epic, repo: str, window: tmux.Window, run: tmux.Tmux) -> str | None:
|
||||
"""Takes a running slot for the parked chunk in window, whose worker has something to do again in the repo called repo: None once the window counts as a running chunk, else why the chunk still waits. The limits are those a starting chunk meets, checked under the same locks. The window itself never counts against them: one started again for a parked chunk, as after a reboot, isn't named as parked until its first read of the gate."""
|
||||
try:
|
||||
with starting(epic.folder):
|
||||
running = [listed for listed in tmux.listed(window.session, run) if not listed.dead and not listed.parked and listed.name != window.name]
|
||||
if len(running) >= epic.cap:
|
||||
return f"the epic runs as many chunks as its `{CAP}` line allows: {epic.cap}"
|
||||
located = epic.locate(repo)
|
||||
if isinstance(located, Failure):
|
||||
return located.reason
|
||||
checkout, limit = located
|
||||
with starting(project_lock(str(checkout), epic.home)):
|
||||
if reason := refusal(repo, room_in(str(checkout), limit, (window.session, window.name), epic.home, run)):
|
||||
return reason
|
||||
tmux.unpark(window, str(checkout), run)
|
||||
return None
|
||||
except OSError as failure:
|
||||
return f"cannot lock {failure.filename or epic.folder / LOCK}: {failure.strerror}"
|
||||
|
||||
|
||||
def status(key: str, home: pathlib.Path, issues: list[EpicIssue], run: tmux.Tmux) -> list[str] | Failure:
|
||||
"""A line per open issue of the epic called key, in the tracker's rank order: that its chunk runs, or why it waits. It doesn't start anything and checks no limit, so the line of a chunk that has yet to start doesn't say which limit holds it back."""
|
||||
found, waits = chunks(issues)
|
||||
parked = parked_chunks(home / STATE / key)
|
||||
if isinstance(parked, Failure):
|
||||
return parked
|
||||
windows = tmux.listed(tmux.session_name(tmux.EPIC, key), run)
|
||||
live = {window.name: window for window in windows if not window.dead}
|
||||
again = f"run `do-epic {key}` to start it again"
|
||||
reasons = {wait.issue: wait.reason for wait in waits}
|
||||
for chunk in found:
|
||||
if chunk.issue in parked:
|
||||
reasons[chunk.issue] = parked[chunk.issue].waits(live[chunk.issue].awaits) if chunk.issue in live else f"{parked[chunk.issue].waits('')}, and its window stopped; {again}"
|
||||
elif chunk.issue not in live:
|
||||
reasons[chunk.issue] = f"its window stopped; {again}" if chunk.issue in {window.name for window in windows} else f"it has not started; `do-epic {key}` starts it once the epic and its repo have room"
|
||||
return [f"{issue.key} waits: {reasons[issue.key]}" if issue.key in reasons else f"{issue.key} runs" for issue in issues if issue.key in reasons or issue.key in live]
|
||||
|
||||
@@ -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,15 +44,13 @@ 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_the_transition_that_finishes_an_issue_and_has_none_where_the_config_names_none(self) -> None:
|
||||
self.write()
|
||||
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.assertIsNone(found.finish_transition)
|
||||
self.write(SETTINGS + 'jira-finish-transition = "Close Issue"\n')
|
||||
found = load(self.home)
|
||||
assert isinstance(found, DoEpicConfig), found
|
||||
self.assertEqual(found.finish_transition, "Close Issue")
|
||||
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)
|
||||
@@ -90,7 +89,6 @@ class ConfigTest(unittest.TestCase):
|
||||
('env-file = "jira.env"', "env-file"),
|
||||
('clone-folder = "code"', "clone-folder"),
|
||||
('language = "sv_SE"', "language"),
|
||||
('jira-finish-transition = " "', "jira-finish-transition"),
|
||||
('repoless-model = "opus"', "repoless-model"),
|
||||
('repoless-model = "claude-opsu-5-5"', "repoless-model"),
|
||||
):
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import fcntl
|
||||
import io
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.test_main import DESCRIPTION, DoEpicTest
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from failure import Failure
|
||||
from loop_claude.test_loop_claude import FakeEffects
|
||||
from record_store.held import Held
|
||||
from do_epic import main
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from loop_state.paths import paths_from
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class WrittenDescription:
|
||||
"""Stands in for an epic's description in Jira that takes writes: kept holds each text it held, the last one now. It refuses a write that claims the human's approval, and notes in locked whether lock was held during each write."""
|
||||
kept: list[str]
|
||||
lock: pathlib.Path
|
||||
locked: list[bool] = dataclasses.field(default_factory=list)
|
||||
approved: frozenset[str] | None = frozenset()
|
||||
|
||||
@property
|
||||
def text(self) -> str:
|
||||
return self.kept[-1]
|
||||
|
||||
def read(self) -> str | Failure:
|
||||
return self.text
|
||||
|
||||
def held(self) -> Held | Failure:
|
||||
return Held(self.text)
|
||||
|
||||
def write(self, text: str, version: str | None) -> Held | Failure:
|
||||
if self.approved != frozenset():
|
||||
return Failure(f"approved is {self.approved!r}")
|
||||
with open(self.lock, "a") as other:
|
||||
try:
|
||||
fcntl.flock(other, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
self.locked.append(False)
|
||||
except BlockingIOError:
|
||||
self.locked.append(True)
|
||||
self.kept.append(text)
|
||||
return Held(text)
|
||||
|
||||
|
||||
class FindingsTest(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.store = MemoryEpic("ABC-12", list(self.issues))
|
||||
self.written = WrittenDescription([DESCRIPTION], self.home / ".local/state/do-epic/ABC-12/decisions.lock")
|
||||
self.keys: list[str] = []
|
||||
|
||||
def backend(self, config: object, key: str) -> tuple[MemoryEpic, EpicRecord]:
|
||||
self.keys.append(key)
|
||||
return self.store, EpicRecord(self.written) # type: ignore[arg-type]
|
||||
|
||||
def run_with(self, argv: list[str], stdin: str = "") -> tuple[int, str, str, FakeEffects]:
|
||||
out, err, fake = io.StringIO(), io.StringIO(), FakeEffects()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
code = main.main(argv, {}, paths_from(self.home), pathlib.Path("/b/do-epic"), fake.effects(), self.backend, io.StringIO(stdin))
|
||||
# Without the time each line of do-epic opens with.
|
||||
return code, out.getvalue().replace("<1790000000> ", ""), err.getvalue().replace("<1790000000> ", ""), fake
|
||||
|
||||
|
||||
class FilingAFinding(FindingsTest):
|
||||
def test_files_an_issue_under_the_epic_with_the_detail_piped_in_and_doesnt_start_anything(self) -> None:
|
||||
code, out, err, fake = self.run_with(["ABC-12", "--file", "Retry the import on a 503"], "The client times out.\n")
|
||||
self.assertEqual((code, out, err), (0, "Filed ABC-102 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", ""))
|
||||
self.assertEqual(self.keys, ["ABC-12"])
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((filed.key, filed.summary, filed.detail, filed.labels, filed.parent, filed.by_loop), ("ABC-102", "Retry the import on a 503", "The client times out.", (), "ABC-12", True))
|
||||
self.assertEqual(fake.calls, [], "filing needs no tmux, clone or claude")
|
||||
|
||||
def test_a_label_says_where_the_issue_is_worked(self) -> None:
|
||||
for argv, label in ((["ABC-12", "--file", "Retry", "--label", "repo:api"], "repo:api"), (["ABC-12", "--file", "--label", "do-epic-claude", "Retry"], "do-epic-claude"), (["ABC-12", "--file", "Retry", "--label", "do-epic-human"], "do-epic-human")):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, _, _ = self.run_with(argv)
|
||||
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):
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--file", "Retry", "--label", label])
|
||||
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"])
|
||||
self.assertEqual((code, err), (1, "cannot file the finding in the epic ABC-12: Jira answered 401\n"))
|
||||
|
||||
def test_stops_where_the_machines_settings_cannot_be_read(self) -> None:
|
||||
(self.home / ".claude-projects/do-epic/config.toml").unlink()
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--file", "Retry"])
|
||||
self.assertEqual((code, out, len(self.store.issues)), (1, "", 2))
|
||||
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"]):
|
||||
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))
|
||||
|
||||
|
||||
class RecordingADecision(FindingsTest):
|
||||
def test_appends_the_entry_to_the_descriptions_decisions(self) -> None:
|
||||
code, out, err, fake = self.run_with(["ABC-12", "--record-decision", "Imports retry three times"], "2026-11-18, the human's answer. Valid while the client's API rate-limits.\n")
|
||||
self.assertEqual((code, out, err, fake.calls), (0, "Recorded the decision in the epic ABC-12's description.\n", "", []))
|
||||
self.assertEqual(self.written.text, DESCRIPTION + "\n## Decisions\n\n### Imports retry three times\n\n2026-11-18, the human's answer. Valid while the client's API rate-limits.\n")
|
||||
self.assertEqual(self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.")[0], 0)
|
||||
self.assertTrue(self.written.text.endswith("rate-limits.\n\n### Merges squash\n\nAlways.\n"), self.written.text)
|
||||
self.assertIn("## Goals\nShip the import.\n\n## Audience\nThe client's team.\n", self.written.text)
|
||||
self.assertEqual((self.keys, self.written.locked), (["ABC-12", "ABC-12"], [True, True]))
|
||||
|
||||
def test_recording_a_decision_twice_keeps_one(self) -> None:
|
||||
self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.\n\n```\n### not a title\n```\n")
|
||||
self.run_with(["ABC-12", "--record-decision", "Imports retry"], "Three times.")
|
||||
held = self.written.text
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--record-decision", " Merges squash "], "Always.\n\n```\n### not a title\n```")
|
||||
self.assertEqual((code, out, err, self.written.text), (0, "The epic ABC-12's description already holds that decision.\n", "", held))
|
||||
self.assertEqual(len(self.written.kept), 3)
|
||||
|
||||
def test_refuses_another_decision_under_a_title_the_description_holds(self) -> None:
|
||||
self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.")
|
||||
held = self.written.text
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always")
|
||||
self.assertEqual((code, out, self.written.text), (1, "", held))
|
||||
self.assertEqual(err, "cannot record the decision in the epic ABC-12's description: ## Decisions already holds another decision titled 'Merges squash': give this one a title of its own\n")
|
||||
|
||||
def test_says_why_the_lock_was_not_taken(self) -> None:
|
||||
self.written.lock.parent.parent.mkdir(parents=True)
|
||||
self.written.lock.parent.write_text("")
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.")
|
||||
self.assertEqual((code, out, self.written.text), (1, "", DESCRIPTION))
|
||||
self.assertRegex(err, f"^cannot record the decision in the epic ABC-12's description: cannot lock {self.written.lock.parent}: \\w")
|
||||
|
||||
def test_refuses_a_decision_without_a_title_or_a_body(self) -> None:
|
||||
for argv, stdin, reason in ((["ABC-12", "--record-decision", "Merges squash"], " \n", "pipe the decision's text in"), (["ABC-12", "--record-decision", "two\nlines"], "Always.", "the title must be one line of text"), (["ABC-12", "--record-decision", " "], "Always.", "the title must be one line of text"), (["ABC-12", "--record-decision", "Merges squash"], "## Goals\nNone.", "the body of ## Decisions holds a level 1 or 2 heading, which would start another section")):
|
||||
with self.subTest(argv=argv, stdin=stdin):
|
||||
code, out, err, _ = self.run_with(argv, stdin)
|
||||
self.assertEqual((code, out, err, self.written.text), (1, "", f"cannot record the decision in the epic ABC-12's description: {reason}\n", DESCRIPTION))
|
||||
|
||||
def test_prints_the_help_for_a_decision_spelt_wrong(self) -> None:
|
||||
for argv in (["ABC-12", "--record-decision"], ["ABC-12", "--record-decision", "a", "b"], ["ABC-12", "--decide", "a"]):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, err, _ = self.run_with(argv, "Always.")
|
||||
self.assertEqual((code, out, err, self.written.text), (1, "", main.HELP + "\n", DESCRIPTION))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import unittest
|
||||
unittest.main()
|
||||
@@ -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"], [])
|
||||
@@ -0,0 +1,148 @@
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.gates import APPROVAL, CHECKS, gate, Gate, NEW_REVIEW, Open
|
||||
from failure import Failure
|
||||
|
||||
WORKTREES = "worktree /code/billing\nHEAD aaa\nbranch refs/heads/main\n\nworktree /code/billing-ABC-21\nHEAD abc\nbranch refs/heads/ABC-21\n"
|
||||
HEAD = "abc" * 4
|
||||
|
||||
|
||||
def thread(resolved: bool, last: str, path: str = "a.py") -> dict:
|
||||
return {"isResolved": resolved, "path": path, "comments": {"nodes": [{"author": {"login": last}}]}}
|
||||
|
||||
|
||||
def review(state: str, at: str, by: str = "reviewer", on: str = HEAD) -> dict:
|
||||
"""A review as `gh pr view --json reviews` prints it: made by `by` at `at`, on the commit `on`."""
|
||||
return {"author": {"login": by}, "state": state, "submittedAt": at, "commit": {"oid": on}}
|
||||
|
||||
|
||||
def comment(by: str, at: str) -> dict:
|
||||
return {"author": {"login": by}, "createdAt": at}
|
||||
|
||||
|
||||
class Forge:
|
||||
"""Stands in for git and the forge's CLI in the checkout and the chunk's worktree; `ran` holds each folder a command ran in. Only the CLI of origin's forge answers: `gh` fails on a Gitea origin, and `tea` on a GitHub one."""
|
||||
|
||||
def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x") -> None:
|
||||
self.cli = "gh" if "github.com" in origin else "tea"
|
||||
self.ran: list[str] = []
|
||||
self.commands: list[list[str]] = []
|
||||
self.fails = fails
|
||||
self.answers = {
|
||||
"git worktree": worktrees,
|
||||
"git remote": origin + "\n",
|
||||
"git rev-parse": HEAD + "\n",
|
||||
"git symbolic-ref": "origin/main\n",
|
||||
"gh pr list": pulls,
|
||||
"gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments)}),
|
||||
"gh pr checks": json.dumps([{"bucket": bucket} for bucket in buckets]),
|
||||
"gh api graphql": json.dumps({"data": {"repository": {"pullRequest": {"author": {"login": "worker"}, "reviewThreads": {"nodes": list(threads)}}}}}),
|
||||
"tea api repos/{owner}/{repo}/pulls?state=open&limit=50": json.dumps([{"number": 7, "merged": False, "head": {"label": "ABC-21", "sha": HEAD, "repo": {"full_name": "o/billing"}}, "base": {"repo": {"full_name": "o/billing"}}}]),
|
||||
"tea api repos/{owner}/{repo}/pulls/7": json.dumps({"number": 7, "title": title}),
|
||||
"tea api repos/{owner}/{repo}/branches/main": '{"name": "main"}',
|
||||
"tea api repos/{owner}/{repo}/commits/" + HEAD + "/status": status,
|
||||
}
|
||||
|
||||
def at(self, folder: str):
|
||||
def run(command: list[str]) -> str | Failure:
|
||||
self.ran.append(folder)
|
||||
self.commands.append(command)
|
||||
if command[0] in ("gh", "tea") and command[0] != self.cli:
|
||||
return Failure(f"{command[0]} cannot read this origin")
|
||||
key = " ".join(command) if command[0] == "tea" else " ".join(command[:3] if command[0] == "gh" else command[:2])
|
||||
return Failure(f"{key} failed") if self.fails and key.startswith(self.fails) else self.answers[key]
|
||||
return run
|
||||
|
||||
def gate(self) -> Gate | Open | Failure:
|
||||
return gate("ABC-21", "/code/billing", self.at)
|
||||
|
||||
|
||||
class GateOfAChunk(unittest.TestCase):
|
||||
def test_a_pull_request_whose_checks_passed_awaits_the_approval_its_protection_requires(self):
|
||||
forge = Forge()
|
||||
self.assertEqual(forge.gate(), Gate("/code/billing-ABC-21", "7", APPROVAL))
|
||||
self.assertEqual((forge.ran[0], set(forge.ran[1:])), ("/code/billing", {"/code/billing-ABC-21"}))
|
||||
self.assertEqual(forge.commands[:4], [["git", "worktree", "list", "--porcelain"], ["git", "remote", "get-url", "origin"], ["git", "rev-parse", "HEAD"], ["git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD"]])
|
||||
self.assertIn(["gh", "pr", "view", "7", "--json", "isDraft,reviewDecision,author,reviews,comments"], forge.commands)
|
||||
self.assertIn(["gh", "pr", "checks", "7", "--json", "bucket"], forge.commands)
|
||||
self.assertTrue(any(command[:3] == ["gh", "api", "graphql"] and "number=7" in command for command in forge.commands), forge.commands)
|
||||
|
||||
def test_a_review_decision_gh_prints_in_no_known_shape_is_a_failure(self):
|
||||
forge = Forge()
|
||||
forge.answers["gh pr view"] = "[1]"
|
||||
self.assertEqual(forge.gate(), Failure("gh pr view printed no review decision: [1]"))
|
||||
|
||||
def test_a_pull_request_awaits_its_checks_while_one_runs_whatever_its_reviews_say(self):
|
||||
for decision in ("REVIEW_REQUIRED", "APPROVED", "CHANGES_REQUESTED", ""):
|
||||
with self.subTest(decision=decision):
|
||||
self.assertEqual(Forge(decision=decision, buckets=("pass", "pending")).gate(), Gate("/code/billing-ABC-21", "7", CHECKS))
|
||||
|
||||
def test_a_gitea_pull_request_awaits_only_its_checks(self):
|
||||
gitea = "https://gitea.larvit.se/o/billing.git"
|
||||
self.assertEqual(Forge(gitea, status='{"state": "pending", "total_count": 1}').gate(), Gate("/code/billing-ABC-21", "7", CHECKS))
|
||||
self.assertEqual(Forge(gitea).gate(), Open("pull request #7 passed its checks"))
|
||||
|
||||
def test_a_gitea_draft_awaits_nothing_though_its_checks_run(self):
|
||||
gitea = "https://gitea.larvit.se/o/billing.git"
|
||||
for title in ("WIP: Add x", "[wip] Add x"):
|
||||
with self.subTest(title=title):
|
||||
self.assertEqual(Forge(gitea, title=title, status='{"state": "pending", "total_count": 1}').gate(), Open("pull request #7 is a draft"))
|
||||
self.assertEqual(Forge(gitea, title="Add WIP: x", status='{"state": "pending", "total_count": 1}').gate(), Gate("/code/billing-ABC-21", "7", CHECKS))
|
||||
unread = Forge(gitea)
|
||||
unread.answers["tea api repos/{owner}/{repo}/pulls/7"] = "[1]"
|
||||
self.assertEqual(unread.gate(), Failure("tea api printed no title of pull request 7: [1]"))
|
||||
|
||||
def test_requested_changes_are_news_until_the_worker_pushed_or_replied_and_then_await_a_new_review(self):
|
||||
asked = review("CHANGES_REQUESTED", "2026-11-18T10:00:00Z")
|
||||
before, after, old = "2026-11-18T09:00:00Z", "2026-11-18T11:00:00Z", "fed" * 4
|
||||
news, waits = Open("a reviewer requested changes on pull request #7"), Gate("/code/billing-ABC-21", "7", NEW_REVIEW)
|
||||
cases = {
|
||||
"nobody answered": ((asked,), (), news),
|
||||
"the worker pushed": ((review("CHANGES_REQUESTED", "2026-11-18T10:00:00Z", on=old),), (), waits),
|
||||
"the worker replied in a thread": ((asked, review("COMMENTED", after, by="worker")), (), waits),
|
||||
"the worker commented": ((asked,), (comment("worker", after),), waits),
|
||||
"the worker spoke only before": ((review("COMMENTED", before, by="worker"), asked, review("PENDING", None, by="worker")), (comment("worker", before),), news), # type: ignore[arg-type]
|
||||
"only a reviewer spoke after": ((asked, review("COMMENTED", after)), (comment("reviewer", after),), news),
|
||||
"a reviewer asked again on the new head": ((asked, review("CHANGES_REQUESTED", before, on=old), review("COMMENTED", "2026-11-18T09:30:00Z", by="worker")), (), news),
|
||||
"GitHub lists no such review": ((review("APPROVED", before, on=old),), (comment("worker", after),), news),
|
||||
}
|
||||
for case, (reviews, comments, found) in cases.items():
|
||||
with self.subTest(case=case):
|
||||
self.assertEqual(Forge(decision="CHANGES_REQUESTED", reviews=reviews, comments=comments).gate(), found)
|
||||
self.assertEqual(NEW_REVIEW, "a new review")
|
||||
|
||||
def test_a_reviewers_unanswered_comment_is_news_though_the_worker_answered_the_requested_changes(self):
|
||||
forge = Forge(decision="CHANGES_REQUESTED", reviews=(review("CHANGES_REQUESTED", "2026-11-18T10:00:00Z", on="fed" * 4),), threads=(thread(False, "reviewer"),))
|
||||
self.assertEqual(forge.gate(), Open("a reviewer's comment on pull request #7 waits for an answer, in a.py"))
|
||||
|
||||
def test_the_worker_goes_on_where_nothing_but_the_worker_moves_the_pull_request(self):
|
||||
cases = {
|
||||
"pull request #7 passed its checks and is approved": Forge(decision="APPROVED"),
|
||||
"pull request #7 passed its checks": Forge(decision=""),
|
||||
"pull request #7 is a draft": Forge(draft=True, buckets=("pending",)),
|
||||
"a check on pull request 7 failed; fix it and push": Forge(buckets=("fail",)),
|
||||
"a reviewer requested changes on pull request #7": Forge(decision="CHANGES_REQUESTED"),
|
||||
"a reviewer's comment on pull request #7 waits for an answer, in a.py, b.py": Forge(threads=(thread(False, "reviewer", "b.py"), thread(False, "reviewer"), thread(True, "reviewer", "c.py"), thread(False, "worker", "d.py"))),
|
||||
"no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already": Forge(pulls=""),
|
||||
"no worktree of /code/billing has the branch ABC-21 checked out": Forge(worktrees="worktree /code/billing\nHEAD aaa\nbranch refs/heads/main\n"),
|
||||
}
|
||||
for news, forge in cases.items():
|
||||
with self.subTest(news=news):
|
||||
self.assertEqual(forge.gate(), Open(news))
|
||||
|
||||
def test_a_read_that_fails_is_a_failure_and_says_nothing_of_the_gate(self):
|
||||
for command in ("git worktree", "git remote", "gh pr list", "gh pr view", "gh pr checks", "gh api graphql"):
|
||||
with self.subTest(command=command):
|
||||
self.assertEqual(Forge(fails=command).gate(), Failure(f"{command} failed"))
|
||||
for endpoint in ("pulls?state=open&limit=50", "pulls/7", "branches/main"):
|
||||
with self.subTest(endpoint=endpoint):
|
||||
self.assertEqual(Forge("https://gitea.larvit.se/o/billing.git", fails=f"tea api repos/{{owner}}/{{repo}}/{endpoint}").gate(), Failure(f"tea api repos/{{owner}}/{{repo}}/{endpoint} failed"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+246
-25
@@ -14,16 +14,18 @@ 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
|
||||
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
|
||||
from failure import Failure
|
||||
from loop_claude.test_loop_claude import FakeEffects, judged, Worker
|
||||
from do_epic.test_gates import Forge
|
||||
from do_epic.test_scheduler import issue
|
||||
from loop_claude.loop.this_loop import Loop
|
||||
from loop_claude.loop.reload import LoopRun
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from do_epic import parked
|
||||
from loop_state.paths import paths_from
|
||||
from model_routing.route import Route
|
||||
from model_routing.ladder import Rung
|
||||
@@ -52,22 +54,43 @@ class DoEpicTest(unittest.TestCase):
|
||||
(folder / "repo-rule.md").write_text("A label that equals a repo's name names that repo.\n", encoding="utf-8")
|
||||
self.issues = [issue("ABC-20"), dataclasses.replace(issue("ABC-21", "do-epic-claude"), detail="Tidy the docs.", scores={"L": 3, "E": 2, "I": 3})]
|
||||
self.description: str | Failure = DESCRIPTION
|
||||
# What the forge answers each read of a chunk's gate, in turn; the last answers every later read. No worktree has the chunk's branch, so no chunk parks.
|
||||
self.forges = [Forge(worktrees="worktree /code/api\nbranch refs/heads/main\n")]
|
||||
self.gate_reads = 0
|
||||
|
||||
def forge_at(self, folder: str):
|
||||
def run(command: list[str]) -> str | Failure:
|
||||
# A read of a gate opens with the checkout's worktrees.
|
||||
self.gate_reads += command[:2] == ["git", "worktree"]
|
||||
return self.forges[min(self.gate_reads, len(self.forges)) - 1].at(folder)(command)
|
||||
return run
|
||||
|
||||
def backend(self, config: object, key: str) -> tuple[MemoryEpic, EpicRecord]:
|
||||
return MemoryEpic(key, list(self.issues)), EpicRecord(Description(self.description)) # type: ignore[arg-type]
|
||||
|
||||
def worker(self) -> Worker:
|
||||
return Worker(paths_from(self.home).claude_code_transcripts.parent)
|
||||
|
||||
def repo_chunk(self) -> pathlib.Path:
|
||||
"""Makes ABC-20 the one issue, a chunk in the repo api whose checkout holds its premises; the folder of the repo's config."""
|
||||
checkout = self.home / "code" / "api"
|
||||
folder = configured(self, checkout, home=self.home)
|
||||
(checkout / "README.md").write_text("## Goals\nServe the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
|
||||
self.issues = [issue("ABC-20", "repo:api")]
|
||||
return folder
|
||||
|
||||
def run_main(self, argv: list[str], fake: FakeEffects, env: dict[str, str] | None = None) -> tuple[int, str, str]:
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
code = main.main(argv, env or {}, paths_from(self.home), pathlib.Path("/b/do-epic"), fake.effects(), self.backend)
|
||||
code = main.main(argv, env or {}, paths_from(self.home), pathlib.Path("/b/do-epic"), fake.effects(), self.backend, forge_at=self.forge_at)
|
||||
return code, out.getvalue(), err.getvalue()
|
||||
|
||||
|
||||
class TheJiraBackend(unittest.TestCase):
|
||||
def test_reads_the_epic_with_the_credentials_and_the_finish_transition_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", "Close Issue")
|
||||
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_by), (Epic("https://acme.atlassian.net", "ABC-12"), pathlib.Path("/h/jira.env"), "Close Issue")) # type: ignore[attr-defined]
|
||||
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]
|
||||
|
||||
|
||||
@@ -99,7 +122,7 @@ class TheCommand(DoEpicTest):
|
||||
self.assertIn("started ABC-21 in the tmux session epic-ABC-12\n", out)
|
||||
self.assertIn("ABC-20 waits: no label names its repo\n", out)
|
||||
started = [args for args in fake.tmux_calls if args[0] == "new-session"]
|
||||
self.assertEqual(started, [["new-session", "-d", "-s", "epic-ABC-12", "-n", "ABC-21", "-c", str(self.home / ".local/state/do-epic/ABC-12"), "-e", "LOOP_CLAUDE_WORKER_MODEL=m", "-P", "-F", "#{window_id}", "--", "/b/do-epic", "--chunk", "ABC-21", "ABC-12"]])
|
||||
self.assertEqual(started, [["new-session", "-d", "-s", "epic-ABC-12", "-n", "ABC-21", "-c", str(self.home / ".local/state/do-epic/ABC-12"), "-e", "LOOP_CLAUDE_WORKER_MODEL=m", "-e", "CHUNK_PR_PARKS=1", "-P", "-F", "#{window_id}", "--", "/b/do-epic", "--chunk", "ABC-21", "ABC-12"]])
|
||||
# The session is no checkout's, so nothing marks it as one's.
|
||||
self.assertNotIn(tmux.OWNER, [args[3] for args in fake.tmux_calls if args[0] == "set-option"])
|
||||
|
||||
@@ -130,12 +153,12 @@ 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, in_repo = place
|
||||
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())
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
found = main.next_cycle(LoopRun(1, root, "", "", chunk="ABC-21"), loop, in_repo, epic)
|
||||
found = main.next_cycle(LoopRun(1, root, "", "", chunk="ABC-21"), loop, repo is not None, epic)
|
||||
assert isinstance(found, main.Cycle), found
|
||||
return found
|
||||
|
||||
@@ -152,11 +175,27 @@ class ACycleOfAChunkWithoutARepo(DoEpicTest):
|
||||
cycle = self.cycle()
|
||||
self.assertEqual((cycle.root, cycle.project_archive, cycle.records), (str(self.home / ".local/state/do-epic/ABC-12"), self.home / ".claude/do-epic-transcripts/ABC-12", ""))
|
||||
|
||||
def test_the_records_are_the_epics_scoring_and_decisions_then_the_humans_rules(self) -> None:
|
||||
self.description = DESCRIPTION + "\n## Scoring\nE + I, bar 4.\n\n## Decisions\n### Merges squash\nAlways.\n"
|
||||
(self.home / ".claude").mkdir()
|
||||
(self.home / ".claude/CLAUDE.md").write_text("# Global\n", encoding="utf-8")
|
||||
self.assertEqual(self.cycle().records, "From the epic ABC-12's description, ## Scoring:\nE + I, bar 4.\n\nFrom the epic ABC-12's description, ## Decisions:\n### Merges squash\nAlways.\n\nFrom ~/.claude/CLAUDE.md:\n# Global")
|
||||
|
||||
def test_stops_where_a_section_of_the_epics_records_cannot_be_read(self) -> None:
|
||||
self.description = DESCRIPTION + "\n## Scoring\nA.\n\n## Scoring\nB.\n"
|
||||
with self.assertRaises(AssertionError) as raised:
|
||||
self.cycle()
|
||||
self.assertIn("the epic ABC-12's description: the epic's description has ## Scoring more than once - the judge cannot read the records.", str(raised.exception))
|
||||
|
||||
def test_the_premises_are_the_epics_goals_and_audience(self) -> None:
|
||||
self.assertEqual(self.cycle().premises, "the epic ABC-12's description:\n## Goals\nShip the import.\n\n## Audience\nThe client's team.")
|
||||
|
||||
def test_the_task_is_the_issue(self) -> None:
|
||||
self.assertEqual(self.cycle().task, "Work the Jira issue ABC-21 of the epic ABC-12 as one chunk, which changes no repo: work in the folder you start in. Its summary: Do ABC-21\n\nIts description:\n\nTidy the docs.")
|
||||
task = self.cycle().task
|
||||
self.assertTrue(task.startswith("Work the Jira issue ABC-21 of the epic ABC-12 as one chunk, which changes no repo: work in the folder you start in. File a finding"), task)
|
||||
self.assertIn('with `/b/do-epic ABC-12 --file "<summary>" --label <label>` and its detail on stdin', task)
|
||||
self.assertIn("Write the issue and the decision in English, the epic's language.", task)
|
||||
self.assertTrue(task.endswith(" Its summary: Do ABC-21\n\nIts description:\n\nTidy the docs."), task)
|
||||
|
||||
def test_an_issue_without_scores_runs_on_the_projects_rung(self) -> None:
|
||||
self.issues[1] = dataclasses.replace(self.issues[1], scores={})
|
||||
@@ -255,8 +294,6 @@ class TheHumansRun(DoEpicTest):
|
||||
|
||||
|
||||
class AChunksRun(DoEpicTest):
|
||||
def worker(self) -> Worker:
|
||||
return Worker(paths_from(self.home).claude_code_transcripts.parent)
|
||||
|
||||
def test_runs_cycles_until_the_judge_rules_it_finished_then_starts_the_next_chunk(self) -> None:
|
||||
self.issues.append(issue("ABC-22", "do-epic-claude"))
|
||||
@@ -343,8 +380,8 @@ class AChunksRun(DoEpicTest):
|
||||
def test_a_split_item_that_jira_will_not_move_to_done_stops_with_the_reason(self) -> None:
|
||||
parent = issue("ABC-21", "split-by-repo")
|
||||
store = MemoryEpic("ABC-12", [self.issues[0], parent, issue("ABC-23", "do-epic-claude", parent="ABC-21")])
|
||||
finish = store.finish
|
||||
store.finish = lambda key: Failure("no way to done") if key == "ABC-21" else finish(key) # type: ignore[method-assign]
|
||||
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)
|
||||
@@ -354,7 +391,7 @@ class AChunksRun(DoEpicTest):
|
||||
|
||||
def test_a_chunk_whose_issue_jira_will_not_move_to_done_stops_with_the_reason_and_starts_no_other(self) -> None:
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
store.finish = lambda key: Failure("ABC-21's status has no transition to a done status") # type: ignore[method-assign]
|
||||
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)
|
||||
@@ -378,24 +415,25 @@ class AChunksRun(DoEpicTest):
|
||||
(checkout / "README.md").write_text("## Goals\nServe the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
|
||||
(checkout / "AGENTS.md").write_text("Squash every merge.\n", encoding="utf-8")
|
||||
self.issues = [dataclasses.replace(issue("ABC-20", "repo:api"), scores={"L": 2, "E": 1, "I": 1})]
|
||||
self.description = DESCRIPTION + "\n## Decisions\nKeep the v1 endpoints.\n"
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
prompt = " ".join([what for seam, what in fake.calls if seam == "stream_claude"][0])
|
||||
self.assertIn(f"Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout {checkout}, on the branch ABC-20.", prompt)
|
||||
self.assertIn(f"Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout {checkout}, on the branch ABC-20. File a finding", prompt)
|
||||
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("Squash every merge.", [what[1] for seam, what in fake.calls if seam == "claude"][0])
|
||||
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)
|
||||
|
||||
def repo_chunk(self) -> pathlib.Path:
|
||||
"""Makes ABC-20 the one issue, a chunk in the repo api whose checkout holds its premises; the folder of the repo's config."""
|
||||
checkout = self.home / "code" / "api"
|
||||
folder = configured(self, checkout, home=self.home)
|
||||
(checkout / "README.md").write_text("## Goals\nServe the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
|
||||
self.issues = [issue("ABC-20", "repo:api")]
|
||||
return folder
|
||||
def test_a_chunk_without_a_repo_reads_no_forge(self) -> None:
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
self.assertEqual(self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)[0], 0)
|
||||
self.assertEqual(self.gate_reads, 0)
|
||||
self.assertTrue(next(what[what.index("-p") + 1] for seam, what in fake.calls if seam == "stream_claude").startswith("Work the Jira issue ABC-21 "))
|
||||
|
||||
def test_a_chunk_in_a_repo_routes_on_the_repos_model(self) -> None:
|
||||
folder = self.repo_chunk()
|
||||
@@ -500,5 +538,188 @@ class WhatAWorkerJudgeAndHumanRead(DoEpicTest):
|
||||
self.assertEqual(escalation_mark.asks_higher_rung(chunk_prompt.DRIVER), "asking do-epic for a higher rung")
|
||||
|
||||
|
||||
WORKTREE = "worktree /code/api\nbranch refs/heads/main\n\nworktree /code/api-ABC-20\nbranch refs/heads/ABC-20\n"
|
||||
PARKED_WINDOW = "ABC-20 awaits an approval\t0\t@9\n"
|
||||
|
||||
|
||||
def awaiting(**answers: object) -> Forge:
|
||||
"""A forge where ABC-20's pull request, #7, passed its checks and still wants its review, but for answers."""
|
||||
return Forge(worktrees=WORKTREE, **answers) # type: ignore[arg-type]
|
||||
|
||||
|
||||
class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.repo_chunk()
|
||||
self.issues.append(issue("ABC-22", "do-epic-claude"))
|
||||
self.file = parked.file_of(self.home / ".local/state/do-epic/ABC-12", "ABC-20")
|
||||
self.session = main.session_named("A ABC-12 do-epic ABC-20", paths_from(self.home).claude_code_transcripts)
|
||||
|
||||
def parked_run(self, fake: FakeEffects) -> tuple[int, str, str, list[str]]:
|
||||
"""The chunk's run, as its exit code, what it printed, and each prompt its workers got."""
|
||||
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
|
||||
return code, out.replace("<1790000000> ", ""), err, [what[what.index("-p") + 1] for seam, what in fake.calls if seam == "stream_claude"]
|
||||
|
||||
def test_it_parks_frees_its_slot_and_works_again_once_approved(self) -> None:
|
||||
self.forges = [awaiting(), awaiting(), awaiting(decision="APPROVED")]
|
||||
fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
states: list[object] = []
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=lambda seconds: states.append((seconds, parked.parked_chunks(self.file.parent.parent)))) # type: ignore[method-assign]
|
||||
checkout = str(self.home / "code/api")
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual(states, [(60, {"ABC-20": parked.Parked("ABC-20", "/code/api-ABC-20", "7", str(self.session.id), "an approval")})] * 2)
|
||||
self.assertFalse(self.file.exists())
|
||||
self.assertIn("parked: pull request #7 awaits an approval\nstarted ABC-22\n", out)
|
||||
self.assertEqual(len(prompts), 2)
|
||||
self.assertTrue(prompts[0].startswith("Work the Jira issue ABC-20 "), prompts[0])
|
||||
self.assertEqual(set(self.forges[0].ran[:1] + self.forges[1].ran[:1]), {checkout})
|
||||
self.assertTrue(prompts[1].startswith(f"do-epic parked the chunk while its pull request awaited an approval. It resumes now: pull request #7 passed its checks and is approved. {chunk_prompt.FEEDBACK}\n\nWork the Jira issue ABC-20 "), prompts[1])
|
||||
self.assertIn("the chunk finished; ", out)
|
||||
shown = [args for args in fake.tmux_calls if args[0] == "rename-window" or tmux.ROOT in args and "%1" in args]
|
||||
self.assertEqual(shown, [["rename-window", "-t", "%1", "ABC-20 awaits an approval"], ["rename-window", "-t", "%1", "ABC-20"], ["set-option", "-w", "-t", "%1", tmux.ROOT, checkout]])
|
||||
|
||||
def test_an_unfinished_chunk_parks_too_and_a_reviewers_comment_resumes_it(self) -> None:
|
||||
self.forges = [awaiting(buckets=("pending",)), awaiting(), awaiting(threads=({"isResolved": False, "path": "a.py", "comments": {"nodes": [{"author": {"login": "reviewer"}}]}},))]
|
||||
fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("unfinished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW + "ABC-22\t1\t@10\n")
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("parked: pull request #7 awaits its checks\nstarted no other\nparked: pull request #7 awaits an approval\n", out)
|
||||
self.assertIn("its pull request awaited an approval. It resumes now: a reviewer's comment on pull request #7 waits for an answer, in a.py. Where a reviewer left feedback, fix what is reasonable", prompts[1])
|
||||
self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits its checks", "ABC-20 awaits an approval", "ABC-20"])
|
||||
|
||||
def test_a_chunk_parked_when_its_window_ended_polls_before_any_cycle_and_resumes_its_session(self) -> None:
|
||||
parked.park(self.file.parent.parent, parked.Parked("ABC-20", "/code/api-ABC-20", "7", str(self.session.id), "an approval"))
|
||||
self.worker()(["--session-id", str(self.session.id)])
|
||||
self.forges = [awaiting(fails="gh pr list"), awaiting(decision="CHANGES_REQUESTED")]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertNotIn("parked: ", out)
|
||||
self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval", "ABC-20"])
|
||||
self.assertEqual(len(prompts), 1)
|
||||
self.assertTrue(prompts[0].startswith("do-epic parked the chunk while its pull request awaited an approval. It resumes now: a reviewer requested changes on pull request #7. "), prompts[0])
|
||||
self.assertFalse(self.file.exists())
|
||||
|
||||
def test_a_chunk_with_work_again_stays_parked_until_a_slot_is_free(self) -> None:
|
||||
self.description = DESCRIPTION.replace("2", "1")
|
||||
self.forges = [awaiting(), awaiting(decision="APPROVED")]
|
||||
fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW + "ABC-22\t0\t@10\n")
|
||||
slept: list[bool] = []
|
||||
|
||||
def sleep(seconds: float) -> None:
|
||||
slept.append(self.file.exists())
|
||||
if len(slept) == 3:
|
||||
fake.windows = PARKED_WINDOW
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=sleep) # type: ignore[method-assign]
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual(slept, [True] * 3)
|
||||
self.assertEqual(out.count("pull request #7 passed its checks and is approved, but the chunk stays parked: the epic runs as many chunks as its `**Max parallel chunks:**` line allows: 1; trying again every 60 seconds\n"), 1)
|
||||
self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval", "ABC-20 awaits a slot", "ABC-20"])
|
||||
self.assertEqual(len(prompts), 2)
|
||||
|
||||
def test_a_chunk_parks_and_resumes_though_the_next_chunk_cannot_start(self) -> None:
|
||||
self.forges = [awaiting(), awaiting(decision="APPROVED")]
|
||||
worker = self.worker()
|
||||
|
||||
def unreadable_after(*args: object) -> object:
|
||||
self.description = Failure("Jira answered 503")
|
||||
return worker(*args) # type: ignore[arg-type]
|
||||
fake = FakeEffects(streams=[unreadable_after, self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
slept: list[bool] = []
|
||||
# The epic's description cannot be read from the first worker's run until the parked chunk first sleeps.
|
||||
description = Description("")
|
||||
object.__setattr__(description, "read", lambda: self.description)
|
||||
self.backend = lambda config, key: (MemoryEpic(key, list(self.issues)), EpicRecord(description)) # type: ignore[method-assign,arg-type]
|
||||
|
||||
def sleep(seconds: float) -> None:
|
||||
slept.append(self.file.exists())
|
||||
self.description = DESCRIPTION
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=sleep) # 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 503\n", out)
|
||||
self.assertEqual(slept, [True])
|
||||
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)
|
||||
code, out, err, _ = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("cannot tell whether the chunk's pull request waits on a gate, so the chunk isn't parked: gh pr checks failed\nthe chunk finished; ", out)
|
||||
self.assertFalse(self.file.exists())
|
||||
self.forges = [awaiting(), awaiting(fails="gh pr list"), awaiting(fails="gh pr list"), awaiting(decision="APPROVED")]
|
||||
self.gate_reads = 0
|
||||
fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertEqual(out.count("cannot read the gate: gh pr list failed; trying again every 60 seconds\n"), 1)
|
||||
self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval", "ABC-20"])
|
||||
self.assertEqual(len(prompts), 2)
|
||||
|
||||
def test_stops_where_the_chunk_cannot_be_recorded_as_parked_or_the_record_cannot_be_read(self) -> None:
|
||||
self.forges = [awaiting()]
|
||||
self.file.parent.parent.mkdir(parents=True)
|
||||
self.file.parent.write_text("a file")
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
code, _, err, _ = self.parked_run(fake)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn(f"cannot record the parked chunk in {self.file}: ", err)
|
||||
self.file.parent.unlink()
|
||||
parked.park(self.file.parent.parent, parked.Parked("ABC-20", "/w", "7", "s", "an approval"))
|
||||
self.file.write_text("{")
|
||||
code, _, err, prompts = self.parked_run(FakeEffects(git=UNREAD))
|
||||
self.assertEqual((code, prompts), (1, []))
|
||||
self.assertIn(f"cannot read the parked chunk in {self.file}: ", err)
|
||||
|
||||
def test_stops_where_the_chunk_cannot_be_recorded_as_parked_no_longer(self) -> None:
|
||||
self.forges = [awaiting(), awaiting(decision="APPROVED")]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=lambda seconds: self.file.parent.chmod(0o555)) # type: ignore[method-assign]
|
||||
self.addCleanup(lambda: self.file.parent.chmod(0o755))
|
||||
code, _, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual((code, len(prompts)), (1, 1))
|
||||
self.assertIn(f"cannot remove {self.file}: Permission denied", err)
|
||||
|
||||
|
||||
class TheStatus(DoEpicTest):
|
||||
def test_prints_what_each_open_issue_does_and_starts_nothing(self) -> None:
|
||||
self.issues = [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api"), issue("ABC-22", "repo:api"), issue("ABC-23", "repo:api", blockers=("ABC-20",)), issue("ABC-24", "repo:api"), issue("ABC-25", "repo:api", done=True), issue("ABC-26", "repo:api"), issue("ABC-27")]
|
||||
folder = self.home / ".local/state/do-epic/ABC-12"
|
||||
parked.park(folder, parked.Parked("ABC-20", "/code/api-ABC-20", "7", "s", "an approval"))
|
||||
parked.park(folder, parked.Parked("ABC-26", "/code/api-ABC-26", "9", "s", "its checks"))
|
||||
parked.park(folder, parked.Parked("ABC-28", "/code/api-ABC-28", "11", "s", "an approval"))
|
||||
self.issues.insert(7, issue("ABC-28", "repo:api"))
|
||||
fake = FakeEffects(windows="ABC-20 awaits an approval\t0\t@1\nABC-21 ?\t0\t@2\nABC-22\t1\t@3\nABC-28 awaits a slot\t0\t@4\n")
|
||||
code, out, err = self.run_main(["ABC-12", "--status"], fake)
|
||||
self.assertEqual((code, err), (0, ""))
|
||||
self.assertEqual(out.replace("<1790000000> ", "").splitlines(), [
|
||||
"ABC-20 waits: it is parked: its pull request #7 awaits an approval",
|
||||
"ABC-21 runs",
|
||||
"ABC-22 waits: its window stopped; run `do-epic ABC-12` to start it again",
|
||||
"ABC-23 waits: ABC-20 blocks it",
|
||||
"ABC-24 waits: it has not started; `do-epic ABC-12` starts it once the epic and its repo have room",
|
||||
"ABC-26 waits: it is parked: its pull request #9 awaits its checks, and its window stopped; run `do-epic ABC-12` to start it again",
|
||||
"ABC-28 waits: it is parked: its worker has work again on pull request #11 and awaits a slot",
|
||||
"ABC-27 waits: no label names its repo",
|
||||
])
|
||||
self.assertEqual({args[0] for args in fake.tmux_calls}, {"-V", "list-windows"})
|
||||
self.assertTrue(all("epic-ABC-12" in " ".join(args) for args in fake.tmux_calls if args[0] == "list-windows"), fake.tmux_calls)
|
||||
|
||||
def test_says_so_where_no_issue_is_open_or_the_epic_cannot_be_read(self) -> None:
|
||||
self.issues = [issue("ABC-20", "repo:api", done=True)]
|
||||
self.assertIn("the epic ABC-12 has no open issue\n", self.run_main(["ABC-12", "--status"], FakeEffects())[1])
|
||||
store = MemoryEpic("ABC-12", [])
|
||||
store.read = lambda: Failure("Jira answered 503") # type: ignore[method-assign]
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
code, _, err = self.run_main(["ABC-12", "--status"], FakeEffects())
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("Jira answered 503\n", err)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from failure import Failure
|
||||
from do_epic.parked import file_of, park, Parked, parked_chunks, unpark
|
||||
|
||||
CHUNK = Parked("ABC-21", "/code/billing-ABC-21", "7", "0c0f", "an approval")
|
||||
|
||||
|
||||
class ParkedChunks(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.folder = pathlib.Path(self.enterContext(tempfile.TemporaryDirectory()))
|
||||
|
||||
def test_an_epic_without_a_parked_chunk_has_none(self):
|
||||
self.assertEqual(parked_chunks(self.folder), {})
|
||||
|
||||
def test_a_parked_chunk_is_read_back_by_its_issue_until_it_is_unparked(self):
|
||||
self.assertIsNone(park(self.folder, CHUNK))
|
||||
self.assertEqual(parked_chunks(self.folder), {"ABC-21": CHUNK})
|
||||
self.assertIsNone(unpark(self.folder, "ABC-21"))
|
||||
self.assertEqual(parked_chunks(self.folder), {})
|
||||
|
||||
def test_parking_again_replaces_what_the_chunk_waits_on_and_leaves_no_partial_file(self):
|
||||
park(self.folder, CHUNK)
|
||||
park(self.folder, Parked("ABC-21", "/code/billing-ABC-21", "7", "0c0f", "its checks"))
|
||||
self.assertEqual(parked_chunks(self.folder)["ABC-21"].on, "its checks")
|
||||
self.assertEqual([file.name for file in (self.folder / "parked").iterdir()], ["ABC-21.json"])
|
||||
|
||||
def test_unparking_a_chunk_that_is_not_parked_does_nothing(self):
|
||||
self.assertIsNone(unpark(self.folder, "ABC-21"))
|
||||
|
||||
def test_says_why_the_human_sees_no_chunk_run(self):
|
||||
self.assertEqual(CHUNK.waits(""), "it is parked: its pull request #7 awaits an approval")
|
||||
self.assertEqual(CHUNK.waits("its checks"), "it is parked: its pull request #7 awaits its checks")
|
||||
self.assertEqual(CHUNK.waits("a slot"), "it is parked: its worker has work again on pull request #7 and awaits a slot")
|
||||
|
||||
def test_fails_naming_the_file_where_it_holds_no_parked_chunk_or_another_issues(self):
|
||||
park(self.folder, CHUNK)
|
||||
file = file_of(self.folder, "ABC-21")
|
||||
for text in ("{", '{"issue": "ABC-21"}', file.read_text().replace("ABC-21", "ABC-22"), file.read_text().replace('"7"', "7")):
|
||||
with self.subTest(text=text):
|
||||
file.write_text(text)
|
||||
failed = parked_chunks(self.folder)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn(f"cannot read the parked chunk in {file}: ", failed.reason)
|
||||
|
||||
def test_fails_naming_the_file_it_cannot_remove(self):
|
||||
park(self.folder, Parked("ABC-21", "/w", "7", "s", "an approval"))
|
||||
file_of(self.folder, "ABC-21").parent.chmod(0o555)
|
||||
self.addCleanup(file_of(self.folder, "ABC-21").parent.chmod, 0o755)
|
||||
self.assertEqual(unpark(self.folder, "ABC-21"), Failure(f"cannot remove {file_of(self.folder, 'ABC-21')}: Permission denied"))
|
||||
|
||||
def test_fails_where_the_folder_cannot_be_written(self):
|
||||
(self.folder / "parked").write_text("a file")
|
||||
self.assertIn(f"cannot record the parked chunk in {file_of(self.folder, 'ABC-21')}: ", park(self.folder, CHUNK).reason)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -6,10 +6,11 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.scheduler import Chunk, CHUNK_FLAG, chunks, Epic, refusal, RepoRoom, start_chunks, Started, Waits
|
||||
from do_epic.scheduler import Chunk, CHUNK_FLAG, chunks, Epic, refusal, RepoRoom, resume, start_chunks, Started, Waits
|
||||
from do_epic import chunk_prompt
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from failure import Failure
|
||||
from do_epic.parked import file_of, park, Parked
|
||||
from do_epic.epic_record import parallel_chunks_in
|
||||
from loop_claude.cycle import prompts
|
||||
from model_routing.route import Route
|
||||
@@ -102,6 +103,12 @@ class Tmux:
|
||||
session = args[args.index("-s") + 1] if args[0] == "new-session" else args[args.index("-t") + 1].removeprefix("=").removesuffix(":")
|
||||
self.windows.append((session, args[args.index("-n") + 1], False, args[args.index("-c") + 1]))
|
||||
out = f"@{len(self.windows) - 1}\n"
|
||||
elif args[0] == "rename-window":
|
||||
at = int(args[2].removeprefix("%"))
|
||||
self.windows[at] = (self.windows[at][0], args[3], *self.windows[at][2:])
|
||||
elif args[0] == "set-option" and tmux.ROOT in args:
|
||||
at = int(args[args.index("-t") + 1].removeprefix("%").removeprefix("@"))
|
||||
self.windows[at] = (*self.windows[at][:3], "" if "-u" in args else args[-1])
|
||||
elif args[0] == "kill-window":
|
||||
self.windows[int(args[2].removeprefix("@"))] = ("", "", True, "")
|
||||
return subprocess.CompletedProcess(args, 0, out, "")
|
||||
@@ -124,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
|
||||
|
||||
@@ -137,6 +144,90 @@ class StartingAnEpicsChunks(unittest.TestCase):
|
||||
self.assertIn("LOOP_CLAUDE_X=1", run.calls[[args[0] for args in run.calls].index("new-session")])
|
||||
self.assertNotIn("OTHER=2", run.calls[[args[0] for args in run.calls].index("new-session")])
|
||||
|
||||
def parked(self, issue_key: str, on: str = "an approval") -> None:
|
||||
self.assertIsNone(park(self.home / ".local/state/do-epic/ABC-12", Parked(issue_key, f"/code/api-{issue_key}", "7", "0c0f", on)))
|
||||
|
||||
def test_a_parked_chunk_waits_in_its_window_and_takes_no_slot_of_the_epic_or_its_repo(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 awaits an approval", False, ""))
|
||||
found = self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api"), issue("ABC-22", "repo:api", blockers=("ABC-20",))], run)
|
||||
self.assertEqual(found, Started(["ABC-21"], [Waits("ABC-20", "it is parked: its pull request #7 awaits an approval"), Waits("ABC-22", "ABC-20 blocks it")]))
|
||||
|
||||
def test_a_parked_chunk_whose_window_awaits_a_slot_says_so(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 awaits a slot", False, ""), ("epic-ABC-12", "ABC-21", False, str(self.home / "code/api")))
|
||||
found = self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], run)
|
||||
self.assertEqual(found, Started([], [Waits("ABC-20", "it is parked: its worker has work again on pull request #7 and awaits a slot")]))
|
||||
|
||||
def test_a_parked_chunk_without_a_window_starts_again_whatever_the_limits_in_the_epics_folder(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
for windows in ((), (("epic-ABC-12", "ABC-20 awaits an approval", True, ""),)):
|
||||
with self.subTest(windows=windows):
|
||||
run = Tmux(*windows, ("epic-ABC-12", "ABC-21", False, str(self.home / "code/api")))
|
||||
found = self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], run)
|
||||
self.assertEqual(found, Started(["ABC-20"], []))
|
||||
self.assertEqual(run.windows[-1], ("epic-ABC-12", "ABC-20", False, str(self.home / ".local/state/do-epic/ABC-12")))
|
||||
self.assertEqual([name for _, name, dead, _ in run.windows if dead], [""] * len(windows))
|
||||
|
||||
def test_a_parked_chunk_that_starts_again_leaves_the_epics_cap_to_the_others(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
found = self.start(self.epic(1, api=2), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], Tmux())
|
||||
self.assertEqual(found, Started(["ABC-20", "ABC-21"], []))
|
||||
|
||||
def test_a_chunk_that_hands_on_starts_no_parked_chunk_whose_window_stopped(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
found = self.start(self.epic(2, api=2), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], Tmux(), own="ABC-21")
|
||||
self.assertEqual(found, Started([], [Waits("ABC-20", "its window stopped; run `do-epic ABC-12` to start it again")]))
|
||||
|
||||
def test_a_chunk_that_parks_frees_its_slot_for_the_next(self) -> None:
|
||||
self.parked("ABC-20")
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 awaits an approval", False, ""))
|
||||
found = self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], run, own="ABC-20")
|
||||
self.assertEqual(found, Started(["ABC-21"], []))
|
||||
|
||||
def test_stops_on_a_parked_chunk_it_cannot_read_and_starts_none(self) -> None:
|
||||
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")], False, None, run)
|
||||
assert isinstance(found, Failure)
|
||||
self.assertIn("cannot read the parked chunk in ", found.reason)
|
||||
self.assertEqual(run.started(), [])
|
||||
|
||||
def test_hands_each_chunk_the_variable_that_makes_its_merge_park(self) -> None:
|
||||
run = Tmux()
|
||||
self.start(self.epic(1, api=1), [issue("ABC-20", "repo:api")], run)
|
||||
self.assertIn("CHUNK_PR_PARKS=1", run.calls[[args[0] for args in run.calls].index("new-session")])
|
||||
|
||||
def resumed(self, epic: Epic, run: Tmux) -> str | None:
|
||||
"""resume for the parked chunk in the first window, which changes the repo api."""
|
||||
return resume(epic, "api", tmux.Window("epic-ABC-12", "ABC-20", "%0"), run)
|
||||
|
||||
def test_a_parked_chunk_resumes_into_a_free_slot_and_counts_in_its_repo_again(self) -> None:
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 awaits an approval", False, ""), ("epic-ABC-12", "ABC-21 awaits its checks", False, ""))
|
||||
self.assertIsNone(self.resumed(self.epic(1, api=1), run))
|
||||
self.assertEqual(run.windows[0], ("epic-ABC-12", "ABC-20", False, str(self.home / "code/api")))
|
||||
|
||||
def test_a_parked_chunk_whose_window_started_again_doesnt_count_itself_as_running(self) -> None:
|
||||
for root in (str(self.home / ".local/state/do-epic/ABC-12"), str(self.home / "code/api")):
|
||||
with self.subTest(root=root):
|
||||
run = Tmux(("epic-ABC-12", "ABC-20", False, root))
|
||||
self.assertIsNone(self.resumed(self.epic(1, api=1), run))
|
||||
self.assertEqual(run.windows[0], ("epic-ABC-12", "ABC-20", False, str(self.home / "code/api")))
|
||||
|
||||
def test_a_parked_chunk_stays_parked_while_the_epic_or_its_repo_is_full(self) -> None:
|
||||
parked = ("epic-ABC-12", "ABC-20 awaits an approval", False, "")
|
||||
cases = {
|
||||
"the epic runs as many chunks as its `**Max parallel chunks:**` line allows: 1": (self.epic(1, api=2), Tmux(parked, ("epic-ABC-12", "ABC-21", False, str(self.home / "code/web")))),
|
||||
"api runs as many chunks as its `parallel-chunks` allows: 1": (self.epic(2, api=1), Tmux(parked, ("epic-XYZ-1", "XYZ-5", False, str(self.home / "code/api")))),
|
||||
"loop-claude runs chunks in api": (self.epic(2, api=1), Tmux(parked, ("loop-api", "item-3", False, str(self.home / "code/api")), owners={"loop-api": str(self.home / "code/api")})),
|
||||
"no project config names api": (self.epic(2), Tmux(parked)),
|
||||
}
|
||||
for reason, (epic, run) in cases.items():
|
||||
with self.subTest(reason=reason):
|
||||
self.assertEqual(self.resumed(epic, run), reason)
|
||||
self.assertEqual(run.windows[0], parked)
|
||||
|
||||
def test_a_running_chunk_counts_and_is_not_started_twice(self) -> None:
|
||||
run = Tmux(("epic-ABC-12", "ABC-20 ?", False, str(self.home / "code/api")))
|
||||
found = self.start(self.epic(2, api=2), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api"), issue("ABC-22", "repo:api")], run)
|
||||
@@ -147,6 +238,11 @@ class StartingAnEpicsChunks(unittest.TestCase):
|
||||
found = self.start(self.epic(3, api=1, web=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:web")], run)
|
||||
self.assertEqual(found, Started(["ABC-21"], [Waits("ABC-20", "api runs as many chunks as its `parallel-chunks` allows: 1")]))
|
||||
|
||||
def test_a_chunk_its_repo_refuses_takes_no_slot_of_the_epics_cap(self) -> None:
|
||||
run = Tmux(("loop-api", "item-3", False, str(self.home / "code/api")), owners={"loop-api": str(self.home / "code/api")})
|
||||
found = self.start(self.epic(1, api=1, web=1), [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:web")], run)
|
||||
self.assertEqual(found, Started(["ABC-21"], [Waits("ABC-20", "loop-claude runs chunks in api")]))
|
||||
|
||||
def test_never_starts_in_a_repo_loop_claude_runs_chunks_in(self) -> None:
|
||||
run = Tmux(("loop-api", "item-3", False, str(self.home / "code/api")), owners={"loop-api": str(self.home / "code/api")})
|
||||
found = self.start(self.epic(3, api=2), [issue("ABC-20", "repo:api")], run)
|
||||
@@ -190,14 +286,23 @@ 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")
|
||||
|
||||
|
||||
class TheFirstPrompt(unittest.TestCase):
|
||||
def test_the_task_names_the_checkout_and_branch_and_quotes_a_description_only_where_there_is_one(self) -> None:
|
||||
self.assertEqual(chunk_prompt.task(issue("ABC-20"), "ABC-12", "/code/api"), "Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout /code/api, on the branch ABC-20. Its summary: Do ABC-20")
|
||||
labels = "`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"
|
||||
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 issue waits for the human. "
|
||||
"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."
|
||||
)
|
||||
self.assertEqual(chunk_prompt.task(issue("ABC-20"), "ABC-12", "/code/api", pathlib.Path("/b/do-epic"), "Swedish"), 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} Its summary: Do ABC-20")
|
||||
|
||||
def test_an_answer_the_judge_quoted_names_the_epics_description_first(self) -> None:
|
||||
self.assertTrue(chunk_prompt.WORKER.answered("Q", "A", Route(Rung("off-the-ladder")), None, False).startswith("Your question: Q\n\nthe epic's description, "))
|
||||
|
||||
def test_opens_with_the_task_then_the_rung_then_the_premises(self) -> None:
|
||||
rest = f"The issue sets the chunk's scope. The goals below choose between ways to deliver that scope, and never widen it. The epic's goals rank first, then code health ({chunk_prompt.CODE_HEALTH}), then the repo's.\n\nFrom P"
|
||||
|
||||
+56
-21
@@ -1,5 +1,7 @@
|
||||
"""Finding a pull request from origin's own branch, and waiting for the checks on its head commit."""
|
||||
import dataclasses
|
||||
import fnmatch
|
||||
import json
|
||||
import time
|
||||
import typing
|
||||
|
||||
@@ -10,6 +12,8 @@ from forge.commands import Forge, gitea, Run
|
||||
POLL_SECONDS = 10
|
||||
# How long checks_passed waits on Gitea for the checks before it gives up; CI took about 3 minutes in 2026-11. gh's watch waits as long as the checks run.
|
||||
WAIT_SECONDS = 30 * 60
|
||||
# What gh says of a pull request whose head has no check.
|
||||
NO_CHECKS = "no checks reported"
|
||||
|
||||
|
||||
def open_pull(forge: Forge, branch: str, head: str, run: Run) -> str | None | Failure:
|
||||
@@ -57,37 +61,68 @@ def required_checks(forge: Forge, base: str, run: Run) -> set[str] | Failure:
|
||||
return Failure(f"tea api answered branch {base} in a shape that can't be read: {str(branch)[:200]}")
|
||||
|
||||
|
||||
def checks_passed(forge: Forge, number: str, head: str, required: set[str], run: Run, sleep: typing.Callable[[float], None] = time.sleep, settle: int = 0) -> Failure | None:
|
||||
"""None once every check on pull request number, whose head commit is head, has passed, or where it has none for settle seconds; a Failure where one fails, or where they have not all passed within WAIT_SECONDS.
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class CheckFailed(Failure):
|
||||
"""A check on a pull request's head failed, which a new push answers. Any other Failure of a read of the checks says the forge could not be read."""
|
||||
|
||||
On Gitea it also waits for a passed check to match each of required: a check CI has yet to queue is no status at all.
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Pending:
|
||||
"""The checks on a pull request's head have not all passed yet, and none failed."""
|
||||
# The checks, or glob patterns, that the protection requires and no passed check matches yet. Empty where a check that reported is still running.
|
||||
missing: list[str]
|
||||
|
||||
|
||||
def checks_now(forge: Forge, number: str, head: str, required: set[str], run: Run, settled: bool = True) -> Pending | Failure | None:
|
||||
"""The checks on pull request number, whose head commit is head, read once: None where every one passed, Pending while one still runs, a CheckFailed where one failed, and any other Failure where the forge cannot be read.
|
||||
|
||||
On Gitea a passed check must also match each of required: a check CI has yet to queue is no status at all. A head without any check counts as passed once settled, and as pending before, since CI may not have queued its checks yet. On GitHub such a head always counts as passed: gh cannot tell a head whose checks have yet to start from a head that has none.
|
||||
"""
|
||||
if forge == "gh":
|
||||
listed = run(["gh", "pr", "checks", number, "--json", "bucket"])
|
||||
if isinstance(listed, Failure):
|
||||
return None if NO_CHECKS in listed.reason else listed
|
||||
try:
|
||||
buckets = {check["bucket"] for check in json.loads(listed)}
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return Failure(f"gh pr checks printed no checks: {listed.strip()[:200]}")
|
||||
if buckets & {"fail", "cancel"}:
|
||||
return CheckFailed(f"a check on pull request {number} failed")
|
||||
return Pending([]) if "pending" in buckets else None
|
||||
status = gitea(run, f"repos/{{owner}}/{{repo}}/commits/{head}/status")
|
||||
if isinstance(status, Failure):
|
||||
return status
|
||||
try:
|
||||
count, state = status["total_count"], status["state"]
|
||||
passed = [check["context"] for check in status.get("statuses") or [] if check["status"] == "success"]
|
||||
except (KeyError, TypeError, AttributeError):
|
||||
return Failure(f"tea api printed no commit status for {head}: {str(status)[:200]}")
|
||||
if state not in ("pending", "success"):
|
||||
return CheckFailed(f"a check on pull request {number} ended in {state}")
|
||||
# Gitea matches a required context as a glob, and reads a commit with no status as pending, with total_count 0.
|
||||
missing = sorted(pattern for pattern in required if not fnmatch.filter(passed, pattern))
|
||||
return None if (count == 0 and settled or state == "success") and not missing else Pending(missing)
|
||||
|
||||
|
||||
def checks_passed(forge: Forge, number: str, head: str, required: set[str], run: Run, sleep: typing.Callable[[float], None] = time.sleep, settle: int = 0) -> Failure | None:
|
||||
"""None once every check on pull request number, whose head commit is head, has passed, or where it has none for settle seconds; a Failure where one fails, or where they have not all passed within WAIT_SECONDS. checks_now says what counts as passed on Gitea."""
|
||||
if forge == "gh":
|
||||
for waited in range(0, settle + 1, POLL_SECONDS):
|
||||
watched = run(["gh", "pr", "checks", number, "--watch", "--fail-fast"])
|
||||
if not isinstance(watched, Failure):
|
||||
return None
|
||||
if "no checks reported" not in watched.reason:
|
||||
if NO_CHECKS not in watched.reason:
|
||||
return watched
|
||||
if waited < settle:
|
||||
sleep(POLL_SECONDS)
|
||||
return None
|
||||
for _ in range(WAIT_SECONDS // POLL_SECONDS + 1):
|
||||
status = gitea(run, f"repos/{{owner}}/{{repo}}/commits/{head}/status")
|
||||
if isinstance(status, Failure):
|
||||
return status
|
||||
try:
|
||||
count, state = status["total_count"], status["state"]
|
||||
passed = [check["context"] for check in status.get("statuses") or [] if check["status"] == "success"]
|
||||
except (KeyError, TypeError, AttributeError):
|
||||
return Failure(f"tea api printed no commit status for {head}: {str(status)[:200]}")
|
||||
if state not in ("pending", "success"):
|
||||
return Failure(f"a check on pull request {number} ended in {state}")
|
||||
# Gitea matches a required context as a glob, and reads a commit with no status as pending, with total_count 0.
|
||||
missing = sorted(pattern for pattern in required if not fnmatch.filter(passed, pattern))
|
||||
if (count == 0 and _ * POLL_SECONDS >= settle or state == "success") and not missing:
|
||||
return None
|
||||
if _ < WAIT_SECONDS // POLL_SECONDS:
|
||||
polls = WAIT_SECONDS // POLL_SECONDS
|
||||
now: Pending | Failure | None = None
|
||||
for poll in range(polls + 1):
|
||||
now = checks_now(forge, number, head, required, run, settled=poll * POLL_SECONDS >= settle)
|
||||
if not isinstance(now, Pending):
|
||||
return now
|
||||
if poll < polls:
|
||||
sleep(POLL_SECONDS)
|
||||
waited_on = f"{', '.join(missing)}, which the protection requires, never passed" if missing else "a check is still pending"
|
||||
waited_on = f"{', '.join(now.missing)}, which the protection requires, never passed" if isinstance(now, Pending) and now.missing else "a check is still pending"
|
||||
return Failure(f"gave up on pull request {number} after {WAIT_SECONDS // 60} minutes: {waited_on}")
|
||||
|
||||
+29
-1
@@ -6,7 +6,8 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from forge.pulls import checks_passed, open_pull, POLL_SECONDS, required_checks, WAIT_SECONDS
|
||||
from forge.pulls import CheckFailed, checks_now, checks_passed, open_pull, Pending, POLL_SECONDS, required_checks, WAIT_SECONDS
|
||||
from failure import Failure
|
||||
from forge.commands import forge_of, gitea, url_beside
|
||||
|
||||
|
||||
@@ -69,6 +70,33 @@ class RequiredChecks(unittest.TestCase):
|
||||
self.assertEqual(required_checks("gh", "main", self.fail), set())
|
||||
|
||||
|
||||
class ChecksNow(unittest.TestCase):
|
||||
def test_reads_on_gh_once_and_says_a_check_is_pending(self):
|
||||
read = []
|
||||
self.assertEqual(checks_now("gh", "7", "abc", set(), lambda command: read.append(command) or '[{"bucket": "pass"}, {"bucket": "pending"}]'), Pending([]))
|
||||
self.assertEqual(read, [["gh", "pr", "checks", "7", "--json", "bucket"]])
|
||||
|
||||
def test_takes_on_gh_passed_and_skipped_checks_and_no_checks_as_passed(self):
|
||||
self.assertIsNone(checks_now("gh", "7", "abc", set(), lambda command: '[{"bucket": "pass"}, {"bucket": "skipping"}]'))
|
||||
self.assertIsNone(checks_now("gh", "7", "abc", set(), lambda command: Failure("gh pr checks: no checks reported on the 'x' branch")))
|
||||
|
||||
def test_fails_on_gh_where_a_check_failed_or_was_cancelled_or_gh_fails(self):
|
||||
for bucket in ("fail", "cancel"):
|
||||
self.assertEqual(checks_now("gh", "7", "abc", set(), lambda command: f'[{{"bucket": "pending"}}, {{"bucket": "{bucket}"}}]'), CheckFailed("a check on pull request 7 failed"))
|
||||
self.assertEqual(checks_now("gh", "7", "abc", set(), lambda command: Failure("no network")), Failure("no network"))
|
||||
self.assertEqual(checks_now("tea", "1", "abc", set(), tea(['{"state": "failure", "total_count": 1}'])), CheckFailed("a check on pull request 1 ended in failure"))
|
||||
self.assertEqual(checks_now("gh", "7", "abc", set(), lambda command: "[1]").reason, "gh pr checks printed no checks: [1]")
|
||||
|
||||
def test_reads_on_tea_once_and_names_each_required_check_that_has_not_passed(self):
|
||||
self.assertEqual(checks_now("tea", "1", "abc", {"lint"}, tea(['{"state": "pending", "total_count": 0, "statuses": []}'])), Pending(["lint"]))
|
||||
self.assertEqual(checks_now("tea", "1", "abc", set(), tea(['{"state": "pending", "total_count": 1}'])), Pending([]))
|
||||
self.assertIsNone(checks_now("tea", "1", "abc", set(), tea(['{"state": "success", "total_count": 1}'])))
|
||||
|
||||
def test_takes_a_commit_with_no_status_on_tea_as_pending_until_settled(self):
|
||||
self.assertEqual(checks_now("tea", "1", "abc", set(), tea(['{"state": "pending", "total_count": 0}']), settled=False), Pending([]))
|
||||
self.assertIsNone(checks_now("tea", "1", "abc", set(), tea(['{"state": "pending", "total_count": 0}'])))
|
||||
|
||||
|
||||
class ChecksPassed(unittest.TestCase):
|
||||
def test_waits_on_tea_while_a_check_is_pending(self):
|
||||
slept = []
|
||||
|
||||
@@ -71,7 +71,7 @@ from model_routing.ladder import Ladder, ProjectRung, REVIEW_STEPS, Rung
|
||||
from claude_code.reply import Limited
|
||||
from model_routing.ladder_file import read_ladder, SHIPPED
|
||||
from loop_claude.project.premises import read_premises
|
||||
from loop_claude.project.records import read_records
|
||||
from loop_claude.project.records import read_records, RECORDS_NAMED
|
||||
from claude_code.transcript import read_transcript
|
||||
from agent_cycle.verdicts import Verdict
|
||||
|
||||
@@ -172,5 +172,5 @@ def rule(case: Case, rung: Rung, home: pathlib.Path, effects: Effects) -> Kind |
|
||||
if isinstance(records, Failure):
|
||||
return verdict_kind(records)
|
||||
# 0 for the route's mark, as before any step-up: the replay compares verdict kinds, and a mark changes only which escalation quotes count.
|
||||
verdict = first_reply(lambda: judge_once(case.root, Brief(task=case.task, premises=premises, records=records, answer_destinations=ANSWER_DESTINATIONS, entries=entries, escalated_at=0, driver=DRIVER), rung, effects))
|
||||
verdict = first_reply(lambda: judge_once(case.root, Brief(task=case.task, premises=premises, records=records, records_named=RECORDS_NAMED, answer_destinations=ANSWER_DESTINATIONS, entries=entries, escalated_at=0, driver=DRIVER), rung, effects))
|
||||
return verdict if isinstance(verdict, Limited) else verdict_kind(verdict)
|
||||
|
||||
@@ -8,7 +8,7 @@ from model_routing.review_choice import chosen, ReviewChoice
|
||||
from loop_claude.cycle.chunk_items import CHUNK_ITEMS
|
||||
from model_routing.route import ESCALATION_MARKER, Route
|
||||
from agent_cycle.routing import escalation_rungs
|
||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
|
||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES, RECORDS_NAMED
|
||||
from review_rules.review_passes import INSTRUCTION_FILES, INSTRUCTION_FOLDERS
|
||||
from text_files.markdown_text import listed, quoted
|
||||
from model_routing.ladder import ProjectRung, Rung
|
||||
@@ -186,9 +186,16 @@ def rungs_held(driver: str, route: Route, project: ProjectRung | None) -> str:
|
||||
return "".join(f" {sentence}" for sentence in rung_sentences(driver, route, project))
|
||||
|
||||
|
||||
def worker_prompts(driver: str, fresh: typing.Callable[[str, str, Route, ProjectRung | None, str], str], naming: str) -> WorkerPrompts:
|
||||
"""The prompts of an entry point's cycles: its own fresh prompt, and the resumed prompt and rung sentences every entry point shares, each naming driver. resumed says what naming is."""
|
||||
return WorkerPrompts(driver, fresh, functools.partial(resumed, driver, naming), functools.partial(rungs_held, driver), QUOTE_SOURCES, ANSWER_DESTINATIONS)
|
||||
class RecordNames(typing.NamedTuple):
|
||||
"""The names an entry point's prompts give the places that answer a question, the places that take an answer, and the records the judge reads; WorkerPrompts says what each field is."""
|
||||
quote_sources: str = QUOTE_SOURCES
|
||||
answer_destinations: str = ANSWER_DESTINATIONS
|
||||
records_named: str = RECORDS_NAMED
|
||||
|
||||
|
||||
def worker_prompts(driver: str, fresh: typing.Callable[[str, str, Route, ProjectRung | None, str], str], naming: str, names: RecordNames = RecordNames()) -> WorkerPrompts:
|
||||
"""The prompts of an entry point's cycles: its own fresh prompt, and the resumed prompt and rung sentences every entry point shares, each naming driver. resumed says what naming is. names is loop-claude's unless the entry point keeps records elsewhere, as do-epic does."""
|
||||
return WorkerPrompts(driver, fresh, functools.partial(resumed, driver, naming), functools.partial(rungs_held, driver), *names)
|
||||
|
||||
|
||||
WORKER = worker_prompts(DRIVER, functools.partial(fresh, DRIVER), NAME_THE_ITEMS)
|
||||
|
||||
@@ -66,8 +66,8 @@ def project_lock(root: str, home: pathlib.Path) -> pathlib.Path:
|
||||
|
||||
|
||||
def epic_chunks(root: str, run: tmux.Tmux) -> list[tmux.Placed]:
|
||||
"""The windows of do-epic's sessions whose chunks run in the checkout root."""
|
||||
return [placed for placed in tmux.everywhere(run) if placed.session.startswith(f"{tmux.EPIC}-") and placed.root == root and not placed.window.dead]
|
||||
"""The windows of do-epic's sessions whose chunks run in the checkout root. A parked chunk doesn't run."""
|
||||
return [placed for placed in tmux.everywhere(run) if placed.session.startswith(f"{tmux.EPIC}-") and placed.root == root and not placed.window.dead and not placed.window.parked]
|
||||
|
||||
|
||||
def held_items(chunks: typing.Iterable[str], key: str, claude_code_transcripts: pathlib.Path) -> set[int]:
|
||||
|
||||
@@ -13,28 +13,35 @@ RECORD_FILES = (WORKING_RULES[0], DECISIONS[0])
|
||||
# then each .md file in the review standards folder the project's config sets.
|
||||
HUMAN_RULES_FILE = "CLAUDE.md"
|
||||
HUMAN_RULE_DIR = "rules"
|
||||
# How the judge's prompt names the records above, in the order it reads them.
|
||||
RECORDS_NAMED = "the project's working rules and decisions, then the human's rules for every project"
|
||||
HUMAN_RULE_NAMES = (f"~/.claude/{HUMAN_RULES_FILE}", f"~/.claude/{HUMAN_RULE_DIR}/", "the project's review standards")
|
||||
|
||||
|
||||
CONSEQUENCE = "the judge cannot read the records"
|
||||
|
||||
|
||||
def read_records(root: str, home: pathlib.Path, claude_dir: pathlib.Path) -> str | Failure:
|
||||
def read_records(root: str | None, home: pathlib.Path, claude_dir: pathlib.Path, first: tuple[tuple[str, str], ...] = ()) -> str | Failure:
|
||||
"""The project's `AGENTS.md` and decision log, then the human's rules, CLAUDE.md first, each headed by its name; one that does not exist, or is empty, is left out.
|
||||
|
||||
`AGENTS.md` is read where the config under home of root's project puts it, and the decision log from the store that config names. Each is headed by its name in RECORD_FILES wherever it is kept."""
|
||||
config = located(root, home)
|
||||
if isinstance(config, Failure):
|
||||
return Failure(f"{config.reason} - {CONSEQUENCE}.")
|
||||
rules = [claude_dir / HUMAN_RULES_FILE, *sorted((claude_dir / HUMAN_RULE_DIR).glob("*.md")), *sorted(config.paths["standards"].glob("*.md"))]
|
||||
decisions = store(config, DECISIONS[1]).read()
|
||||
texts = [(WORKING_RULES[0], file_text(config.paths[WORKING_RULES[1]])), (DECISIONS[0], Failure(f"{decisions.reason} - {CONSEQUENCE}.") if isinstance(decisions, Failure) else decisions)]
|
||||
`AGENTS.md` is read where the config under home of root's project puts it, and the decision log from the store that config names. Each is headed by its name in RECORD_FILES wherever it is kept.
|
||||
|
||||
first holds records kept outside the project, such as the sections of a Jira epic's description, each as its heading and text: they come before the project's. A root of None is work without a checkout, which has no project records and no review standards."""
|
||||
texts: list[tuple[str, str | Failure]] = list(first)
|
||||
rules = [claude_dir / HUMAN_RULES_FILE, *sorted((claude_dir / HUMAN_RULE_DIR).glob("*.md"))]
|
||||
if root is not None:
|
||||
config = located(root, home)
|
||||
if isinstance(config, Failure):
|
||||
return Failure(f"{config.reason} - {CONSEQUENCE}.")
|
||||
rules += sorted(config.paths["standards"].glob("*.md"))
|
||||
decisions = store(config, DECISIONS[1]).read()
|
||||
texts += [(WORKING_RULES[0], file_text(config.paths[WORKING_RULES[1]])), (DECISIONS[0], Failure(f"{decisions.reason} - {CONSEQUENCE}.") if isinstance(decisions, Failure) else decisions)]
|
||||
texts += [(named(rule, home, claude_dir), file_text(rule)) for rule in rules]
|
||||
records = []
|
||||
for heading, text in texts:
|
||||
if isinstance(text, Failure):
|
||||
return text
|
||||
if text:
|
||||
if text.strip():
|
||||
records.append(f"From {heading}:\n{text.strip()}")
|
||||
return "\n\n".join(records)
|
||||
|
||||
|
||||
@@ -1907,6 +1907,21 @@ class Records(unittest.TestCase):
|
||||
config.unlink()
|
||||
self.assertEqual(records.read_records(root, claude_md.parents[1], claude_md.parent), Failure(f"no config names the checkout {root}: write ~/.claude-projects/<key>/config.toml, as `project-config --help` shows - the judge cannot read the records."))
|
||||
|
||||
def test_puts_the_records_handed_in_first_and_reads_only_the_humans_rules_without_a_checkout(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
claude_md = pathlib.Path(root, "home", ".claude", "CLAUDE.md")
|
||||
configured(self, pathlib.Path(root), home=claude_md.parents[1])
|
||||
claude_md.parent.mkdir(parents=True)
|
||||
claude_md.write_text("# Global\n")
|
||||
pathlib.Path(claude_md.parent, "rules").mkdir()
|
||||
pathlib.Path(claude_md.parent, "rules", "todo-items.md").write_text("# Todo\n")
|
||||
pathlib.Path(claude_md.parent, "skills", "larv-review", "standards").mkdir(parents=True)
|
||||
pathlib.Path(claude_md.parent, "skills", "larv-review", "standards", "comments.md").write_text("# Comments\n")
|
||||
pathlib.Path(root, "AGENTS.md").write_text("# Rules\n")
|
||||
first = (("the epic ABC-1's description, ## Decisions", "Squash.\n"), ("the epic ABC-1's description, ## Scoring", " \n"))
|
||||
self.assertEqual(records.read_records(root, claude_md.parents[1], claude_md.parent, first), "From the epic ABC-1's description, ## Decisions:\nSquash.\n\nFrom AGENTS.md:\n# Rules\n\nFrom ~/.claude/CLAUDE.md:\n# Global\n\nFrom ~/.claude/rules/todo-items.md:\n# Todo\n\nFrom ~/.claude/skills/larv-review/standards/comments.md:\n# Comments")
|
||||
self.assertEqual(records.read_records(None, claude_md.parents[1], claude_md.parent, first), "From the epic ABC-1's description, ## Decisions:\nSquash.\n\nFrom ~/.claude/CLAUDE.md:\n# Global\n\nFrom ~/.claude/rules/todo-items.md:\n# Todo")
|
||||
|
||||
def test_stops_on_a_record_it_cannot_read(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
claude_md = pathlib.Path(root, "home", ".claude", "CLAUDE.md")
|
||||
@@ -1931,7 +1946,7 @@ class Records(unittest.TestCase):
|
||||
class JudgePrompt(unittest.TestCase):
|
||||
def test_shows_the_transcripts_tail_and_returns_what_it_showed(self):
|
||||
entries = [assistant({"type": "text", "text": "old " + "x" * judge.JUDGE_PROMPT_CHARS}), assistant({"type": "text", "text": "new"})]
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
self.assertTrue(grounds.shown.endswith("\n\nnew"))
|
||||
self.assertNotIn("old", grounds.shown)
|
||||
self.assertIn(grounds.shown, prompt)
|
||||
@@ -1940,11 +1955,11 @@ class JudgePrompt(unittest.TestCase):
|
||||
self.assertEqual(grounds.quotable, "## Goals\n\n")
|
||||
|
||||
def test_the_judge_prompt_and_schema_call_the_worker_the_worker(self):
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(assistant({"type": "text", "text": "done"})), 1, prompts.DRIVER))
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(assistant({"type": "text", "text": "done"})), 1, prompts.DRIVER))
|
||||
self.assertNotRegex(prompt + json.dumps(judge.judge_schema(prompts.DRIVER)), r"\b[Aa]gent")
|
||||
|
||||
def test_the_judge_prompt_names_the_entry_points_answer_destinations_in_both_rules_on_a_recorded_answer(self):
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", "the ledger", kinds(assistant({"type": "text", "text": "done"})), 0, prompts.DRIVER))
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, "the ledger", kinds(assistant({"type": "text", "text": "done"})), 0, prompts.DRIVER))
|
||||
self.assertIn("is recorded in the ledger at the one place it governs", prompt)
|
||||
self.assertIn("the worker writing it into the ledger, but not into one of the human's rules", prompt)
|
||||
|
||||
@@ -1957,24 +1972,24 @@ class JudgePrompt(unittest.TestCase):
|
||||
|
||||
def test_shows_the_judge_where_the_worker_last_stepped_up_and_checks_an_escalation_only_after_it(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "round 3: 🔴"})]
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertRegex(prompt, "round 2: 🔴\n\n\\[step\\] [^\n]+\n\nround 3: 🔴\n\n")
|
||||
self.assertEqual(grounds.after_mark, "round 3: 🔴")
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
self.assertNotIn("stepped the worker up", prompt)
|
||||
self.assertEqual(grounds.shown, "round 2: 🔴\n\nround 3: 🔴")
|
||||
self.assertEqual(grounds.after_mark, "round 2: 🔴\n\nround 3: 🔴")
|
||||
|
||||
def test_drops_an_escalation_quote_from_after_the_step_up_that_the_tail_it_shows_cuts_off(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "old " + "x" * judge.JUDGE_PROMPT_CHARS}), assistant({"type": "text", "text": "new"})]
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertEqual(judge.quotes_checked(Unfinished("e", "old x", entries_read=3), grounds), Unfinished("e", entries_read=3))
|
||||
self.assertEqual(judge.quotes_checked(Unfinished("e", "new", entries_read=3), grounds), Unfinished("e", "new", entries_read=3))
|
||||
|
||||
def test_shows_a_typed_answer_before_the_step_up_as_the_humans(self):
|
||||
typed = prompts.WORKER.typed("Which one?", "Use B.", Route(Rung("worker-model")), None, False)
|
||||
entries = [{**human(typed), "promptSource": "sdk"}, assistant({"type": "text", "text": "round 3: 🔴"})]
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertIn("\n\n[human] Use B.\n\n[step] ", grounds.shown)
|
||||
|
||||
|
||||
@@ -2201,7 +2216,7 @@ class Verdict(unittest.TestCase):
|
||||
def test_drops_an_escalation_quote_found_only_in_the_transcript_entries_before_the_workers_last_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "round 3: 🔴"}), assistant({"type": "text", "text": "working"})]
|
||||
def judged_on(mark, escalation):
|
||||
return judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), mark, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation=escalation)]).effects())
|
||||
return judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), mark, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation=escalation)]).effects())
|
||||
self.assertEqual(judged_on(0, "round 2: 🔴"), Unfinished("working", "round 2: 🔴", entries_read=3))
|
||||
self.assertEqual(judged_on(1, "round 2: 🔴"), Unfinished("working", entries_read=3))
|
||||
self.assertEqual(judged_on(1, "round 3: 🔴"), Unfinished("working", "round 3: 🔴", entries_read=3))
|
||||
@@ -2210,12 +2225,12 @@ class Verdict(unittest.TestCase):
|
||||
|
||||
def test_drops_an_escalation_quote_that_only_loop_claudes_prompts_or_the_humans_lines_repeat_after_the_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), {**human("as the work remaining: round 2: 🔴"), "promptSource": "sdk"}, human("round 2: 🔴 again"), assistant({"type": "text", "text": "working"})]
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation="round 2: 🔴")]).effects())
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation="round 2: 🔴")]).effects())
|
||||
self.assertEqual(verdict, Unfinished("working", entries_read=4))
|
||||
|
||||
def test_takes_evidence_from_before_the_workers_last_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "working"})]
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", evidence="round 2: 🔴")]).effects())
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", evidence="round 2: 🔴")]).effects())
|
||||
self.assertEqual(verdict, Unfinished("round 2: 🔴", entries_read=2))
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import typing
|
||||
|
||||
|
||||
def piped(stdin: typing.TextIO) -> str:
|
||||
"""The text piped in, empty from a terminal. Claude Code's Bash tool gives a command /dev/null as stdin (readlink /proc/self/fd/0 shows it), so without a heredoc read() returns "" at once."""
|
||||
return "" if stdin.isatty() else stdin.read()
|
||||
@@ -85,6 +85,8 @@ import pathlib
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from text_files.piped_text import piped
|
||||
|
||||
from plan.todo_table import BLOCKED_BY, MOVES
|
||||
from failure import Failure
|
||||
from project_config.main import located
|
||||
@@ -184,11 +186,6 @@ def fields(args: argparse.Namespace) -> dict[str, str]:
|
||||
return {field: value for field, value in given.items() if value is not None}
|
||||
|
||||
|
||||
def piped(stdin: typing.TextIO) -> str:
|
||||
"""The text piped in, empty from a terminal. Claude Code's Bash tool gives a command /dev/null as stdin (readlink /proc/self/fd/0 shows it), so without a heredoc read() returns "" at once."""
|
||||
return "" if stdin.isatty() else stdin.read()
|
||||
|
||||
|
||||
def reported(written: Written | Failure, refusal: str, done: typing.Callable[[Written], str]) -> str | Failure:
|
||||
"""What a write prints: done's line, after the backend's notes on stderr; else the Failure, opened with refusal."""
|
||||
if isinstance(written, Failure):
|
||||
|
||||
+1
-1
@@ -153,7 +153,7 @@ Valid while `~/.claude` is a checkout of this repo.
|
||||
- **Releases.** An epic item has no release. It ships into its repo's unreleased work: a bullet under `CHANGELOG.md` → `## Unreleased`, or nothing where the repo's plan is in Jira.
|
||||
- **Repos.** A repo's name is its main checkout's folder name, and a project config names that checkout. A missing checkout is cloned from the host of the epic's other repos; where unsure, do-epic asks. Unsure means the other repos don't all sit under one host and owner (the same host spelt as https and as ssh counts as two), an origin can't be read or isn't an https, ssh or scp-style address, the folder to clone into holds something else, or the clone fails. A repo no config names is cloned into the clone folder, and the human is asked to write its config. Each chunk uses its repo's model, routing, and language for commits and PRs. Jira text is in the epic's language, or else the machine's default.
|
||||
- **Running.** The epic caps the chunks running at once, and each repo's `parallel-chunks` still applies. do-epic and loop-claude never run chunks in the same repo at once. The cap is a line of the epic's description, `**Max parallel chunks:** 2`, and 1 without it, as `parallel-chunks` is. A repo's `parallel-chunks` counts the chunks of every epic in its checkout. Each window is named for its issue's key, and a tmux window option, `@chunk-root`, names the folder its chunk works in, which is how loop-claude sees do-epic's chunks in a checkout. do-epic and loop-claude each hold the checkout's `starting` lock from checking the checkout's chunks to starting a window there. A chunk without a repo works in `~/.local/state/do-epic/<EPIC-KEY>/`. do-epic archives its cycles under `~/.claude/do-epic-transcripts/`, not in loop-claude's archive, whose readers parse loop-claude's prompts. An open issue runs once a label records its repo; until do-epic picks repos itself, an issue without one waits, and `do-epic <EPIC-KEY>` says so.
|
||||
- **Long gates.** A chunk whose PR waits on a gate, such as a human approval, parks. It keeps its worktree, PR and session, and its state is in a file that survives a reboot. A parked chunk takes no running slot, and the items it blocks wait. do-epic polls the forge and resumes the chunk's session when the gate passes or a reviewer comments. It fixes reasonable feedback, replies to the rest, and changes the setup so review would have caught it. `do-epic <key> --status` and the tmux window names show what each chunk waits on.
|
||||
- **Long gates.** A chunk whose PR waits on a gate, such as a human approval, parks. It keeps its worktree, PR and session, and its state is in a file that survives a reboot. A parked chunk takes no running slot, and the items it blocks wait. do-epic polls the forge and resumes the chunk's session when the gate passes or a reviewer comments. It fixes reasonable feedback, replies to the rest, and changes the setup so review would have caught it. `do-epic <key> --status` and the tmux window names show what each chunk waits on. A gate is a pull request's pending checks or, on GitHub, the approval its branch protection requires; a draft waits on neither, since its worker has yet to mark it ready. On Gitea a draft is a pull request whose title opens with `WIP:` or `[WIP]`, Gitea's default `WORK_IN_PROGRESS_PREFIXES`. Changes a reviewer requested resume the chunk only while that review was made on the pull request's head commit and the pull request's author has not commented or replied after it; once the worker pushed or replied, the chunk parks on a new review, since GitHub keeps the decision until the reviewer reviews again. The chunk's window reads the forge once a minute, which no forge's rate limit notices. A chunk resumes only into a free slot, under the limits a starting chunk meets, and stays parked until then. `do-epic <key>` starts a parked chunk's window again whatever the limits, since the chunk stays parked. do-epic sets `CHUNK_PR_PARKS=1` for each worker, so `chunk-pr merge` fails at once where the pull request awaits an approval, and the worker's run doesn't hold a slot while the pull request waits.
|
||||
- **Human tasks.** do-epic DMs the human when one blocks the next item, and polls until its issue closes.
|
||||
- **Findings.** A finding about the epic's goals is filed in the epic. A finding about a repo's goals follows that repo's rules. Where unsure which, do-epic asks. A set of new items toward an epic goal needs the human's approval before work starts; a finding filed during a chunk doesn't.
|
||||
- **Finishing.** When the epic holds no open item: release-review passes on each repo the epic changed, then the items they file, then the human confirms each achieve goal and that no maintain goal has a defect. For a goal that isn't met, do-epic proposes items for approval. Then a summary comment on the epic, and closing the epic in Jira, as the very last step.
|
||||
|
||||
@@ -2910,3 +2910,20 @@ Read most (opens and searches):
|
||||
- `docs/decisions.md` 2
|
||||
- `bin/agent_cycle/tmux.py` 1
|
||||
- `bin/loop-claude` 1
|
||||
|
||||
## Reading cost, chunk 43ac6d329242, finished 2026-11-18T22:50:16Z
|
||||
|
||||
104341 new input tokens before the first commit.
|
||||
|
||||
Read most (opens and searches):
|
||||
|
||||
- `bin/agent_cycle/judge.py` 3
|
||||
- `rules/todo-items.md` 3
|
||||
- `bin/do_epic/main.py` 2
|
||||
- `bin/loop_claude/cycle/prompts.py` 2
|
||||
- `bin/agent_cycle/run.py` 1
|
||||
- `bin/agent_cycle/worker_prompts.py` 1
|
||||
- `bin/do_epic/chunk_prompt.py` 1
|
||||
- `bin/do_epic/epic_record.py` 1
|
||||
- `bin/loop_claude/project/premises.py` 1
|
||||
- `bin/loop_claude/project/records.py` 1
|
||||
|
||||
@@ -121,6 +121,7 @@ A fix meets every row it fits, except that a fix for a 🟡 meets only the 🟡
|
||||
**Findings.** A reviewer rates each finding 🔴 must fix, 🟡 should fix, 🟢 nit, ❓ question, or 🔀 escalation naming the reviewer whose concern it is.
|
||||
|
||||
- **Outside the chunk.** A finding outside the chunk's change, whatever its pass or severity, is scored and filed in `todo.md` per `~/.claude/rules/todo-items.md`. A 🔴 is marked `defect`. A 🟡 against a file in the config's principles folder is marked `principle`, its detail naming the principle, where no other reason fits. One under the bar and not exempt is named in the summary with its score. A verified security HIGH is handled per "Security". In the release review the whole project is the chunk's change, so nothing lies outside it; "Release review" → "Findings" says which of its findings are filed.
|
||||
- **Under do-epic.** A chunk do-epic runs files a finding about one of the epic's goals in the epic, as its prompt says, in place of `todo.md`. Where unsure whether a finding is about the epic's goals or a repo's, ask the human.
|
||||
- **Goal or decision.** A fix that would change a goal, or a `docs/decisions.md` entry the repo held before the chunk began, is asked; no user reachable → filed, marked `question`, the goal or decision left as is.
|
||||
- **New decision.** Each decision a fix or an answer records in `docs/decisions.md` is checked against the project principles per `~/.claude/rules/decisions.md` → "Decisions: one home, each linked to a goal or a technical principle", "Check each new decision against the project's principles", before the commit that records it.
|
||||
- **🔴.** A 🔴 is fixed, or shown factually wrong, and what disproved it recorded per the review standards' `comments.md` → "Where a choice goes": in a comment at the code the finding concerns, or in `docs/decisions.md` when it concerns more than one place. Never declined.
|
||||
|
||||
@@ -14,12 +14,9 @@
|
||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||
| 441 | 0.12.0 | | | **Move an epic's issue to done in Jira when its chunk finishes, so no finished chunk starts again and what it blocks starts.** | 2 | 2 | 2 | 4 | 3 | 1 by 6 | 2.3 |
|
||||
| 416 | 0.12.0 | | | **Finish an epic's repo item with a bullet under its repo's `CHANGELOG.md` → `## Unreleased`, or with none where the repo's plan is in Jira.** | 1 | 1 | 1 | 1 | 2 | 1 by 5 | 2.1 |
|
||||
| 413 | 0.12.0 | | | **File a finding about an epic goal in the epic and one about a repo goal by that repo's rules, ask the human where unsure which, and give the judge the epic's records beside the repo's.** | 3 | 2 | 3 | 6 | 4 | 1 by 5 | 1.6 |
|
||||
| 415 | 0.12.0 | 413 | | **Finish an epic: run release-review passes on each repo it changed, work what they file, have the human confirm each goal, post a summary comment, and close the epic in Jira last.** | 3 | 2 | 3 | 6 | 5 | 1 by 5 | 1.2 |
|
||||
| 418 | 0.12.0 | 415 | | **Describe do-epic in `README.md`'s tools and setup, with its machine settings and `repo-rule.md`.** | 1 | 2 | 1 | 2 | 2 | 1 by 5 | 2.1 |
|
||||
| 418 | 0.12.0 | | | **Describe do-epic in `README.md`'s tools and setup, with its machine settings and `repo-rule.md`.** | 1 | 2 | 1 | 2 | 2 | 1 by 5 | 2.1 |
|
||||
| 420 | 0.12.0 | | | **End a worker that printed its final result and lingers, by killing the background shells it left, after a few minutes, and print each kill with its evidence on loop-claude's terminal.** | 2 | 2 | 2 | 4 | 3 | 1.5 by 6 | 2.0 |
|
||||
| 411 | 0.12.0 | | | **Park a chunk whose PR waits on a long gate, keeping its worktree, PR and session in a state file that survives a reboot, and resume its session when the gate passes or a reviewer comments.** | 3 | 2 | 3 | 6 | 5 | 1 by 5 | 1.2 |
|
||||
| 412 | 0.12.0 | 411 | | **Print each chunk of an epic, running, parked with its gate and since when, or stopped, each human task and each open interrupt with `do-epic <key> --status`, and name a parked chunk's gate in its tmux window's name.** | 2 | 1 | 1 | 2 | 3 | 1 by 5 | 1.9 |
|
||||
| 412 | 0.12.0 | | | **Print each chunk of an epic, running, parked with its gate and since when, or stopped, each human task and each open interrupt with `do-epic <key> --status`, and name a parked chunk's gate in its tmux window's name.** | 2 | 1 | 1 | 2 | 3 | 1 by 5 | 1.9 |
|
||||
| 414 | 0.12.0 | | | **DM the human through the notifier when a human-task issue blocks the epic's next item, and poll until it closes.** | 2 | 2 | 2 | 4 | 3 | 1 by 5 | 1.9 |
|
||||
| 417 | 0.12.0 | | | **Run do-epic end to end against a sandbox epic on a real Jira site with a command of its own, outside `run-tests`.** | 2 | 1 | 1 | 2 | 3 | 1 by 5 | 1.9 |
|
||||
| 440 | 0.12.0 | | | **End the shell that the interrupt test of `mutate-changes` starts within a minute, so a mutation run of this repo never waits on it for ever.** | 1 | 1 | 2 | 2 | 2 | 1 by 4 | 1.7 |
|
||||
@@ -97,29 +94,6 @@ Touches:
|
||||
|
||||
- `bin/do_epic/main.py`
|
||||
|
||||
### 413. File a finding about an epic goal in the epic and one about a repo goal by that repo's rules, ask the human where unsure which, and give the judge the epic's records beside the repo's.
|
||||
|
||||
The epic's records are its description's sections (`docs/decisions.md` → `do-epic: drives one Jira epic …`). `read_records` and `read_premises` take the epic's record as a parameter, so loop-claude's judge is unchanged.
|
||||
|
||||
Touches:
|
||||
|
||||
- `bin/loop_claude/project/records.py`: `read_records` (small)
|
||||
- `bin/loop_claude/project/premises.py`: `read_premises` (small)
|
||||
- `bin/agent_cycle/judge.py`: `judge_prompt` (small)
|
||||
- `bin/loop_claude/cycle/prompts.py`: `ANSWER_DESTINATIONS` (small)
|
||||
- `skills/larv-review/SKILL.md`: `## 3. Passes` (small)
|
||||
- `bin/do_epic/findings.py`
|
||||
|
||||
### 415. Finish an epic: run release-review passes on each repo it changed, work what they file, have the human confirm each goal, post a summary comment, and close the epic in Jira last.
|
||||
|
||||
A goal is met only where the human confirms it: each achieve goal achieved, and no defect against a maintain goal. For a goal that isn't met, do-epic proposes a set of items, and the human approves the set before work starts (`docs/decisions.md` → `do-epic: drives one Jira epic …`). The summary names what shipped per repo and each goal's evidence, in the epic's language. The epic's transition is configured as `todo-item finish`'s is.
|
||||
|
||||
Touches:
|
||||
|
||||
- `bin/plan_store/jira_epic.py`: `JiraPlan.finish`, `transition_of` (small)
|
||||
- `bin/release_plan/release_standing.py`: `release_reviewed` (small)
|
||||
- `bin/do_epic/finish.py`
|
||||
|
||||
### 418. Describe do-epic in `README.md`'s tools and setup, with its machine settings and `repo-rule.md`.
|
||||
|
||||
Each chunk keeps the README true for what it changes; this item writes the overview a new reader needs (`docs/decisions.md` → `do-epic: drives one Jira epic …`).
|
||||
@@ -144,18 +118,6 @@ Touches:
|
||||
- `bin/loop_claude/loop/lingering_workers.py`
|
||||
- `README.md`: `## Tools` (small)
|
||||
|
||||
### 411. Park a chunk whose PR waits on a long gate, keeping its worktree, PR and session in a state file that survives a reboot, and resume its session when the gate passes or a reviewer comments.
|
||||
|
||||
A parked chunk takes no running slot, and the items it blocks wait (`docs/decisions.md` → `do-epic: drives one Jira epic …`). On reviewer feedback the resumed chunk fixes what is reasonable, replies to the rest, and changes the setup so review would have caught it. The forge checks need forms that return instead of blocking. `chunk_pr/main.py` `merged` is a place the seats found hard: make it easier to read where it changes.
|
||||
|
||||
Touches:
|
||||
|
||||
- `bin/chunk_pr/main.py`: `merged`, `merge_turn` (small)
|
||||
- `bin/chunk_pr/approval.py`: `approval`, `unanswered` (small)
|
||||
- `bin/forge/pulls.py`: `checks_passed` (small)
|
||||
- `bin/do_epic/gates.py`
|
||||
- `bin/do_epic/parked.py`
|
||||
|
||||
### 412. Print each chunk of an epic, running, parked with its gate and since when, or stopped, each human task and each open interrupt with `do-epic <key> --status`, and name a parked chunk's gate in its tmux window's name.
|
||||
|
||||
A plain `do-epic <key>` resumes all of them, as after a reboot (`docs/decisions.md` → `do-epic: drives one Jira epic …`). The window suffix generalises the interrupt's " ?".
|
||||
|
||||
Reference in New Issue
Block a user