Merge remote-tracking branch 'origin/main' into item-417
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
# Conflicts: # README.md # docs/reading-cost.md
This commit is contained in:
@@ -24,7 +24,7 @@ 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.
|
||||
{LABEL} is {LABELS}; without one, the next `do-epic <EPIC-KEY>` you run picks where the issue is worked.
|
||||
A second {LABEL}, `{REVIEW_LABEL}`, marks the issue as a repo's release review, which the epic's finishing files.
|
||||
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."""
|
||||
@@ -34,7 +34,7 @@ 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. "
|
||||
f"The label is {LABELS}; leave it out where you cannot tell, and the next `do-epic` the human runs picks it. "
|
||||
"Where filing fails and says the issue may exist, ask the human to look before you file it again. "
|
||||
"File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. "
|
||||
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. "
|
||||
@@ -79,7 +79,7 @@ def written(epic: str, flag: str, value: str, labels: tuple[str, ...], store: Ep
|
||||
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}.")
|
||||
return f"Filed {key} in the epic {epic}." + ("" if any(of_label(label) for label in labels) else f" It has no label that says where it is worked, so the next `do-epic {epic}` picks one: {LABELS}.")
|
||||
try:
|
||||
with decisions_locked(folder):
|
||||
added = record.append_decision(value, text)
|
||||
|
||||
+20
-7
@@ -1,6 +1,6 @@
|
||||
"""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. The window of a human's task runs no cycle: it waits until the task no longer holds up an issue (`human_tasks`), then does the same.
|
||||
`do-epic <EPIC-KEY>` first plans the epic's open issues (`planning`): each that no label places is split by repo or gets its pick, and the scored issues do-epic filed are re-ranked. Then it starts each of the epic's chunks that may start now, each in a window of the epic's tmux session, as `scheduler` picks them, and puts that session on the terminal. Each window runs `do-epic --chunk <ISSUE-KEY> <EPIC-KEY>`: the cycles of one issue's chunk, run by the code that runs loop-claude's (`agent_cycle`), until the judge rules it finished. Then it starts the chunks that may start now, and its window closes. The window of a human's task runs no cycle: it waits until the task no longer holds up an issue (`human_tasks`), then does the same.
|
||||
|
||||
After each cycle of a chunk in a repo, the window reads what the chunk's pull request waits on (`gates`). While that is a gate only time or a person passes, the chunk is parked (`parked`): the window frees its running slot and polls the forge, and the chunk's next cycle starts once the worker has something to do and a slot is free. `do-epic <EPIC-KEY> --status` prints what each open issue does."""
|
||||
import dataclasses
|
||||
@@ -9,7 +9,7 @@ import sys
|
||||
import typing
|
||||
|
||||
from loop_claude.loop.chunk_start import archived_route, routed
|
||||
from do_epic import chunk_prompt, findings, finish, gates, human_tasks, parked, scheduler, split, status
|
||||
from do_epic import chunk_prompt, findings, finish, gates, human_tasks, parked, planning, scheduler, split, status
|
||||
from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo
|
||||
from loop_claude.loop.close import closed_cycle
|
||||
from project_config.main import located as config_located
|
||||
@@ -27,6 +27,7 @@ from loop_claude.project.model_choice import get_or_ask_models, Models
|
||||
from plan_store.jira_epic import ISSUE_KEY
|
||||
from do_epic.backend.jira import JiraEpic
|
||||
from agent_cycle.routing import judge_rung
|
||||
from claude_code.reply import Limited
|
||||
from do_epic.repos import locate
|
||||
from loop_claude.loop.this_loop import Loop
|
||||
from loop_claude.loop.reload import LoopRun
|
||||
@@ -46,8 +47,12 @@ HELP = f"""usage: do-epic <EPIC-KEY> [--status]
|
||||
{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.
|
||||
Before it starts chunks, do-epic <EPIC-KEY> plans each open issue that has none of these labels:
|
||||
`repo:<name>` for its repo, `do-epic-claude` for work of Claude's that changes no repo, `do-epic-human` for a task of yours.
|
||||
Where such an issue changes several repos, it files a sub-task per repo. Otherwise it gives the issue its label, as repo-rule.md says.
|
||||
Where the rule leaves the label unclear, it asks you on the terminal. Answer with the label, or with Enter alone to leave the issue waiting.
|
||||
It then puts the scored issues that do-epic itself filed in order of score, by the `Score = ...` line under the epic's ## Scoring.
|
||||
An open issue labelled `repo:<name>` or `do-epic-claude` runs as a chunk once no issue blocks it.
|
||||
A `do-epic-human` issue that blocks another gets a window too. The window DMs you once, then waits without taking a place until you close the issue in Jira.
|
||||
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.
|
||||
@@ -152,9 +157,17 @@ def epic_written(key: str, writes: tuple[str, str, tuple[str, ...]] | None, path
|
||||
|
||||
|
||||
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()
|
||||
started = issues if isinstance(issues, Failure) else chunks_started(epic, issues, None)
|
||||
"""What the do-epic the human runs does: plans the open issues (`planning`), 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."""
|
||||
read = epic.store.read()
|
||||
if isinstance(read, Failure):
|
||||
return Stop(1, read.reason)
|
||||
issues, stopped = planning.planned(planning.Planned(epic.key, epic.config, epic.store, epic.record, epic.paths.home, epic.effects), read)
|
||||
if isinstance(stopped, Limited):
|
||||
return Stop(1, f"the epic is not planned, so no chunk started: {stopped.said}")
|
||||
if stopped is not None:
|
||||
# One issue or repo that cannot be planned holds back only itself: each chunk that may start still does.
|
||||
say(f"the epic {epic.key} is not planned in full: {stopped.reason}", epic.effects)
|
||||
started = chunks_started(epic, issues, None)
|
||||
if isinstance(started, Failure):
|
||||
return Stop(1, started.reason)
|
||||
say(f"started {', '.join(started.started)} in the tmux session {epic.session}" if started.started else "started no chunk", epic.effects, stdout=True)
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
"""What `do-epic <EPIC-KEY>` settles before it starts chunks: where each open issue is worked, and the order the loop's issues come in (docs/decisions.md → `do-epic: drives one Jira epic …`).
|
||||
|
||||
An open child issue that no label places is first split by repo (`split`), and where it changes one repo or none, its repo is picked (`repo_pick`). Each is a headless claude call on `repoless-model`'s rung of the shipped ladder. Where the repo rule leaves a pick unclear, the human answers on the terminal. Then the issues do-epic filed are scored and Jira's backlog re-ranked to match (`ranking`).
|
||||
|
||||
Planning runs only in the `do-epic <EPIC-KEY>` the human starts. A chunk that finishes starts the next chunks from the labels and the order it finds, so no window waits on a question.
|
||||
|
||||
Planning holds no lock: one `do-epic <EPIC-KEY>` at a time is assumed. A second one started meanwhile finds the sub-tasks the first filed, since `split` reads them before it files, unless Jira's search lags."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
from do_epic.config import DoEpicConfig
|
||||
from loop_effects.effects import Effects, say
|
||||
from do_epic.backend.protocol import EpicIssue, EpicStore
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from failure import Failure
|
||||
from record_store.stores import goals_store, store as record_store
|
||||
from plan.todo_table import Item
|
||||
from claude_code.reply import Limited
|
||||
from plan_store.jira_epic import number
|
||||
from do_epic import ranking, repo_pick, repos, split
|
||||
from model_routing.ladder_file import read_ladder, SHIPPED
|
||||
from model_routing.ladder import Rung
|
||||
from do_epic.scheduler import STATE
|
||||
from plan_store.scoring import weighing_texts
|
||||
|
||||
# The epic's formula, stated under its `## Scoring` as a todo.md states its own.
|
||||
FORMULA = re.compile(r"^`Score = ([^`]+)`$", re.M)
|
||||
# An epic item has no release, and ranking wants every item of one epic in the same one.
|
||||
NO_RELEASE = (0, 0, 0)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Planned:
|
||||
"""The epic whose open issues are planned."""
|
||||
key: str
|
||||
config: DoEpicConfig
|
||||
store: EpicStore
|
||||
record: EpicRecord
|
||||
home: pathlib.Path
|
||||
effects: Effects
|
||||
|
||||
|
||||
def planned(epic: Planned, issues: list[EpicIssue]) -> tuple[list[EpicIssue], Failure | Limited | None]:
|
||||
"""The epic's issues as far as they are planned, and why the planning stopped early, None where it didn't. issues are the epic's, as just read.
|
||||
|
||||
Each open child issue that no label places is split or gets its pick. Then the issues do-epic filed are re-ranked. What was labelled, filed or ranked before a Failure or a Limited stays, and the issues returned show it."""
|
||||
unplaced = [issue for issue in issues if issue.parent == epic.key and not issue.done and split.SPLIT_LABEL not in issue.labels and repo_pick.recorded(issue) is None]
|
||||
added: dict[str, str] = {}
|
||||
stopped = placed(epic, issues, unplaced, added) if unplaced else None
|
||||
if added:
|
||||
read = epic.store.read()
|
||||
# A search may not show a label added a moment ago, so each label added here counts whatever the read says. A sub-task the search doesn't show yet starts on the next run.
|
||||
issues = [labelled(each, added.get(each.key)) for each in (issues if isinstance(read, Failure) else read)]
|
||||
stopped = stopped or (read if isinstance(read, Failure) else None)
|
||||
if stopped is not None:
|
||||
return issues, stopped
|
||||
order = ranked_keys(epic, issues)
|
||||
if isinstance(order, Failure):
|
||||
return issues, order
|
||||
if [issue.key for issue in issues if issue.key in order] == order:
|
||||
return issues, None
|
||||
say(f"re-ranking the issues do-epic filed in {epic.key}'s backlog", epic.effects, stdout=True)
|
||||
refused = ranking.reranked(epic.store, order)
|
||||
if refused:
|
||||
return issues, refused
|
||||
# A search may not show the new order yet, so the issues are put in it here, as `reranked` put them in Jira: each ranked issue in a position a ranked issue held.
|
||||
by_key, ranked = {issue.key: issue for issue in issues}, iter(order)
|
||||
return [by_key[next(ranked)] if issue.key in order else issue for issue in issues], None
|
||||
|
||||
|
||||
def labelled(issue: EpicIssue, label: str | None) -> EpicIssue:
|
||||
"""issue with label among its labels; issue itself where label is None."""
|
||||
return issue if label is None or label in issue.labels else dataclasses.replace(issue, labels=tuple(sorted((*issue.labels, label))))
|
||||
|
||||
|
||||
def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue], added: dict[str, str]) -> None | Failure | Limited:
|
||||
"""Splits each of unplaced by repo, or labels it with its pick, and notes in added the label each got, by its key. An issue that claude or the tracker fails on is named and left for the next run, as is one whose question the human doesn't answer; a usage limit ends the planning."""
|
||||
rung = planning_rung(epic.config.repoless_model)
|
||||
language = epic.record.language()
|
||||
# Claude reads every repo a label of the epic names, a finished issue's too, to predict which of them an issue changes.
|
||||
places = located(epic, [repo for issue in issues if isinstance(repo := repo_pick.recorded(issue), repo_pick.Repo)])
|
||||
if failed := next((each for each in (rung, language, places) if isinstance(each, Failure)), None):
|
||||
return failed
|
||||
assert isinstance(rung, Rung) and not isinstance(language, Failure) and isinstance(places, dict)
|
||||
folder = epic.home / STATE / epic.key
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
checkouts = tuple(str(place.checkout) for place in places.values())
|
||||
for issue in unplaced:
|
||||
say(f"planning {issue.key}", epic.effects, stdout=True)
|
||||
parts = split.split(epic.store, issue, not issue.by_loop, epic.config.repo_rule, language or epic.config.language, checkouts, rung, epic.effects.claude, str(folder))
|
||||
if isinstance(parts, split.Split) and parts.repos:
|
||||
added[issue.key] = split.SPLIT_LABEL
|
||||
say(f"{issue.key} is split into a sub-task for each of {', '.join(parts.repos)}", epic.effects, stdout=True)
|
||||
continue
|
||||
pick: repo_pick.Pick | repo_pick.Unclear | Failure | Limited | None = parts if not isinstance(parts, split.Split) else repo_pick.picked(epic.store, issue, epic.config.repo_rule, rung, epic.effects.claude, str(folder))
|
||||
if isinstance(pick, repo_pick.Unclear):
|
||||
pick = answered(epic, issue, pick.question)
|
||||
if isinstance(pick, Limited):
|
||||
return pick
|
||||
if isinstance(pick, Failure):
|
||||
say(f"{issue.key} is not planned: {pick.reason}", epic.effects, stdout=True)
|
||||
elif pick is not None and not isinstance(pick, repo_pick.Unclear):
|
||||
added[issue.key] = repo_pick.label_of(pick)
|
||||
say(f"{issue.key} is labelled {added[issue.key]}", epic.effects, stdout=True)
|
||||
return None
|
||||
|
||||
|
||||
def planning_rung(model: str) -> Rung | Failure:
|
||||
"""The rung each planning call runs on: the model's cheapest on the shipped ladder."""
|
||||
ladder = read_ladder(SHIPPED)
|
||||
if isinstance(ladder, Failure):
|
||||
return ladder
|
||||
project = ladder.project_rung(model)
|
||||
return project.rung if project else Failure(f"`repoless-model` names {model}, which is not on the routing ladder {SHIPPED}")
|
||||
|
||||
|
||||
def answered(epic: Planned, issue: EpicIssue, question: str) -> repo_pick.Pick | None | Failure:
|
||||
"""The pick the human types for an issue the repo rule leaves unclear, once it is recorded; None where nobody is at a terminal to answer, or the human answers with Enter alone, so the issue waits for the next run. The answer is the label to give the issue, so that it is spelt as a person would spell it in Jira.
|
||||
|
||||
A repo's name is not checked against the repos do-epic knows: an epic's first issue in a repo names one it has not seen."""
|
||||
if not epic.effects.on_terminal():
|
||||
say(f"{issue.key} waits for your answer: {question} Run `do-epic {epic.key}` on a terminal to answer, or label the issue in Jira.", epic.effects, stdout=True)
|
||||
return None
|
||||
say(f"\n{issue.key}, {issue.summary}: {question}", epic.effects)
|
||||
while True:
|
||||
try:
|
||||
typed = epic.effects.input(f"The label that says where {issue.key} is worked, `{repo_pick.REPO_PREFIX}<name>`, `{repo_pick.CLAUDE_LABEL}` or `{repo_pick.HUMAN_LABEL}`, or Enter alone to leave it waiting: ")
|
||||
except EOFError:
|
||||
return None
|
||||
label = typed.strip()
|
||||
if not label:
|
||||
return None
|
||||
pick = repo_pick.of_label(label)
|
||||
if pick is not None:
|
||||
return repo_pick.record(epic.store, issue, pick)
|
||||
named = f"; the repo {label}'s label is `{repo_pick.REPO_PREFIX}{label}`" if repo_pick.of_label(repo_pick.REPO_PREFIX + label) else ""
|
||||
say(f"`{label}` is none of those labels{named}", epic.effects)
|
||||
|
||||
|
||||
def located(epic: Planned, picks: list[repo_pick.Repo]) -> dict[str, repos.Located] | Failure:
|
||||
"""Each picked repo's checkout and project config, by the repo's name."""
|
||||
places: dict[str, repos.Located] = {}
|
||||
for name in sorted({pick.name for pick in picks}):
|
||||
place = repos.locate(name, [each.checkout for each in places.values()], epic.config, epic.home, epic.effects.git)
|
||||
if isinstance(place, Failure):
|
||||
return place
|
||||
places[name] = place
|
||||
return places
|
||||
|
||||
|
||||
def ranked_keys(epic: Planned, issues: list[EpicIssue]) -> list[str] | Failure:
|
||||
"""The keys of the open child issues do-epic filed that hold scores and one pick, in the order ranking gives them; empty where fewer than two do, since one issue has no order.
|
||||
|
||||
Every other issue keeps its position: a person's issue, one nobody scored, one with no pick yet or with two, and an item split by repo, since several repos' goals would score it."""
|
||||
ours = [issue for issue in issues if issue.parent == epic.key and issue.by_loop and not issue.done and split.SPLIT_LABEL not in issue.labels and (pick := repo_pick.recorded(issue)) is not None and not isinstance(pick, Failure) and not ranking.unscored(item_of(issue, {}), issue.key)]
|
||||
if len(ours) < 2:
|
||||
return []
|
||||
numbers = {issue.key: number(issue.key) for issue in ours}
|
||||
keys = {id_: key for key, id_ in numbers.items()}
|
||||
if clash := next(((key, keys[id_]) for key, id_ in numbers.items() if keys[id_] != key), None):
|
||||
return Failure(f"{clash[0]} and {clash[1]} share a number in different Jira projects, so the issues do-epic filed in the epic {epic.key} cannot be ranked; move one of the two to the other's Jira project")
|
||||
scoring, goals = epic.record.section("Scoring"), epic.record.section("Goals")
|
||||
if failed := next((each for each in (scoring, goals) if isinstance(each, Failure)), None):
|
||||
return Failure(f"the epic {epic.key}'s description: {failed.reason}")
|
||||
assert isinstance(scoring, str) and isinstance(goals, str)
|
||||
formulas = FORMULA.findall(scoring)
|
||||
if len(formulas) != 1:
|
||||
return Failure(f"the epic {epic.key}'s description states `Score = ...` {len(formulas)} times under ## Scoring; state the formula that ranks its issues once, on a line of its own and inside backticks, such as `Score = 100 * V / (2**S + 32)`")
|
||||
picks = {issue.key: repo_pick.recorded(issue) for issue in ours}
|
||||
places = located(epic, [pick for pick in picks.values() if isinstance(pick, repo_pick.Repo)])
|
||||
if isinstance(places, Failure):
|
||||
return places
|
||||
rankings: dict[str, ranking.RepoRanking] = {}
|
||||
for name, place in places.items():
|
||||
texts = weighing_texts(goals_store(place.config), record_store(place.config, "decisions"), record_store(place.config, "comprehension-history"))
|
||||
if isinstance(texts, Failure):
|
||||
return Failure(f"{name}: {texts.reason}")
|
||||
rankings[name] = ranking.RepoRanking(*texts, place.config.readability_floor)
|
||||
items = [ranking.EpicItem(item_of(issue, numbers), pick.name if isinstance(pick := picks[issue.key], repo_pick.Repo) else None) for issue in ours]
|
||||
scored = ranking.ranked(items, formulas[0], goals, rankings)
|
||||
return scored if isinstance(scored, Failure) else [keys[item.id] for item, _ in scored]
|
||||
|
||||
|
||||
def item_of(issue: EpicIssue, numbers: dict[str, int]) -> Item:
|
||||
"""The issue as ranking scores it. numbers holds the number of each issue ranked with it, by key; the item is blocked by those of them that block the issue."""
|
||||
return Item(numbers.get(issue.key, 0), NO_RELEASE, issue.exempt, issue.summary, issue.scores, issue.moves, tuple(sorted(numbers[key] for key in issue.blockers if key in numbers)))
|
||||
@@ -84,14 +84,14 @@ def split(store: EpicStore, issue: EpicIssue, by_person: bool, rule: str, langua
|
||||
continue
|
||||
key = store.file(issue.key, task_summary(part.repo, issue.summary), part.change, (label_of(Repo(part.repo)),))
|
||||
if isinstance(key, Failure):
|
||||
return Failure(f"cannot file the sub-task for {part.repo} under {issue.key}: {key.reason}; {sub_tasks_filed(filed)}; run split again to file the rest")
|
||||
return Failure(f"cannot file the sub-task for {part.repo} under {issue.key}: {key.reason}; {sub_tasks_filed(filed)}; run do-epic again to file the rest")
|
||||
filed.append(key)
|
||||
posted = store.comment(issue.key, predicted.comment) if by_person else None
|
||||
if isinstance(posted, Failure):
|
||||
return Failure(f"cannot comment on {issue.key}: {posted.reason}; {sub_tasks_filed(filed)}; run split again to post it")
|
||||
return Failure(f"cannot comment on {issue.key}: {posted.reason}; {sub_tasks_filed(filed)}; run do-epic again to post it")
|
||||
marked = store.add_label(issue.key, SPLIT_LABEL)
|
||||
if isinstance(marked, Failure):
|
||||
return Failure(f"cannot mark {issue.key} as split: {marked.reason}; {sub_tasks_filed(filed)}; run split again to mark it")
|
||||
return Failure(f"cannot mark {issue.key} as split: {marked.reason}; {sub_tasks_filed(filed)}; run do-epic again to mark it")
|
||||
return Split(repos, tuple(filed))
|
||||
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class FindingsTest(DoEpicTest):
|
||||
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((code, out, err), (0, "Filed ABC-102 in the epic ABC-12. It has no label that says where it is worked, so the next `do-epic ABC-12` picks one: `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's.\n", ""))
|
||||
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))
|
||||
@@ -88,7 +88,7 @@ class FilingAFinding(FindingsTest):
|
||||
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"))
|
||||
self.assertEqual((code, out), (0, f"Filed {self.store.issues[-1].key} in the epic ABC-12. It has no label that says where it is worked, so the next `do-epic ABC-12` picks one: `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's.\n"))
|
||||
|
||||
def test_refuses_a_label_the_scheduler_doesnt_read(self) -> None:
|
||||
for label in ("api", "repo:", "repo:a b"):
|
||||
|
||||
@@ -168,7 +168,7 @@ class TheFinishingChunk(DoEpicTest):
|
||||
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")], []):
|
||||
for issues in ([issue("ABC-20", "do-epic-claude", done=True), issue("ABC-21", "do-epic-human")], []):
|
||||
self.issues = issues
|
||||
fake = FakeEffects(on_terminal=False)
|
||||
code, out, _ = self.run_main(["ABC-12"], fake)
|
||||
|
||||
@@ -34,6 +34,11 @@ from do_epic.test_do_epic import SETTINGS
|
||||
DESCRIPTION = "**Max parallel chunks:** 2\n\n## Goals\nShip the import.\n\n## Audience\nThe client's team.\n"
|
||||
|
||||
|
||||
def structured(output: object, key: str | None = "structured_output") -> subprocess.CompletedProcess[str]:
|
||||
"""claude's reply that holds output as its structured answer. Where key is None, output is the whole result event."""
|
||||
return subprocess.CompletedProcess([], 0, json.dumps({"type": "result", key: output} if key else output), "")
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Description:
|
||||
"""Stands in for an epic's description in Jira."""
|
||||
@@ -52,7 +57,7 @@ class DoEpicTest(unittest.TestCase):
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "config.toml").write_text(SETTINGS, encoding="utf-8")
|
||||
(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.issues = [issue("ABC-20", "do-epic-human"), 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")]
|
||||
@@ -126,12 +131,35 @@ class TheCommand(DoEpicTest):
|
||||
code, out, _ = self.run_main(["ABC-12"], fake, {"LOOP_CLAUDE_WORKER_MODEL": "m"})
|
||||
self.assertEqual(code, 0)
|
||||
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)
|
||||
self.assertIn("ABC-20 waits: it is a human's task\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", "-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"])
|
||||
|
||||
def test_plans_an_issue_no_label_places_before_it_starts_the_chunks(self) -> None:
|
||||
self.issues = [issue("ABC-20")]
|
||||
fake = FakeEffects(on_terminal=False, claude=[structured({"parts": []}), structured({"pick": "claude"})])
|
||||
code, out, err = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertLess(out.index("ABC-20 is labelled do-epic-claude\n"), out.index("started ABC-20 in the tmux session epic-ABC-12\n"))
|
||||
|
||||
def test_starts_no_chunk_where_a_usage_limit_ends_the_planning(self) -> None:
|
||||
self.issues.append(issue("ABC-22"))
|
||||
limit = {"type": "result", "is_error": True, "api_error_status": 429, "result": "You've hit your limit"}
|
||||
fake = FakeEffects(claude=[structured(limit, None)])
|
||||
code, _, err = self.run_main(["ABC-12"], fake)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("the epic is not planned, so no chunk started: You've hit your limit\n", err)
|
||||
self.assertEqual([args for args in fake.tmux_calls if args[0] == "new-session"], [])
|
||||
|
||||
def test_says_why_the_epic_is_not_planned_in_full_and_starts_the_chunks_that_may_start(self) -> None:
|
||||
self.issues = [dataclasses.replace(issue(key, "do-epic-claude"), scores={"L": 1, "E": 1, "I": 1, "S": 1}, by_loop=True) for key in ("ABC-20", "ABC-21")]
|
||||
code, out, err = self.run_main(["ABC-12"], FakeEffects())
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("the epic ABC-12 is not planned in full: the epic ABC-12's description states `Score = ...` 0 times under ## Scoring", err)
|
||||
self.assertIn("started ABC-20, ABC-21 in the tmux session epic-ABC-12\n", out)
|
||||
|
||||
def test_stops_on_an_epic_it_cannot_read(self) -> None:
|
||||
self.description = Failure("Jira answered 401")
|
||||
code, _, err = self.run_main(["ABC-12"], FakeEffects())
|
||||
@@ -298,6 +326,15 @@ class TheHumansRun(DoEpicTest):
|
||||
|
||||
class AChunksRun(DoEpicTest):
|
||||
|
||||
def test_a_finished_chunk_starts_the_next_without_planning_again(self) -> None:
|
||||
self.issues.append(issue("ABC-22"))
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows="ABC-21\t0\t@9\n")
|
||||
code, out, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("the chunk finished; started no other\n", out)
|
||||
# The one claude call is the judge's: ABC-22, which no label places, waits for the human's do-epic.
|
||||
self.assertEqual(len(fake.made("claude")), 1)
|
||||
|
||||
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"))
|
||||
self.description = DESCRIPTION.replace("2", "1")
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import io
|
||||
import json
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from project_config.test_project_config import configured
|
||||
from do_epic.test_main import Description, DoEpicTest, structured as says
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from failure import Failure
|
||||
from loop_claude.test_loop_claude import FakeEffects
|
||||
from do_epic.test_scheduler import issue
|
||||
from claude_code.reply import Limited
|
||||
from do_epic.config import load
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from plan.todo_table import parse_moves
|
||||
from do_epic import planning
|
||||
|
||||
RANKED = "## Goals\n1. **Achieve:** Ship the import.\n\n## Audience\nThe client's team.\n\n## Scoring\n`Score = V`\n"
|
||||
LIMIT = {"type": "result", "is_error": True, "api_error_status": 429, "result": "You've hit your limit"}
|
||||
|
||||
|
||||
def scored(key: str, moves: str, *labels: str, blockers: tuple[str, ...] = (), by_loop: bool = True) -> EpicIssue:
|
||||
"""An open issue the loop filed, holding scores and moving the goals moves names."""
|
||||
parsed = parse_moves(key, moves)
|
||||
assert not isinstance(parsed, Failure), parsed
|
||||
return dataclasses.replace(issue(key, *labels, blockers=blockers), scores={"L": 1, "E": 1, "I": 1, "S": 1}, moves=parsed, by_loop=by_loop)
|
||||
|
||||
|
||||
class Planning(DoEpicTest):
|
||||
def plan(self, fake: FakeEffects) -> tuple[list[EpicIssue] | Failure | Limited, MemoryEpic, str]:
|
||||
"""What planning answers for self.issues, the store it changed and what it printed on stdout. self.asked holds what it asked the human, on stderr."""
|
||||
config = load(self.home)
|
||||
assert not isinstance(config, Failure), config
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, fake.effects()) # type: ignore[arg-type]
|
||||
out, self.asked = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(self.asked):
|
||||
read = store.read()
|
||||
assert not isinstance(read, Failure)
|
||||
issues, stopped = planning.planned(epic, read)
|
||||
return issues if stopped is None else stopped, store, out.getvalue()
|
||||
|
||||
def labels(self, store: MemoryEpic) -> dict[str, tuple[str, ...]]:
|
||||
return {each.key: each.labels for each in store.issues}
|
||||
|
||||
def test_an_issue_a_label_places_is_planned_without_claude(self) -> None:
|
||||
self.issues = [issue("ABC-20", "repo:api"), issue("ABC-21", "do-epic-claude"), issue("ABC-22", "split-by-repo"), issue("ABC-23", done=True)]
|
||||
fake = FakeEffects()
|
||||
found, _, out = self.plan(fake)
|
||||
self.assertEqual((found, out, fake.made("claude")), (self.issues, "", []))
|
||||
|
||||
def test_labels_an_unplaced_issue_with_the_repo_claude_picks_on_the_repoless_models_rung(self) -> None:
|
||||
self.issues = [issue("ABC-20")]
|
||||
fake = FakeEffects(claude=[says({"parts": [{"repo": "api", "change": "Add the endpoint."}]}), says({"pick": "repo", "repo": "api"})])
|
||||
found, store, out = self.plan(fake)
|
||||
self.assertEqual(found, [issue("ABC-20", "repo:api")])
|
||||
self.assertEqual(self.labels(store), {"ABC-20": ("repo:api",)})
|
||||
self.assertIn("planning ABC-20\n", out)
|
||||
self.assertIn("ABC-20 is labelled repo:api\n", out)
|
||||
for args, _ in fake.made("claude"):
|
||||
self.assertEqual(args[args.index("--model") + 1], "claude-opus-5-5")
|
||||
self.assertIn("A label that equals a repo's name names that repo.", fake.made("claude")[1][1])
|
||||
|
||||
def test_labels_work_without_a_repo_as_claudes_or_a_humans(self) -> None:
|
||||
for pick, label in (("claude", "do-epic-claude"), ("human", "do-epic-human")):
|
||||
with self.subTest(pick=pick):
|
||||
self.issues = [issue("ABC-20")]
|
||||
_, store, _ = self.plan(FakeEffects(claude=[says({"parts": []}), says({"pick": pick})]))
|
||||
self.assertEqual(self.labels(store), {"ABC-20": (label,)})
|
||||
|
||||
def test_splits_an_issue_that_changes_several_repos_into_a_sub_task_for_each_and_picks_no_repo_for_it(self) -> None:
|
||||
self.issues = [issue("ABC-20")]
|
||||
fake = FakeEffects(claude=[says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."})])
|
||||
found, store, out = self.plan(fake)
|
||||
assert not isinstance(found, Failure | Limited), found
|
||||
self.assertEqual([(each.key, each.parent, each.labels) for each in found], [("ABC-20", "ABC-12", ("split-by-repo",)), ("ABC-101", "ABC-20", ("repo:api",)), ("ABC-102", "ABC-20", ("repo:web",))])
|
||||
# A person filed ABC-20, so the team is told.
|
||||
self.assertEqual(store.comments, {"ABC-20": ["Split by repo: api and web."]})
|
||||
self.assertIn("ABC-20 is split into a sub-task for each of api, web\n", out)
|
||||
self.assertIn("in English, that tells the team why it is split by repo", fake.made("claude")[0][1])
|
||||
|
||||
def test_plans_the_issue_after_one_that_is_split(self) -> None:
|
||||
self.issues = [issue("ABC-20"), issue("ABC-21")]
|
||||
parts = says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."})
|
||||
_, store, _ = self.plan(FakeEffects(claude=[parts, says({"parts": []}), says({"pick": "human"})]))
|
||||
self.assertEqual(self.labels(store)["ABC-21"], ("do-epic-human",))
|
||||
|
||||
def test_writes_to_the_team_in_the_epics_language(self) -> None:
|
||||
self.description = "**Language:** Swedish\n"
|
||||
self.issues = [issue("ABC-20")]
|
||||
fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})])
|
||||
self.plan(fake)
|
||||
self.assertIn("in Swedish, that tells the team why it is split by repo", fake.made("claude")[0][1])
|
||||
|
||||
def test_each_claude_call_runs_in_the_epics_state_folder(self) -> None:
|
||||
self.issues = [issue("ABC-20")]
|
||||
fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})])
|
||||
effects, folders = fake.effects(), []
|
||||
|
||||
def claude(args: object, cwd: str, stdin: object) -> object:
|
||||
folders.append(cwd)
|
||||
return effects.claude(args, cwd, stdin) # type: ignore[arg-type]
|
||||
config = load(self.home)
|
||||
epic = planning.Planned("ABC-12", config, MemoryEpic("ABC-12", list(self.issues)), EpicRecord(Description("")), self.home, dataclasses.replace(effects, claude=claude)) # type: ignore[arg-type]
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
planning.planned(epic, list(self.issues))
|
||||
folder = self.home / ".local" / "state" / "do-epic" / "ABC-12"
|
||||
self.assertEqual((folders, folder.is_dir()), ([str(folder)] * 2, True))
|
||||
|
||||
def test_a_model_off_the_routing_ladder_has_no_rung(self) -> None:
|
||||
found = planning.planning_rung("claude-nope-1")
|
||||
assert isinstance(found, Failure), found
|
||||
self.assertIn("`repoless-model` names claude-nope-1, which is not on the routing ladder ", found.reason)
|
||||
|
||||
def test_fails_where_a_labelled_repo_has_no_checkout_to_read(self) -> None:
|
||||
self.issues = [issue("ABC-19", "repo:ghost"), issue("ABC-20")]
|
||||
fake = FakeEffects()
|
||||
found, _, _ = self.plan(fake)
|
||||
assert isinstance(found, Failure), found
|
||||
self.assertIn("ghost", found.reason)
|
||||
self.assertEqual(fake.made("claude"), [])
|
||||
|
||||
def test_the_split_reads_the_checkout_of_each_repo_a_label_of_the_epic_names(self) -> None:
|
||||
checkout = self.home / "code" / "api"
|
||||
configured(self, checkout, home=self.home)
|
||||
self.issues = [issue("ABC-19", "repo:api", done=True), issue("ABC-20")]
|
||||
fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})])
|
||||
self.plan(fake)
|
||||
args = fake.made("claude")[0][0]
|
||||
self.assertEqual(args[args.index("--add-dir") + 1], str(checkout))
|
||||
|
||||
def test_asks_the_human_for_the_label_of_an_issue_the_rule_leaves_unclear_until_one_is_typed(self) -> None:
|
||||
self.issues = [issue("ABC-20")]
|
||||
fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "unclear", "question": "Is the importer in api or in web?"})], inputs=["api", "a b", " repo:web "])
|
||||
found, store, out = self.plan(fake)
|
||||
self.assertEqual(found, [issue("ABC-20", "repo:web")])
|
||||
self.assertIn("ABC-20, Do ABC-20: Is the importer in api or in web?\n", self.asked.getvalue())
|
||||
self.assertIn("`api` is none of those labels; the repo api's label is `repo:api`\n", self.asked.getvalue())
|
||||
self.assertIn("`a b` is none of those labels\n", self.asked.getvalue())
|
||||
self.assertEqual(fake.made("input"), ["The label that says where ABC-20 is worked, `repo:<name>`, `do-epic-claude` or `do-epic-human`, or Enter alone to leave it waiting: "] * 3)
|
||||
|
||||
def unclear_then_claudes(self, **fake: object) -> tuple[dict[str, tuple[str, ...]], str]:
|
||||
"""The labels and the output after planning ABC-20, which the rule leaves unclear, and ABC-21, which is Claude's, on a FakeEffects made with fake."""
|
||||
self.issues = [issue("ABC-20"), issue("ABC-21")]
|
||||
unclear = says({"pick": "unclear", "question": "Is the importer in api or in web?"})
|
||||
_, store, out = self.plan(FakeEffects(claude=[says({"parts": []}), unclear, says({"parts": []}), says({"pick": "claude"})], **fake)) # type: ignore[arg-type]
|
||||
return self.labels(store), out
|
||||
|
||||
def test_an_unclear_issue_waits_off_a_terminal_and_the_next_is_planned(self) -> None:
|
||||
labels, out = self.unclear_then_claudes(on_terminal=False)
|
||||
self.assertEqual(labels, {"ABC-20": (), "ABC-21": ("do-epic-claude",)})
|
||||
self.assertNotIn("ABC-20 is labelled", out)
|
||||
self.assertIn("ABC-20 waits for your answer: Is the importer in api or in web? Run `do-epic ABC-12` on a terminal to answer, or label the issue in Jira.\n", out)
|
||||
|
||||
def test_an_unclear_issue_waits_where_the_human_answers_with_enter_alone(self) -> None:
|
||||
labels, out = self.unclear_then_claudes(inputs=[" "])
|
||||
self.assertEqual((labels, "ABC-20 is labelled" in out), ({"ABC-20": (), "ABC-21": ("do-epic-claude",)}, False))
|
||||
|
||||
def test_an_unclear_issue_waits_where_the_terminals_input_ends(self) -> None:
|
||||
labels, out = self.unclear_then_claudes(inputs=[EOFError()])
|
||||
self.assertEqual((labels, "ABC-20 is labelled" in out), ({"ABC-20": (), "ABC-21": ("do-epic-claude",)}, False))
|
||||
|
||||
def test_clones_a_labelled_repo_without_a_checkout_beside_the_origin_of_the_others(self) -> None:
|
||||
configured(self, self.home / "code" / "api", home=self.home)
|
||||
configured(self, self.home / "code" / "web", home=self.home)
|
||||
shutil.rmtree(self.home / "code" / "web")
|
||||
self.issues = [issue("ABC-18", "repo:api", done=True), issue("ABC-19", "repo:web", done=True), issue("ABC-20")]
|
||||
fake = FakeEffects(git=["https://git.example/acme/api.git\n", ""], claude=[says({"parts": []}), says({"pick": "claude"})])
|
||||
self.plan(fake)
|
||||
origin, clone = fake.made("git")
|
||||
self.assertEqual((origin, clone[-4:]), (["remote", "get-url", "origin"], ["clone", "--", "https://git.example/acme/web", str(self.home / "code" / "web")]))
|
||||
|
||||
def health_first(self, floor: str) -> list[str]:
|
||||
"""The order of ABC-20, which moves the epic's goal by 9, and ABC-21, which moves code health by 3 in a repo that scored 7.5 and whose config ends with the line floor."""
|
||||
checkout = self.home / "code" / "api"
|
||||
folder = configured(self, checkout, home=self.home)
|
||||
with (folder / "config.toml").open("a", encoding="utf-8") as config:
|
||||
config.write(floor)
|
||||
(checkout / "README.md").write_text("## Goals\n\n1. **Achieve:** Serve the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
|
||||
(checkout / "docs").mkdir()
|
||||
(checkout / "docs" / "comprehension-history.md").write_text("# Comprehension history\n\n## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mid A | 6 |\n| Mean | 7.5 |\n", encoding="utf-8")
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 9", "do-epic-claude"), scored("ABC-21", "code health by 3", "repo:api")]
|
||||
found = self.plan(FakeEffects())[0]
|
||||
assert not isinstance(found, Failure | Limited), found
|
||||
return [each.key for each in found]
|
||||
|
||||
def test_code_health_weighs_four_times_in_a_repo_under_the_floor_its_config_sets(self) -> None:
|
||||
# 4 * 3 * 0.97 is above the 9 of the epic's first goal.
|
||||
self.assertEqual(self.health_first("readability-floor = 8.0\n"), ["ABC-21", "ABC-20"])
|
||||
|
||||
def test_code_health_weighs_once_in_a_repo_at_its_floor(self) -> None:
|
||||
# 3 * 0.97 is under the 9 of the epic's first goal.
|
||||
self.assertEqual(self.health_first(""), ["ABC-20", "ABC-21"])
|
||||
|
||||
def test_an_issue_claude_fails_on_is_named_and_the_next_is_planned(self) -> None:
|
||||
self.issues = [issue("ABC-20"), issue("ABC-21")]
|
||||
fake = FakeEffects(claude=[subprocess.CompletedProcess([], 1, "", ""), says({"parts": []}), says({"pick": "claude"})])
|
||||
_, store, out = self.plan(fake)
|
||||
self.assertEqual(self.labels(store), {"ABC-20": (), "ABC-21": ("do-epic-claude",)})
|
||||
self.assertIn("ABC-20 is not planned: the repo split exited 1\n", out)
|
||||
|
||||
def test_a_usage_limit_ends_the_planning(self) -> None:
|
||||
self.issues = [issue("ABC-20"), issue("ABC-21")]
|
||||
fake = FakeEffects(claude=[subprocess.CompletedProcess([], 0, json.dumps(LIMIT), "")])
|
||||
found, _, _ = self.plan(fake)
|
||||
self.assertIsInstance(found, Limited)
|
||||
self.assertEqual(len(fake.made("claude")), 1)
|
||||
|
||||
def test_re_ranks_the_loops_scored_issues_by_score_with_a_blocker_first_and_leaves_every_other_issue_in_place(self) -> None:
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude", by_loop=False), scored("ABC-22", "epic 1 by 5", "do-epic-claude", blockers=("ABC-24",)), dataclasses.replace(issue("ABC-23", "do-epic-claude"), by_loop=True), scored("ABC-24", "epic 1 by 3", "do-epic-claude")]
|
||||
found, store, out = self.plan(FakeEffects())
|
||||
assert not isinstance(found, Failure | Limited), found
|
||||
# ABC-22 scores highest, and ABC-24 blocks it. ABC-21 is a person's, and nobody scored ABC-23.
|
||||
self.assertEqual([each.key for each in found], ["ABC-24", "ABC-21", "ABC-22", "ABC-23", "ABC-20"])
|
||||
self.assertIn("re-ranking the issues do-epic filed in ABC-12's backlog\n", out)
|
||||
|
||||
def test_ranks_an_issue_in_a_repo_by_that_repos_goals_after_the_epics(self) -> None:
|
||||
checkout = self.home / "code" / "api"
|
||||
configured(self, checkout, home=self.home)
|
||||
(checkout / "README.md").write_text("## Goals\n\n**Void:** code health, since it is a one-off script.\n\n1. **Achieve:** Serve the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "repo 1 by 9", "repo:api"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
|
||||
found, _, _ = self.plan(FakeEffects())
|
||||
assert not isinstance(found, Failure | Limited), found
|
||||
self.assertEqual([each.key for each in found], ["ABC-21", "ABC-20"])
|
||||
|
||||
def test_issues_already_in_their_order_are_not_ranked_again(self) -> None:
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 9", "do-epic-claude"), scored("ABC-21", "epic 1 by 2", "do-epic-claude")]
|
||||
found, _, out = self.plan(FakeEffects())
|
||||
self.assertEqual((found, out), (self.issues, ""))
|
||||
|
||||
def test_fails_where_the_epic_states_no_formula_to_rank_two_scored_issues_by(self) -> None:
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
|
||||
found, store, _ = self.plan(FakeEffects())
|
||||
self.assertEqual(found, Failure("the epic ABC-12's description states `Score = ...` 0 times under ## Scoring; state the formula that ranks its issues once, on a line of its own and inside backticks, such as `Score = 100 * V / (2**S + 32)`"))
|
||||
self.assertEqual([each.key for each in store.issues], ["ABC-20", "ABC-21"])
|
||||
|
||||
def test_fails_where_the_formula_names_a_score_no_issue_holds(self) -> None:
|
||||
self.description = RANKED.replace("Score = V", "Score = Q")
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
|
||||
self.assertIsInstance(self.plan(FakeEffects())[0], Failure)
|
||||
|
||||
def test_fails_where_two_issues_to_rank_share_a_number(self) -> None:
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("XYZ-20", "epic 1 by 9", "do-epic-claude")]
|
||||
self.assertEqual(self.plan(FakeEffects())[0], Failure("ABC-20 and XYZ-20 share a number in different Jira projects, so the issues do-epic filed in the epic ABC-12 cannot be ranked; move one of the two to the other's Jira project"))
|
||||
|
||||
def test_fails_where_the_description_cannot_be_read_to_rank_by(self) -> None:
|
||||
self.description = Failure("Jira answered 503")
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
|
||||
self.assertEqual(self.plan(FakeEffects())[0], Failure("the epic ABC-12's description: Jira answered 503"))
|
||||
|
||||
def test_fails_naming_the_repo_whose_goals_cannot_be_read(self) -> None:
|
||||
checkout = self.home / "code" / "api"
|
||||
configured(self, checkout, home=self.home)
|
||||
(checkout / "README.md").unlink(missing_ok=True)
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "repo 1 by 9", "repo:api"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
|
||||
found = self.plan(FakeEffects())[0]
|
||||
assert isinstance(found, Failure), found
|
||||
self.assertRegex(found.reason, r"^api: .*missing or empty")
|
||||
|
||||
def test_ranks_a_security_issue_first(self) -> None:
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 9", "do-epic-claude"), dataclasses.replace(scored("ABC-21", "epic 1 by 2", "do-epic-claude"), exempt="security")]
|
||||
found = self.plan(FakeEffects())[0]
|
||||
assert not isinstance(found, Failure | Limited), found
|
||||
self.assertEqual([each.key for each in found], ["ABC-21", "ABC-20"])
|
||||
|
||||
def test_one_scored_issue_needs_no_formula(self) -> None:
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), issue("ABC-21", "do-epic-claude")]
|
||||
self.assertEqual(self.plan(FakeEffects())[0], self.issues)
|
||||
|
||||
def planned_on(self, store: MemoryEpic, fake: FakeEffects) -> tuple[list[EpicIssue], Failure | Limited | None]:
|
||||
"""What planning answers for self.issues on a store that doesn't read as MemoryEpic does."""
|
||||
config = load(self.home)
|
||||
assert not isinstance(config, Failure), config
|
||||
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, fake.effects()) # type: ignore[arg-type]
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
return planning.planned(epic, list(self.issues))
|
||||
|
||||
def test_a_label_it_added_counts_where_the_tracker_cannot_be_read_afterwards(self) -> None:
|
||||
self.issues = [issue("ABC-20")]
|
||||
found = self.planned_on(Unreadable("ABC-12", list(self.issues)), FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})]))
|
||||
self.assertEqual(found, ([issue("ABC-20", "do-epic-claude")], Failure("Jira answered 503")))
|
||||
|
||||
def test_a_label_and_an_order_it_wrote_count_where_the_trackers_search_lags(self) -> None:
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9"), issue("ABC-22")]
|
||||
parts = says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."})
|
||||
found, stopped = self.planned_on(Lagging("ABC-12", list(self.issues)), FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"}), parts]))
|
||||
self.assertEqual(([(each.key, each.labels) for each in found], stopped), ([("ABC-21", ("do-epic-claude",)), ("ABC-20", ("do-epic-claude",)), ("ABC-22", ("split-by-repo",))], None))
|
||||
|
||||
def test_keeps_the_order_and_says_why_where_the_tracker_refuses_the_ranking(self) -> None:
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")]
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
store.fails = "Jira answered 503"
|
||||
found, stopped = self.planned_on(store, FakeEffects())
|
||||
assert isinstance(stopped, Failure), stopped
|
||||
self.assertEqual(([each.key for each in found], "Jira answered 503" in stopped.reason), (["ABC-20", "ABC-21"], True))
|
||||
|
||||
def test_an_issue_without_a_pick_is_not_ranked(self) -> None:
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "code health by 9")]
|
||||
found, _, out = self.plan(FakeEffects(claude=[subprocess.CompletedProcess([], 1, "", "")]))
|
||||
self.assertEqual((found, "re-ranking" in out), (self.issues, False))
|
||||
|
||||
|
||||
class Unreadable(MemoryEpic):
|
||||
"""A tracker that fails each read once an issue is labelled."""
|
||||
def add_label(self, key: str, label: str) -> None | Failure:
|
||||
self.fails = "Jira answered 503"
|
||||
return None
|
||||
|
||||
|
||||
class Lagging(MemoryEpic):
|
||||
"""A tracker whose search shows the issues as they were before any write."""
|
||||
def read(self) -> list[EpicIssue] | Failure:
|
||||
return list(self.before)
|
||||
|
||||
def __init__(self, key: str, issues: list[EpicIssue]) -> None:
|
||||
super().__init__(key, issues)
|
||||
self.before = list(issues)
|
||||
@@ -322,7 +322,7 @@ class TheFirstPrompt(unittest.TestCase):
|
||||
def test_the_task_names_the_checkout_and_branch_and_quotes_a_description_only_where_there_is_one(self) -> None:
|
||||
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. "
|
||||
f"File a finding about one of the epic's goals in the epic, with `/b/do-epic ABC-12 --file \"<summary>\" --label <label>` and its detail on stdin. The label is {labels}; leave it out where you cannot tell, and the next `do-epic` the human runs picks it. "
|
||||
"Where filing fails and says the issue may exist, ask the human to look before you file it again. File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. "
|
||||
"Record a decision that governs the epic, such as an answer the human typed, with `/b/do-epic ABC-12 --record-decision \"<title>\"` and its text on stdin. Write the issue and the decision in Swedish, the epic's language."
|
||||
)
|
||||
|
||||
@@ -72,13 +72,13 @@ class Split_(unittest.TestCase):
|
||||
|
||||
def test_a_first_filing_that_fails_says_the_run_filed_no_sub_task(self) -> None:
|
||||
self.store.fails_files = True
|
||||
self.assertEqual(self.run_split(says(TWO)), Failure(f"cannot file the sub-task for api under {self.key}: Jira answered 500; this run filed no sub-task; run split again to file the rest"))
|
||||
self.assertEqual(self.run_split(says(TWO)), Failure(f"cannot file the sub-task for api under {self.key}: Jira answered 500; this run filed no sub-task; run do-epic again to file the rest"))
|
||||
|
||||
def test_a_comment_that_fails_leaves_the_item_unmarked_and_the_next_run_files_nothing_again(self) -> None:
|
||||
self.store.fails_comments = True
|
||||
failed = self.run_split(says(TWO), by_person=True)
|
||||
first, second = (task.key for task in self.tasks())
|
||||
self.assertEqual(failed, Failure(f"cannot comment on {self.key}: Jira answered 500; this run filed {first}, {second}; run split again to post it"))
|
||||
self.assertEqual(failed, Failure(f"cannot comment on {self.key}: Jira answered 500; this run filed {first}, {second}; run do-epic again to post it"))
|
||||
self.assertEqual(self.issue().labels, ("api",))
|
||||
self.store.fails_comments = False
|
||||
done = self.run_split(says(TWO), by_person=True)
|
||||
@@ -116,7 +116,7 @@ class Split_(unittest.TestCase):
|
||||
self.store.jammed = True
|
||||
failed = self.run_split(says(TWO), by_person=True)
|
||||
first = self.tasks()[0].key
|
||||
self.assertEqual(failed, Failure(f"cannot file the sub-task for web under {self.key}: Jira answered 500; this run filed {first}; run split again to file the rest"))
|
||||
self.assertEqual(failed, Failure(f"cannot file the sub-task for web under {self.key}: Jira answered 500; this run filed {first}; run do-epic again to file the rest"))
|
||||
self.assertEqual(self.issue().labels, ("api",))
|
||||
self.store.jammed = False
|
||||
done = self.run_split(says(TWO), by_person=True)
|
||||
@@ -176,7 +176,7 @@ class Split_(unittest.TestCase):
|
||||
self.store.add_label = lambda key, label: Failure("Jira answered 500") if label == SPLIT_LABEL else None # type: ignore[method-assign]
|
||||
failed = self.run_split(says(TWO))
|
||||
first, second = (task.key for task in self.tasks())
|
||||
self.assertEqual(failed, Failure(f"cannot mark {self.key} as split: Jira answered 500; this run filed {first}, {second}; run split again to mark it"))
|
||||
self.assertEqual(failed, Failure(f"cannot mark {self.key} as split: Jira answered 500; this run filed {first}, {second}; run do-epic again to mark it"))
|
||||
|
||||
def test_passes_on_a_failed_or_limited_claude(self) -> None:
|
||||
self.assertEqual(self.run_split(Claude("", 1)), Failure("the repo split exited 1"))
|
||||
|
||||
Reference in New Issue
Block a user