Answer stability round 1: 0 🔴, 5 🟡 (1 misread); start chunks after a partial planning and keep what planning wrote

This commit is contained in:
2026-11-19 04:46:55 +01:00
parent 999fca6f17
commit 0ce3cc6ac6
10 changed files with 192 additions and 84 deletions
+3 -3
View File
@@ -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)
+16 -11
View File
@@ -1,6 +1,6 @@
"""The do-epic command (docs/decisions.md → `do-epic: drives one Jira epic …`).
`do-epic <EPIC-KEY>` first plans the epic's open issues (`planning`): it splits each by repo, picks the repo of each that no label places, and re-ranks the loop's issues. 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.
`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.
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
@@ -47,12 +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>.
Before it starts chunks, do-epic <EPIC-KEY> plans each open issue that no label places: it files a sub-task
per repo where the issue changes several, and else labels it `repo:<name>` for its repo, `do-epic-claude`
for work of Claude's that changes no repo, or `do-epic-human` for a task of yours, as repo-rule.md says.
Where the rule leaves that unclear, it asks you on the terminal, and you answer with the label.
It then ranks the issues it filed that hold scores, by the `Score = ...` line under the epic's ## Scoring.
An open issue runs as a chunk once it has such a label and no issue blocks it.
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.
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
@@ -158,10 +158,15 @@ 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: 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()
issues = read if isinstance(read, Failure) else planning.planned(planning.Planned(epic.key, epic.config, epic.store, epic.record, epic.paths.home, epic.effects), read)
if isinstance(issues, Limited):
return Stop(1, f"the epic is not planned, so no chunk started: {issues.said}")
started = issues if isinstance(issues, Failure) else chunks_started(epic, issues, None)
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)
+52 -28
View File
@@ -1,8 +1,10 @@
"""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 loop's issues are scored and Jira's backlog re-ranked to match (`ranking`).
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`).
Only the do-epic the human runs plans. A chunk that finishes starts the next chunks from the labels and the order it finds, so no window waits on a question."""
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
@@ -39,29 +41,41 @@ class Planned:
effects: Effects
def planned(epic: Planned, issues: list[EpicIssue]) -> list[EpicIssue] | Failure | Limited:
"""The epic's issues, read again after each open child issue that no label placed was split or got its pick, and the loop's issues were re-ranked. issues are the epic's, as just read. A Failure or a Limited says why the epic isn't planned; what was labelled, filed or ranked before it stays."""
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]
if unplaced:
stopped = placed(epic, issues, unplaced)
if stopped is not None:
return stopped
added: dict[str, str] = {}
stopped = placed(epic, issues, unplaced, added) if unplaced else None
if added:
read = epic.store.read()
if isinstance(read, Failure):
return read
issues = 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 order
return issues, order
if [issue.key for issue in issues if issue.key in order] == order:
return issues
say(f"re-ranking the loop's issues in {epic.key}'s backlog", epic.effects, stdout=True)
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)
return refused or epic.store.read()
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 placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) -> None | Failure | Limited:
"""Splits each of unplaced by repo, or labels it with its pick. 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."""
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.
@@ -76,6 +90,7 @@ def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) ->
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))
@@ -86,7 +101,8 @@ def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) ->
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):
say(f"{issue.key} is labelled {repo_pick.label_of(pick)}", epic.effects, stdout=True)
added[issue.key] = repo_pick.label_of(pick)
say(f"{issue.key} is labelled {added[issue.key]}", epic.effects, stdout=True)
return None
@@ -100,20 +116,26 @@ def planning_rung(model: str) -> Rung | Failure:
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, 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."""
"""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}`: ")
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
pick = repo_pick.of_label(typed.strip())
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)
say(f"`{typed.strip()}` is none of those labels", epic.effects)
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:
@@ -128,21 +150,23 @@ def located(epic: Planned, picks: list[repo_pick.Repo]) -> dict[str, repos.Locat
def ranked_keys(epic: Planned, issues: list[EpicIssue]) -> list[str] | Failure:
"""The keys of the loop's open child issues that hold scores, in the order ranking gives them; empty where fewer than two do, since one issue has no order. Every other issue keeps its position, as a person's does: an issue nobody scored, one labelled with two picks, and an item split by repo, which has no one repo whose goals to score it by."""
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 not isinstance(repo_pick.recorded(issue), Failure) and not ranking.unscored(item_of(issue, {}), issue.key)]
"""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 len(keys) < len(numbers):
return Failure(f"two of the loop's issues in the epic {epic.key} share a number in different Jira projects, so they cannot be ranked; move one of them")
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, such as `Score = 100 * V / (2**S + 32)`")
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):
@@ -159,5 +183,5 @@ def ranked_keys(epic: Planned, issues: list[EpicIssue]) -> list[str] | Failure:
def item_of(issue: EpicIssue, numbers: dict[str, int]) -> Item:
"""The issue as ranking scores it, blocked by each of its blockers among numbers, the issues ranked with it by key."""
"""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)))
+3 -3
View File
@@ -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))
+2 -2
View File
@@ -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"):
+6 -5
View File
@@ -35,7 +35,7 @@ DESCRIPTION = "**Max parallel chunks:** 2\n\n## Goals\nShip the import.\n\n## Au
def structured(output: object, key: str | None = "structured_output") -> subprocess.CompletedProcess[str]:
"""claude's reply that holds output as its structured answer; as the whole result event where key is None."""
"""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), "")
@@ -153,11 +153,12 @@ class TheCommand(DoEpicTest):
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_stops_where_the_epic_cannot_be_planned(self) -> None:
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, _, err = self.run_main(["ABC-12"], FakeEffects())
self.assertEqual(code, 1)
self.assertIn("states `Score = ...` 0 times under ## Scoring", err)
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")
+100 -24
View File
@@ -3,6 +3,7 @@ import dataclasses
import io
import json
import pathlib
import shutil
import subprocess
import sys
@@ -43,7 +44,8 @@ class Planning(DoEpicTest):
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(self.asked):
read = store.read()
assert not isinstance(read, Failure)
return planning.planned(epic, read), store, out.getvalue()
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}
@@ -140,19 +142,62 @@ class Planning(DoEpicTest):
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\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`: "] * 2)
self.assertIn("`api` is none of those labels; the repo api's label is `repo:api`\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: "] * 2)
def test_an_unclear_issue_waits_where_nobody_can_answer_and_the_next_is_planned(self) -> None:
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?"})
for fake in (FakeEffects(claude=[says({"parts": []}), unclear, says({"parts": []}), says({"pick": "claude"})], on_terminal=False), FakeEffects(claude=[says({"parts": []}), unclear, says({"parts": []}), says({"pick": "claude"})], inputs=[EOFError()])):
with self.subTest(on_terminal=fake.terminal):
self.issues = [issue("ABC-20"), issue("ABC-21")]
_, store, out = self.plan(fake)
self.assertEqual(self.labels(store), {"ABC-20": (), "ABC-21": ("do-epic-claude",)})
self.assertNotIn("ABC-20 is labelled", out)
if not fake.terminal:
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)
_, 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")]
@@ -175,7 +220,7 @@ class Planning(DoEpicTest):
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 loop's issues in ABC-12's backlog\n", out)
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"
@@ -196,7 +241,7 @@ class Planning(DoEpicTest):
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, such as `Score = 100 * V / (2**S + 32)`"))
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:
@@ -207,7 +252,7 @@ class Planning(DoEpicTest):
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("two of the loop's issues in the epic ABC-12 share a number in different Jira projects, so they cannot be ranked; move one of them"))
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")
@@ -235,14 +280,45 @@ class Planning(DoEpicTest):
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 test_fails_where_the_tracker_cannot_be_read_after_a_pick(self) -> None:
self.issues = [issue("ABC-20")]
def failing(_: object) -> subprocess.CompletedProcess[str]:
self.store.fails = "Jira answered 503"
return says({"parts": []})
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)
self.store = MemoryEpic("ABC-12", list(self.issues))
epic = planning.Planned("ABC-12", config, self.store, EpicRecord(Description(self.description)), self.home, FakeEffects(claude=[failing, says({"pick": "claude"})]).effects()) # type: ignore[arg-type]
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()):
self.assertEqual(planning.planned(epic, list(self.issues)), Failure("Jira answered 503"))
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_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)
+1 -1
View File
@@ -299,7 +299,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."
)
+4 -4
View File
@@ -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"))