Answer stability round 1: 0 🔴, 3 🟡 (0 misread); bound the forge's CLI with a timeout in one runner, and read a pull request from a deleted fork
CI / tests (pull_request) Successful in 3m20s

This commit is contained in:
Lilleman
2026-11-19 23:30:30 +01:00
parent 356ae263e1
commit 0c52688ff8
7 changed files with 35 additions and 30 deletions
+17 -7
View File
@@ -9,7 +9,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from forge.pulls import CheckFailed, checks_now, checks_passed, open_pull, Pending, POLL_SECONDS, ready_pulls, ReadyPull, required_checks, WAIT_SECONDS
from failure import Failure
from forge.commands import forge_of, gitea, url_beside
from forge.commands import forge_of, gitea, runner, url_beside
class ForgeOf(unittest.TestCase):
@@ -136,11 +136,6 @@ class ChecksPassed(unittest.TestCase):
self.assertEqual(checks_passed("tea", "1", "abc", set(), tea([LONG]), self.fail).reason, f"tea api printed no commit status for abc: {LONG[:200]}")
if __name__ == "__main__":
unittest.main()
SHA = "a" * 40
GITEA_PULL = {"number": 7, "html_url": "https://gitea.example/o/r/pulls/7", "title": "Do 7", "head": {"sha": SHA, "repo": {"full_name": "o/r"}}, "base": {"repo": {"full_name": "o/r"}}}
@@ -158,10 +153,25 @@ class ReadyPulls(unittest.TestCase):
def test_lists_on_tea_each_open_pull_request_from_origins_own_branches_whose_title_marks_no_draft(self):
fork = {**GITEA_PULL, "number": 8, "head": {"sha": SHA, "repo": {"full_name": "other/r"}}}
draft = {**GITEA_PULL, "number": 9, "title": "wip: Do 9"}
deleted_fork = {**GITEA_PULL, "number": 10, "head": {"sha": SHA, "repo": None}}
commands: list[list[str]] = []
self.assertEqual(ready_pulls("tea", lambda command: commands.append(command) or json.dumps([GITEA_PULL, fork, draft])), [ReadyPull("7", "https://gitea.example/o/r/pulls/7", SHA)])
self.assertEqual(ready_pulls("tea", lambda command: commands.append(command) or json.dumps([GITEA_PULL, fork, draft, deleted_fork])), [ReadyPull("7", "https://gitea.example/o/r/pulls/7", SHA)])
self.assertEqual(commands, [["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"]])
def test_fails_where_the_forge_cannot_list_them(self):
self.assertEqual(ready_pulls("gh", lambda command: Failure("gh: no network")).reason, "gh: no network")
self.assertEqual(ready_pulls("tea", lambda command: LONG).reason, f"tea api listed pull requests in a shape that can't be read: {LONG[:200]}")
class Runner(unittest.TestCase):
def test_prints_what_a_command_printed_and_fails_where_it_exits_nonzero_cannot_start_or_outlasts_its_timeout(self):
self.assertEqual(runner("/")(["echo", "hello"]), "hello\n")
self.assertEqual(runner("/")(["sh", "-c", "echo no >&2; exit 3"]), Failure("sh -c echo no >&2; exit 3: no"))
failed = runner("/")(["no-such-forge-cli", "pr", "list"])
self.assertIsInstance(failed, Failure)
self.assertTrue(failed.reason.startswith("no-such-forge-cli could not start: "), failed.reason)
self.assertEqual(runner("/", 0.05)(["sleep", "5"]), Failure("sleep 5: stopped after 0.05 s"))
if __name__ == "__main__":
unittest.main()