File a finding and record a decision in a do-epic epic, and give the judge the epic's records beside the repo's
CI / tests (pull_request) Failing after 4m22s
CI / tests (pull_request) Failing after 4m22s
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import io
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic import main
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from do_epic.test_main import DESCRIPTION, DoEpicTest
|
||||
from failure import Failure
|
||||
from loop_claude.test_loop_claude import FakeEffects
|
||||
from loop_state.paths import paths_from
|
||||
from record_store.held import Held
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class WrittenDescription:
|
||||
"""Stands in for an epic's description in Jira that takes writes: kept holds each text it held, the last one now."""
|
||||
kept: list[str]
|
||||
approved: frozenset[str] = frozenset()
|
||||
|
||||
@property
|
||||
def text(self) -> str:
|
||||
return self.kept[-1]
|
||||
|
||||
def read(self) -> str | Failure:
|
||||
return self.text
|
||||
|
||||
def held(self) -> Held | Failure:
|
||||
return Held(self.text)
|
||||
|
||||
def write(self, text: str, version: str | None) -> Held | Failure:
|
||||
self.kept.append(text)
|
||||
return Held(text)
|
||||
|
||||
|
||||
class FindingsTest(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.store = MemoryEpic("ABC-12", list(self.issues))
|
||||
self.written = WrittenDescription([DESCRIPTION])
|
||||
|
||||
def backend(self, config: object, key: str) -> tuple[MemoryEpic, EpicRecord]:
|
||||
return self.store, EpicRecord(self.written) # type: ignore[arg-type]
|
||||
|
||||
def run_with(self, argv: list[str], stdin: str = "") -> tuple[int, str, str, FakeEffects]:
|
||||
out, err, fake = io.StringIO(), io.StringIO(), FakeEffects()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
code = main.main(argv, {}, paths_from(self.home), pathlib.Path("/b/do-epic"), fake.effects(), self.backend, io.StringIO(stdin))
|
||||
# Without the time each line of do-epic opens with.
|
||||
return code, out.getvalue().replace("<1790000000> ", ""), err.getvalue().replace("<1790000000> ", ""), fake
|
||||
|
||||
|
||||
class FilingAFinding(FindingsTest):
|
||||
def test_files_an_issue_under_the_epic_with_the_detail_piped_in_and_starts_nothing(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 a label names its repo.\n", ""))
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((filed.key, filed.summary, filed.detail, filed.labels, filed.parent, filed.by_loop), ("ABC-102", "Retry the import on a 503", "The client times out.", (), "ABC-12", True))
|
||||
self.assertEqual(fake.calls, [], "filing needs no tmux, clone or claude")
|
||||
|
||||
def test_a_label_names_the_issues_repo(self) -> None:
|
||||
for argv in (["ABC-12", "--file", "Retry", "--label", "api"], ["ABC-12", "--file", "--label", "api", "Retry"]):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, _, _ = self.run_with(argv)
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((code, out, filed.labels, filed.detail), (0, f"Filed {filed.key} in the epic ABC-12.\n", ("api",), ""))
|
||||
|
||||
def test_says_why_an_issue_was_not_filed(self) -> None:
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--file", "Retry", "--label", "a b"])
|
||||
self.assertEqual((code, out, len(self.store.issues)), (1, "", 2))
|
||||
self.assertEqual(err, "cannot file the finding in the epic ABC-12: the label 'a b' is empty or holds white space\n")
|
||||
self.store.fails = "Jira answered 401"
|
||||
code, _, err, _ = self.run_with(["ABC-12", "--file", "Retry"])
|
||||
self.assertEqual((code, err), (1, "cannot file the finding in the epic ABC-12: Jira answered 401\n"))
|
||||
|
||||
def test_prints_the_help_for_a_filing_spelt_wrong(self) -> None:
|
||||
for argv in (["ABC-12", "--file"], ["ABC-12", "--file", "a", "b"], ["ABC-12", "--file", "a", "--label"], ["ABC-12", "--file", "a", "--labels", "x"], ["--file", "ABC-12", "a"], ["ABC-12", "--file", "--label", "x"]):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, err, _ = self.run_with(argv)
|
||||
self.assertEqual((code, out, err, len(self.store.issues)), (1, "", main.HELP + "\n", 2))
|
||||
|
||||
|
||||
class RecordingADecision(FindingsTest):
|
||||
def test_appends_the_entry_to_the_descriptions_decisions(self) -> None:
|
||||
code, out, err, fake = self.run_with(["ABC-12", "--record-decision", "Imports retry three times"], "2026-11-18, the human's answer. Valid while the client's API rate-limits.\n")
|
||||
self.assertEqual((code, out, err, fake.calls), (0, "Recorded the decision in the epic ABC-12's description.\n", "", []))
|
||||
self.assertEqual(self.written.text, DESCRIPTION + "\n## Decisions\n\n### Imports retry three times\n\n2026-11-18, the human's answer. Valid while the client's API rate-limits.\n")
|
||||
self.assertEqual(self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.")[0], 0)
|
||||
self.assertTrue(self.written.text.endswith("rate-limits.\n\n### Merges squash\n\nAlways.\n"), self.written.text)
|
||||
self.assertIn("## Goals\nShip the import.\n\n## Audience\nThe client's team.\n", self.written.text)
|
||||
|
||||
def test_refuses_a_decision_without_a_title_or_a_body(self) -> None:
|
||||
for argv, stdin, reason in ((["ABC-12", "--record-decision", "Merges squash"], " \n", "pipe the decision's text in"), (["ABC-12", "--record-decision", "two\nlines"], "Always.", "the title must be one line of text"), (["ABC-12", "--record-decision", "Merges squash"], "## Goals\nNone.", "the body of ## Decisions holds a level 1 or 2 heading, which would start another section")):
|
||||
with self.subTest(argv=argv, stdin=stdin):
|
||||
code, out, err, _ = self.run_with(argv, stdin)
|
||||
self.assertEqual((code, out, err, self.written.text), (1, "", f"cannot record the decision in the epic ABC-12's description: {reason}\n", DESCRIPTION))
|
||||
|
||||
def test_prints_the_help_for_a_decision_spelt_wrong(self) -> None:
|
||||
for argv in (["ABC-12", "--record-decision"], ["ABC-12", "--record-decision", "a", "b"], ["ABC-12", "--decide", "a"]):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, err, _ = self.run_with(argv, "Always.")
|
||||
self.assertEqual((code, out, err, self.written.text), (1, "", main.HELP + "\n", DESCRIPTION))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import unittest
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user