Answer stability round 1: 1 🔴, 5 🟡 (0 misread); hold a pull request's base on the forge to the recorded one, ask origin for the epic branch, and name where a chunk's work landed
CI / tests (pull_request) Successful in 3m46s

This commit is contained in:
Lilleman
2026-11-20 21:42:32 +01:00
parent 525f3f8836
commit d464f271bf
13 changed files with 352 additions and 74 deletions
+14 -4
View File
@@ -28,7 +28,7 @@ def comment(by: str, at: str) -> dict:
class Forge:
"""Stands in for git and the forge's CLI in the checkout and the chunk's worktree; `ran` holds each folder a command ran in. Only the CLI of origin's forge answers: `gh` fails on a Gitea origin, and `tea` on a GitHub one."""
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}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x") -> None:
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}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x", base: str = "main") -> None:
self.cli = "gh" if "github.com" in origin else "tea"
self.ran: list[str] = []
self.commands: list[list[str]] = []
@@ -40,11 +40,11 @@ class Forge:
"git symbolic-ref": "origin/main\n",
"git config": Failure("git config: unset"),
"gh pr list": pulls,
"gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments), "mergeable": mergeable, "mergeStateStatus": merge_state}),
"gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments), "mergeable": mergeable, "mergeStateStatus": merge_state, "baseRefName": base}),
"gh pr checks": json.dumps([{"bucket": bucket} for bucket in buckets]),
"gh api graphql": json.dumps({"data": {"repository": {"pullRequest": {"author": {"login": "worker"}, "reviewThreads": {"nodes": list(threads)}}}}}),
"tea api repos/{owner}/{repo}/pulls?state=open&limit=50": json.dumps([{"number": 7, "merged": False, "head": {"label": "ABC-21", "sha": HEAD, "repo": {"full_name": "o/billing"}}, "base": {"repo": {"full_name": "o/billing"}}}]),
"tea api repos/{owner}/{repo}/pulls/7": json.dumps({"number": 7, "title": title, "mergeable": mergeable == "MERGEABLE"}),
"tea api repos/{owner}/{repo}/pulls/7": json.dumps({"number": 7, "title": title, "mergeable": mergeable == "MERGEABLE", "base": {"ref": base}}),
"tea api repos/{owner}/{repo}/branches/main": '{"name": "main"}',
"tea api repos/{owner}/{repo}/commits/" + HEAD + "/status": status,
}
@@ -122,13 +122,23 @@ class GateOfAChunk(unittest.TestCase):
self.assertEqual(Forge(gitea).gate(), Open("pull request #7 passed its checks"))
def test_a_chunk_that_merges_into_an_epics_working_branch_reads_the_checks_that_branch_requires(self):
forge = Forge("https://gitea.larvit.se/o/billing.git")
forge = Forge("https://gitea.larvit.se/o/billing.git", base="ABC-12")
forge.answers["git config"] = "ABC-12\n"
forge.answers["tea api repos/{owner}/{repo}/branches/ABC-12"] = '{"enable_status_check": true, "status_check_contexts": ["epic-gate"]}'
self.assertEqual(forge.gate(), Gate("/code/billing-ABC-21", "7", CHECKS))
self.assertIn(["git", "config", "--get", "branch.ABC-21.chunk-base"], forge.commands)
self.assertNotIn(["tea", "api", "repos/{owner}/{repo}/branches/main"], forge.commands)
def test_a_pull_request_the_forge_merges_into_another_branch_than_the_checkout_records_is_a_failure_naming_both(self):
differs = "pull request #7 merges into {} on the forge, but this checkout takes {} as the base of its branch; a person settles which holds, and changes the pull request's base on the forge or the branch's `chunk-base` in git's config"
for origin in ("git@github.com:o/billing.git", "https://gitea.larvit.se/o/billing.git"):
with self.subTest(origin):
recorded = Forge(origin, decision="APPROVED")
recorded.answers["git config"] = "ABC-12\n"
self.assertEqual(recorded.gate(by_human=False), Failure(differs.format("main", "ABC-12")), "no pull request into the default branch reads as one that merges without a person")
self.assertNotIn(["tea", "api", "repos/{owner}/{repo}/branches/ABC-12"], recorded.commands)
self.assertEqual(Forge(origin, decision="APPROVED", base="ABC-12").gate(by_human=True), Failure(differs.format("ABC-12", "main")))
def test_a_gitea_draft_awaits_nothing_though_its_checks_run(self):
gitea = "https://gitea.larvit.se/o/billing.git"
for title in ("WIP: Add x", "[wip] Add x"):