diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b4e28a..5e660c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ Format: [Keep a Changelog](https://keepachangelog.com/de/1.1.0/), [Semantic Vers ### Behoben / Fixed +- `actions.rerun`: Sicherheitsabstand von einer Stunde vor der 30-Tage-Grenze (`_RERUN_WINDOW`), damit Uhrabweichung oder ein genau 30 Tage alter Lauf den POST nicht doch absetzen und einen 403 mit host-weitem policy HOLD ausloesen / one-hour safety margin before the 30-day re-run limit (Folgepunkt zu #21, T-20261127-325831929). + +### Behoben / Fixed + - `actions.rerun`: Ein Lauf außerhalb des 30-Tage-Rerun-Fensters von GitHub wird lokal abgelehnt, ohne den POST zu senden. Der sonst folgende HTTP 403 setzte einen persistenten host-weiten `policy_hold` und blockierte alle koordinierten Schreibaktionen / a run older than 30 days is refused locally without sending the POST; its 403 used to set a persistent host-wide policy HOLD. Jeder andere 403 bleibt unverändert fail-closed (Ticket T-20261127-325831929). ## [0.2.2] - 2026-11-22 diff --git a/src/githubbot_core/typed_actions.py b/src/githubbot_core/typed_actions.py index bd78974..150aca8 100644 --- a/src/githubbot_core/typed_actions.py +++ b/src/githubbot_core/typed_actions.py @@ -43,6 +43,10 @@ ) REVIEW_STATES = {"COMMENT": "COMMENTED", "APPROVE": "APPROVED", "REQUEST_CHANGES": "CHANGES_REQUESTED"} +# GitHub re-runs only up to 30 days after the initial run; one hour less keeps host clock drift +# and a run of exactly 30 days from sending a POST that would earn a 403 (host-wide policy HOLD). +_RERUN_WINDOW = timedelta(days=30) - timedelta(hours=1) + _PARTIAL_TEST_RE = re.compile( r"(?i)(?:\bfollowup\w*\b|\bdialog[- ]?test\b|\bteilmenge\b|" r"\bpartial\s+(?:test|tests|suite|run)\b|\bsubset\b|\bsingle[- ]test\b|" @@ -541,7 +545,7 @@ def exec_rerun(transport, params: dict, config: dict): # unreadable timestamp changes nothing: the request goes out as before. try: started = datetime.fromisoformat(str(run.get("created_at")).replace("Z", "+00:00")) - if datetime.now(timezone.utc) - started > timedelta(days=30): + if datetime.now(timezone.utc) - started > _RERUN_WINDOW: return None, "run is outside the 30-day re-run window; not re-run" except ValueError: pass diff --git a/tests/test_typed_actions.py b/tests/test_typed_actions.py index 2765945..69a8ec0 100644 --- a/tests/test_typed_actions.py +++ b/tests/test_typed_actions.py @@ -392,6 +392,24 @@ def run(age_days): assert transport.writes == [("POST", f"repos/{REPO}/actions/runs/5/rerun", None)] +def test_rerun_keeps_a_safety_margin_before_the_30_day_limit(): + # Host clock drift or an exactly-30-day-old run must not let the POST out: GitHub would + # answer 403 and the transport would set a host-wide policy HOLD. Limit = 30 d - 1 h. + from datetime import datetime, timedelta, timezone + + def run(age): + stamp = (datetime.now(timezone.utc) - age).strftime("%Y-%m-%dT%H:%M:%SZ") + return {"head_sha": SHA, "status": "completed", "head_repository": {"full_name": REPO}, "created_at": stamp} + + inside = timedelta(days=30) - timedelta(minutes=70) + margin = timedelta(days=30) - timedelta(minutes=50) + for n, (age, posted) in enumerate(((inside, True), (margin, False), (timedelta(days=30), False)), 11): + action = Action("actions.rerun", {"repo": REPO, "run_id": n, "sha": SHA}) + transport = Transport({f"repos/{REPO}/actions/runs/{n}": run(age)}) + status = actions.apply([action], transport, config())["receipts"][0]["status"] + assert (status, bool(transport.writes)) == (("applied" if posted else "failed"), posted), age + + def test_dispatch_needs_an_active_workflow(): action = Action("actions.dispatch", {"repo": REPO, "workflow": "ci.yml", "ref": "bot/fix"}) transport = Transport({f"repos/{REPO}/actions/workflows/ci.yml": {"state": "disabled_manually"}})