From e70b5cb3a55698460bedcf3096c4408877d360f9 Mon Sep 17 00:00:00 2001 From: obs-rust worker Date: Wed, 11 Nov 2026 13:20:20 -0500 Subject: [PATCH 1/2] test(ci): pin ai-rebase skips when AI_REBASE_TOKEN unset (RED) Refs #4461. The check fails against the current ai-rebase.yaml: its root job reads secrets.AI_REBASE_TOKEN in steps with no configured guard, so checkout paid for setup and then died. GREEN adds the guard. --- ci/test_ai_rebase_token_guard.py | 89 ++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 ci/test_ai_rebase_token_guard.py diff --git a/ci/test_ai_rebase_token_guard.py b/ci/test_ai_rebase_token_guard.py new file mode 100644 index 0000000000..50100af715 --- /dev/null +++ b/ci/test_ai_rebase_token_guard.py @@ -0,0 +1,89 @@ +#!/usr/bin/env -S uv run --script +"""The optional ai-rebase workflow must skip when its token is unset (#4461). + + uv run python -m unittest ci/test_ai_rebase_token_guard.py + +`actions/checkout` fails with `Input required and not supplied: token` when +`secrets.AI_REBASE_TOKEN` is empty, so a master push armed the ai-rebase job, +paid for setup, and then died before its rebase logic (run 42724921146 of the +#4450 master push). The workflow is optional: with no token configured it must +skip its root job instead. Every root job whose body reads +`secrets.AI_REBASE_TOKEN` now carries `secrets.AI_REBASE_TOKEN != ''` in its +`if:`, so an unconfigured repository skips the whole job. +""" + +from __future__ import annotations + +import re +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent +WORKFLOW = ROOT / ".github" / "workflows" / "ai-rebase.yaml" + +TOKEN_REF = "secrets.AI_REBASE_TOKEN" +GUARD = "secrets.AI_REBASE_TOKEN != ''" + + +def jobs(text: str) -> dict[str, str]: + """Each job's name and body (the lines below ` :`).""" + body = text.split("\njobs:\n", 1)[1] + parts = re.split(r"^ ([A-Za-z0-9_-]+):\n", body, flags=re.M) + return dict(zip(parts[1::2], parts[2::2])) + + +def condition(job: str) -> str: + """The job's `if:`, with a folded block (`>-`) joined into one line.""" + m = re.search(r"^ if: *(.*)\n((?: .*\n)*)", job, re.M) + if not m: + return "" + lines = [m.group(1)] if m.group(1) not in (">-", ">", "|") else [] + lines += [line.strip() for line in m.group(2).splitlines()] + return " ".join(lines) + + +def unguarded_token_jobs(text: str) -> list[str]: + return [ + name + for name, job in jobs(text).items() + if TOKEN_REF in job and GUARD not in condition(job) + ] + + +WITH_GUARD = """\ +on: + push: + branches: [master] +jobs: + rebase: + if: >- + (github.event_name != 'schedule' || github.repository == 'obs-rust/obs-studio') && + secrets.AI_REBASE_TOKEN != '' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout + with: + token: ${{ secrets.AI_REBASE_TOKEN }} +""" + +WITHOUT_GUARD = WITH_GUARD.replace(" secrets.AI_REBASE_TOKEN != ''\n", "") + + +class ParserTest(unittest.TestCase): + def test_accepts_a_folded_guarded_condition(self): + self.assertEqual(unguarded_token_jobs(WITH_GUARD), []) + + def test_reports_the_unguarded_token_job(self): + self.assertEqual(unguarded_token_jobs(WITHOUT_GUARD), ["rebase"]) + + def test_ignores_jobs_without_the_token(self): + self.assertEqual(unguarded_token_jobs("on:\nx\njobs:\n other:\n runs-on: x\n"), []) + + +class WorkflowTest(unittest.TestCase): + def test_ai_rebase_skips_when_the_token_is_unset(self): + self.assertEqual(unguarded_token_jobs(WORKFLOW.read_text(encoding="utf-8")), []) + + +if __name__ == "__main__": + unittest.main() From ae0f6e73c0fac49c6cbd7b6c4c19ee56236704a3 Mon Sep 17 00:00:00 2001 From: obs-rust worker Date: Wed, 11 Nov 2026 13:20:33 -0500 Subject: [PATCH 2/2] ci: skip ai-rebase when its token is not configured (GREEN) Refs #4461. Fold secrets.AI_REBASE_TOKEN != '' into the root job if alongside the fork guard, so an unconfigured repository skips the optional job instead of failing actions/checkout with a missing token. Ci-Attestation: local RED/GREEN pairs for ci/test_ai_rebase_token_guard and ci/test_workflow_schedule_guard; 9 unit tests pass on the branch tip. --- .github/workflows/ai-rebase.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ai-rebase.yaml b/.github/workflows/ai-rebase.yaml index f9ee48763f..5c36c920ff 100644 --- a/.github/workflows/ai-rebase.yaml +++ b/.github/workflows/ai-rebase.yaml @@ -38,7 +38,9 @@ concurrency: jobs: rebase: - if: github.event_name != 'schedule' || github.repository == 'obs-rust/obs-studio' + if: >- + (github.event_name != 'schedule' || github.repository == 'obs-rust/obs-studio') && + secrets.AI_REBASE_TOKEN != '' runs-on: ubuntu-24.04 timeout-minutes: 30 steps: