From eec17883b31bf55cd944813d9f7eaa5b41b2a080 Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Mon, 16 Nov 2026 04:24:34 -0500 Subject: [PATCH 1/2] ci: Test that the AI rebase job skips without its token (RED) The real workflow passes AI_REBASE_TOKEN straight to actions/checkout, so a repository without that secret gets a red run. The new check fails until every step is guarded on a job env flag set from the secret; it also rejects `secrets` in a job `if:`, which GitHub does not allow. Refs #4461 Co-Authored-By: Claude Opus 5.5 --- ci/test_ai_rebase_token_guard.py | 161 +++++++++++++++++++++++++++++++ 1 file changed, 161 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..d3f2116abc --- /dev/null +++ b/ci/test_ai_rebase_token_guard.py @@ -0,0 +1,161 @@ +#!/usr/bin/env -S uv run --script +"""The AI rebase job skips its steps when AI_REBASE_TOKEN is not set (#4461). + + uv run python -m unittest ci/test_ai_rebase_token_guard.py + +`actions/checkout` failed with "Input required and not supplied: token" on +every master push while the repository had no AI_REBASE_TOKEN secret, so an +optional workflow showed a red run. GitHub does not allow the `secrets` +context in `jobs..if` (actionlint error; #4730 tried it and was closed), +so the job exposes whether the token is set through its `env` and every step +is guarded on that variable: with no token the run only prints a notice. +""" + +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" +SECRET = "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 job_if(job: str) -> str: + m = re.search(r"^ if: *(.*)\n((?: .*\n)*)", job, re.M) + return "" if not m else " ".join([m.group(1), *m.group(2).split()]) + + +def token_flag(job: str) -> str | None: + """The job-level env variable set from `secrets.AI_REBASE_TOKEN != ''`.""" + env = re.search(r"^ env:\n((?: .*\n)*)", job, re.M) + if not env: + return None + for name, value in re.findall(r"^ ([A-Za-z0-9_]+): *(.*)$", env.group(1), re.M): + if re.fullmatch(r"\$\{\{ *" + re.escape(SECRET) + r" *!= *'' *\}\}", value.strip()): + return name + return None + + +def steps(job: str) -> list[str]: + """Each step's text, split on the ` - ` items under ` steps:`.""" + m = re.search(r"^ steps:\n((?:(?: .*)?\n)*)", job, re.M) + if not m: + return [] + return [s for s in re.split(r"^ - ", m.group(1), flags=re.M) if s.strip()] + + +def step_if(step: str) -> str: + m = re.search(r"^(?:| )if: *(.*)$", step, re.M) + return m.group(1).strip() if m else "" + + +def problems(text: str) -> list[str]: + found = [] + for name, job in jobs(text).items(): + if "secrets" in job_if(job): + found.append(f"{name}: `secrets` in the job `if:` (GitHub rejects it)") + if SECRET not in job: + continue + flag = token_flag(job) + if flag is None: + found.append(f"{name}: no job env variable set from `{SECRET} != ''`") + continue + for step in steps(job): + cond = step_if(step) + if not re.search(r"\benv\." + flag + r" *[!=]= *'true'", cond): + first = step.splitlines()[0].strip() + found.append(f"{name}: step `{first}` is not guarded on env.{flag}") + return found + + +UNGUARDED = """\ +on: push + +jobs: + rebase: + if: github.event_name != 'schedule' + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.AI_REBASE_TOKEN }} + - name: Rebase + run: echo +""" + +SECRETS_IN_IF = """\ +on: push + +jobs: + rebase: + if: secrets.AI_REBASE_TOKEN != '' + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.AI_REBASE_TOKEN }} +""" + +GUARDED = """\ +on: push + +jobs: + rebase: + if: github.event_name != 'schedule' + runs-on: ubuntu-24.04 + env: + HAS_TOKEN: ${{ secrets.AI_REBASE_TOKEN != '' }} + steps: + - name: Skip + if: env.HAS_TOKEN != 'true' + run: echo skip + + - uses: actions/checkout@v4 + if: env.HAS_TOKEN == 'true' + with: + token: ${{ secrets.AI_REBASE_TOKEN }} + - name: Rebase + if: env.HAS_TOKEN == 'true' + run: echo +""" + + +class TokenGuardTest(unittest.TestCase): + def test_checker_catches_unguarded_steps(self) -> None: + self.assertEqual( + problems(UNGUARDED), + ["rebase: no job env variable set from `secrets.AI_REBASE_TOKEN != ''`"], + ) + broken = GUARDED.replace(" if: env.HAS_TOKEN == 'true'\n run: echo\n", " run: echo\n") + self.assertEqual(problems(broken), ["rebase: step `name: Rebase` is not guarded on env.HAS_TOKEN"]) + + def test_checker_rejects_secrets_in_job_if(self) -> None: + self.assertIn("rebase: `secrets` in the job `if:` (GitHub rejects it)", problems(SECRETS_IN_IF)) + + def test_checker_accepts_guarded_job(self) -> None: + self.assertEqual(problems(GUARDED), []) + + def test_real_workflow_is_guarded(self) -> None: + text = WORKFLOW.read_text(encoding="utf-8") + self.assertIn(SECRET, text) + self.assertEqual(problems(text), []) + + def test_real_workflow_says_why_it_skipped(self) -> None: + job = jobs(WORKFLOW.read_text(encoding="utf-8"))["rebase"] + flag = token_flag(job) + notices = [s for s in steps(job) if f"env.{flag} != 'true'" in step_if(s)] + self.assertEqual(len(notices), 1) + self.assertIn("::notice", notices[0]) + + +if __name__ == "__main__": + unittest.main() From 9d272889f6b007999fd236f707e13c6af76c78be Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Mon, 16 Nov 2026 04:26:13 -0500 Subject: [PATCH 2/2] ci: Skip the AI rebase steps when AI_REBASE_TOKEN is not set (GREEN) actions/checkout failed with "Input required and not supplied: token" on every master push of a repository without the secret. GitHub does not allow `secrets` in a job `if:`, so the job sets HAS_TOKEN in its env and every step checks it; without the token the run prints one notice and succeeds. A shellcheck directive covers PRS and DRY, which split into arguments on purpose, so actionlint reports nothing for the file. Refs #4461 Co-Authored-By: Claude Opus 5.5 Ci-Attestation: {"at":1794821242,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":54,"stamp":"903e71eff217ee45132570c26c84e9a4","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821242,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":54,"stamp":"c272dd106e4db5b69cd7c3ded5843b29","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821242,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":54,"stamp":"7762eb890d08ec0afa0ad2d93025c387","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821242,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":54,"stamp":"aa81c6279b0e8f86ca2de1db6a2b563b","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821186,"gate":"general/all/client-lint","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"842795822936d00964dda439c3962ec6","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821242,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":54,"stamp":"6705a3add7c245822f0cd785c2f8a7a3","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821187,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"c6d3e8cf30d8fe20db2acf2508d17b17","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821187,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"9e562fd7e1266775eb99724b5d9b739f","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821187,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"036bf3fde04c94c52d386b27b621572d","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821187,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"fbab428d3b376a59f6698852a1dd88d7","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821186,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"8d3ca73b4b6f95361fa1237f30cbc212","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821186,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"4a433fe94382b9aedc86f5dfcd9e1c43","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821187,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"5029528ba8c646136abebf2e4824c964","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821187,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"524420046deda1bca2dfba1e68db88d1","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821186,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"409fa7d7d08abe167f2a3144c4b925e8","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821187,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"f806a69aa8aa66251921909440a55b8a","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821186,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"c751e2dad10ce40f3bdf87b9f08491b4","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821186,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"053fb229c735a20c0c1a49ed477d2f42bd3e4bc7ee068827c7a936ade4cc1895","lane":"client-lint","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":9,"stamp":"bad5077737acd35630c19f1a9d1993fc","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Ci-Attestation: {"at":1794821481,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"959e07692f51ac0fff258d78eeec46fb7fd0896bf99642aea28e80eae476a80d","lane":"client-test-x86_64-unknown-linux-gnu","parents":["eec17883b31bf55cd944813d9f7eaa5b41b2a080"],"secs":239,"stamp":"f5651ed94552672022b80d8353724e8b","tree":"3048451576af9a789fd648b32823f242b9e5181f","v":1,"via":"run"} Client-Checks: {"checks":{"base":"390b55edb206c56e08c063098b433b0d1818f7d2","coverage":"all-tracked-applicable-files","diff":[".github/workflows/ai-rebase.yaml","ci/test_ai_rebase_token_guard.py"],"head":"ac6ce7fc120a55a4c8e4fa5faea72bcd8e119767","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"d4f83a5d9e1ef1aeca78a990982a53fd22ffb7d6737c94f1e52f48e61864c33d","tree":"3048451576af9a789fd648b32823f242b9e5181f"}} --- .github/workflows/ai-rebase.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/ai-rebase.yaml b/.github/workflows/ai-rebase.yaml index f9ee48763f..2b98757078 100644 --- a/.github/workflows/ai-rebase.yaml +++ b/.github/workflows/ai-rebase.yaml @@ -41,24 +41,37 @@ jobs: if: github.event_name != 'schedule' || github.repository == 'obs-rust/obs-studio' runs-on: ubuntu-24.04 timeout-minutes: 30 + # GitHub does not allow `secrets` in a job `if:`, so whether the token is + # set comes through env and every step checks it (#4461). Without it the + # run only prints a notice instead of failing in actions/checkout. + env: + HAS_TOKEN: ${{ secrets.AI_REBASE_TOKEN != '' }} steps: + - name: Skip without AI_REBASE_TOKEN + if: env.HAS_TOKEN != 'true' + run: echo "::notice::AI_REBASE_TOKEN is not set, so this run rebases nothing." - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + if: env.HAS_TOKEN == 'true' with: fetch-depth: 0 token: ${{ secrets.AI_REBASE_TOKEN }} - uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0 + if: env.HAS_TOKEN == 'true' with: save-cache: ${{ github.ref == 'refs/heads/master' }} # rustfmt for resolved Rust files (the agent runs `soldr cargo fmt`). - uses: zackees/setup-soldr@d01d9bae0d5a42ceed086dab6f8f272a0c876ac2 # s3 remote cache + if: env.HAS_TOKEN == 'true' with: build-cache: false save-cache-remote: ${{ github.ref == 'refs/heads/master' }} # The conflict resolver: the clud agent, unattended, on DeepSeek Flash # through OpenRouter, driven by ci/ai_rebase_prompt.md. - name: Install clud + if: env.HAS_TOKEN == 'true' run: uv tool install clud - name: Rebase + if: env.HAS_TOKEN == 'true' env: GH_TOKEN: ${{ secrets.AI_REBASE_TOKEN }} OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} @@ -67,6 +80,7 @@ jobs: run: | git config user.name "obs-rust ai-rebase" git config user.email "ai-rebase@users.noreply.github.com" + # shellcheck disable=SC2086 # PRS and DRY split into arguments on purpose if [ -n "$PRS" ]; then uv run --no-project --script ci/ai_rebase.py $PRS $DRY --comment else