Answer stability round 1: 2 🔴, 5 🟡 (0 misread); fixed the import order and the unused return, tested the scenario steps offline, passed env and timeout in, reused the paged search
This commit is contained in:
+28
-20
@@ -1,15 +1,15 @@
|
||||
"""What the e2e command does to a sandbox epic: runs `do-epic --file`, `--record-decision` and `--close-epic`, each as a process of its own against the real Jira site, and checks what the site holds after each."""
|
||||
import dataclasses
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import tempfile
|
||||
import typing
|
||||
|
||||
from do_epic.repo_pick import CLAUDE_LABEL, HUMAN_LABEL
|
||||
from project_config.settings import Epic, Finish
|
||||
from do_epic import epic_record, findings, finish
|
||||
from record_store.jira_description import EpicDescription
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from do_epic.backend.protocol import EpicIssue, EpicStore
|
||||
from failure import Failure
|
||||
from do_epic.e2e.sandbox import FINISH_STATUS, FINISH_TRANSITION
|
||||
from do_epic.backend.jira import JiraEpic
|
||||
@@ -27,26 +27,34 @@ class Report:
|
||||
held: list[str] = dataclasses.field(default_factory=list)
|
||||
broke: list[str] = dataclasses.field(default_factory=list)
|
||||
|
||||
def check(self, holds: bool, what: str) -> bool:
|
||||
def check(self, holds: bool, what: str) -> None:
|
||||
(self.held if holds else self.broke).append(what)
|
||||
return holds
|
||||
|
||||
|
||||
class DoEpic(typing.Protocol):
|
||||
"""What the steps run do-epic through: a Machine, or a stand-in in a test."""
|
||||
|
||||
def do_epic(self, *args: str, stdin: str = "") -> subprocess.CompletedProcess[str]:
|
||||
"""Runs `do-epic args`, feeding it stdin."""
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Machine:
|
||||
"""A home folder of its own, holding the do-epic settings that point at the sandbox, so that do-epic writes its state there. The sandbox's env-file stays where it is."""
|
||||
"""A home folder of its own, holding the do-epic settings that point at the sandbox, so that do-epic writes its state there. The sandbox's env-file stays where it is. do-epic runs in env with HOME set to the home folder, and is stopped after timeout seconds."""
|
||||
home: pathlib.Path
|
||||
launcher: pathlib.Path
|
||||
env: typing.Mapping[str, str]
|
||||
timeout: int = TIMEOUT
|
||||
|
||||
def do_epic(self, *args: str, stdin: str = "") -> subprocess.CompletedProcess[str]:
|
||||
env = {**os.environ, "HOME": str(self.home)}
|
||||
env = {**self.env, "HOME": str(self.home)}
|
||||
try:
|
||||
return subprocess.run([str(self.launcher), *args], input=stdin, env=env, capture_output=True, text=True, timeout=TIMEOUT, check=False)
|
||||
return subprocess.run([str(self.launcher), *args], input=stdin, env=env, capture_output=True, text=True, timeout=self.timeout, check=False)
|
||||
except subprocess.TimeoutExpired:
|
||||
return subprocess.CompletedProcess(args, 124, "", f"do-epic {' '.join(args)} ran over {TIMEOUT} seconds and was stopped")
|
||||
return subprocess.CompletedProcess(args, 124, "", f"do-epic {' '.join(args)} ran over {self.timeout} seconds and was stopped")
|
||||
|
||||
|
||||
def machine_made(home: pathlib.Path, sandbox: Sandbox, launcher: pathlib.Path) -> Machine | Failure:
|
||||
def machine_made(home: pathlib.Path, sandbox: Sandbox, launcher: pathlib.Path, env: typing.Mapping[str, str]) -> Machine | Failure:
|
||||
folder = home / ".claude-projects" / "do-epic"
|
||||
folder.mkdir(parents=True)
|
||||
ladder = read_ladder(SHIPPED)
|
||||
@@ -56,28 +64,28 @@ def machine_made(home: pathlib.Path, sandbox: Sandbox, launcher: pathlib.Path) -
|
||||
f'jira-url = "{sandbox.jira_url}"\nenv-file = "{sandbox.env_file}"\nrepoless-model = "{ladder.rungs[0].model}"\n'
|
||||
f'jira-finish-transition = "{FINISH_TRANSITION}"\njira-finish-status = "{FINISH_STATUS}"\n', encoding="utf-8")
|
||||
(folder / "repo-rule.md").write_text(RULE, encoding="utf-8")
|
||||
return Machine(home, launcher)
|
||||
return Machine(home, launcher, env)
|
||||
|
||||
|
||||
def run(sandbox: Sandbox, epic_key: str, launcher: pathlib.Path) -> Report:
|
||||
def run(sandbox: Sandbox, epic_key: str, launcher: pathlib.Path, env: typing.Mapping[str, str]) -> Report:
|
||||
"""Drives do-epic against the epic epic_key in the sandbox, an epic with no issue yet."""
|
||||
report = Report()
|
||||
epic = Epic(sandbox.jira_url, epic_key)
|
||||
store = JiraEpic(epic, sandbox.env_file, finish=Finish(FINISH_TRANSITION, FINISH_STATUS))
|
||||
record = epic_record.EpicRecord(EpicDescription(epic, sandbox.env_file))
|
||||
with tempfile.TemporaryDirectory() as home:
|
||||
machine = machine_made(pathlib.Path(home).resolve(), sandbox, launcher)
|
||||
machine = machine_made(pathlib.Path(home).resolve(), sandbox, launcher, env)
|
||||
if isinstance(machine, Failure):
|
||||
report.check(False, f"set up do-epic's settings: {machine.reason}")
|
||||
return report
|
||||
items_filed(report, store, epic_key)
|
||||
finding_filed(report, machine, store, epic_key)
|
||||
decision_recorded(report, machine, record, epic_key)
|
||||
decision_recorded(report, machine, record.section, epic_key)
|
||||
closed(report, machine, store, epic_key)
|
||||
return report
|
||||
|
||||
|
||||
def read(report: Report, store: JiraEpic, what: str) -> list[EpicIssue]:
|
||||
def read(report: Report, store: EpicStore, what: str) -> list[EpicIssue]:
|
||||
issues = store.read()
|
||||
if isinstance(issues, Failure):
|
||||
report.check(False, f"read the epic's issues {what}: {issues.reason}")
|
||||
@@ -85,7 +93,7 @@ def read(report: Report, store: JiraEpic, what: str) -> list[EpicIssue]:
|
||||
return issues
|
||||
|
||||
|
||||
def items_filed(report: Report, store: JiraEpic, epic_key: str) -> None:
|
||||
def items_filed(report: Report, store: EpicStore, epic_key: str) -> None:
|
||||
"""Files an item, its sub-task and a second item in the epic, and checks that a read answers them in the tracker's order."""
|
||||
parent = store.file(epic_key, "Sandbox item with a sub-task", "The first item.", (HUMAN_LABEL,))
|
||||
second = store.file(epic_key, "Sandbox second item", "", ())
|
||||
@@ -96,23 +104,23 @@ def items_filed(report: Report, store: JiraEpic, epic_key: str) -> None:
|
||||
report.check([issue.summary for issue in issues] == ["Sandbox item with a sub-task", "Sandbox sub-task", "Sandbox second item"], f"read the filed issues back in order, the sub-task after its parent (found {[issue.summary for issue in issues]})")
|
||||
|
||||
|
||||
def finding_filed(report: Report, machine: Machine, store: JiraEpic, epic_key: str) -> None:
|
||||
def finding_filed(report: Report, machine: DoEpic, store: EpicStore, epic_key: str) -> None:
|
||||
done = machine.do_epic(epic_key, findings.FILE, "Sandbox finding", findings.LABEL, CLAUDE_LABEL, stdin="Why the finding matters.\n")
|
||||
report.check(done.returncode == 0 and " Filed " in done.stdout, f"`do-epic {findings.FILE}` files the finding and says so (exit {done.returncode}: {done.stdout.strip() or done.stderr.strip()})")
|
||||
found = [issue for issue in read(report, store, "after the finding") if issue.summary == "Sandbox finding"]
|
||||
report.check(len(found) == 1 and found[0].labels == (CLAUDE_LABEL,) and found[0].detail == "Why the finding matters." and found[0].by_loop, f"the finding is an issue of the epic with its label, its detail and the loop's mark (found {found})")
|
||||
|
||||
|
||||
def decision_recorded(report: Report, machine: Machine, record: epic_record.EpicRecord, epic_key: str) -> None:
|
||||
def decision_recorded(report: Report, machine: DoEpic, section: typing.Callable[[str], str | Failure], epic_key: str) -> None:
|
||||
done = machine.do_epic(epic_key, findings.RECORD_DECISION, "Sandbox decision", stdin="The text of the decision.\n")
|
||||
report.check(done.returncode == 0 and "Recorded the decision" in done.stdout, f"`do-epic {findings.RECORD_DECISION}` records the decision and says so (exit {done.returncode}: {done.stdout.strip() or done.stderr.strip()})")
|
||||
decisions = record.section("Decisions")
|
||||
decisions = section("Decisions")
|
||||
report.check(isinstance(decisions, str) and "Sandbox decision" in decisions and "The text of the decision." in decisions, f"the epic's description holds the decision under ## Decisions (found {decisions!r})")
|
||||
goals = record.section("Goals")
|
||||
goals = section("Goals")
|
||||
report.check(isinstance(goals, str) and "Prove do-epic's commands" in goals, f"the decision leaves the description's ## Goals as it was (found {goals!r})")
|
||||
|
||||
|
||||
def closed(report: Report, machine: Machine, store: JiraEpic, epic_key: str) -> None:
|
||||
def closed(report: Report, machine: DoEpic, store: EpicStore, epic_key: str) -> None:
|
||||
early = machine.do_epic(epic_key, finish.CLOSE, stdin="Too early.\n")
|
||||
still = store.closed()
|
||||
report.check(early.returncode == 1 and " open" in early.stderr and still is False, f"`do-epic {finish.CLOSE}` refuses while issues are open and leaves the epic open (exit {early.returncode}: {early.stderr.strip()}; epic closed: {still!r})")
|
||||
|
||||
Reference in New Issue
Block a user