Add do-epic --dry-run, which prints the Jira writes planning would make and the chunks that would start, and makes none
CI / tests (pull_request) Failing after 2m36s
CI / tests (pull_request) Failing after 2m36s
This commit is contained in:
@@ -198,7 +198,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
|
||||
- `command-patterns [<version>] [--calls <file>]` prints a table of the shell command patterns a release's archived chunks ran, such as `tea pr create`, for an audit of the release, and with `--calls <file>` saves each call as a JSON line; `command-patterns --help` states the columns and the line's keys.
|
||||
- `compress-archives` gzips each transcript in loop-claude's archive and each file in the review folders 30 days after it last changed, keeping all of them; Install's crontab line runs it daily.
|
||||
- `deploy-release [--cut] [<checkout>]` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says.
|
||||
- `do-epic <EPIC-KEY>` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-<EPIC-KEY>`, on the same cycle, judge and interrupt as loop-claude. The epic's description is its record: goals, audience, scoring and decisions. Before it starts chunks, do-epic plans each open issue that no label places yet, as "Set up a project" says. It files a sub-task per repo where the issue changes several repos. Otherwise it labels the issue with where it is worked, and asks you where that is unclear. It plans no issue your team filed a sub-task under: those sub-tasks run instead, each under a label of its own, and your team closes the issue. Then it puts the scored issues that do-epic itself filed in order of score. An open issue runs once a label names its repo or marks it as Claude's, in Jira's backlog order, as many at once as a line such as `**Max parallel chunks:** 2` in the epic's description allows, 1 without it, and as each repo's `parallel-chunks` allows. A chunk whose pull request waits on a gate parks. An open task of yours that blocks another issue gets a window that DMs you once and reads the epic every minute; once you close the task, the issues it blocked may start. do-epic closes the epic only once you confirm every goal. Install → "Set up a project" says how to set it up; `do-epic --help` states the flags and the contract.
|
||||
- `do-epic <EPIC-KEY>` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-<EPIC-KEY>`, on the same cycle, judge and interrupt as loop-claude. The epic's description is its record: goals, audience, scoring and decisions. Before it starts chunks, do-epic plans each open issue that no label places yet, as "Set up a project" says. It files a sub-task per repo where the issue changes several repos. Otherwise it labels the issue with where it is worked, and asks you where that is unclear. It plans no issue your team filed a sub-task under: those sub-tasks run instead, each under a label of its own, and your team closes the issue. Then it puts the scored issues that do-epic itself filed in order of score. An open issue runs once a label names its repo or marks it as Claude's, in Jira's backlog order, as many at once as a line such as `**Max parallel chunks:** 2` in the epic's description allows, 1 without it, and as each repo's `parallel-chunks` allows. A chunk whose pull request waits on a gate parks. An open task of yours that blocks another issue gets a window that DMs you once and reads the epic every minute; once you close the task, the issues it blocked may start. `do-epic <EPIC-KEY> --dry-run` runs the planning and the scheduling against the epic as Jira holds it, and prints each label, sub-task, comment and rank move planning would write, each chunk that would start and why each other issue waits, without writing to Jira, starting a window or asking a question; run it first on a team's epic. do-epic closes the epic only once you confirm every goal. Install → "Set up a project" says how to set it up; `do-epic --help` states the flags and the contract.
|
||||
- `do-epic-e2e` runs `do-epic` against a sandbox epic on a real Jira site, as Test says.
|
||||
- `judge-replay <model> [--offline]` replays loop-claude's judge on archived verdicts of the projects run on the model. It prints what each rung a review climbs to misses, and the lowest rung below those that returns every verdict, as each candidate above it does. With `--offline` it doesn't call a judge: it counts what a "?" rule, a decision table and a classifier trained on the archive decide of each verdict's kind from the worker's final message, and how many interrupts each misses. `judge-replay --help` states both replays.
|
||||
- `larv-review <command>` holds larv-review's mechanical rules: the chunk's review folder, the paired ruling's base and vote count, each pass's round count and the opening of its round commit's title, the scoring run's trigger and setup; the comprehension history's format, its latest places and its count of how often seats agree; and each reviewer's prompt header. `larv-review --help` states them. `settings.json` → `hooks` runs `larv-review reviewer-context` as each subagent starts. A reviewer under `agents/` whose frontmatter has `omitClaudeMd: true` starts without `CLAUDE.md`, and the command hands it that file's "Shared goal", "Prose" and "Vocabulary" sections.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""An epic held in memory, for do-epic's tests, held to contract.py like every backend."""
|
||||
"""An epic held in memory, for do-epic's tests and its `--dry-run`, held to contract.py like every backend."""
|
||||
import dataclasses
|
||||
|
||||
from do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_words, unfit, unfit_label
|
||||
@@ -7,12 +7,13 @@ from failure import Failure
|
||||
|
||||
@dataclasses.dataclass
|
||||
class MemoryEpic:
|
||||
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every read, filing, label, comment, rank, issue finish and closing fails with it as the reason. comments holds each issue's comments, and the epic's, by key. done says whether the epic is closed."""
|
||||
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every read, filing, label, comment, rank, issue finish and closing fails with it as the reason. comments holds each issue's comments, and the epic's, by key. done says whether the epic is closed. writes says each write that succeeded, in order."""
|
||||
epic_key: str
|
||||
issues: list[EpicIssue] = dataclasses.field(default_factory=list)
|
||||
comments: dict[str, list[str]] = dataclasses.field(default_factory=dict)
|
||||
fails: str | None = None
|
||||
done: bool = False
|
||||
writes: list[str] = dataclasses.field(default_factory=list)
|
||||
|
||||
def read(self) -> list[EpicIssue] | Failure:
|
||||
if self.fails:
|
||||
@@ -29,10 +30,15 @@ class MemoryEpic:
|
||||
return no_parent(self.epic_key, parent)
|
||||
if blocked_by is not None and blocked_by not in {issue.key for issue in self.issues if issue.parent == self.epic_key or issue.parent in children}:
|
||||
return no_blocker(self.epic_key, blocked_by)
|
||||
key = f"{self.epic_key.rpartition('-')[0]}-{len(self.issues) + 100}"
|
||||
key = self.next_key()
|
||||
self.issues.append(EpicIssue(key, summary, detail.strip(), tuple(sorted(labels)), None, "To Do", False, parent, blockers=(blocked_by,) if blocked_by else (), by_loop=True))
|
||||
self.writes.append(f"file {key} under {parent}: {summary}" + (f", labelled {', '.join(sorted(labels))}" if labels else "") + (f", blocked by {blocked_by}" if blocked_by else ""))
|
||||
return key
|
||||
|
||||
def next_key(self) -> str:
|
||||
"""The key of the next issue filed."""
|
||||
return f"{self.epic_key.rpartition('-')[0]}-{len(self.issues) + 100}"
|
||||
|
||||
def add_label(self, key: str, label: str) -> None | Failure:
|
||||
if self.fails:
|
||||
return Failure(self.fails)
|
||||
@@ -52,6 +58,7 @@ class MemoryEpic:
|
||||
return Failure(f"{stray} is not one of the child issues of the epic {self.epic_key}, so {key} is not ranked")
|
||||
self.issues.remove(children[key])
|
||||
self.issues.insert(self.issues.index(children[before]), children[key])
|
||||
self.writes.append(f"rank {key} before {before}")
|
||||
return None
|
||||
|
||||
def comment(self, key: str, text: str) -> None | Failure:
|
||||
@@ -62,6 +69,7 @@ class MemoryEpic:
|
||||
if not any(issue.key == key and issue.parent == self.epic_key for issue in self.issues):
|
||||
return no_child(self.epic_key, key, "commented on")
|
||||
self.comments.setdefault(key, []).append(text.strip())
|
||||
self.writes.append(f"comment on {key}: {text.strip()}")
|
||||
return None
|
||||
|
||||
def closed(self) -> bool | Failure:
|
||||
@@ -74,6 +82,7 @@ class MemoryEpic:
|
||||
return refused
|
||||
self.comments.setdefault(self.epic_key, []).append(summary.strip())
|
||||
self.done = True
|
||||
self.writes.append(f"close the epic: {summary.strip()}")
|
||||
return None
|
||||
|
||||
def finish_issue(self, key: str) -> None | Failure:
|
||||
@@ -85,6 +94,7 @@ class MemoryEpic:
|
||||
return no_child(self.epic_key, key, "finished")
|
||||
if not child.done:
|
||||
self.change(key, status="Done", done=True)
|
||||
self.writes.append(f"finish {key}")
|
||||
return None
|
||||
|
||||
def change(self, key: str, **fields: object) -> None:
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"""What `do-epic <EPIC-KEY> --dry-run` runs planning and the scheduler on, in place of Jira and tmux: an in-memory copy of the epic that records each write, and a tmux that starts no window. Reads of the epic and of tmux's windows are real, so the run sees the epic and the chunks as they are now."""
|
||||
import dataclasses
|
||||
import subprocess
|
||||
|
||||
from agent_cycle.tmux import Tmux
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from do_epic.backend.protocol import EpicStore
|
||||
from failure import Failure
|
||||
from git_cli.git_repo import Git
|
||||
|
||||
# The tmux commands that only read. Each other command makes or changes a session or a window.
|
||||
READS = ("list-windows", "show-options")
|
||||
# The commands that start a window, which a later listing shows.
|
||||
STARTS = ("new-session", "new-window")
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class DryEpic(MemoryEpic):
|
||||
"""The epic as `store` holds it. A sub-task it files gets a key no Jira issue has, such as ABC-new1, since Jira alone gives the next number."""
|
||||
filed: int = 0
|
||||
|
||||
def next_key(self) -> str:
|
||||
self.filed += 1
|
||||
return f"{self.epic_key.rpartition('-')[0]}-new{self.filed}"
|
||||
|
||||
|
||||
def seeded(store: EpicStore) -> DryEpic | Failure:
|
||||
"""A DryEpic with the issues and the closed state that store holds now, or why they cannot be read."""
|
||||
issues = store.read()
|
||||
done = store.closed()
|
||||
if isinstance(issues, Failure):
|
||||
return issues
|
||||
return done if isinstance(done, Failure) else DryEpic(store.epic_key, list(issues), done=done)
|
||||
|
||||
|
||||
def recording(real: Tmux) -> Tmux:
|
||||
"""real for each read; a command that starts a window is answered as if it had, and the window shows in every later listing, as a window that runs. Any other command, which would change a window, is answered as done."""
|
||||
started: list[tuple[str, str, str]] = []
|
||||
|
||||
def run(args: list[str]) -> subprocess.CompletedProcess[str]:
|
||||
if args[0] in STARTS:
|
||||
named = "-s" if "-s" in args else "-t"
|
||||
session = args[args.index(named) + 1].strip("=:")
|
||||
started.append((session, args[args.index("-n") + 1], args[args.index("-c") + 1]))
|
||||
return subprocess.CompletedProcess(args, 0, f"@dry{len(started)}\n", "")
|
||||
if args[0] not in READS:
|
||||
return subprocess.CompletedProcess(args, 0, "", "")
|
||||
done = real(args)
|
||||
if args[0] != "list-windows":
|
||||
return done
|
||||
rows = done.stdout if done.returncode == 0 else ""
|
||||
if "-a" in args:
|
||||
rows += "".join(f"{session}\t{name}\t0\t@dry{at}\t{cwd}\n" for at, (session, name, cwd) in enumerate(started, 1))
|
||||
else:
|
||||
rows += "".join(f"{name}\t0\t@dry{at}\n" for at, (session, name, _) in enumerate(started, 1) if f"={session}" == args[args.index("-t") + 1])
|
||||
return subprocess.CompletedProcess(args, 0, rows, "")
|
||||
|
||||
return run
|
||||
|
||||
|
||||
def without_clones(real: Git) -> Git:
|
||||
"""real, except that a command with `clone` among its words fails, so that no repo is cloned."""
|
||||
def run(*args: str, cwd: str | None = None, timeout: float | None = None, guarded: bool = False, errors: str = "strict") -> str | Failure:
|
||||
if "clone" in args:
|
||||
return Failure("a dry run clones nothing")
|
||||
return real(*args, cwd=cwd, timeout=timeout, guarded=guarded, errors=errors)
|
||||
|
||||
return run
|
||||
+47
-14
@@ -10,7 +10,7 @@ import typing
|
||||
|
||||
from chunk_driver.cycle_start import announced_route, cycle_of, project_routing, routing_on
|
||||
from chunk_driver.claims import CHUNK_FLAG
|
||||
from do_epic import chunk_prompt, findings, finish, gates, human_tasks, parked, planning, scheduler, split, status
|
||||
from do_epic import chunk_prompt, dry_run, findings, finish, gates, human_tasks, parked, planning, scheduler, split, status
|
||||
from chunk_driver.chunk_run import ChunkRun, closed_cycle
|
||||
from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo
|
||||
from project_config.main import located as config_located
|
||||
@@ -40,7 +40,7 @@ from agent_cycle.stop import Stop
|
||||
from agent_cycle.direct_message import tell
|
||||
from agent_cycle import tmux
|
||||
|
||||
HELP = f"""usage: do-epic <EPIC-KEY> [--status]
|
||||
HELP = f"""usage: do-epic <EPIC-KEY> [--status | --dry-run]
|
||||
{findings.USAGE}
|
||||
{finish.USAGE}
|
||||
|
||||
@@ -62,6 +62,7 @@ on once the checks pass, the approval comes or a reviewer comments, and a place
|
||||
name says `awaits a slot`. In a repo whose config sets `merge = "human"`, a chunk never merges: once its pull
|
||||
request is ready, with nothing else to wait on, the window's name says `awaits your merge`, and its worker goes on once you merged it. A parked chunk survives a reboot: run do-epic <EPIC-KEY> again to go on polling.
|
||||
--status doesn't start any chunk. It prints a line per open issue: that its chunk runs or asks you a question, or why it waits, such as the gate a parked chunk awaits and since when.
|
||||
--dry-run runs the planning and the scheduling against the epic as Jira holds it, and writes nothing to Jira, starts no window and asks no question. It prints each label, sub-task, comment and rank move that planning would write, each chunk that would start and why each other issue waits. Planning's claude calls still run, and a repo that is missing isn't cloned. A question planning would ask is printed instead.
|
||||
{findings.HELP}
|
||||
{finish.HELP}
|
||||
The Jira site and its credentials are set in ~/.claude-projects/do-epic/config.toml."""
|
||||
@@ -69,6 +70,8 @@ The Jira site and its credentials are set in ~/.claude-projects/do-epic/config.t
|
||||
ARCHIVE = ".claude/do-epic-transcripts"
|
||||
# The flag that prints what each open issue does.
|
||||
STATUS_FLAG = "--status"
|
||||
# The flag that prints what planning and the scheduler would do, and does none of it.
|
||||
DRY_RUN_FLAG = "--dry-run"
|
||||
# How often a parked chunk reads its pull request's gate, and a human task's window reads the epic: a person answers in hours, and each read is a few calls.
|
||||
POLL_SECONDS = 60
|
||||
|
||||
@@ -119,7 +122,8 @@ def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher:
|
||||
def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend, stdin: typing.TextIO, forge_at: typing.Callable[[str], Run]) -> Stop:
|
||||
chunk, words = (argv[1], argv[2:]) if len(argv) >= 2 and argv[0] == CHUNK_FLAG else (None, argv)
|
||||
status_asked = chunk is None and words[1:] == [STATUS_FLAG]
|
||||
words = words[:1] if status_asked else words
|
||||
dry_run_asked = chunk is None and words[1:] == [DRY_RUN_FLAG]
|
||||
words = words[:1] if status_asked or dry_run_asked else words
|
||||
# What the words after the epic's key write into the epic, where they are a filing or a decision.
|
||||
writes = findings.parsed(words[1:]) if chunk is None else None
|
||||
closes = chunk is None and words[1:] == [finish.CLOSE]
|
||||
@@ -128,12 +132,14 @@ def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher:
|
||||
if writes or closes:
|
||||
return epic_written(words[0], writes, paths, backend, stdin)
|
||||
# Before anything starts: a clone, a claude session or a tmux window.
|
||||
if reason := tmux.unusable(effects.tmux, chunk_prompt.DRIVER):
|
||||
if not dry_run_asked and (reason := tmux.unusable(effects.tmux, chunk_prompt.DRIVER)):
|
||||
return Stop(1, reason)
|
||||
config = load(paths.home)
|
||||
if isinstance(config, Failure):
|
||||
return Stop(1, config.reason)
|
||||
store, record = backend(config, words[0])
|
||||
if dry_run_asked:
|
||||
return dry_run_printed(EpicRun(words[0], config, store, record, paths, env, launcher, effects, forge_at))
|
||||
epic = EpicRun(words[0], config, store, record, paths, env, launcher, effects, forge_at)
|
||||
if status_asked:
|
||||
return status_printed(epic)
|
||||
@@ -159,6 +165,21 @@ def epic_written(key: str, writes: findings.Write | None, paths: Paths, backend:
|
||||
|
||||
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."""
|
||||
started = planned_and_started(epic)
|
||||
if isinstance(started, Stop):
|
||||
return started
|
||||
chunks_said(epic, started, "started", f" in the tmux session {epic.session}")
|
||||
if not tmux.listed(epic.session, epic.effects.tmux):
|
||||
return Stop(0, "")
|
||||
if not epic.effects.on_terminal():
|
||||
say(f"not on a terminal; see the chunks with `tmux attach -t ={epic.session}`", epic.effects, stdout=True)
|
||||
return Stop(0, "")
|
||||
shown = tmux.show(epic.session, "TMUX" in epic.env)
|
||||
return Stop(1, f"`tmux {' '.join(shown)}` failed; the chunks go on in the tmux session") if epic.effects.tmux_on_terminal(shown) else Stop(0, "")
|
||||
|
||||
|
||||
def planned_and_started(epic: EpicRun) -> scheduler.Started | Stop:
|
||||
"""Plans the epic's open issues, then starts each chunk that may start now."""
|
||||
read = epic.store.read()
|
||||
if isinstance(read, Failure):
|
||||
return Stop(1, read.reason)
|
||||
@@ -169,20 +190,32 @@ def windows_opened(epic: EpicRun) -> Stop:
|
||||
# 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)
|
||||
return Stop(1, started.reason) if isinstance(started, Failure) else started
|
||||
|
||||
|
||||
def chunks_said(epic: EpicRun, started: scheduler.Started, verb: str, where: str) -> None:
|
||||
"""Prints each chunk that started, after verb and before where, else that none did, then why each other open issue waits, and whether the epic is closed."""
|
||||
say(f"{verb} {', '.join(started.started)}{where}" if started.started else f"{verb} no chunk", epic.effects, stdout=True)
|
||||
for wait in started.waits:
|
||||
say(f"{wait.issue} waits: {wait.reason}", epic.effects, stdout=True)
|
||||
if started.closed:
|
||||
say(f"the epic {epic.key} is closed", epic.effects, stdout=True)
|
||||
if not tmux.listed(epic.session, epic.effects.tmux):
|
||||
return Stop(0, "")
|
||||
if not epic.effects.on_terminal():
|
||||
say(f"not on a terminal; see the chunks with `tmux attach -t ={epic.session}`", epic.effects, stdout=True)
|
||||
return Stop(0, "")
|
||||
shown = tmux.show(epic.session, "TMUX" in epic.env)
|
||||
return Stop(1, f"`tmux {' '.join(shown)}` failed; the chunks go on in the tmux session") if epic.effects.tmux_on_terminal(shown) else Stop(0, "")
|
||||
|
||||
|
||||
def dry_run_printed(epic: EpicRun) -> Stop:
|
||||
"""What `do-epic <EPIC-KEY> --dry-run` does: runs windows_opened's planning and scheduling on a copy of the epic and a tmux that starts nothing, then prints each Jira write planning made there. It never puts the session on the terminal or asks a question."""
|
||||
dry = dry_run.seeded(epic.store)
|
||||
if isinstance(dry, Failure):
|
||||
return Stop(1, dry.reason)
|
||||
effects = dataclasses.replace(epic.effects, tmux=dry_run.recording(epic.effects.tmux), git=dry_run.without_clones(epic.effects.git), on_terminal=lambda: False)
|
||||
rehearsal = dataclasses.replace(epic, store=dry, effects=effects)
|
||||
say("dry run: nothing is written to Jira and no window starts", effects, stdout=True)
|
||||
started = planned_and_started(rehearsal)
|
||||
say("planning would write to Jira:\n" + "\n".join(f"- {write}" for write in dry.writes) if dry.writes else "planning would write nothing to Jira", effects, stdout=True)
|
||||
if isinstance(started, Stop):
|
||||
return started
|
||||
chunks_said(rehearsal, started, "would start", "")
|
||||
return Stop(0, "")
|
||||
|
||||
|
||||
def chunks_started(epic: EpicRun, issues: list[EpicIssue], own: str | None) -> scheduler.Started | Failure:
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic import dry_run
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from do_epic.test_scheduler import issue
|
||||
from failure import Failure
|
||||
|
||||
LISTED = "-t", "=epic-ABC-12", "-F", "#{window_name}\t#{pane_dead}\t#{window_id}"
|
||||
START = ["new-window", "-d", "-t", "=epic-ABC-12:", "-n", "ABC-21", "-c", "/code/api", "-P", "-F", "#{window_id}", "--", "do-epic"]
|
||||
|
||||
|
||||
def tmux(calls: list[list[str]], shown: str = "ABC-20\t0\t@1\n"):
|
||||
def run(args: list[str]) -> subprocess.CompletedProcess[str]:
|
||||
calls.append(args)
|
||||
return subprocess.CompletedProcess(args, 0, shown, "")
|
||||
return run
|
||||
|
||||
|
||||
class TheRecordingTmux(unittest.TestCase):
|
||||
def test_starts_no_window_and_lists_the_one_it_would_start_beside_the_real_ones(self) -> None:
|
||||
calls: list[list[str]] = []
|
||||
run = dry_run.recording(tmux(calls))
|
||||
self.assertEqual(run(START).stdout, "@dry1\n")
|
||||
self.assertEqual(run(["list-windows", *LISTED]).stdout, "ABC-20\t0\t@1\nABC-21\t0\t@dry1\n")
|
||||
everywhere = run(["list-windows", "-a", "-F", "x"]).stdout
|
||||
self.assertEqual(everywhere, "ABC-20\t0\t@1\nepic-ABC-12\tABC-21\t0\t@dry1\t/code/api\n")
|
||||
self.assertEqual([call[0] for call in calls], ["list-windows", "list-windows"])
|
||||
|
||||
def test_lists_the_window_it_would_start_where_tmux_finds_no_session(self) -> None:
|
||||
def none(args: list[str]) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.CompletedProcess(args, 1, "", "no server running")
|
||||
run = dry_run.recording(none)
|
||||
run(["new-session", "-d", "-s", "epic-ABC-12", "-n", "ABC-21", "-c", "/code/api"])
|
||||
self.assertEqual(run(["list-windows", *LISTED]).stdout, "ABC-21\t0\t@dry1\n")
|
||||
self.assertEqual(run(["list-windows", "-t", "=epic-ABC-99", "-F", "x"]).stdout, "")
|
||||
|
||||
def test_answers_a_change_as_done_and_reads_the_real_tmux_for_a_read(self) -> None:
|
||||
calls: list[list[str]] = []
|
||||
run = dry_run.recording(tmux(calls))
|
||||
self.assertEqual(run(["kill-window", "-t", "@1"]).returncode, 0)
|
||||
self.assertEqual(run(["show-options", "-qv", "-t", "=s:", "@loop-root"]).stdout, "ABC-20\t0\t@1\n")
|
||||
self.assertEqual(calls, [["show-options", "-qv", "-t", "=s:", "@loop-root"]])
|
||||
|
||||
|
||||
class TheGitThatClonesNothing(unittest.TestCase):
|
||||
def test_fails_a_clone_and_runs_any_other_command(self) -> None:
|
||||
ran: list[tuple[str, ...]] = []
|
||||
|
||||
def real(*args: str, cwd: str | None = None, timeout: float | None = None, guarded: bool = False, errors: str = "strict") -> str | Failure:
|
||||
ran.append(args)
|
||||
return "ok"
|
||||
git = dry_run.without_clones(real)
|
||||
self.assertEqual(git("-c", "a=b", "clone", "--", "url", "dir"), Failure("a dry run clones nothing"))
|
||||
self.assertEqual(git("remote", cwd="/c"), "ok")
|
||||
self.assertEqual(ran, [("remote",)])
|
||||
|
||||
|
||||
class TheEpicItCopies(unittest.TestCase):
|
||||
def test_copies_the_issues_and_the_closed_state_and_files_under_keys_jira_never_gives(self) -> None:
|
||||
real = MemoryEpic("ABC-12", [issue("ABC-20"), issue("ABC-21")], done=True)
|
||||
copy = dry_run.seeded(real)
|
||||
assert not isinstance(copy, Failure)
|
||||
self.assertEqual((copy.closed(), [each.key for each in copy.read()]), (True, ["ABC-20", "ABC-21"])) # type: ignore[union-attr]
|
||||
self.assertEqual([copy.file("ABC-20", "A", "d", ()), copy.file("ABC-20", "B", "d", ())], ["ABC-new1", "ABC-new2"])
|
||||
self.assertEqual((real.writes, [each.key for each in real.issues]), ([], ["ABC-20", "ABC-21"]))
|
||||
self.assertEqual(copy.writes, ["file ABC-new1 under ABC-20: A", "file ABC-new2 under ABC-20: B"])
|
||||
|
||||
def test_fails_where_the_real_epic_cannot_be_read(self) -> None:
|
||||
self.assertEqual(dry_run.seeded(MemoryEpic("ABC-12", [], fails="Jira answered 503")), Failure("Jira answered 503"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -150,7 +150,7 @@ class ClosingTheEpic(DoEpicTest):
|
||||
for argv in (["ABC-12", "--close-epic", "now"], ["--close-epic", "ABC-12"], ["--close-epic"]):
|
||||
code, out, err = self.run_main(argv, FakeEffects())
|
||||
self.assertEqual((code, out), (1, ""), argv)
|
||||
self.assertIn("usage: do-epic <EPIC-KEY> [--status]\n", err)
|
||||
self.assertIn("usage: do-epic <EPIC-KEY> [--status | --dry-run]\n", err)
|
||||
self.assertIn("do-epic <EPIC-KEY> --close-epic <<'EOF' summary EOF", err)
|
||||
|
||||
|
||||
|
||||
@@ -968,6 +968,69 @@ class TheStatus(DoEpicTest):
|
||||
self.assertIn("Jira answered 503\n", err)
|
||||
|
||||
|
||||
class TheDryRun(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
for repo in ("api", "web"):
|
||||
configured(self, self.home / "code" / repo, home=self.home)
|
||||
(self.home / "code" / repo / "README.md").write_text("## Goals\nServe the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
|
||||
self.stores: list[MemoryEpic] = []
|
||||
made = self.backend
|
||||
self.backend = lambda config, key: (self.stores.append(made(config, key)[0]) or self.stores[-1], EpicRecord(Description(self.description))) # type: ignore[method-assign,assignment]
|
||||
|
||||
def test_prints_each_write_and_each_chunk_it_would_start_and_makes_none_of_them(self) -> None:
|
||||
self.issues = [issue("ABC-20"), issue("ABC-21", "do-epic-claude")]
|
||||
parts = structured({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."})
|
||||
fake = FakeEffects(on_terminal=True, claude=[parts])
|
||||
code, out, err = self.run_main(["ABC-12", "--dry-run"], fake)
|
||||
self.assertEqual((code, err), (0, ""))
|
||||
shown = out.replace("<1790000000> ", "")
|
||||
self.assertIn("planning would write to Jira:\n- file ABC-new1 under ABC-20: [api] Do ABC-20, labelled repo:api\n- file ABC-new2 under ABC-20: [web] Do ABC-20, labelled repo:web\n- comment on ABC-20: Split by repo: api and web.\n", shown)
|
||||
self.assertIn("would start ABC-new1, ABC-new2\nABC-21 waits: the epic runs as many chunks as its `**Max parallel chunks:**` line allows: 2\n", shown)
|
||||
self.assertEqual(self.stores[0].writes, [])
|
||||
self.assertEqual([each.key for each in self.stores[0].issues], ["ABC-20", "ABC-21"])
|
||||
changing = {"new-session", "new-window", "kill-window", "set-option", "rename-window"}
|
||||
self.assertEqual([args for args in fake.tmux_calls if args[0] in changing], [])
|
||||
|
||||
def test_counts_the_chunks_it_would_start_against_the_epics_cap_and_a_repos_limit(self) -> None:
|
||||
self.issues = [issue("ABC-21", "do-epic-claude"), issue("ABC-22", "do-epic-claude"), issue("ABC-23", "do-epic-claude")]
|
||||
self.description = DESCRIPTION.replace("2", "1")
|
||||
code, out, _ = self.run_main(["ABC-12", "--dry-run"], FakeEffects(on_terminal=True))
|
||||
self.assertEqual(code, 0)
|
||||
shown = out.replace("<1790000000> ", "")
|
||||
self.assertIn("planning would write nothing to Jira\nwould start ABC-21\n", shown)
|
||||
self.assertIn("ABC-22 waits: the epic runs as many chunks as its `**Max parallel chunks:**` line allows: 1\n", shown)
|
||||
|
||||
def test_prints_the_question_planning_would_ask_and_asks_none(self) -> None:
|
||||
self.issues = [issue("ABC-20")]
|
||||
unclear = structured({"pick": "unclear", "question": "Is the importer in api or in web?"})
|
||||
fake = FakeEffects(on_terminal=True, claude=[structured({"parts": []}), unclear], inputs=["api"])
|
||||
code, out, _ = self.run_main(["ABC-12", "--dry-run"], fake)
|
||||
self.assertEqual(code, 0)
|
||||
self.assertIn("ABC-20 waits for your answer: Is the importer in api or in web?", out)
|
||||
self.assertEqual([seam for seam, _ in fake.calls if seam == "input"], [])
|
||||
self.assertIn("planning would write nothing to Jira\n", out)
|
||||
|
||||
def test_works_without_tmux_and_a_chunk_in_a_missing_repo_waits(self) -> None:
|
||||
self.issues = [issue("ABC-20", "repo:missing"), issue("ABC-21", "do-epic-claude")]
|
||||
fake = FakeEffects(on_terminal=False, tmux_version="")
|
||||
code, out, _ = self.run_main(["ABC-12", "--dry-run"], fake)
|
||||
self.assertEqual(code, 0)
|
||||
self.assertIn("would start ABC-21\n", out)
|
||||
self.assertIn("ABC-20 waits:", out)
|
||||
self.assertIn("ABC-20 waits: missing is missing", out)
|
||||
self.assertEqual([what for seam, what in fake.calls if seam == "git" and "clone" in what], [])
|
||||
|
||||
def test_stops_where_the_epic_cannot_be_read(self) -> None:
|
||||
store = MemoryEpic("ABC-12", [], fails="Jira answered 503")
|
||||
self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
|
||||
code, _, err = self.run_main(["ABC-12", "--dry-run"], FakeEffects())
|
||||
self.assertEqual((code, "Jira answered 503\n" in err), (1, True))
|
||||
|
||||
def test_is_in_the_help(self) -> None:
|
||||
self.assertIn("--dry-run", main.HELP)
|
||||
self.assertEqual(self.run_main(["ABC-12", "--dry-run", "--status"], FakeEffects())[0], 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user