diff --git a/tests/integration/test_trust_live.py b/tests/integration/test_trust_live.py index 32208ab..bd63917 100644 --- a/tests/integration/test_trust_live.py +++ b/tests/integration/test_trust_live.py @@ -5,6 +5,7 @@ and a commit pushed after the approval needs approving again: at once by the agent's own check, and by Gitea once it has dismissed the approval.""" import base64 +import re import time import uuid from pathlib import Path @@ -44,13 +45,29 @@ def wait_for_dismissal(gitea: GiteaClient, repo: str, pr: int) -> None: in the push itself, and its merge check counts what isn't dismissed yet. A merge tried before that job has run can still go through (#162).""" deadline = time.monotonic() + DISMISS_WAIT_S - while gitea.approvals(repo, pr): # dismissed ones aren't listed + while True: + try: + if not gitea.approvals(repo, pr): # dismissed ones aren't listed + return + except GiteaError as exc: + # A busy Gitea may drop a call or answer 5xx; ask again. Anything + # else, such as a 4xx, is a real failure. + if not transient(exc) or time.monotonic() > deadline: + raise assert time.monotonic() < deadline, ( f"Gitea didn't dismiss the approval within {DISMISS_WAIT_S}s" ) time.sleep(0.5) +def transient(exc: GiteaError) -> bool: + """A dropped connection or a 5xx: worth asking again.""" + text = str(exc) + return text.startswith("gitea request failed") or bool( + re.search(r" returned 5\d\d:", text) + ) + + def test_merging_needs_the_operators_approval_of_the_pr_as_it_is( tmp_path: Path, live_config: AgentConfig, gitea: GiteaClient ) -> None: