Test the commands a gate read runs, a parked chunk's window calls and the failures of unparking

This commit is contained in:
2026-11-18 23:29:04 +01:00
parent 2dcf93a55f
commit 0eea8aa10d
4 changed files with 38 additions and 7 deletions
+12 -1
View File
@@ -21,6 +21,7 @@ class Forge:
def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', worktrees: str = WORKTREES, fails: str = "") -> None:
self.ran: list[str] = []
self.commands: list[list[str]] = []
self.fails = fails
self.answers = {
"git worktree": worktrees,
@@ -39,6 +40,7 @@ class Forge:
def at(self, folder: str):
def run(command: list[str]) -> str | Failure:
self.ran.append(folder)
self.commands.append(command)
key = " ".join(command) if command[0] == "tea" else " ".join(command[:3] if command[0] == "gh" else command[:2])
return Failure(f"{key} failed") if self.fails and key.startswith(self.fails) else self.answers[key]
return run
@@ -51,7 +53,16 @@ class GateOfAChunk(unittest.TestCase):
def test_a_pull_request_whose_checks_passed_awaits_the_approval_its_protection_requires(self):
forge = Forge()
self.assertEqual(forge.gate(), Gate("/code/billing-ABC-21", "7", APPROVAL))
self.assertEqual(set(forge.ran[1:]), {"/code/billing-ABC-21"})
self.assertEqual((forge.ran[0], set(forge.ran[1:])), ("/code/billing", {"/code/billing-ABC-21"}))
self.assertEqual(forge.commands[:4], [["git", "worktree", "list", "--porcelain"], ["git", "remote", "get-url", "origin"], ["git", "rev-parse", "HEAD"], ["git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD"]])
self.assertIn(["gh", "pr", "view", "7", "--json", "isDraft,reviewDecision"], forge.commands)
self.assertIn(["gh", "pr", "checks", "7", "--json", "bucket"], forge.commands)
self.assertTrue(any(command[:3] == ["gh", "api", "graphql"] and "number=7" in command for command in forge.commands), forge.commands)
def test_a_review_decision_gh_prints_in_no_known_shape_is_a_failure(self):
forge = Forge()
forge.answers["gh pr view"] = "[1]"
self.assertEqual(forge.gate(), Failure("gh pr view printed no review decision: [1]"))
def test_a_pull_request_awaits_its_checks_while_one_runs_whatever_its_reviews_say(self):
for decision in ("REVIEW_REQUIRED", "APPROVED", "CHANGES_REQUESTED", ""):