From 7a4a6c94370fe06711e3a1a184a83a871954f4a2 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 4 Oct 2026 00:58:32 +0000 Subject: [PATCH 01/70] ci: scope website lint gates --- .github/actions/changes-filter/action.yaml | 6 ++ .github/workflows/README.md | 5 + .github/workflows/ci-lint-format-queue.yaml | 70 ++++++++++++++ .github/workflows/ci-lint-format.yaml | 100 ++++++++++++++++++++ 4 files changed, 181 insertions(+) diff --git a/.github/actions/changes-filter/action.yaml b/.github/actions/changes-filter/action.yaml index d34211d417a..a250ccc96cf 100644 --- a/.github/actions/changes-filter/action.yaml +++ b/.github/actions/changes-filter/action.yaml @@ -87,6 +87,9 @@ outputs: dependency-changes: description: 'Root `.nvmrc`, `package.json`, `pnpm-lock.yaml`, or `pnpm-workspace.yaml` changed.' value: ${{ steps.mode.outputs.evaluate != 'true' || steps.filter.outputs.deps == 'true' }} + website-only-changes: + description: 'Every changed file is under `apps/website/**`.' + value: ${{ steps.mode.outputs.evaluate == 'true' && steps.filter.outputs.app_website == 'true' && steps.relevant.outputs.outside_website != 'true' }} runs: using: composite @@ -157,3 +160,6 @@ runs: - *unit - '!**/*.test.ts' - '!**/__mocks__/**' + outside_website: + - '**' + - '!apps/website/**' diff --git a/.github/workflows/README.md b/.github/workflows/README.md index c2398a00abe..0c5cda7152a 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -22,4 +22,9 @@ The candidate dependency prototype lives in `ci-tests-e2e.yaml`. See [CI-PREREQUISITES-0038](../../docs/adr/CI-PREREQUISITES-0038-gate-expensive-candidate-tests.md) for measured runtimes, required-check compatibility, and rollout limits. +The required `lint-and-format` context keeps one stable name across pull requests and merge-queue +candidates. Changes confined to `apps/website/**` run website-scoped lint, format, typecheck, and +Knip jobs. Any file outside that directory selects the full repository jobs; pushes to protected +branches always run the full jobs. + For GitHub Actions documentation, see [Events that trigger workflows](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows). diff --git a/.github/workflows/ci-lint-format-queue.yaml b/.github/workflows/ci-lint-format-queue.yaml index 139bfd403a0..6265ccbf3ac 100644 --- a/.github/workflows/ci-lint-format-queue.yaml +++ b/.github/workflows/ci-lint-format-queue.yaml @@ -32,7 +32,22 @@ env: packages/*/node_modules/.cache/tsbuildinfo jobs: + changes: + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + website-only: ${{ steps.changes.outputs.website-only-changes }} + steps: + - uses: actions/checkout@v7 + - id: changes + uses: ./.github/actions/changes-filter + with: + evaluate-candidate: 'true' + lint: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout ref @@ -62,6 +77,8 @@ jobs: path: ${{ env.LINT_CACHE_PATHS }} typecheck: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout ref @@ -88,6 +105,8 @@ jobs: path: ${{ env.TYPECHECK_CACHE_PATHS }} typecheck-aux: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout ref @@ -114,6 +133,8 @@ jobs: path: ${{ env.TYPECHECK_CACHE_PATHS }} repo-checks: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout ref @@ -130,6 +151,55 @@ jobs: - name: Verify knip, locale integrity and ADR index uses: ./.github/actions/repo-checks + website-lint: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: ./.github/actions/setup-frontend + + - name: Restore lint caches + id: lint-cache + uses: ./.github/actions/tool-cache-restore + with: + scope: website-lint + path: ${{ env.LINT_CACHE_PATHS }} + + - name: Verify website lint and format + run: | + pnpm exec stylelint --cache --cache-strategy content 'apps/website/**/*.{css,vue}' + pnpm exec oxlint apps/website --type-aware + pnpm exec eslint apps/website --cache --cache-strategy content --concurrency auto + pnpm --filter @comfyorg/website format:check + + - name: Save lint caches + if: always() + uses: ./.github/actions/tool-cache-save + with: + cache-key: ${{ steps.lint-cache.outputs.cache-key }} + path: ${{ env.LINT_CACHE_PATHS }} + + website-typecheck: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: ./.github/actions/setup-frontend + - name: Typecheck website + run: pnpm typecheck:website + + website-repo-checks: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: ./.github/actions/setup-frontend + - name: Find unused website files, exports and dependencies + run: pnpm knip --workspace apps/website + # Single stable branch-protection context over the parallel jobs above. lint-and-format: needs: [lint, typecheck, typecheck-aux, repo-checks] diff --git a/.github/workflows/ci-lint-format.yaml b/.github/workflows/ci-lint-format.yaml index 6434861bbf6..02e26cc1402 100644 --- a/.github/workflows/ci-lint-format.yaml +++ b/.github/workflows/ci-lint-format.yaml @@ -23,7 +23,20 @@ env: packages/*/node_modules/.cache/tsbuildinfo jobs: + changes: + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + website-only: ${{ steps.changes.outputs.website-only-changes }} + steps: + - uses: actions/checkout@v7 + - id: changes + uses: ./.github/actions/changes-filter + lint: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout PR @@ -110,6 +123,8 @@ jobs: path: ${{ env.LINT_CACHE_PATHS }} typecheck: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout PR @@ -136,6 +151,8 @@ jobs: path: ${{ env.TYPECHECK_CACHE_PATHS }} typecheck-aux: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout PR @@ -162,6 +179,8 @@ jobs: path: ${{ env.TYPECHECK_CACHE_PATHS }} repo-checks: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout PR @@ -177,3 +196,84 @@ jobs: - name: Verify knip, locale integrity and ADR index uses: ./.github/actions/repo-checks + + website-lint: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} + runs-on: ubuntu-latest + steps: + - name: Checkout PR + uses: actions/checkout@v7 + with: + ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || github.ref }} + token: ${{ !github.event.pull_request.head.repo.fork && secrets.PR_GH_TOKEN || github.token }} + + - name: Setup frontend + uses: ./.github/actions/setup-frontend + with: + node_cache: 'false' + + - name: Restore lint caches + id: lint-cache + uses: ./.github/actions/tool-cache-restore + with: + scope: website-lint + path: ${{ env.LINT_CACHE_PATHS }} + + - name: Apply website lint and format fixes + run: | + pnpm exec stylelint --cache --cache-strategy content --fix 'apps/website/**/*.{css,vue}' + pnpm exec oxlint apps/website --type-aware --fix + pnpm exec eslint apps/website --cache --cache-strategy content --concurrency auto --fix + pnpm --filter @comfyorg/website format + + - name: Check for changes + id: verify-changed-files + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + else + echo "changed=false" >> "$GITHUB_OUTPUT" + fi + + - name: Commit changes + if: steps.verify-changed-files.outputs.changed == 'true' && github.event.pull_request.head.repo.full_name == github.repository + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add apps/website + git commit -m "[automated] Apply website lint and format fixes" + git push + + - name: Fail for fork PRs with unfixed lint or format issues + if: steps.verify-changed-files.outputs.changed == 'true' && github.event.pull_request.head.repo.full_name != github.repository + run: | + echo "::error::Website linting or formatting issues found. Run the website checks locally and push the changes." + exit 1 + + - name: Save lint caches + if: always() + uses: ./.github/actions/tool-cache-save + with: + cache-key: ${{ steps.lint-cache.outputs.cache-key }} + path: ${{ env.LINT_CACHE_PATHS }} + + website-typecheck: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: ./.github/actions/setup-frontend + - name: Typecheck website + run: pnpm typecheck:website + + website-repo-checks: + needs: changes + if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: ./.github/actions/setup-frontend + - name: Find unused website files, exports and dependencies + run: pnpm knip --workspace apps/website From a1aa8f67686e9471fa37a054b774d59546ca4ebf Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 4 Oct 2026 01:17:27 +0000 Subject: [PATCH 02/70] ci: auto-approve trusted website changes --- .github/scripts/website-auto-approve.mjs | 222 ++++++++++++++++++ .github/scripts/website-auto-approve.test.mjs | 140 +++++++++++ .github/workflows/README.md | 14 ++ .../workflows/pr-website-auto-approve.yaml | 47 ++++ 4 files changed, 423 insertions(+) create mode 100644 .github/scripts/website-auto-approve.mjs create mode 100644 .github/scripts/website-auto-approve.test.mjs create mode 100644 .github/workflows/pr-website-auto-approve.yaml diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs new file mode 100644 index 00000000000..a09b57c6e97 --- /dev/null +++ b/.github/scripts/website-auto-approve.mjs @@ -0,0 +1,222 @@ +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' + +const API_VERSION = '2022-11-28' +const PAGE_SIZE = 100 + +export function parseApprovedAuthors(raw) { + let authors + try { + authors = JSON.parse(raw) + } catch (error) { + throw new Error( + `WEBSITE_AUTO_APPROVE_AUTHORS must be JSON: ${error.message}` + ) + } + + if ( + !Array.isArray(authors) || + authors.some((author) => typeof author !== 'string') + ) { + throw new Error( + 'WEBSITE_AUTO_APPROVE_AUTHORS must be a JSON array of GitHub logins' + ) + } + + return new Set( + authors.map((author) => author.trim().toLowerCase()).filter(Boolean) + ) +} + +export function isWebsiteOnly(paths) { + return ( + paths.length > 0 && + paths.every((changedPath) => changedPath.startsWith('apps/website/')) + ) +} + +export function changedPaths(files) { + const paths = [] + for (const file of files) { + if (typeof file?.filename !== 'string') return null + paths.push(file.filename) + if (file.status === 'renamed') { + if (typeof file.previous_filename !== 'string') return null + paths.push(file.previous_filename) + } + } + return paths +} + +export function isSameRepository(pull, repository) { + return pull?.head?.repo?.full_name?.toLowerCase() === repository.toLowerCase() +} + +export function targetsDefaultBranch(pull, repository, defaultBranch) { + return ( + pull?.base?.repo?.full_name?.toLowerCase() === repository.toLowerCase() && + pull?.base?.ref === defaultBranch + ) +} + +export function alreadyApprovedCurrentHead(reviews, approverLogin, headSha) { + const expectedLogin = approverLogin.toLowerCase() + return reviews.some( + (review) => + review?.state === 'APPROVED' && + review?.commit_id === headSha && + review?.user?.login?.toLowerCase() === expectedLogin + ) +} + +function requiredEnv(name) { + const value = process.env[name]?.trim() + if (!value) throw new Error(`${name} is required`) + return value +} + +function githubClient(token, repository) { + const root = `https://api.github.com/repos/${repository}` + const headers = { + accept: 'application/vnd.github+json', + authorization: `Bearer ${token}`, + 'x-github-api-version': API_VERSION, + 'user-agent': 'comfy-website-auto-approve/1.0' + } + + async function request(requestPath, options = {}) { + const url = requestPath.startsWith('https://') + ? requestPath + : `${root}${requestPath}` + const response = await fetch(url, { + ...options, + headers: { ...headers, ...options.headers } + }) + if (!response.ok) { + const body = (await response.text()).slice(0, 500) + throw new Error( + `GitHub API ${options.method ?? 'GET'} ${requestPath} failed: ${response.status} ${body}` + ) + } + if (response.status === 204) return null + return response.json() + } + + async function paginate(requestPath) { + const rows = [] + for (let page = 1; ; page += 1) { + const separator = requestPath.includes('?') ? '&' : '?' + const body = await request( + `${requestPath}${separator}per_page=${PAGE_SIZE}&page=${page}` + ) + if (!Array.isArray(body)) + throw new Error(`GitHub API ${requestPath} did not return an array`) + rows.push(...body) + if (body.length < PAGE_SIZE) return rows + } + } + + return { paginate, request } +} + +function summary(message) { + process.stdout.write(`${message}\n`) + if (process.env.GITHUB_STEP_SUMMARY) { + fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${message}\n`) + } +} + +async function main() { + const token = requiredEnv('WEBSITE_APPROVAL_TOKEN') + const repository = requiredEnv('GITHUB_REPOSITORY') + const prNumber = Number(requiredEnv('PR_NUMBER')) + const eventHeadSha = requiredEnv('PR_HEAD_SHA') + const defaultBranch = requiredEnv('WEBSITE_APPROVAL_BASE_REF') + const expectedApprover = requiredEnv('WEBSITE_APPROVER_LOGIN') + const approvedAuthors = parseApprovedAuthors( + requiredEnv('WEBSITE_AUTO_APPROVE_AUTHORS') + ) + if (!Number.isSafeInteger(prNumber) || prNumber <= 0) + throw new Error('PR_NUMBER must be positive') + + const github = githubClient(token, repository) + const actor = await github.request('https://api.github.com/user') + if (actor?.login?.toLowerCase() !== expectedApprover.toLowerCase()) { + throw new Error( + `WEBSITE_APPROVAL_TOKEN belongs to ${actor?.login ?? 'an unknown account'}, expected ${expectedApprover}` + ) + } + + const pull = await github.request(`/pulls/${prNumber}`) + const author = pull?.user?.login?.toLowerCase() + const liveHeadSha = pull?.head?.sha + + if (pull?.state !== 'open' || pull?.draft) { + summary('Skipped: the pull request is not open and ready for review.') + return + } + if (!targetsDefaultBranch(pull, repository, defaultBranch)) { + summary( + `Skipped: website fast-lane approvals apply only to ${defaultBranch}.` + ) + return + } + if (!isSameRepository(pull, repository)) { + summary( + 'Skipped: website fast-lane approvals do not apply to fork pull requests.' + ) + return + } + if (liveHeadSha !== eventHeadSha) { + summary( + 'Skipped: the pull request head advanced after this workflow started.' + ) + return + } + if (!author || !approvedAuthors.has(author)) { + summary( + `Skipped: @${author ?? 'unknown'} is not in the website fast-lane author allowlist.` + ) + return + } + if (author === expectedApprover.toLowerCase()) { + throw new Error('the approval bot cannot approve its own pull request') + } + + const files = await github.paginate(`/pulls/${prNumber}/files`) + const paths = changedPaths(files) + if (paths === null || !isWebsiteOnly(paths)) { + summary('Skipped: at least one changed file is outside apps/website/**.') + return + } + + const reviews = await github.paginate(`/pulls/${prNumber}/reviews`) + if (alreadyApprovedCurrentHead(reviews, expectedApprover, liveHeadSha)) { + summary( + `Already approved ${liveHeadSha.slice(0, 12)} as @${expectedApprover}.` + ) + return + } + + await github.request(`/pulls/${prNumber}/reviews`, { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ + event: 'APPROVE', + commit_id: liveHeadSha, + body: 'Automatically approved: trusted website fast-lane author; all changed files are under `apps/website/**`.' + }) + }) + summary(`Approved ${liveHeadSha.slice(0, 12)} as @${expectedApprover}.`) +} + +if ( + process.argv[1] && + fileURLToPath(import.meta.url) === path.resolve(process.argv[1]) +) { + main().catch((error) => { + process.stderr.write(`${error.stack ?? error.message}\n`) + process.exitCode = 1 + }) +} diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs new file mode 100644 index 00000000000..59d5cae2319 --- /dev/null +++ b/.github/scripts/website-auto-approve.test.mjs @@ -0,0 +1,140 @@ +import assert from 'node:assert/strict' +import test from 'node:test' + +import { + alreadyApprovedCurrentHead, + changedPaths, + isSameRepository, + isWebsiteOnly, + parseApprovedAuthors, + targetsDefaultBranch +} from './website-auto-approve.mjs' + +test('parses and normalizes the explicit author allowlist', () => { + assert.deepEqual( + parseApprovedAuthors('["bertfy", "BERTFY", ""]'), + new Set(['bertfy']) + ) + assert.throws(() => parseApprovedAuthors('bertfy'), /must be JSON/) + assert.throws( + () => parseApprovedAuthors('{"bertfy":true}'), + /must be a JSON array/ + ) +}) + +test('requires a non-empty website-only path set', () => { + assert.equal(isWebsiteOnly(['apps/website/src/pages/index.astro']), true) + assert.equal( + isWebsiteOnly([ + 'apps/website/src/pages/index.astro', + 'apps/website/public/hero.webp' + ]), + true + ) + assert.equal(isWebsiteOnly([]), false) + assert.equal( + isWebsiteOnly(['apps/website/src/pages/index.astro', 'pnpm-lock.yaml']), + false + ) + assert.equal(isWebsiteOnly(['apps/website-evil/file.ts']), false) +}) + +test('a rename must stay inside the website on both sides', () => { + assert.deepEqual( + changedPaths([ + { + status: 'renamed', + previous_filename: 'apps/website/old.astro', + filename: 'apps/website/new.astro' + } + ]), + ['apps/website/new.astro', 'apps/website/old.astro'] + ) + const crossBoundaryRename = changedPaths([ + { + status: 'renamed', + previous_filename: 'src/sensitive.ts', + filename: 'apps/website/sensitive.ts' + } + ]) + assert.equal(isWebsiteOnly(crossBoundaryRename), false) + assert.equal( + changedPaths([{ status: 'renamed', filename: 'apps/website/new.astro' }]), + null + ) +}) + +test('fork pull requests are not eligible', () => { + assert.equal( + isSameRepository( + { head: { repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } } }, + 'comfy-org/comfyui_frontend' + ), + true + ) + assert.equal( + isSameRepository( + { head: { repo: { full_name: 'bertfy/ComfyUI_frontend' } } }, + 'Comfy-Org/ComfyUI_frontend' + ), + false + ) + assert.equal( + isSameRepository({ head: { repo: null } }, 'Comfy-Org/ComfyUI_frontend'), + false + ) +}) + +test('only pull requests targeting the default branch are eligible', () => { + assert.equal( + targetsDefaultBranch( + { + base: { + ref: 'main', + repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + } + }, + 'comfy-org/comfyui_frontend', + 'main' + ), + true + ) + assert.equal( + targetsDefaultBranch( + { + base: { + ref: 'release', + repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + } + }, + 'Comfy-Org/ComfyUI_frontend', + 'main' + ), + false + ) +}) + +test('idempotency is scoped to the bot and exact head commit', () => { + const reviews = [ + { state: 'APPROVED', commit_id: 'old', user: { login: 'webreviewer-bot' } }, + { state: 'APPROVED', commit_id: 'head', user: { login: 'someone-else' } }, + { + state: 'CHANGES_REQUESTED', + commit_id: 'head', + user: { login: 'webreviewer-bot' } + } + ] + assert.equal( + alreadyApprovedCurrentHead(reviews, 'webreviewer-bot', 'head'), + false + ) + reviews.push({ + state: 'APPROVED', + commit_id: 'head', + user: { login: 'WebReviewer-Bot' } + }) + assert.equal( + alreadyApprovedCurrentHead(reviews, 'webreviewer-bot', 'head'), + true + ) +}) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 0c5cda7152a..aa5e077dd0f 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -28,3 +28,17 @@ Knip jobs. Any file outside that directory selects the full repository jobs; pus branches always run the full jobs. For GitHub Actions documentation, see [Events that trigger workflows](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows). + +## Website auto-approval + +`pr-website-auto-approve.yaml` removes the human approval wait for explicitly +allowlisted authors when every changed file is under `apps/website/**`. It runs +from the protected default branch on `pull_request_target`, never executes PR code, +rejects other base branches and fork pull requests, rechecks the live head, and verifies that +`WEBSITE_APPROVAL_TOKEN` belongs to `webreviewer-bot` before approving. The bot is a member of +`comfy_website_devs`, so its review satisfies the website path reviewer rule. + +The initial author allowlist contains only `bertfy`. Expand it by reviewing a +change to `WEBSITE_AUTO_APPROVE_AUTHORS` in the workflow. A repository +administrator must provide the bot's classic PAT as the Actions secret +`WEBSITE_APPROVAL_TOKEN`; missing or mismatched credentials fail closed. diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml new file mode 100644 index 00000000000..2009d99a09b --- /dev/null +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -0,0 +1,47 @@ +# Auto-approve website-only pull requests from explicitly trusted authors. +# +# Security boundary: +# - pull_request_target reads this workflow from the trusted base branch. +# - automation is checked out from the repository's protected default branch; +# pull request code is never executed. +# - the script rejects other base branches and forks, re-fetches the live PR, +# verifies the exact head SHA, requires every changed path to be under +# apps/website/**, and verifies the PAT owner. +name: 'PR: Website Auto-Approve' + +on: + pull_request_target: + types: [opened, reopened, synchronize, ready_for_review] + +permissions: + contents: read + +concurrency: + group: website-auto-approve-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + approve: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout trusted base automation + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + ref: refs/heads/${{ github.event.repository.default_branch }} + persist-credentials: false + sparse-checkout: .github/scripts + + - name: Approve eligible website pull request + env: + GITHUB_REPOSITORY: ${{ github.repository }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PR_NUMBER: ${{ github.event.pull_request.number }} + WEBSITE_APPROVAL_BASE_REF: ${{ github.event.repository.default_branch }} + WEBSITE_APPROVAL_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} + WEBSITE_APPROVER_LOGIN: webreviewer-bot + # This is intentionally checked in: changing who can receive an + # automatic approval must itself pass normal repository review. + WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy"]' + run: node .github/scripts/website-auto-approve.mjs From 10d64a6e84089d6be3609481b0b9c7b3c6f60546 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 4 Oct 2026 01:32:38 +0000 Subject: [PATCH 03/70] ci: satisfy approval policy quality gates --- .fallowrc.jsonc | 1 + .github/scripts/website-auto-approve.mjs | 223 +++++++++++------- .github/scripts/website-auto-approve.test.mjs | 12 +- 3 files changed, 146 insertions(+), 90 deletions(-) diff --git a/.fallowrc.jsonc b/.fallowrc.jsonc index a724a31fa3e..f57a46dc8be 100644 --- a/.fallowrc.jsonc +++ b/.fallowrc.jsonc @@ -27,6 +27,7 @@ "name": "comfyui-test-entry-points", "enablers": ["@playwright/test"], "entryPoints": [ + ".github/scripts/**/*.test.mjs", "apps/website/src/**/__mocks__/**/*.ts", "browser_tests/global{Setup,Teardown}.ts", "playwright.session.config.ts", diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index a09b57c6e97..2ee8f10c1bf 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -11,7 +11,8 @@ export function parseApprovedAuthors(raw) { authors = JSON.parse(raw) } catch (error) { throw new Error( - `WEBSITE_AUTO_APPROVE_AUTHORS must be JSON: ${error.message}` + `WEBSITE_AUTO_APPROVE_AUTHORS must be JSON: ${error.message}`, + { cause: error } ) } @@ -37,16 +38,16 @@ export function isWebsiteOnly(paths) { } export function changedPaths(files) { - const paths = [] - for (const file of files) { - if (typeof file?.filename !== 'string') return null - paths.push(file.filename) - if (file.status === 'renamed') { - if (typeof file.previous_filename !== 'string') return null - paths.push(file.previous_filename) - } - } - return paths + const pathGroups = files.map(changedPathGroup) + if (pathGroups.includes(null)) return null + return pathGroups.flat() +} + +function changedPathGroup(file) { + if (typeof file?.filename !== 'string') return null + if (file.status !== 'renamed') return [file.filename] + if (typeof file.previous_filename !== 'string') return null + return [file.filename, file.previous_filename] } export function isSameRepository(pull, repository) { @@ -62,14 +63,17 @@ export function targetsDefaultBranch(pull, repository, defaultBranch) { export function alreadyApprovedCurrentHead(reviews, approverLogin, headSha) { const expectedLogin = approverLogin.toLowerCase() - return reviews.some( - (review) => - review?.state === 'APPROVED' && - review?.commit_id === headSha && - review?.user?.login?.toLowerCase() === expectedLogin + return reviews.some((review) => + isApprovalForHead(review, expectedLogin, headSha) ) } +function isApprovalForHead(review, expectedLogin, headSha) { + if (review?.state !== 'APPROVED') return false + if (review.commit_id !== headSha) return false + return review.user?.login?.toLowerCase() === expectedLogin +} + function requiredEnv(name) { const value = process.env[name]?.trim() if (!value) throw new Error(`${name} is required`) @@ -86,32 +90,18 @@ function githubClient(token, repository) { } async function request(requestPath, options = {}) { - const url = requestPath.startsWith('https://') - ? requestPath - : `${root}${requestPath}` - const response = await fetch(url, { + const response = await fetch(apiUrl(root, requestPath), { ...options, headers: { ...headers, ...options.headers } }) - if (!response.ok) { - const body = (await response.text()).slice(0, 500) - throw new Error( - `GitHub API ${options.method ?? 'GET'} ${requestPath} failed: ${response.status} ${body}` - ) - } - if (response.status === 204) return null - return response.json() + return responseBody(response, options.method, requestPath) } async function paginate(requestPath) { const rows = [] for (let page = 1; ; page += 1) { - const separator = requestPath.includes('?') ? '&' : '?' - const body = await request( - `${requestPath}${separator}per_page=${PAGE_SIZE}&page=${page}` - ) - if (!Array.isArray(body)) - throw new Error(`GitHub API ${requestPath} did not return an array`) + const body = await request(pagePath(requestPath, page)) + assertArrayResponse(body, requestPath) rows.push(...body) if (body.length < PAGE_SIZE) return rows } @@ -120,6 +110,33 @@ function githubClient(token, repository) { return { paginate, request } } +function apiUrl(root, requestPath) { + if (requestPath.startsWith('https://')) return requestPath + return `${root}${requestPath}` +} + +async function responseBody(response, method, requestPath) { + if (!response.ok) { + const body = (await response.text()).slice(0, 500) + throw new Error( + `GitHub API ${method ?? 'GET'} ${requestPath} failed: ${response.status} ${body}` + ) + } + if (response.status === 204) return null + return response.json() +} + +function pagePath(requestPath, page) { + const separator = requestPath.includes('?') ? '&' : '?' + return `${requestPath}${separator}per_page=${PAGE_SIZE}&page=${page}` +} + +function assertArrayResponse(body, requestPath) { + if (!Array.isArray(body)) { + throw new Error(`GitHub API ${requestPath} did not return an array`) + } +} + function summary(message) { process.stdout.write(`${message}\n`) if (process.env.GITHUB_STEP_SUMMARY) { @@ -127,79 +144,115 @@ function summary(message) { } } -async function main() { - const token = requiredEnv('WEBSITE_APPROVAL_TOKEN') - const repository = requiredEnv('GITHUB_REPOSITORY') - const prNumber = Number(requiredEnv('PR_NUMBER')) - const eventHeadSha = requiredEnv('PR_HEAD_SHA') - const defaultBranch = requiredEnv('WEBSITE_APPROVAL_BASE_REF') - const expectedApprover = requiredEnv('WEBSITE_APPROVER_LOGIN') - const approvedAuthors = parseApprovedAuthors( - requiredEnv('WEBSITE_AUTO_APPROVE_AUTHORS') - ) - if (!Number.isSafeInteger(prNumber) || prNumber <= 0) +function configuration() { + const config = { + token: requiredEnv('WEBSITE_APPROVAL_TOKEN'), + repository: requiredEnv('GITHUB_REPOSITORY'), + prNumber: Number(requiredEnv('PR_NUMBER')), + eventHeadSha: requiredEnv('PR_HEAD_SHA'), + defaultBranch: requiredEnv('WEBSITE_APPROVAL_BASE_REF'), + expectedApprover: requiredEnv('WEBSITE_APPROVER_LOGIN'), + approvedAuthors: parseApprovedAuthors( + requiredEnv('WEBSITE_AUTO_APPROVE_AUTHORS') + ) + } + if (!Number.isSafeInteger(config.prNumber) || config.prNumber <= 0) { throw new Error('PR_NUMBER must be positive') + } + return config +} + +function readinessFailure({ pull }) { + if (pull?.state !== 'open') { + return 'Skipped: the pull request is not open and ready for review.' + } + if (pull.draft) { + return 'Skipped: the pull request is not open and ready for review.' + } +} + +function baseFailure({ pull, config }) { + if (targetsDefaultBranch(pull, config.repository, config.defaultBranch)) + return + return `Skipped: website fast-lane approvals apply only to ${config.defaultBranch}.` +} + +function repositoryFailure({ pull, config }) { + if (isSameRepository(pull, config.repository)) return + return 'Skipped: website fast-lane approvals do not apply to fork pull requests.' +} + +function headFailure({ pull, config }) { + if (pull?.head?.sha === config.eventHeadSha) return + return 'Skipped: the pull request head advanced after this workflow started.' +} - const github = githubClient(token, repository) +function authorFailure({ pull, config }) { + const author = pull?.user?.login?.toLowerCase() + if (author && config.approvedAuthors.has(author)) return + return `Skipped: @${author ?? 'unknown'} is not in the website fast-lane author allowlist.` +} + +const ELIGIBILITY_CHECKS = [ + readinessFailure, + baseFailure, + repositoryFailure, + headFailure, + authorFailure +] + +function eligibilityFailure(context) { + return ELIGIBILITY_CHECKS.map((check) => check(context)).find(Boolean) +} + +async function assertApproverIdentity(github, expectedApprover) { const actor = await github.request('https://api.github.com/user') if (actor?.login?.toLowerCase() !== expectedApprover.toLowerCase()) { throw new Error( `WEBSITE_APPROVAL_TOKEN belongs to ${actor?.login ?? 'an unknown account'}, expected ${expectedApprover}` ) } +} - const pull = await github.request(`/pulls/${prNumber}`) - const author = pull?.user?.login?.toLowerCase() - const liveHeadSha = pull?.head?.sha - - if (pull?.state !== 'open' || pull?.draft) { - summary('Skipped: the pull request is not open and ready for review.') - return - } - if (!targetsDefaultBranch(pull, repository, defaultBranch)) { - summary( - `Skipped: website fast-lane approvals apply only to ${defaultBranch}.` - ) - return - } - if (!isSameRepository(pull, repository)) { - summary( - 'Skipped: website fast-lane approvals do not apply to fork pull requests.' - ) - return - } - if (liveHeadSha !== eventHeadSha) { - summary( - 'Skipped: the pull request head advanced after this workflow started.' - ) - return +function assertNotSelfApproval(pull, expectedApprover) { + if (pull.user.login.toLowerCase() === expectedApprover.toLowerCase()) { + throw new Error('the approval bot cannot approve its own pull request') } - if (!author || !approvedAuthors.has(author)) { - summary( - `Skipped: @${author ?? 'unknown'} is not in the website fast-lane author allowlist.` - ) +} + +async function main() { + const config = configuration() + const github = githubClient(config.token, config.repository) + await assertApproverIdentity(github, config.expectedApprover) + + const pull = await github.request(`/pulls/${config.prNumber}`) + const failure = eligibilityFailure({ pull, config }) + if (failure) { + summary(failure) return } - if (author === expectedApprover.toLowerCase()) { - throw new Error('the approval bot cannot approve its own pull request') - } + assertNotSelfApproval(pull, config.expectedApprover) - const files = await github.paginate(`/pulls/${prNumber}/files`) + const liveHeadSha = pull.head.sha + + const files = await github.paginate(`/pulls/${config.prNumber}/files`) const paths = changedPaths(files) if (paths === null || !isWebsiteOnly(paths)) { summary('Skipped: at least one changed file is outside apps/website/**.') return } - const reviews = await github.paginate(`/pulls/${prNumber}/reviews`) - if (alreadyApprovedCurrentHead(reviews, expectedApprover, liveHeadSha)) { + const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) + if ( + alreadyApprovedCurrentHead(reviews, config.expectedApprover, liveHeadSha) + ) { summary( - `Already approved ${liveHeadSha.slice(0, 12)} as @${expectedApprover}.` + `Already approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` ) return } - await github.request(`/pulls/${prNumber}/reviews`, { + await github.request(`/pulls/${config.prNumber}/reviews`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ @@ -208,7 +261,9 @@ async function main() { body: 'Automatically approved: trusted website fast-lane author; all changed files are under `apps/website/**`.' }) }) - summary(`Approved ${liveHeadSha.slice(0, 12)} as @${expectedApprover}.`) + summary( + `Approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` + ) } if ( diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index 59d5cae2319..c2fc81468d6 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -10,7 +10,7 @@ import { targetsDefaultBranch } from './website-auto-approve.mjs' -test('parses and normalizes the explicit author allowlist', () => { +void test('parses and normalizes the explicit author allowlist', () => { assert.deepEqual( parseApprovedAuthors('["bertfy", "BERTFY", ""]'), new Set(['bertfy']) @@ -22,7 +22,7 @@ test('parses and normalizes the explicit author allowlist', () => { ) }) -test('requires a non-empty website-only path set', () => { +void test('requires a non-empty website-only path set', () => { assert.equal(isWebsiteOnly(['apps/website/src/pages/index.astro']), true) assert.equal( isWebsiteOnly([ @@ -39,7 +39,7 @@ test('requires a non-empty website-only path set', () => { assert.equal(isWebsiteOnly(['apps/website-evil/file.ts']), false) }) -test('a rename must stay inside the website on both sides', () => { +void test('a rename must stay inside the website on both sides', () => { assert.deepEqual( changedPaths([ { @@ -64,7 +64,7 @@ test('a rename must stay inside the website on both sides', () => { ) }) -test('fork pull requests are not eligible', () => { +void test('fork pull requests are not eligible', () => { assert.equal( isSameRepository( { head: { repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } } }, @@ -85,7 +85,7 @@ test('fork pull requests are not eligible', () => { ) }) -test('only pull requests targeting the default branch are eligible', () => { +void test('only pull requests targeting the default branch are eligible', () => { assert.equal( targetsDefaultBranch( { @@ -114,7 +114,7 @@ test('only pull requests targeting the default branch are eligible', () => { ) }) -test('idempotency is scoped to the bot and exact head commit', () => { +void test('idempotency is scoped to the bot and exact head commit', () => { const reviews = [ { state: 'APPROVED', commit_id: 'old', user: { login: 'webreviewer-bot' } }, { state: 'APPROVED', commit_id: 'head', user: { login: 'someone-else' } }, From 79e8b144a50ffbe09b657205a4bc5a42e965ae62 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 4 Oct 2026 01:36:01 +0000 Subject: [PATCH 04/70] ci: close approval race conditions --- .github/scripts/website-auto-approve.mjs | 15 +++++++++++++++ .github/scripts/website-auto-approve.test.mjs | 8 ++++++++ .github/workflows/pr-website-auto-approve.yaml | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index 2ee8f10c1bf..01b40a70a8f 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -37,6 +37,12 @@ export function isWebsiteOnly(paths) { ) } +export function hasCompleteChangedFileList(files, changedFileCount) { + return ( + Number.isSafeInteger(changedFileCount) && files.length === changedFileCount + ) +} + export function changedPaths(files) { const pathGroups = files.map(changedPathGroup) if (pathGroups.includes(null)) return null @@ -236,6 +242,10 @@ async function main() { const liveHeadSha = pull.head.sha const files = await github.paginate(`/pulls/${config.prNumber}/files`) + if (!hasCompleteChangedFileList(files, pull.changed_files)) { + summary('Skipped: could not enumerate every changed file.') + return + } const paths = changedPaths(files) if (paths === null || !isWebsiteOnly(paths)) { summary('Skipped: at least one changed file is outside apps/website/**.') @@ -243,6 +253,11 @@ async function main() { } const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) + const recheckedPull = await github.request(`/pulls/${config.prNumber}`) + if (recheckedPull?.head?.sha !== liveHeadSha) { + summary('Skipped: the pull request head advanced during validation.') + return + } if ( alreadyApprovedCurrentHead(reviews, config.expectedApprover, liveHeadSha) ) { diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index c2fc81468d6..e21dc3fc450 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -4,12 +4,20 @@ import test from 'node:test' import { alreadyApprovedCurrentHead, changedPaths, + hasCompleteChangedFileList, isSameRepository, isWebsiteOnly, parseApprovedAuthors, targetsDefaultBranch } from './website-auto-approve.mjs' +void test('requires complete changed-file enumeration', () => { + const files = [{ filename: 'apps/website/a.astro' }] + assert.equal(hasCompleteChangedFileList(files, 1), true) + assert.equal(hasCompleteChangedFileList(files, 2), false) + assert.equal(hasCompleteChangedFileList(files, undefined), false) +}) + void test('parses and normalizes the explicit author allowlist', () => { assert.deepEqual( parseApprovedAuthors('["bertfy", "BERTFY", ""]'), diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 2009d99a09b..34b06831593 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -11,7 +11,7 @@ name: 'PR: Website Auto-Approve' on: pull_request_target: - types: [opened, reopened, synchronize, ready_for_review] + types: [opened, reopened, synchronize, ready_for_review, edited] permissions: contents: read From 6d093f9b44a01081dd0476fbdd312c06bd0a45ab Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 03:27:51 +0000 Subject: [PATCH 05/70] validation: harden website canary and production oracle --- .github/scripts/website-auto-approve.mjs | 152 ++++++++++++++++-- .github/scripts/website-auto-approve.test.mjs | 53 ++++++ .github/workflows/README.md | 17 ++ .../workflows/ci-vercel-website-preview.yaml | 139 +++++++++++++++- .../workflows/pr-website-auto-approve.yaml | 11 +- .../validation-website-rollback.yaml | 90 +++++++++++ apps/website/vercel.json | 13 ++ 7 files changed, 454 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/validation-website-rollback.yaml diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index 01b40a70a8f..75b7289feb0 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url' const API_VERSION = '2022-11-28' const PAGE_SIZE = 100 +const HOLD_LABEL = 'website-fast-lane:hold' export function parseApprovedAuthors(raw) { let authors @@ -51,11 +52,32 @@ export function changedPaths(files) { function changedPathGroup(file) { if (typeof file?.filename !== 'string') return null - if (file.status !== 'renamed') return [file.filename] + if (file.previous_filename === undefined) { + if (file.status === 'renamed' || file.status === 'copied') return null + return [file.filename] + } if (typeof file.previous_filename !== 'string') return null return [file.filename, file.previous_filename] } +export function hasHoldLabel(pull) { + return pull?.labels?.some( + (label) => label?.name?.toLowerCase() === HOLD_LABEL + ) +} + +export function hasActiveChangeRequest(reviews) { + const latestStateByReviewer = new Map() + for (const review of reviews) { + const login = review?.user?.login?.toLowerCase() + if (!login || review.user?.type === 'Bot' || login.endsWith('[bot]')) { + continue + } + latestStateByReviewer.set(login, review.state) + } + return [...latestStateByReviewer.values()].includes('CHANGES_REQUESTED') +} + export function isSameRepository(pull, repository) { return pull?.head?.repo?.full_name?.toLowerCase() === repository.toLowerCase() } @@ -199,12 +221,18 @@ function authorFailure({ pull, config }) { return `Skipped: @${author ?? 'unknown'} is not in the website fast-lane author allowlist.` } +function holdFailure({ pull }) { + if (!hasHoldLabel(pull)) return + return `Skipped: ${HOLD_LABEL} is applied.` +} + const ELIGIBILITY_CHECKS = [ readinessFailure, baseFailure, repositoryFailure, headFailure, - authorFailure + authorFailure, + holdFailure ] function eligibilityFailure(context) { @@ -226,15 +254,53 @@ function assertNotSelfApproval(pull, expectedApprover) { } } +function approvalForHead(reviews, approverLogin, headSha) { + const expectedLogin = approverLogin.toLowerCase() + for (let index = reviews.length - 1; index >= 0; index -= 1) { + const review = reviews[index] + if (isApprovalForHead(review, expectedLogin, headSha)) return review + } +} + +async function dismissApproval(github, prNumber, review, reason) { + if (!review?.id) return false + await github.request(`/pulls/${prNumber}/reviews/${review.id}/dismissals`, { + method: 'PUT', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ message: reason }) + }) + return true +} + +async function stopWithSummary({ github, config, reviews, headSha, message }) { + const approval = approvalForHead(reviews, config.expectedApprover, headSha) + if (approval) { + await dismissApproval( + github, + config.prNumber, + approval, + `Website fast-lane approval withdrawn: ${message}` + ) + } + summary(message) +} + async function main() { const config = configuration() const github = githubClient(config.token, config.repository) await assertApproverIdentity(github, config.expectedApprover) const pull = await github.request(`/pulls/${config.prNumber}`) + const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) const failure = eligibilityFailure({ pull, config }) if (failure) { - summary(failure) + await stopWithSummary({ + github, + config, + reviews, + headSha: pull?.head?.sha, + message: failure + }) return } assertNotSelfApproval(pull, config.expectedApprover) @@ -248,18 +314,47 @@ async function main() { } const paths = changedPaths(files) if (paths === null || !isWebsiteOnly(paths)) { - summary('Skipped: at least one changed file is outside apps/website/**.') + await stopWithSummary({ + github, + config, + reviews, + headSha: liveHeadSha, + message: 'Skipped: at least one changed file is outside apps/website/**.' + }) return } - const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) const recheckedPull = await github.request(`/pulls/${config.prNumber}`) - if (recheckedPull?.head?.sha !== liveHeadSha) { - summary('Skipped: the pull request head advanced during validation.') + const recheckedReviews = await github.paginate( + `/pulls/${config.prNumber}/reviews` + ) + const recheckedFailure = eligibilityFailure({ pull: recheckedPull, config }) + if (recheckedFailure) { + await stopWithSummary({ + github, + config, + reviews: recheckedReviews, + headSha: liveHeadSha, + message: recheckedFailure + }) + return + } + if (hasActiveChangeRequest(recheckedReviews)) { + await stopWithSummary({ + github, + config, + reviews: recheckedReviews, + headSha: liveHeadSha, + message: 'Skipped: an active reviewer change request is present.' + }) return } if ( - alreadyApprovedCurrentHead(reviews, config.expectedApprover, liveHeadSha) + alreadyApprovedCurrentHead( + recheckedReviews, + config.expectedApprover, + liveHeadSha + ) ) { summary( `Already approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` @@ -267,15 +362,40 @@ async function main() { return } - await github.request(`/pulls/${config.prNumber}/reviews`, { - method: 'POST', - headers: { 'content-type': 'application/json' }, - body: JSON.stringify({ - event: 'APPROVE', - commit_id: liveHeadSha, - body: 'Automatically approved: trusted website fast-lane author; all changed files are under `apps/website/**`.' - }) + const createdReview = await github.request( + `/pulls/${config.prNumber}/reviews`, + { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ + event: 'APPROVE', + commit_id: liveHeadSha, + body: '[Validation canary] Policy-only automatic approval. No diff review was performed; eligibility was bound to the trusted author, exact head commit, and `apps/website/**` path boundary.' + }) + } + ) + + const verifiedPull = await github.request(`/pulls/${config.prNumber}`) + const verifiedReviews = await github.paginate( + `/pulls/${config.prNumber}/reviews` + ) + const verificationFailure = eligibilityFailure({ + pull: verifiedPull, + config }) + if (verificationFailure || hasActiveChangeRequest(verifiedReviews)) { + const reason = + verificationFailure ?? + 'Skipped: an active reviewer change request appeared during approval.' + await dismissApproval( + github, + config.prNumber, + createdReview, + `Website fast-lane approval withdrawn: ${reason}` + ) + summary(`Approval withdrawn: ${reason}`) + return + } summary( `Approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` ) diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index e21dc3fc450..66c593f8d18 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -4,7 +4,9 @@ import test from 'node:test' import { alreadyApprovedCurrentHead, changedPaths, + hasActiveChangeRequest, hasCompleteChangedFileList, + hasHoldLabel, isSameRepository, isWebsiteOnly, parseApprovedAuthors, @@ -72,6 +74,57 @@ void test('a rename must stay inside the website on both sides', () => { ) }) +void test('a copied file retains both paths for boundary evaluation', () => { + assert.deepEqual( + changedPaths([ + { + status: 'copied', + previous_filename: 'src/sensitive.ts', + filename: 'apps/website/sensitive.ts' + } + ]), + ['apps/website/sensitive.ts', 'src/sensitive.ts'] + ) +}) + +void test('the explicit hold label stops fast-lane approval', () => { + assert.equal(hasHoldLabel({ labels: [] }), false) + assert.equal( + hasHoldLabel({ labels: [{ name: 'website-fast-lane:hold' }] }), + true + ) + assert.equal( + hasHoldLabel({ labels: [{ name: 'WEBSITE-FAST-LANE:HOLD' }] }), + true + ) +}) + +void test('only each non-app reviewer latest state can actively block', () => { + assert.equal( + hasActiveChangeRequest([ + { + state: 'CHANGES_REQUESTED', + user: { login: 'coderabbitai[bot]', type: 'Bot' } + }, + { + state: 'CHANGES_REQUESTED', + user: { login: 'DrJKL', type: 'User' } + }, + { state: 'APPROVED', user: { login: 'DrJKL', type: 'User' } } + ]), + false + ) + assert.equal( + hasActiveChangeRequest([ + { + state: 'CHANGES_REQUESTED', + user: { login: 'webreviewer-bot', type: 'User' } + } + ]), + true + ) +}) + void test('fork pull requests are not eligible', () => { assert.equal( isSameRepository( diff --git a/.github/workflows/README.md b/.github/workflows/README.md index aa5e077dd0f..cc9ada7d6a7 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -38,7 +38,24 @@ rejects other base branches and fork pull requests, rechecks the live head, and `WEBSITE_APPROVAL_TOKEN` belongs to `webreviewer-bot` before approving. The bot is a member of `comfy_website_devs`, so its review satisfies the website path reviewer rule. +The `website-fast-lane:hold` label, draft state, an active non-app reviewer change request, a base +or head change, or a path outside `apps/website/**` stops approval and withdraws an existing +current-head policy approval. The review body identifies the verdict as policy-only; it must not be +interpreted as a diff review. + The initial author allowlist contains only `bertfy`. Expand it by reviewing a change to `WEBSITE_AUTO_APPROVE_AUTHORS` in the workflow. A repository administrator must provide the bot's classic PAT as the Actions secret `WEBSITE_APPROVAL_TOKEN`; missing or mismatched credentials fail closed. + +## Website production identity and validation rollback + +Every website preview and production build writes a cache-disabled `/__build.json` containing the +repository, exact source SHA, workflow run, attempt, and build time. The deploy workflow verifies +the immutable Vercel URL before it accepts canonical `comfy.org` promotion and retains the prior +deployment ID/SHA as a short-lived artifact. + +`validation-website-rollback.yaml` is a manually dispatched validation-only workflow. It accepts +that captured immutable deployment ID and expected SHA, uses Vercel's instant rollback, verifies +the canonical marker and public homepage, then promotes the same known-good deployment to preserve +it while resuming normal automatic production-domain assignment. diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index 16d0fa63828..f8a0665387c 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -55,6 +55,22 @@ jobs: - name: Pull Vercel environment information run: vercel pull --yes --environment=preview + - name: Write preview build identity + env: + BUILD_REPOSITORY: ${{ github.repository }} + BUILD_SHA: ${{ github.event.pull_request.head.sha }} + BUILD_RUN_ID: ${{ github.run_id }} + BUILD_RUN_ATTEMPT: ${{ github.run_attempt }} + run: | + jq -n \ + --arg repository "$BUILD_REPOSITORY" \ + --arg sha "$BUILD_SHA" \ + --arg runId "$BUILD_RUN_ID" \ + --arg runAttempt "$BUILD_RUN_ATTEMPT" \ + --arg builtAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + '{repository: $repository, sha: $sha, runId: $runId, runAttempt: $runAttempt, builtAt: $builtAt}' \ + > apps/website/public/__build.json + - name: Build project artifacts env: WEBSITE_ASHBY_API_KEY: ${{ secrets.WEBSITE_ASHBY_API_KEY }} @@ -100,6 +116,24 @@ jobs: --meta githubRepo="$GIT_REPO") echo "url=$URL" >> "$GITHUB_OUTPUT" + - name: Verify immutable preview identity + env: + DEPLOY_URL: ${{ steps.deploy.outputs.url }} + EXPECTED_SHA: ${{ github.event.pull_request.head.sha }} + run: | + for attempt in {1..30}; do + ACTUAL_SHA=$(curl -fsS \ + -H 'Cache-Control: no-cache' \ + "$DEPLOY_URL/__build.json?run=$GITHUB_RUN_ID-$attempt" | + jq -r '.sha // empty') || true + if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" ]]; then + exit 0 + fi + sleep 5 + done + echo "::error::Immutable preview did not serve expected SHA $EXPECTED_SHA" + exit 1 + - name: Alias deployment to stable PR hostname id: alias-set continue-on-error: true @@ -164,6 +198,38 @@ jobs: - name: Pull Vercel environment information run: vercel pull --yes --environment=production + - name: Capture the current production deployment + id: previous-production + env: + CANONICAL_BUILD_URL: https://comfy.org/__build.json + run: | + ALIAS=$(curl -fsS --retry 3 \ + -H "Authorization: Bearer $VERCEL_TOKEN" \ + "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID") + PREVIOUS_DEPLOYMENT_ID=$(jq -er '.deploymentId' <<< "$ALIAS") + PREVIOUS_SHA=$(curl -fsS \ + -H 'Cache-Control: no-cache' \ + "$CANONICAL_BUILD_URL?before=$GITHUB_RUN_ID" | + jq -r '.sha // empty') || true + echo "deployment-id=$PREVIOUS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" + echo "sha=${PREVIOUS_SHA:-unavailable}" >> "$GITHUB_OUTPUT" + + - name: Write production build identity + env: + BUILD_REPOSITORY: ${{ github.repository }} + BUILD_SHA: ${{ github.sha }} + BUILD_RUN_ID: ${{ github.run_id }} + BUILD_RUN_ATTEMPT: ${{ github.run_attempt }} + run: | + jq -n \ + --arg repository "$BUILD_REPOSITORY" \ + --arg sha "$BUILD_SHA" \ + --arg runId "$BUILD_RUN_ID" \ + --arg runAttempt "$BUILD_RUN_ATTEMPT" \ + --arg builtAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + '{repository: $repository, sha: $sha, runId: $runId, runAttempt: $runAttempt, builtAt: $builtAt}' \ + > apps/website/public/__build.json + - name: Verify WEBSITE_CLOUD_API_KEY is present for production build env: WEBSITE_CLOUD_API_KEY: ${{ secrets.WEBSITE_CLOUD_API_KEY }} @@ -198,9 +264,76 @@ jobs: - name: Deploy project artifacts to Vercel id: deploy + env: + GIT_COMMIT_SHA: ${{ github.sha }} + GIT_REPO: ${{ github.repository }} run: | - URL=$(vercel deploy --prebuilt --prod --archive=tgz) + URL=$(vercel deploy --prebuilt --prod --archive=tgz \ + --meta githubCommitSha="$GIT_COMMIT_SHA" \ + --meta githubRepo="$GIT_REPO" \ + --meta githubRunId="$GITHUB_RUN_ID") echo "url=$URL" >> "$GITHUB_OUTPUT" - - name: Add deployment URL to summary - run: echo "**Production:** ${{ steps.deploy.outputs.url }}" >> "$GITHUB_STEP_SUMMARY" + - name: Verify immutable and canonical production identity + env: + DEPLOY_URL: ${{ steps.deploy.outputs.url }} + EXPECTED_SHA: ${{ github.sha }} + timeout-minutes: 12 + run: | + verify_marker() { + local base_url="$1" + local attempts="$2" + local delay="$3" + for ((attempt = 1; attempt <= attempts; attempt += 1)); do + ACTUAL_SHA=$(curl -fsS \ + -H 'Cache-Control: no-cache' \ + "${base_url%/}/__build.json?run=$GITHUB_RUN_ID-$attempt" | + jq -r '.sha // empty') || true + if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" ]]; then + return 0 + fi + sleep "$delay" + done + return 1 + } + + verify_marker "$DEPLOY_URL" 30 5 || { + echo "::error::Immutable deployment did not serve expected SHA $EXPECTED_SHA" + exit 1 + } + verify_marker https://comfy.org 60 10 || { + echo "::error::Canonical production did not promote expected SHA $EXPECTED_SHA" + exit 1 + } + curl -fsS -o /dev/null https://comfy.org/ + + - name: Retain production transition evidence + env: + DEPLOY_URL: ${{ steps.deploy.outputs.url }} + PREVIOUS_DEPLOYMENT_ID: ${{ steps.previous-production.outputs.deployment-id }} + PREVIOUS_SHA: ${{ steps.previous-production.outputs.sha }} + DEPLOYED_SHA: ${{ github.sha }} + run: | + mkdir -p temp/website-production-transition + jq -n \ + --arg previousDeploymentId "$PREVIOUS_DEPLOYMENT_ID" \ + --arg previousSha "$PREVIOUS_SHA" \ + --arg deploymentUrl "$DEPLOY_URL" \ + --arg deployedSha "$DEPLOYED_SHA" \ + --arg runId "$GITHUB_RUN_ID" \ + '{previousDeploymentId: $previousDeploymentId, previousSha: $previousSha, deploymentUrl: $deploymentUrl, deployedSha: $deployedSha, runId: $runId}' \ + > temp/website-production-transition/transition.json + { + echo "**Production:** $DEPLOY_URL" + echo "**Deployed SHA:** $DEPLOYED_SHA" + echo "**Previous deployment:** $PREVIOUS_DEPLOYMENT_ID" + echo "**Previous SHA:** $PREVIOUS_SHA" + } >> "$GITHUB_STEP_SUMMARY" + + - name: Upload production transition evidence + uses: actions/upload-artifact@v6 + with: + name: website-production-transition + path: temp/website-production-transition/transition.json + retention-days: 7 + if-no-files-found: error diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 34b06831593..f9573a96138 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -11,7 +11,15 @@ name: 'PR: Website Auto-Approve' on: pull_request_target: - types: [opened, reopened, synchronize, ready_for_review, edited] + types: + - opened + - reopened + - synchronize + - ready_for_review + - converted_to_draft + - edited + - labeled + - unlabeled permissions: contents: read @@ -22,7 +30,6 @@ concurrency: jobs: approve: - if: github.event.pull_request.draft == false runs-on: ubuntu-latest timeout-minutes: 5 steps: diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml new file mode 100644 index 00000000000..384cd655ab5 --- /dev/null +++ b/.github/workflows/validation-website-rollback.yaml @@ -0,0 +1,90 @@ +name: 'Validation: Website Production Rollback' + +on: + workflow_dispatch: + inputs: + deployment_id: + description: 'Immutable Vercel deployment ID captured before the canary deploy' + required: true + type: string + expected_sha: + description: 'Source SHA expected at the canonical hostname after rollback' + required: true + type: string + +permissions: + contents: read + +concurrency: + group: website-production-rollback + cancel-in-progress: false + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_WEBSITE_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_WEBSITE_PROJECT_ID }} + VERCEL_TOKEN: ${{ secrets.VERCEL_WEBSITE_TOKEN }} + VERCEL_SCOPE: comfyui + +jobs: + rollback: + if: github.repository == 'Comfy-Org/ComfyUI_frontend' + runs-on: ubuntu-latest + timeout-minutes: 25 + steps: + - uses: actions/checkout@v7 + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Pull Vercel project information + run: vercel pull --yes --environment=production + + - name: Roll back to the captured deployment + env: + TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} + run: | + vercel rollback "$TARGET_DEPLOYMENT" \ + --timeout=10m \ + --non-interactive \ + --scope="$VERCEL_SCOPE" + + - name: Verify rollback at the canonical hostname + env: + EXPECTED_SHA: ${{ inputs.expected_sha }} + run: | + for attempt in {1..60}; do + ACTUAL_SHA=$(curl -fsS \ + -H 'Cache-Control: no-cache' \ + "https://comfy.org/__build.json?rollback=$GITHUB_RUN_ID-$attempt" | + jq -r '.sha // empty') || true + if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" ]]; then + curl -fsS -o /dev/null https://comfy.org/ + exit 0 + fi + sleep 10 + done + echo "::error::Canonical production did not return to expected SHA $EXPECTED_SHA" + exit 1 + + - name: Preserve the rolled-back deployment and resume automatic promotion + env: + TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} + run: | + vercel promote "$TARGET_DEPLOYMENT" \ + --timeout=10m \ + --non-interactive \ + --scope="$VERCEL_SCOPE" + + - name: Verify post-rollback promotion state + env: + EXPECTED_SHA: ${{ inputs.expected_sha }} + run: | + ACTUAL_SHA=$(curl -fsS \ + -H 'Cache-Control: no-cache' \ + "https://comfy.org/__build.json?promote=$GITHUB_RUN_ID" | + jq -r '.sha // empty') + test "$ACTUAL_SHA" = "$EXPECTED_SHA" + { + echo "**Rollback target:** ${{ inputs.deployment_id }}" + echo "**Verified canonical SHA:** $ACTUAL_SHA" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/apps/website/vercel.json b/apps/website/vercel.json index b78b51713a0..037de07f7cc 100644 --- a/apps/website/vercel.json +++ b/apps/website/vercel.json @@ -8,6 +8,19 @@ "enabled": false }, "headers": [ + { + "source": "/__build.json", + "headers": [ + { + "key": "Cache-Control", + "value": "no-store, max-age=0" + }, + { + "key": "X-Robots-Tag", + "value": "noindex" + } + ] + }, { "source": "/(.*)", "has": [ From 845307ea5564e9f85600ffbce0ed455970117d76 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 03:40:52 +0000 Subject: [PATCH 06/70] ci: simplify website approval validation --- .github/scripts/website-auto-approve.mjs | 73 +++++++++++++++--------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index 75b7289feb0..4cc52774031 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -285,32 +285,17 @@ async function stopWithSummary({ github, config, reviews, headSha, message }) { summary(message) } -async function main() { - const config = configuration() - const github = githubClient(config.token, config.repository) - await assertApproverIdentity(github, config.expectedApprover) - - const pull = await github.request(`/pulls/${config.prNumber}`) - const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) - const failure = eligibilityFailure({ pull, config }) - if (failure) { +async function validateWebsitePaths(github, config, pull, reviews) { + const files = await github.paginate(`/pulls/${config.prNumber}/files`) + if (!hasCompleteChangedFileList(files, pull.changed_files)) { await stopWithSummary({ github, config, reviews, - headSha: pull?.head?.sha, - message: failure + headSha: pull.head.sha, + message: 'Skipped: could not enumerate every changed file.' }) - return - } - assertNotSelfApproval(pull, config.expectedApprover) - - const liveHeadSha = pull.head.sha - - const files = await github.paginate(`/pulls/${config.prNumber}/files`) - if (!hasCompleteChangedFileList(files, pull.changed_files)) { - summary('Skipped: could not enumerate every changed file.') - return + return false } const paths = changedPaths(files) if (paths === null || !isWebsiteOnly(paths)) { @@ -318,12 +303,15 @@ async function main() { github, config, reviews, - headSha: liveHeadSha, + headSha: pull.head.sha, message: 'Skipped: at least one changed file is outside apps/website/**.' }) - return + return false } + return true +} +async function revalidatePull(github, config, liveHeadSha) { const recheckedPull = await github.request(`/pulls/${config.prNumber}`) const recheckedReviews = await github.paginate( `/pulls/${config.prNumber}/reviews` @@ -349,12 +337,12 @@ async function main() { }) return } + return recheckedReviews +} + +async function approveCurrentHead(github, config, liveHeadSha, reviews) { if ( - alreadyApprovedCurrentHead( - recheckedReviews, - config.expectedApprover, - liveHeadSha - ) + alreadyApprovedCurrentHead(reviews, config.expectedApprover, liveHeadSha) ) { summary( `Already approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` @@ -401,6 +389,35 @@ async function main() { ) } +async function main() { + const config = configuration() + const github = githubClient(config.token, config.repository) + await assertApproverIdentity(github, config.expectedApprover) + + const pull = await github.request(`/pulls/${config.prNumber}`) + const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) + const failure = eligibilityFailure({ pull, config }) + if (failure) { + await stopWithSummary({ + github, + config, + reviews, + headSha: pull?.head?.sha, + message: failure + }) + return + } + assertNotSelfApproval(pull, config.expectedApprover) + + const liveHeadSha = pull.head.sha + if (!(await validateWebsitePaths(github, config, pull, reviews))) return + + const recheckedReviews = await revalidatePull(github, config, liveHeadSha) + if (!recheckedReviews) return + + await approveCurrentHead(github, config, liveHeadSha, recheckedReviews) +} + if ( process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1]) From 17da17b78a6a70505abecf8a57ff7534941aec74 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 03:47:48 +0000 Subject: [PATCH 07/70] ci: harden website canary controls --- .github/scripts/website-auto-approve.mjs | 6 ++++ .github/scripts/website-auto-approve.test.mjs | 10 +++++++ .github/workflows/ci-lint-format.yaml | 1 + .../workflows/ci-vercel-website-preview.yaml | 12 ++++++-- .../validation-website-rollback.yaml | 30 +++++++++++++++++++ 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index 4cc52774031..a3ff0ee6c4c 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -5,6 +5,11 @@ import { fileURLToPath } from 'node:url' const API_VERSION = '2022-11-28' const PAGE_SIZE = 100 const HOLD_LABEL = 'website-fast-lane:hold' +const DECISIVE_REVIEW_STATES = new Set([ + 'APPROVED', + 'CHANGES_REQUESTED', + 'DISMISSED' +]) export function parseApprovedAuthors(raw) { let authors @@ -73,6 +78,7 @@ export function hasActiveChangeRequest(reviews) { if (!login || review.user?.type === 'Bot' || login.endsWith('[bot]')) { continue } + if (!DECISIVE_REVIEW_STATES.has(review.state)) continue latestStateByReviewer.set(login, review.state) } return [...latestStateByReviewer.values()].includes('CHANGES_REQUESTED') diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index 66c593f8d18..06599ae197e 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -123,6 +123,16 @@ void test('only each non-app reviewer latest state can actively block', () => { ]), true ) + assert.equal( + hasActiveChangeRequest([ + { + state: 'CHANGES_REQUESTED', + user: { login: 'DrJKL', type: 'User' } + }, + { state: 'COMMENTED', user: { login: 'DrJKL', type: 'User' } } + ]), + true + ) }) void test('fork pull requests are not eligible', () => { diff --git a/.github/workflows/ci-lint-format.yaml b/.github/workflows/ci-lint-format.yaml index 02e26cc1402..1e2032eada3 100644 --- a/.github/workflows/ci-lint-format.yaml +++ b/.github/workflows/ci-lint-format.yaml @@ -27,6 +27,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: read + pull-requests: read outputs: website-only: ${{ steps.changes.outputs.website-only-changes }} steps: diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index f8a0665387c..e88b7a4658d 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -200,16 +200,22 @@ jobs: - name: Capture the current production deployment id: previous-production - env: - CANONICAL_BUILD_URL: https://comfy.org/__build.json run: | ALIAS=$(curl -fsS --retry 3 \ -H "Authorization: Bearer $VERCEL_TOKEN" \ "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID") PREVIOUS_DEPLOYMENT_ID=$(jq -er '.deploymentId' <<< "$ALIAS") + DEPLOYMENT=$(curl -fsS --retry 3 \ + -H "Authorization: Bearer $VERCEL_TOKEN" \ + "https://api.vercel.com/v13/deployments/$PREVIOUS_DEPLOYMENT_ID?teamId=$VERCEL_ORG_ID") + PREVIOUS_DEPLOYMENT_URL=$(jq -er \ + --arg deploymentId "$PREVIOUS_DEPLOYMENT_ID" \ + --arg projectId "$VERCEL_PROJECT_ID" \ + 'select(.id == $deploymentId and (.projectId // .project.id) == $projectId) | .url' \ + <<< "$DEPLOYMENT") PREVIOUS_SHA=$(curl -fsS \ -H 'Cache-Control: no-cache' \ - "$CANONICAL_BUILD_URL?before=$GITHUB_RUN_ID" | + "https://$PREVIOUS_DEPLOYMENT_URL/__build.json?before=$GITHUB_RUN_ID" | jq -r '.sha // empty') || true echo "deployment-id=$PREVIOUS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" echo "sha=${PREVIOUS_SHA:-unavailable}" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml index 384cd655ab5..db39de6958f 100644 --- a/.github/workflows/validation-website-rollback.yaml +++ b/.github/workflows/validation-website-rollback.yaml @@ -39,6 +39,36 @@ jobs: - name: Pull Vercel project information run: vercel pull --yes --environment=production + - name: Verify the captured deployment + env: + EXPECTED_SHA: ${{ inputs.expected_sha }} + TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} + run: | + if [[ ! "$TARGET_DEPLOYMENT" =~ ^dpl_[A-Za-z0-9]+$ ]]; then + echo "::error::Invalid Vercel deployment ID" + exit 1 + fi + if [[ ! "$EXPECTED_SHA" =~ ^[0-9a-f]{40}$ ]]; then + echo "::error::Expected SHA must be a full lowercase Git commit SHA" + exit 1 + fi + DEPLOYMENT=$(curl -fsS --retry 3 \ + -H "Authorization: Bearer $VERCEL_TOKEN" \ + "https://api.vercel.com/v13/deployments/$TARGET_DEPLOYMENT?teamId=$VERCEL_ORG_ID") + TARGET_URL=$(jq -er \ + --arg deploymentId "$TARGET_DEPLOYMENT" \ + --arg projectId "$VERCEL_PROJECT_ID" \ + 'select(.id == $deploymentId and (.projectId // .project.id) == $projectId) | .url' \ + <<< "$DEPLOYMENT") + ACTUAL_SHA=$(curl -fsS \ + -H 'Cache-Control: no-cache' \ + "https://$TARGET_URL/__build.json?preflight=$GITHUB_RUN_ID" | + jq -er '.sha') + if [[ "$ACTUAL_SHA" != "$EXPECTED_SHA" ]]; then + echo "::error::Deployment $TARGET_DEPLOYMENT serves $ACTUAL_SHA, expected $EXPECTED_SHA" + exit 1 + fi + - name: Roll back to the captured deployment env: TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} From 78b2df06947f934384ef2f30438a21705bd63603 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 03:57:33 +0000 Subject: [PATCH 08/70] ci: require rollback baseline preflight --- .github/workflows/README.md | 18 ++++++++++++++---- .../workflows/ci-vercel-website-preview.yaml | 16 +++++++++++++++- .../workflows/validation-website-rollback.yaml | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index cc9ada7d6a7..c665617a345 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -53,9 +53,19 @@ administrator must provide the bot's classic PAT as the Actions secret Every website preview and production build writes a cache-disabled `/__build.json` containing the repository, exact source SHA, workflow run, attempt, and build time. The deploy workflow verifies the immutable Vercel URL before it accepts canonical `comfy.org` promotion and retains the prior -deployment ID/SHA as a short-lived artifact. +and newly deployed IDs/SHA values as a short-lived artifact. `validation-website-rollback.yaml` is a manually dispatched validation-only workflow. It accepts -that captured immutable deployment ID and expected SHA, uses Vercel's instant rollback, verifies -the canonical marker and public homepage, then promotes the same known-good deployment to preserve -it while resuming normal automatic production-domain assignment. +that captured immutable deployment ID and expected SHA. Its safe default validates that the target +belongs to the website project and serves the expected marker without changing production. Setting +`perform_rollback` to true uses Vercel's instant rollback, verifies the canonical marker and public +homepage, then promotes the same known-good deployment to preserve it while resuming normal +automatic production-domain assignment. + +The first production deploy containing `/__build.json` is the rollback bootstrap, not the positive +canary. Before any disposable canary PR is opened or queued, download that deploy's transition +artifact and run `Validation: Website Production Rollback` with its `deployedDeploymentId` and +`deployedSha`, leaving `perform_rollback` false. The positive canary may start only after this +no-mutation preflight is green. This ensures its captured previous deployment is a known-good, +marker-bearing rollback target; an older legacy deployment with an unavailable marker is never +silently accepted as the canary rollback proof. diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index e88b7a4658d..4b38fd3337d 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -320,17 +320,31 @@ jobs: PREVIOUS_SHA: ${{ steps.previous-production.outputs.sha }} DEPLOYED_SHA: ${{ github.sha }} run: | + DEPLOYMENT_HOST=${DEPLOY_URL#https://} + if [[ ! "$DEPLOYMENT_HOST" =~ ^[A-Za-z0-9.-]+\.vercel\.app$ ]]; then + echo "::error::Unexpected immutable deployment URL: $DEPLOY_URL" + exit 1 + fi + DEPLOYMENT=$(curl -fsS --retry 3 \ + -H "Authorization: Bearer $VERCEL_TOKEN" \ + "https://api.vercel.com/v13/deployments/$DEPLOYMENT_HOST?teamId=$VERCEL_ORG_ID") + DEPLOYED_DEPLOYMENT_ID=$(jq -er \ + --arg projectId "$VERCEL_PROJECT_ID" \ + 'select((.projectId // .project.id) == $projectId) | .id' \ + <<< "$DEPLOYMENT") mkdir -p temp/website-production-transition jq -n \ --arg previousDeploymentId "$PREVIOUS_DEPLOYMENT_ID" \ --arg previousSha "$PREVIOUS_SHA" \ + --arg deployedDeploymentId "$DEPLOYED_DEPLOYMENT_ID" \ --arg deploymentUrl "$DEPLOY_URL" \ --arg deployedSha "$DEPLOYED_SHA" \ --arg runId "$GITHUB_RUN_ID" \ - '{previousDeploymentId: $previousDeploymentId, previousSha: $previousSha, deploymentUrl: $deploymentUrl, deployedSha: $deployedSha, runId: $runId}' \ + '{previousDeploymentId: $previousDeploymentId, previousSha: $previousSha, deployedDeploymentId: $deployedDeploymentId, deploymentUrl: $deploymentUrl, deployedSha: $deployedSha, runId: $runId}' \ > temp/website-production-transition/transition.json { echo "**Production:** $DEPLOY_URL" + echo "**Deployment ID:** $DEPLOYED_DEPLOYMENT_ID" echo "**Deployed SHA:** $DEPLOYED_SHA" echo "**Previous deployment:** $PREVIOUS_DEPLOYMENT_ID" echo "**Previous SHA:** $PREVIOUS_SHA" diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml index db39de6958f..bbc8de07893 100644 --- a/.github/workflows/validation-website-rollback.yaml +++ b/.github/workflows/validation-website-rollback.yaml @@ -11,6 +11,11 @@ on: description: 'Source SHA expected at the canonical hostname after rollback' required: true type: string + perform_rollback: + description: 'Change production after target validation; false performs a safe preflight only' + required: true + default: false + type: boolean permissions: contents: read @@ -68,8 +73,14 @@ jobs: echo "::error::Deployment $TARGET_DEPLOYMENT serves $ACTUAL_SHA, expected $EXPECTED_SHA" exit 1 fi + { + echo "**Validated rollback target:** $TARGET_DEPLOYMENT" + echo "**Validated rollback SHA:** $ACTUAL_SHA" + echo "**Production mutation requested:** ${{ inputs.perform_rollback }}" + } >> "$GITHUB_STEP_SUMMARY" - name: Roll back to the captured deployment + if: inputs.perform_rollback env: TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} run: | @@ -79,6 +90,7 @@ jobs: --scope="$VERCEL_SCOPE" - name: Verify rollback at the canonical hostname + if: inputs.perform_rollback env: EXPECTED_SHA: ${{ inputs.expected_sha }} run: | @@ -97,6 +109,7 @@ jobs: exit 1 - name: Preserve the rolled-back deployment and resume automatic promotion + if: inputs.perform_rollback env: TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} run: | @@ -106,6 +119,7 @@ jobs: --scope="$VERCEL_SCOPE" - name: Verify post-rollback promotion state + if: inputs.perform_rollback env: EXPECTED_SHA: ${{ inputs.expected_sha }} run: | From a471460dc4609d9a9f621effc1ca3c280012725b Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 04:06:49 +0000 Subject: [PATCH 09/70] ci: verify exact production deployment --- .github/workflows/ci-vercel-website-preview.yaml | 14 ++++++++++---- .github/workflows/validation-website-rollback.yaml | 14 +++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index 4b38fd3337d..cfd7f69f781 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -283,6 +283,8 @@ jobs: - name: Verify immutable and canonical production identity env: DEPLOY_URL: ${{ steps.deploy.outputs.url }} + EXPECTED_RUN_ATTEMPT: ${{ github.run_attempt }} + EXPECTED_RUN_ID: ${{ github.run_id }} EXPECTED_SHA: ${{ github.sha }} timeout-minutes: 12 run: | @@ -291,11 +293,15 @@ jobs: local attempts="$2" local delay="$3" for ((attempt = 1; attempt <= attempts; attempt += 1)); do - ACTUAL_SHA=$(curl -fsS \ + if MARKER=$(curl -fsS \ -H 'Cache-Control: no-cache' \ - "${base_url%/}/__build.json?run=$GITHUB_RUN_ID-$attempt" | - jq -r '.sha // empty') || true - if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" ]]; then + "${base_url%/}/__build.json?run=$GITHUB_RUN_ID-$attempt") && + jq -e \ + --arg sha "$EXPECTED_SHA" \ + --arg runId "$EXPECTED_RUN_ID" \ + --arg runAttempt "$EXPECTED_RUN_ATTEMPT" \ + '.sha == $sha and .runId == $runId and .runAttempt == $runAttempt' \ + <<< "$MARKER" >/dev/null; then return 0 fi sleep "$delay" diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml index bbc8de07893..02205d92a30 100644 --- a/.github/workflows/validation-website-rollback.yaml +++ b/.github/workflows/validation-website-rollback.yaml @@ -93,13 +93,18 @@ jobs: if: inputs.perform_rollback env: EXPECTED_SHA: ${{ inputs.expected_sha }} + TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} run: | for attempt in {1..60}; do ACTUAL_SHA=$(curl -fsS \ -H 'Cache-Control: no-cache' \ "https://comfy.org/__build.json?rollback=$GITHUB_RUN_ID-$attempt" | jq -r '.sha // empty') || true - if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" ]]; then + ALIAS_DEPLOYMENT_ID=$(curl -fsS --retry 3 \ + -H "Authorization: Bearer $VERCEL_TOKEN" \ + "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" | + jq -r '.deploymentId // empty') || true + if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" && "$ALIAS_DEPLOYMENT_ID" == "$TARGET_DEPLOYMENT" ]]; then curl -fsS -o /dev/null https://comfy.org/ exit 0 fi @@ -122,13 +127,20 @@ jobs: if: inputs.perform_rollback env: EXPECTED_SHA: ${{ inputs.expected_sha }} + TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} run: | ACTUAL_SHA=$(curl -fsS \ -H 'Cache-Control: no-cache' \ "https://comfy.org/__build.json?promote=$GITHUB_RUN_ID" | jq -r '.sha // empty') + ALIAS_DEPLOYMENT_ID=$(curl -fsS --retry 3 \ + -H "Authorization: Bearer $VERCEL_TOKEN" \ + "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" | + jq -er '.deploymentId') test "$ACTUAL_SHA" = "$EXPECTED_SHA" + test "$ALIAS_DEPLOYMENT_ID" = "$TARGET_DEPLOYMENT" { echo "**Rollback target:** ${{ inputs.deployment_id }}" echo "**Verified canonical SHA:** $ACTUAL_SHA" + echo "**Verified canonical deployment:** $ALIAS_DEPLOYMENT_ID" } >> "$GITHUB_STEP_SUMMARY" From b5b3bc71deda9313dfc5068b5d019fbf17fbe5cf Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 04:07:48 +0000 Subject: [PATCH 10/70] ci: serialize website production controls --- .github/workflows/ci-vercel-website-preview.yaml | 4 ++-- .github/workflows/pr-website-auto-approve.yaml | 7 ++++++- .github/workflows/validation-website-rollback.yaml | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index cfd7f69f781..31d8e521b16 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -25,8 +25,8 @@ env: VERCEL_SCOPE: comfyui concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + group: ${{ github.event_name == 'push' && 'website-production' || format('{0}-{1}', github.workflow, github.ref) }} + cancel-in-progress: ${{ github.event_name != 'push' }} jobs: deploy-preview: diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index f9573a96138..f33a484fa0d 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -1,7 +1,8 @@ # Auto-approve website-only pull requests from explicitly trusted authors. # # Security boundary: -# - pull_request_target reads this workflow from the trusted base branch. +# - pull_request_target and pull_request_review load this workflow from the +# trusted default branch. # - automation is checked out from the repository's protected default branch; # pull request code is never executed. # - the script rejects other base branches and forks, re-fetches the live PR, @@ -20,6 +21,10 @@ on: - edited - labeled - unlabeled + pull_request_review: + types: + - submitted + - dismissed permissions: contents: read diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml index 02205d92a30..2d850551d33 100644 --- a/.github/workflows/validation-website-rollback.yaml +++ b/.github/workflows/validation-website-rollback.yaml @@ -21,7 +21,7 @@ permissions: contents: read concurrency: - group: website-production-rollback + group: website-production cancel-in-progress: false env: From 585d62f904dc7819585100a85171c8254938807a Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 04:34:29 +0000 Subject: [PATCH 11/70] ci: secure staged website promotion --- .github/workflows/README.md | 13 +- .../workflows/ci-vercel-website-preview.yaml | 122 +++++++++++------- .../workflows/pr-website-auto-approve.yaml | 8 +- 3 files changed, 88 insertions(+), 55 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index c665617a345..9ab3e211fca 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -40,13 +40,16 @@ rejects other base branches and fork pull requests, rechecks the live head, and The `website-fast-lane:hold` label, draft state, an active non-app reviewer change request, a base or head change, or a path outside `apps/website/**` stops approval and withdraws an existing -current-head policy approval. The review body identifies the verdict as policy-only; it must not be -interpreted as a diff review. +current-head policy approval when the trusted workflow evaluates the PR. A human change request +submitted after policy approval blocks merge immediately through GitHub's review rules; the next +trusted PR event reevaluates and withdraws the policy approval. The review body identifies the +verdict as policy-only; it must not be interpreted as a diff review. The initial author allowlist contains only `bertfy`. Expand it by reviewing a -change to `WEBSITE_AUTO_APPROVE_AUTHORS` in the workflow. A repository -administrator must provide the bot's classic PAT as the Actions secret -`WEBSITE_APPROVAL_TOKEN`; missing or mismatched credentials fail closed. +change to `WEBSITE_AUTO_APPROVE_AUTHORS` in the workflow. A repository administrator must configure +a `website-approval` environment whose deployment branch restriction allows only the protected +default branch, then provide the bot's classic PAT as that environment's +`WEBSITE_APPROVAL_TOKEN` secret. Missing or mismatched credentials fail closed. ## Website production identity and validation rollback diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index 31d8e521b16..fb3127d9b1a 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -274,57 +274,16 @@ jobs: GIT_COMMIT_SHA: ${{ github.sha }} GIT_REPO: ${{ github.repository }} run: | - URL=$(vercel deploy --prebuilt --prod --archive=tgz \ + URL=$(vercel deploy --prebuilt --archive=tgz \ --meta githubCommitSha="$GIT_COMMIT_SHA" \ --meta githubRepo="$GIT_REPO" \ --meta githubRunId="$GITHUB_RUN_ID") echo "url=$URL" >> "$GITHUB_OUTPUT" - - name: Verify immutable and canonical production identity + - name: Capture staged deployment identity + id: deployed-production env: DEPLOY_URL: ${{ steps.deploy.outputs.url }} - EXPECTED_RUN_ATTEMPT: ${{ github.run_attempt }} - EXPECTED_RUN_ID: ${{ github.run_id }} - EXPECTED_SHA: ${{ github.sha }} - timeout-minutes: 12 - run: | - verify_marker() { - local base_url="$1" - local attempts="$2" - local delay="$3" - for ((attempt = 1; attempt <= attempts; attempt += 1)); do - if MARKER=$(curl -fsS \ - -H 'Cache-Control: no-cache' \ - "${base_url%/}/__build.json?run=$GITHUB_RUN_ID-$attempt") && - jq -e \ - --arg sha "$EXPECTED_SHA" \ - --arg runId "$EXPECTED_RUN_ID" \ - --arg runAttempt "$EXPECTED_RUN_ATTEMPT" \ - '.sha == $sha and .runId == $runId and .runAttempt == $runAttempt' \ - <<< "$MARKER" >/dev/null; then - return 0 - fi - sleep "$delay" - done - return 1 - } - - verify_marker "$DEPLOY_URL" 30 5 || { - echo "::error::Immutable deployment did not serve expected SHA $EXPECTED_SHA" - exit 1 - } - verify_marker https://comfy.org 60 10 || { - echo "::error::Canonical production did not promote expected SHA $EXPECTED_SHA" - exit 1 - } - curl -fsS -o /dev/null https://comfy.org/ - - - name: Retain production transition evidence - env: - DEPLOY_URL: ${{ steps.deploy.outputs.url }} - PREVIOUS_DEPLOYMENT_ID: ${{ steps.previous-production.outputs.deployment-id }} - PREVIOUS_SHA: ${{ steps.previous-production.outputs.sha }} - DEPLOYED_SHA: ${{ github.sha }} run: | DEPLOYMENT_HOST=${DEPLOY_URL#https://} if [[ ! "$DEPLOYMENT_HOST" =~ ^[A-Za-z0-9.-]+\.vercel\.app$ ]]; then @@ -338,6 +297,41 @@ jobs: --arg projectId "$VERCEL_PROJECT_ID" \ 'select((.projectId // .project.id) == $projectId) | .id' \ <<< "$DEPLOYMENT") + echo "deployment-id=$DEPLOYED_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" + + - name: Verify staged production identity + env: + DEPLOY_URL: ${{ steps.deploy.outputs.url }} + EXPECTED_RUN_ATTEMPT: ${{ github.run_attempt }} + EXPECTED_RUN_ID: ${{ github.run_id }} + EXPECTED_SHA: ${{ github.sha }} + timeout-minutes: 12 + run: | + for attempt in {1..30}; do + if MARKER=$(curl -fsS \ + -H 'Cache-Control: no-cache' \ + "${DEPLOY_URL%/}/__build.json?staged=$GITHUB_RUN_ID-$attempt") && + jq -e \ + --arg sha "$EXPECTED_SHA" \ + --arg runId "$EXPECTED_RUN_ID" \ + --arg runAttempt "$EXPECTED_RUN_ATTEMPT" \ + '.sha == $sha and .runId == $runId and .runAttempt == $runAttempt' \ + <<< "$MARKER" >/dev/null; then + exit 0 + fi + sleep 5 + done + echo "::error::Staged deployment did not serve expected build identity" + exit 1 + + - name: Retain production transition evidence + env: + DEPLOY_URL: ${{ steps.deploy.outputs.url }} + DEPLOYED_DEPLOYMENT_ID: ${{ steps.deployed-production.outputs.deployment-id }} + PREVIOUS_DEPLOYMENT_ID: ${{ steps.previous-production.outputs.deployment-id }} + PREVIOUS_SHA: ${{ steps.previous-production.outputs.sha }} + DEPLOYED_SHA: ${{ github.sha }} + run: | mkdir -p temp/website-production-transition jq -n \ --arg previousDeploymentId "$PREVIOUS_DEPLOYMENT_ID" \ @@ -363,3 +357,43 @@ jobs: path: temp/website-production-transition/transition.json retention-days: 7 if-no-files-found: error + + - name: Promote the staged deployment to production + env: + DEPLOY_URL: ${{ steps.deploy.outputs.url }} + run: | + vercel promote "$DEPLOY_URL" \ + --timeout=10m \ + --non-interactive \ + --scope="$VERCEL_SCOPE" + + - name: Verify canonical production identity + env: + EXPECTED_DEPLOYMENT_ID: ${{ steps.deployed-production.outputs.deployment-id }} + EXPECTED_RUN_ATTEMPT: ${{ github.run_attempt }} + EXPECTED_RUN_ID: ${{ github.run_id }} + EXPECTED_SHA: ${{ github.sha }} + timeout-minutes: 12 + run: | + for attempt in {1..60}; do + MARKER=$(curl -fsS \ + -H 'Cache-Control: no-cache' \ + "https://comfy.org/__build.json?promoted=$GITHUB_RUN_ID-$attempt") || true + ALIAS_DEPLOYMENT_ID=$(curl -fsS --retry 3 \ + -H "Authorization: Bearer $VERCEL_TOKEN" \ + "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" | + jq -r '.deploymentId // empty') || true + if jq -e \ + --arg sha "$EXPECTED_SHA" \ + --arg runId "$EXPECTED_RUN_ID" \ + --arg runAttempt "$EXPECTED_RUN_ATTEMPT" \ + '.sha == $sha and .runId == $runId and .runAttempt == $runAttempt' \ + <<< "${MARKER:-{}}" >/dev/null && + [[ "$ALIAS_DEPLOYMENT_ID" == "$EXPECTED_DEPLOYMENT_ID" ]]; then + curl -fsS -o /dev/null https://comfy.org/ + exit 0 + fi + sleep 10 + done + echo "::error::Canonical production did not serve the promoted deployment identity" + exit 1 diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index f33a484fa0d..739d48a69dd 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -1,8 +1,7 @@ # Auto-approve website-only pull requests from explicitly trusted authors. # # Security boundary: -# - pull_request_target and pull_request_review load this workflow from the -# trusted default branch. +# - pull_request_target loads this workflow from the trusted default branch. # - automation is checked out from the repository's protected default branch; # pull request code is never executed. # - the script rejects other base branches and forks, re-fetches the live PR, @@ -21,10 +20,6 @@ on: - edited - labeled - unlabeled - pull_request_review: - types: - - submitted - - dismissed permissions: contents: read @@ -35,6 +30,7 @@ concurrency: jobs: approve: + environment: website-approval runs-on: ubuntu-latest timeout-minutes: 5 steps: From c84bdaf9f0e5e5cff19d0c95047a774e061e3abe Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 04:42:47 +0000 Subject: [PATCH 12/70] ci: preserve canonical marker json --- .github/workflows/ci-vercel-website-preview.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index fb3127d9b1a..90e5bdfba4a 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -378,17 +378,17 @@ jobs: for attempt in {1..60}; do MARKER=$(curl -fsS \ -H 'Cache-Control: no-cache' \ - "https://comfy.org/__build.json?promoted=$GITHUB_RUN_ID-$attempt") || true + "https://comfy.org/__build.json?promoted=$GITHUB_RUN_ID-$attempt") || MARKER='{}' ALIAS_DEPLOYMENT_ID=$(curl -fsS --retry 3 \ -H "Authorization: Bearer $VERCEL_TOKEN" \ "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" | jq -r '.deploymentId // empty') || true if jq -e \ --arg sha "$EXPECTED_SHA" \ - --arg runId "$EXPECTED_RUN_ID" \ - --arg runAttempt "$EXPECTED_RUN_ATTEMPT" \ - '.sha == $sha and .runId == $runId and .runAttempt == $runAttempt' \ - <<< "${MARKER:-{}}" >/dev/null && + --arg runId "$EXPECTED_RUN_ID" \ + --arg runAttempt "$EXPECTED_RUN_ATTEMPT" \ + '.sha == $sha and .runId == $runId and .runAttempt == $runAttempt' \ + <<< "$MARKER" >/dev/null && [[ "$ALIAS_DEPLOYMENT_ID" == "$EXPECTED_DEPLOYMENT_ID" ]]; then curl -fsS -o /dev/null https://comfy.org/ exit 0 From 206eb03a9be24efcbe45609ec2161e289c612dcb Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 04:58:58 +0000 Subject: [PATCH 13/70] ci: withdraw unverifiable website approvals --- .github/scripts/website-auto-approve.mjs | 20 +++++++++--- .github/scripts/website-auto-approve.test.mjs | 32 +++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index a3ff0ee6c4c..9c1e9e0b413 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -346,7 +346,7 @@ async function revalidatePull(github, config, liveHeadSha) { return recheckedReviews } -async function approveCurrentHead(github, config, liveHeadSha, reviews) { +export async function approveCurrentHead(github, config, liveHeadSha, reviews) { if ( alreadyApprovedCurrentHead(reviews, config.expectedApprover, liveHeadSha) ) { @@ -369,10 +369,20 @@ async function approveCurrentHead(github, config, liveHeadSha, reviews) { } ) - const verifiedPull = await github.request(`/pulls/${config.prNumber}`) - const verifiedReviews = await github.paginate( - `/pulls/${config.prNumber}/reviews` - ) + let verifiedPull + let verifiedReviews + try { + verifiedPull = await github.request(`/pulls/${config.prNumber}`) + verifiedReviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) + } catch (error) { + await dismissApproval( + github, + config.prNumber, + createdReview, + 'Website fast-lane approval withdrawn: post-approval verification failed.' + ) + throw error + } const verificationFailure = eligibilityFailure({ pull: verifiedPull, config diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index 06599ae197e..b4a6f57ea9e 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -2,6 +2,7 @@ import assert from 'node:assert/strict' import test from 'node:test' import { + approveCurrentHead, alreadyApprovedCurrentHead, changedPaths, hasActiveChangeRequest, @@ -13,6 +14,37 @@ import { targetsDefaultBranch } from './website-auto-approve.mjs' +void test('a failed post-approval verification withdraws the new approval', async () => { + const calls = [] + const verificationError = new Error('verification unavailable') + const github = { + async request(requestPath, options = {}) { + calls.push({ requestPath, method: options.method ?? 'GET' }) + if (options.method === 'POST') return { id: 123 } + if (options.method === 'PUT') return null + throw verificationError + }, + async paginate() { + throw new Error('review verification should not run after pull failure') + } + } + + await assert.rejects( + approveCurrentHead( + github, + { prNumber: 42, expectedApprover: 'webreviewer-bot' }, + '0123456789abcdef0123456789abcdef01234567', + [] + ), + verificationError + ) + assert.deepEqual(calls, [ + { requestPath: '/pulls/42/reviews', method: 'POST' }, + { requestPath: '/pulls/42', method: 'GET' }, + { requestPath: '/pulls/42/reviews/123/dismissals', method: 'PUT' } + ]) +}) + void test('requires complete changed-file enumeration', () => { const files = [{ filename: 'apps/website/a.astro' }] assert.equal(hasCompleteChangedFileList(files, 1), true) From 11294dcb54e1291b954197068d553dd9a60966b9 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 17:45:33 +0000 Subject: [PATCH 14/70] validation: add synthetic website canary author --- .github/workflows/README.md | 9 +++++---- .github/workflows/pr-website-auto-approve.yaml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 9ab3e211fca..6921b9fd796 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -45,10 +45,11 @@ submitted after policy approval blocks merge immediately through GitHub's review trusted PR event reevaluates and withdraws the policy approval. The review body identifies the verdict as policy-only; it must not be interpreted as a diff review. -The initial author allowlist contains only `bertfy`. Expand it by reviewing a -change to `WEBSITE_AUTO_APPROVE_AUTHORS` in the workflow. A repository administrator must configure -a `website-approval` environment whose deployment branch restriction allows only the protected -default branch, then provide the bot's classic PAT as that environment's +The Stage 1 author allowlist contains `bertfy` plus `christian-byrne` as the explicitly labeled +synthetic contributor; the latter must be removed when the canary ends. Expand or retain it only by +reviewing a change to `WEBSITE_AUTO_APPROVE_AUTHORS` in the workflow. A repository administrator +must configure a `website-approval` environment whose deployment branch restriction allows only the +protected default branch, then provide the bot's classic PAT as that environment's `WEBSITE_APPROVAL_TOKEN` secret. Missing or mismatched credentials fail closed. ## Website production identity and validation rollback diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 739d48a69dd..098b87c973b 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -51,5 +51,5 @@ jobs: WEBSITE_APPROVER_LOGIN: webreviewer-bot # This is intentionally checked in: changing who can receive an # automatic approval must itself pass normal repository review. - WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy"]' + WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy", "christian-byrne"]' run: node .github/scripts/website-auto-approve.mjs From abe470237284873885a07544a36f9177144cfd8d Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 18:12:27 +0000 Subject: [PATCH 15/70] test(ci): cover website-only output defaults --- scripts/cicd/changes-filter.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/cicd/changes-filter.test.ts b/scripts/cicd/changes-filter.test.ts index 131ed3f592f..182d49e2a0a 100644 --- a/scripts/cicd/changes-filter.test.ts +++ b/scripts/cicd/changes-filter.test.ts @@ -135,7 +135,8 @@ it.for(['merge_group', 'push', 'workflow_dispatch'])( 'packages-changes': true, 'storybook-changes': true, 'docs-changes': true, - 'dependency-changes': true + 'dependency-changes': true, + 'website-only-changes': false }) } ) From c975dd3f2ffc0394db8212dfe0e3a2bd3720d485 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 19:56:39 +0000 Subject: [PATCH 16/70] ci: add authorized label approval route --- .github/scripts/website-auto-approve.mjs | 48 ++++++++++++++++--- .github/scripts/website-auto-approve.test.mjs | 48 +++++++++++++++++++ .github/workflows/README.md | 13 +++-- .../workflows/pr-website-auto-approve.yaml | 10 +++- 4 files changed, 106 insertions(+), 13 deletions(-) diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index 9c1e9e0b413..c2a18aebe6c 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url' const API_VERSION = '2022-11-28' const PAGE_SIZE = 100 const HOLD_LABEL = 'website-fast-lane:hold' +const APPROVE_LABEL = 'website-fast-lane:approve' const DECISIVE_REVIEW_STATES = new Set([ 'APPROVED', 'CHANGES_REQUESTED', @@ -71,6 +72,24 @@ export function hasHoldLabel(pull) { ) } +function hasLabel(pull, expectedLabel) { + return pull?.labels?.some( + (label) => label?.name?.toLowerCase() === expectedLabel + ) +} + +export function hasAuthorizedApprovalLabel(pull, events, approvedLabelers) { + if (!hasLabel(pull, APPROVE_LABEL)) return false + + for (let index = events.length - 1; index >= 0; index -= 1) { + const event = events[index] + if (event?.label?.name?.toLowerCase() !== APPROVE_LABEL) continue + const actor = event?.actor?.login?.toLowerCase() + return event.event === 'labeled' && approvedLabelers.has(actor) + } + return false +} + export function hasActiveChangeRequest(reviews) { const latestStateByReviewer = new Map() for (const review of reviews) { @@ -188,6 +207,9 @@ function configuration() { expectedApprover: requiredEnv('WEBSITE_APPROVER_LOGIN'), approvedAuthors: parseApprovedAuthors( requiredEnv('WEBSITE_AUTO_APPROVE_AUTHORS') + ), + approvedLabelers: parseApprovedAuthors( + requiredEnv('WEBSITE_AUTO_APPROVE_LABELERS') ) } if (!Number.isSafeInteger(config.prNumber) || config.prNumber <= 0) { @@ -221,10 +243,11 @@ function headFailure({ pull, config }) { return 'Skipped: the pull request head advanced after this workflow started.' } -function authorFailure({ pull, config }) { +function authorizationFailure({ pull, config, events }) { const author = pull?.user?.login?.toLowerCase() if (author && config.approvedAuthors.has(author)) return - return `Skipped: @${author ?? 'unknown'} is not in the website fast-lane author allowlist.` + if (hasAuthorizedApprovalLabel(pull, events, config.approvedLabelers)) return + return `Skipped: @${author ?? 'unknown'} is not allowlisted and ${APPROVE_LABEL} was not applied by an authorized operator.` } function holdFailure({ pull }) { @@ -237,7 +260,7 @@ const ELIGIBILITY_CHECKS = [ baseFailure, repositoryFailure, headFailure, - authorFailure, + authorizationFailure, holdFailure ] @@ -322,7 +345,14 @@ async function revalidatePull(github, config, liveHeadSha) { const recheckedReviews = await github.paginate( `/pulls/${config.prNumber}/reviews` ) - const recheckedFailure = eligibilityFailure({ pull: recheckedPull, config }) + const recheckedEvents = await github.paginate( + `/issues/${config.prNumber}/events` + ) + const recheckedFailure = eligibilityFailure({ + pull: recheckedPull, + config, + events: recheckedEvents + }) if (recheckedFailure) { await stopWithSummary({ github, @@ -364,16 +394,18 @@ export async function approveCurrentHead(github, config, liveHeadSha, reviews) { body: JSON.stringify({ event: 'APPROVE', commit_id: liveHeadSha, - body: '[Validation canary] Policy-only automatic approval. No diff review was performed; eligibility was bound to the trusted author, exact head commit, and `apps/website/**` path boundary.' + body: '[Validation canary] Policy-only automatic approval. No diff review was performed; eligibility was bound to a trusted author or authorized approval-label event, the exact head commit, and the `apps/website/**` path boundary.' }) } ) let verifiedPull let verifiedReviews + let verifiedEvents try { verifiedPull = await github.request(`/pulls/${config.prNumber}`) verifiedReviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) + verifiedEvents = await github.paginate(`/issues/${config.prNumber}/events`) } catch (error) { await dismissApproval( github, @@ -385,7 +417,8 @@ export async function approveCurrentHead(github, config, liveHeadSha, reviews) { } const verificationFailure = eligibilityFailure({ pull: verifiedPull, - config + config, + events: verifiedEvents }) if (verificationFailure || hasActiveChangeRequest(verifiedReviews)) { const reason = @@ -412,7 +445,8 @@ async function main() { const pull = await github.request(`/pulls/${config.prNumber}`) const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) - const failure = eligibilityFailure({ pull, config }) + const events = await github.paginate(`/issues/${config.prNumber}/events`) + const failure = eligibilityFailure({ pull, config, events }) if (failure) { await stopWithSummary({ github, diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index b4a6f57ea9e..e86a07c9aac 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -6,6 +6,7 @@ import { alreadyApprovedCurrentHead, changedPaths, hasActiveChangeRequest, + hasAuthorizedApprovalLabel, hasCompleteChangedFileList, hasHoldLabel, isSameRepository, @@ -131,6 +132,53 @@ void test('the explicit hold label stops fast-lane approval', () => { ) }) +void test('approval label requires provenance from an authorized operator', () => { + const pull = { labels: [{ name: 'website-fast-lane:approve' }] } + const authorized = new Set(['drjkl']) + assert.equal( + hasAuthorizedApprovalLabel( + pull, + [ + { + event: 'labeled', + label: { name: 'website-fast-lane:approve' }, + actor: { login: 'DrJKL' } + } + ], + authorized + ), + true + ) + assert.equal( + hasAuthorizedApprovalLabel( + pull, + [ + { + event: 'labeled', + label: { name: 'website-fast-lane:approve' }, + actor: { login: 'not-authorized' } + } + ], + authorized + ), + false + ) + assert.equal( + hasAuthorizedApprovalLabel( + { labels: [] }, + [ + { + event: 'labeled', + label: { name: 'website-fast-lane:approve' }, + actor: { login: 'DrJKL' } + } + ], + authorized + ), + false + ) +}) + void test('only each non-app reviewer latest state can actively block', () => { assert.equal( hasActiveChangeRequest([ diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 6921b9fd796..2d8623e9ab1 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -32,13 +32,17 @@ For GitHub Actions documentation, see [Events that trigger workflows](https://do ## Website auto-approval `pr-website-auto-approve.yaml` removes the human approval wait for explicitly -allowlisted authors when every changed file is under `apps/website/**`. It runs +allowlisted authors, or after an allowlisted operator applies +`website-fast-lane:approve`, when every changed file is under +`apps/website/**`. It runs from the protected default branch on `pull_request_target`, never executes PR code, rejects other base branches and fork pull requests, rechecks the live head, and verifies that `WEBSITE_APPROVAL_TOKEN` belongs to `webreviewer-bot` before approving. The bot is a member of `comfy_website_devs`, so its review satisfies the website path reviewer rule. -The `website-fast-lane:hold` label, draft state, an active non-app reviewer change request, a base +Approval-label eligibility is provenance-checked against the issue event +history; label presence by itself is not authorization. The +`website-fast-lane:hold` label, draft state, an active non-app reviewer change request, a base or head change, or a path outside `apps/website/**` stops approval and withdraws an existing current-head policy approval when the trusted workflow evaluates the PR. A human change request submitted after policy approval blocks merge immediately through GitHub's review rules; the next @@ -46,8 +50,9 @@ trusted PR event reevaluates and withdraws the policy approval. The review body verdict as policy-only; it must not be interpreted as a diff review. The Stage 1 author allowlist contains `bertfy` plus `christian-byrne` as the explicitly labeled -synthetic contributor; the latter must be removed when the canary ends. Expand or retain it only by -reviewing a change to `WEBSITE_AUTO_APPROVE_AUTHORS` in the workflow. A repository administrator +synthetic contributor; the latter must be removed when the canary ends. Expand or retain either +allowlist only by reviewing a change to `WEBSITE_AUTO_APPROVE_AUTHORS` or +`WEBSITE_AUTO_APPROVE_LABELERS` in the workflow. A repository administrator must configure a `website-approval` environment whose deployment branch restriction allows only the protected default branch, then provide the bot's classic PAT as that environment's `WEBSITE_APPROVAL_TOKEN` secret. Missing or mismatched credentials fail closed. diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 098b87c973b..ee376ed178e 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -1,4 +1,5 @@ -# Auto-approve website-only pull requests from explicitly trusted authors. +# Auto-approve website-only pull requests from explicitly trusted authors or +# after an explicitly trusted operator applies the approval label. # # Security boundary: # - pull_request_target loads this workflow from the trusted default branch. @@ -23,6 +24,8 @@ on: permissions: contents: read + issues: read + pull-requests: read concurrency: group: website-auto-approve-${{ github.event.pull_request.number }} @@ -35,7 +38,7 @@ jobs: timeout-minutes: 5 steps: - name: Checkout trusted base automation - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + uses: actions/checkout@v6.1.0 with: ref: refs/heads/${{ github.event.repository.default_branch }} persist-credentials: false @@ -52,4 +55,7 @@ jobs: # This is intentionally checked in: changing who can receive an # automatic approval must itself pass normal repository review. WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy", "christian-byrne"]' + # The label is a second route for a non-allowlisted author. The script + # verifies its latest event came from one of these operators. + WEBSITE_AUTO_APPROVE_LABELERS: '["christian-byrne", "DrJKL", "benjcooley"]' run: node .github/scripts/website-auto-approve.mjs From 0b43ec4b6b04a561c26d1437a8cf572a594e264e Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 19:58:45 +0000 Subject: [PATCH 17/70] ci: bind approval label to current revision --- .github/scripts/website-auto-approve.mjs | 33 +++++++++++++++---- .github/scripts/website-auto-approve.test.mjs | 18 ++++++++++ .github/workflows/README.md | 4 ++- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index c2a18aebe6c..c600dbe8da1 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -81,13 +81,30 @@ function hasLabel(pull, expectedLabel) { export function hasAuthorizedApprovalLabel(pull, events, approvedLabelers) { if (!hasLabel(pull, APPROVE_LABEL)) return false + let latestCodeEvent = -1 + let latestApprovalLabelEvent = -1 for (let index = events.length - 1; index >= 0; index -= 1) { const event = events[index] - if (event?.label?.name?.toLowerCase() !== APPROVE_LABEL) continue - const actor = event?.actor?.login?.toLowerCase() - return event.event === 'labeled' && approvedLabelers.has(actor) + if ( + latestCodeEvent === -1 && + (event?.event === 'committed' || event?.event === 'head_ref_force_pushed') + ) { + latestCodeEvent = index + } + if ( + latestApprovalLabelEvent === -1 && + event?.label?.name?.toLowerCase() === APPROVE_LABEL + ) { + latestApprovalLabelEvent = index + } + } + + if (latestCodeEvent === -1 || latestApprovalLabelEvent <= latestCodeEvent) { + return false } - return false + const labelEvent = events[latestApprovalLabelEvent] + const actor = labelEvent?.actor?.login?.toLowerCase() + return labelEvent.event === 'labeled' && approvedLabelers.has(actor) } export function hasActiveChangeRequest(reviews) { @@ -346,7 +363,7 @@ async function revalidatePull(github, config, liveHeadSha) { `/pulls/${config.prNumber}/reviews` ) const recheckedEvents = await github.paginate( - `/issues/${config.prNumber}/events` + `/issues/${config.prNumber}/timeline` ) const recheckedFailure = eligibilityFailure({ pull: recheckedPull, @@ -405,7 +422,9 @@ export async function approveCurrentHead(github, config, liveHeadSha, reviews) { try { verifiedPull = await github.request(`/pulls/${config.prNumber}`) verifiedReviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) - verifiedEvents = await github.paginate(`/issues/${config.prNumber}/events`) + verifiedEvents = await github.paginate( + `/issues/${config.prNumber}/timeline` + ) } catch (error) { await dismissApproval( github, @@ -445,7 +464,7 @@ async function main() { const pull = await github.request(`/pulls/${config.prNumber}`) const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) - const events = await github.paginate(`/issues/${config.prNumber}/events`) + const events = await github.paginate(`/issues/${config.prNumber}/timeline`) const failure = eligibilityFailure({ pull, config, events }) if (failure) { await stopWithSummary({ diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index e86a07c9aac..ac545a3ff41 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -139,6 +139,7 @@ void test('approval label requires provenance from an authorized operator', () = hasAuthorizedApprovalLabel( pull, [ + { event: 'committed' }, { event: 'labeled', label: { name: 'website-fast-lane:approve' }, @@ -153,6 +154,7 @@ void test('approval label requires provenance from an authorized operator', () = hasAuthorizedApprovalLabel( pull, [ + { event: 'committed' }, { event: 'labeled', label: { name: 'website-fast-lane:approve' }, @@ -167,6 +169,7 @@ void test('approval label requires provenance from an authorized operator', () = hasAuthorizedApprovalLabel( { labels: [] }, [ + { event: 'committed' }, { event: 'labeled', label: { name: 'website-fast-lane:approve' }, @@ -177,6 +180,21 @@ void test('approval label requires provenance from an authorized operator', () = ), false ) + assert.equal( + hasAuthorizedApprovalLabel( + pull, + [ + { + event: 'labeled', + label: { name: 'website-fast-lane:approve' }, + actor: { login: 'DrJKL' } + }, + { event: 'committed' } + ], + authorized + ), + false + ) }) void test('only each non-app reviewer latest state can actively block', () => { diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 2d8623e9ab1..5b93658dafe 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -41,7 +41,9 @@ rejects other base branches and fork pull requests, rechecks the live head, and `comfy_website_devs`, so its review satisfies the website path reviewer rule. Approval-label eligibility is provenance-checked against the issue event -history; label presence by itself is not authorization. The +timeline; the latest matching label event must be from an allowlisted operator +and later than the latest commit or force-push event. Every new head therefore +requires a fresh authorized label. Label presence by itself is not authorization. The `website-fast-lane:hold` label, draft state, an active non-app reviewer change request, a base or head change, or a path outside `apps/website/**` stops approval and withdraws an existing current-head policy approval when the trusted workflow evaluates the PR. A human change request From ef0f493036d2f061b2cf31a1a52597f13ce81060 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 Oct 2026 20:39:58 +0000 Subject: [PATCH 18/70] ci: exclude website path from CodeRabbit review --- .coderabbit.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index ee33d84378d..8cda5f49355 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -5,6 +5,11 @@ reviews: profile: assertive high_level_summary: false request_changes_workflow: true + # Website PRs use the dedicated website reviewer / Greenlight fast lane. + # Keep CodeRabbit on mixed PRs by reviewing every non-website file, but do + # not let website-only changes generate an independent request-changes loop. + path_filters: + - '!apps/website/**' # Without this, a review that never happened (rate limit, internal error) # still reports green, so an unreviewed PR is indistinguishable from a # cleanly reviewed one. From 75fc52fd29270d5aa74c4784e933f08c8b542406 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 6 Oct 2026 04:17:55 +0000 Subject: [PATCH 19/70] fix: use approved website workflow identity --- .github/workflows/README.md | 13 +++++++------ .github/workflows/pr-website-auto-approve.yaml | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 5b93658dafe..8713ab6252e 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -37,8 +37,10 @@ allowlisted authors, or after an allowlisted operator applies `apps/website/**`. It runs from the protected default branch on `pull_request_target`, never executes PR code, rejects other base branches and fork pull requests, rechecks the live head, and verifies that -`WEBSITE_APPROVAL_TOKEN` belongs to `webreviewer-bot` before approving. The bot is a member of -`comfy_website_devs`, so its review satisfies the website path reviewer rule. +`WEBSITE_APPROVAL_TOKEN` belongs to `christian-byrne` before approving. Christian is a member of +`comfy_website_devs`, so the review satisfies the website path reviewer rule. The workflow cannot +approve Christian's own pull requests; use another allowlisted author or the fresh-label route on +a pull request from a different author. Approval-label eligibility is provenance-checked against the issue event timeline; the latest matching label event must be from an allowlisted operator @@ -51,12 +53,11 @@ submitted after policy approval blocks merge immediately through GitHub's review trusted PR event reevaluates and withdraws the policy approval. The review body identifies the verdict as policy-only; it must not be interpreted as a diff review. -The Stage 1 author allowlist contains `bertfy` plus `christian-byrne` as the explicitly labeled -synthetic contributor; the latter must be removed when the canary ends. Expand or retain either -allowlist only by reviewing a change to `WEBSITE_AUTO_APPROVE_AUTHORS` or +The Stage 1 author allowlist contains `bertfy`. Expand or retain either allowlist only by reviewing +a change to `WEBSITE_AUTO_APPROVE_AUTHORS` or `WEBSITE_AUTO_APPROVE_LABELERS` in the workflow. A repository administrator must configure a `website-approval` environment whose deployment branch restriction allows only the -protected default branch, then provide the bot's classic PAT as that environment's +protected default branch, then provide Christian's token as that environment's `WEBSITE_APPROVAL_TOKEN` secret. Missing or mismatched credentials fail closed. ## Website production identity and validation rollback diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index ee376ed178e..957289aa350 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -51,10 +51,10 @@ jobs: PR_NUMBER: ${{ github.event.pull_request.number }} WEBSITE_APPROVAL_BASE_REF: ${{ github.event.repository.default_branch }} WEBSITE_APPROVAL_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} - WEBSITE_APPROVER_LOGIN: webreviewer-bot + WEBSITE_APPROVER_LOGIN: christian-byrne # This is intentionally checked in: changing who can receive an # automatic approval must itself pass normal repository review. - WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy", "christian-byrne"]' + WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy"]' # The label is a second route for a non-allowlisted author. The script # verifies its latest event came from one of these operators. WEBSITE_AUTO_APPROVE_LABELERS: '["christian-byrne", "DrJKL", "benjcooley"]' From 32b249c5d4105eb615c3b3403ab0d1be9a9ed4b1 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 6 Oct 2026 04:33:10 +0000 Subject: [PATCH 20/70] fix: pin website approval checkout action --- .github/workflows/pr-website-auto-approve.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 957289aa350..9f6e933d087 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -38,7 +38,7 @@ jobs: timeout-minutes: 5 steps: - name: Checkout trusted base automation - uses: actions/checkout@v6.1.0 + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 with: ref: refs/heads/${{ github.event.repository.default_branch }} persist-credentials: false From 5d4b8f19ce27a1df33715ad98aded1cb6a691c37 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 6 Oct 2026 06:57:54 +0000 Subject: [PATCH 21/70] docs: name website approval primary path --- .coderabbit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index 8cda5f49355..2fc4a4c09af 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -5,7 +5,7 @@ reviews: profile: assertive high_level_summary: false request_changes_workflow: true - # Website PRs use the dedicated website reviewer / Greenlight fast lane. + # Website PRs use the dedicated Christian-identity approval fast lane. # Keep CodeRabbit on mixed PRs by reviewing every non-website file, but do # not let website-only changes generate an independent request-changes loop. path_filters: From a15963c8462941b50efc1956b9435341a4a96971 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 6 Oct 2026 11:17:21 +0000 Subject: [PATCH 22/70] ci: queue approved website changes --- .github/scripts/website-auto-approve.mjs | 249 ++++++++++++++++-- .github/scripts/website-auto-approve.test.mjs | 151 ++++++++++- .github/workflows/README.md | 12 + .../workflows/pr-website-auto-approve.yaml | 39 ++- 4 files changed, 425 insertions(+), 26 deletions(-) diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index c600dbe8da1..de607d5d1cc 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -6,6 +6,9 @@ const API_VERSION = '2022-11-28' const PAGE_SIZE = 100 const HOLD_LABEL = 'website-fast-lane:hold' const APPROVE_LABEL = 'website-fast-lane:approve' +const GRAPHQL_URL = 'https://api.github.com/graphql' +const POLICY_REVIEW_PREFIX = + '[Validation canary] Policy-only automatic approval.' const DECISIVE_REVIEW_STATES = new Set([ 'APPROVED', 'CHANGES_REQUESTED', @@ -150,6 +153,16 @@ function requiredEnv(name) { return value } +function optionalPositiveIntegerEnv(name) { + const value = process.env[name]?.trim() + if (!value) return + const number = Number(value) + if (!Number.isSafeInteger(number) || number <= 0) { + throw new Error(`${name} must be positive`) + } + return number +} + function githubClient(token, repository) { const root = `https://api.github.com/repos/${repository}` const headers = { @@ -177,7 +190,23 @@ function githubClient(token, repository) { } } - return { paginate, request } + async function graphql(query, variables) { + const body = await request(GRAPHQL_URL, { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ query, variables }) + }) + if (body?.errors?.length) { + throw new Error( + `GitHub GraphQL failed: ${body.errors + .map((error) => error.message) + .join('; ')}` + ) + } + return body?.data + } + + return { graphql, paginate, request } } function apiUrl(root, requestPath) { @@ -218,7 +247,7 @@ function configuration() { const config = { token: requiredEnv('WEBSITE_APPROVAL_TOKEN'), repository: requiredEnv('GITHUB_REPOSITORY'), - prNumber: Number(requiredEnv('PR_NUMBER')), + prNumber: optionalPositiveIntegerEnv('PR_NUMBER'), eventHeadSha: requiredEnv('PR_HEAD_SHA'), defaultBranch: requiredEnv('WEBSITE_APPROVAL_BASE_REF'), expectedApprover: requiredEnv('WEBSITE_APPROVER_LOGIN'), @@ -229,12 +258,33 @@ function configuration() { requiredEnv('WEBSITE_AUTO_APPROVE_LABELERS') ) } - if (!Number.isSafeInteger(config.prNumber) || config.prNumber <= 0) { - throw new Error('PR_NUMBER must be positive') - } return config } +async function resolvePullNumber(github, config) { + if (config.prNumber) return config.prNumber + const pulls = await github.request(`/commits/${config.eventHeadSha}/pulls`) + if (!Array.isArray(pulls)) { + throw new Error('GitHub did not return pull requests for the commit') + } + const matches = pulls.filter((pull) => { + return ( + pull?.state === 'open' && + pull?.head?.sha === config.eventHeadSha && + isSameRepository(pull, config.repository) && + targetsDefaultBranch(pull, config.repository, config.defaultBranch) + ) + }) + if (matches.length !== 1) { + summary( + `Skipped: expected one open same-repository pull request for ${config.eventHeadSha.slice(0, 12)}, found ${matches.length}.` + ) + return + } + config.prNumber = matches[0].number + return config.prNumber +} + function readinessFailure({ pull }) { if (pull?.state !== 'open') { return 'Skipped: the pull request is not open and ready for review.' @@ -308,6 +358,17 @@ function approvalForHead(reviews, approverLogin, headSha) { } } +function latestPolicyReview(reviews, approverLogin) { + const expectedLogin = approverLogin.toLowerCase() + return [...reviews].reverse().find((review) => { + return ( + review?.user?.login?.toLowerCase() === expectedLogin && + review?.body?.startsWith(POLICY_REVIEW_PREFIX) && + !Number.isNaN(Date.parse(review.submitted_at)) + ) + }) +} + async function dismissApproval(github, prNumber, review, reason) { if (!review?.id) return false await github.request(`/pulls/${prNumber}/reviews/${review.id}/dismissals`, { @@ -318,8 +379,143 @@ async function dismissApproval(github, prNumber, review, reason) { return true } -async function stopWithSummary({ github, config, reviews, headSha, message }) { - const approval = approvalForHead(reviews, config.expectedApprover, headSha) +const MERGE_AUTOMATION_STATE = ` + query WebsiteFastLaneMergeState($pullRequestId: ID!) { + node(id: $pullRequestId) { + ... on PullRequest { + id + headRefOid + mergeStateStatus + autoMergeRequest { enabledAt enabledBy { login } } + mergeQueueEntry { + id + enqueuedAt + enqueuer { login } + headCommit { oid } + } + } + } + } +` + +function actorMatches(actor, expectedLogin) { + return actor?.login?.toLowerCase() === expectedLogin.toLowerCase() +} + +async function mergeAutomationState(github, pullRequestId) { + const data = await github.graphql(MERGE_AUTOMATION_STATE, { pullRequestId }) + if (!data?.node?.id) { + throw new Error('GitHub did not return the pull request merge state') + } + return data.node +} + +function atOrAfter(value, floor) { + return Date.parse(value) >= Date.parse(floor) +} + +export async function stopMergeAutomation(github, config, pull, policyReview) { + // Christian may also use native auto-merge manually. Only touch merge state + // created after this workflow's identifiable policy review. + if (!policyReview) return + if (!pull?.node_id) { + throw new Error( + 'the pull request node id is required to stop merge automation' + ) + } + const state = await mergeAutomationState(github, pull.node_id) + const entry = state.mergeQueueEntry + if ( + entry && + actorMatches(entry.enqueuer, config.expectedApprover) && + atOrAfter(entry.enqueuedAt, policyReview.submitted_at) + ) { + await github.graphql( + `mutation WebsiteFastLaneDequeue($id: ID!) { + dequeuePullRequest(input: { id: $id }) { clientMutationId } + }`, + { id: entry.id } + ) + } + if ( + state.autoMergeRequest && + actorMatches(state.autoMergeRequest.enabledBy, config.expectedApprover) && + atOrAfter(state.autoMergeRequest.enabledAt, policyReview.submitted_at) + ) { + await github.graphql( + `mutation WebsiteFastLaneDisableAutoMerge($pullRequestId: ID!) { + disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) { + clientMutationId + } + }`, + { pullRequestId: pull.node_id } + ) + } +} + +export async function armMergeAutomation(github, config, pull) { + if (!pull?.node_id) { + throw new Error( + 'the pull request node id is required to arm merge automation' + ) + } + const state = await mergeAutomationState(github, pull.node_id) + if (state.headRefOid !== pull.head.sha) { + throw new Error('the pull request head advanced before merge automation') + } + if (state.mergeQueueEntry) { + summary(`Already queued ${pull.head.sha.slice(0, 12)}.`) + return + } + if (state.mergeStateStatus === 'CLEAN') { + await github.graphql( + `mutation WebsiteFastLaneEnqueue( + $pullRequestId: ID! + $expectedHeadOid: GitObjectID! + ) { + enqueuePullRequest(input: { + pullRequestId: $pullRequestId + expectedHeadOid: $expectedHeadOid + jump: false + }) { clientMutationId } + }`, + { + pullRequestId: pull.node_id, + expectedHeadOid: pull.head.sha + } + ) + summary(`Entered the native merge queue for ${pull.head.sha.slice(0, 12)}.`) + return + } + if (state.autoMergeRequest) { + summary(`Auto-merge already armed for ${pull.head.sha.slice(0, 12)}.`) + return + } + await github.graphql( + `mutation WebsiteFastLaneEnableAutoMerge( + $pullRequestId: ID! + $expectedHeadOid: GitObjectID! + ) { + enablePullRequestAutoMerge(input: { + pullRequestId: $pullRequestId + expectedHeadOid: $expectedHeadOid + mergeMethod: SQUASH + }) { clientMutationId } + }`, + { + pullRequestId: pull.node_id, + expectedHeadOid: pull.head.sha + } + ) + summary(`Armed native auto-merge for ${pull.head.sha.slice(0, 12)}.`) +} + +async function stopWithSummary({ github, config, pull, reviews, message }) { + const approval = approvalForHead( + reviews, + config.expectedApprover, + pull?.head?.sha + ) if (approval) { await dismissApproval( github, @@ -328,6 +524,12 @@ async function stopWithSummary({ github, config, reviews, headSha, message }) { `Website fast-lane approval withdrawn: ${message}` ) } + await stopMergeAutomation( + github, + config, + pull, + latestPolicyReview(reviews, config.expectedApprover) + ) summary(message) } @@ -337,8 +539,8 @@ async function validateWebsitePaths(github, config, pull, reviews) { await stopWithSummary({ github, config, + pull, reviews, - headSha: pull.head.sha, message: 'Skipped: could not enumerate every changed file.' }) return false @@ -348,8 +550,8 @@ async function validateWebsitePaths(github, config, pull, reviews) { await stopWithSummary({ github, config, + pull, reviews, - headSha: pull.head.sha, message: 'Skipped: at least one changed file is outside apps/website/**.' }) return false @@ -374,8 +576,8 @@ async function revalidatePull(github, config, liveHeadSha) { await stopWithSummary({ github, config, + pull: recheckedPull, reviews: recheckedReviews, - headSha: liveHeadSha, message: recheckedFailure }) return @@ -384,8 +586,8 @@ async function revalidatePull(github, config, liveHeadSha) { await stopWithSummary({ github, config, + pull: recheckedPull, reviews: recheckedReviews, - headSha: liveHeadSha, message: 'Skipped: an active reviewer change request is present.' }) return @@ -400,7 +602,7 @@ export async function approveCurrentHead(github, config, liveHeadSha, reviews) { summary( `Already approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` ) - return + return true } const createdReview = await github.request( @@ -411,7 +613,7 @@ export async function approveCurrentHead(github, config, liveHeadSha, reviews) { body: JSON.stringify({ event: 'APPROVE', commit_id: liveHeadSha, - body: '[Validation canary] Policy-only automatic approval. No diff review was performed; eligibility was bound to a trusted author or authorized approval-label event, the exact head commit, and the `apps/website/**` path boundary.' + body: `${POLICY_REVIEW_PREFIX} No diff review was performed; eligibility was bound to a trusted author or authorized approval-label event, the exact head commit, and the \`apps/website/**\` path boundary.` }) } ) @@ -450,17 +652,19 @@ export async function approveCurrentHead(github, config, liveHeadSha, reviews) { `Website fast-lane approval withdrawn: ${reason}` ) summary(`Approval withdrawn: ${reason}`) - return + return false } summary( `Approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` ) + return true } async function main() { const config = configuration() const github = githubClient(config.token, config.repository) await assertApproverIdentity(github, config.expectedApprover) + if (!(await resolvePullNumber(github, config))) return const pull = await github.request(`/pulls/${config.prNumber}`) const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) @@ -470,8 +674,8 @@ async function main() { await stopWithSummary({ github, config, + pull, reviews, - headSha: pull?.head?.sha, message: failure }) return @@ -484,7 +688,20 @@ async function main() { const recheckedReviews = await revalidatePull(github, config, liveHeadSha) if (!recheckedReviews) return - await approveCurrentHead(github, config, liveHeadSha, recheckedReviews) + const approved = await approveCurrentHead( + github, + config, + liveHeadSha, + recheckedReviews + ) + if (!approved) return + + const queuePull = await github.request(`/pulls/${config.prNumber}`) + await armMergeAutomation(github, config, queuePull) + + // Recheck once more after arming. A concurrent hold, new commit, or human + // change request must withdraw both the policy approval and merge intent. + await revalidatePull(github, config, liveHeadSha) } if ( diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index ac545a3ff41..6ca28051cae 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -2,6 +2,7 @@ import assert from 'node:assert/strict' import test from 'node:test' import { + armMergeAutomation, approveCurrentHead, alreadyApprovedCurrentHead, changedPaths, @@ -12,6 +13,7 @@ import { isSameRepository, isWebsiteOnly, parseApprovedAuthors, + stopMergeAutomation, targetsDefaultBranch } from './website-auto-approve.mjs' @@ -33,7 +35,7 @@ void test('a failed post-approval verification withdraws the new approval', asyn await assert.rejects( approveCurrentHead( github, - { prNumber: 42, expectedApprover: 'webreviewer-bot' }, + { prNumber: 42, expectedApprover: 'christian-byrne' }, '0123456789abcdef0123456789abcdef01234567', [] ), @@ -216,7 +218,7 @@ void test('only each non-app reviewer latest state can actively block', () => { hasActiveChangeRequest([ { state: 'CHANGES_REQUESTED', - user: { login: 'webreviewer-bot', type: 'User' } + user: { login: 'human-reviewer', type: 'User' } } ]), true @@ -283,27 +285,160 @@ void test('only pull requests targeting the default branch are eligible', () => ) }) -void test('idempotency is scoped to the bot and exact head commit', () => { +void test('idempotency is scoped to Christian and the exact head commit', () => { const reviews = [ - { state: 'APPROVED', commit_id: 'old', user: { login: 'webreviewer-bot' } }, + { state: 'APPROVED', commit_id: 'old', user: { login: 'christian-byrne' } }, { state: 'APPROVED', commit_id: 'head', user: { login: 'someone-else' } }, { state: 'CHANGES_REQUESTED', commit_id: 'head', - user: { login: 'webreviewer-bot' } + user: { login: 'christian-byrne' } } ] assert.equal( - alreadyApprovedCurrentHead(reviews, 'webreviewer-bot', 'head'), + alreadyApprovedCurrentHead(reviews, 'christian-byrne', 'head'), false ) reviews.push({ state: 'APPROVED', commit_id: 'head', - user: { login: 'WebReviewer-Bot' } + user: { login: 'Christian-Byrne' } }) assert.equal( - alreadyApprovedCurrentHead(reviews, 'webreviewer-bot', 'head'), + alreadyApprovedCurrentHead(reviews, 'christian-byrne', 'head'), true ) }) + +void test('arms native auto-merge for the exact head with squash', async () => { + const calls = [] + const github = { + async graphql(query, variables) { + calls.push({ query, variables }) + if (calls.length === 1) { + return { + node: { + id: 'PR_1', + headRefOid: 'head-sha', + mergeStateStatus: 'BLOCKED', + autoMergeRequest: null, + mergeQueueEntry: null + } + } + } + return { enablePullRequestAutoMerge: { clientMutationId: null } } + } + } + await armMergeAutomation( + github, + { expectedApprover: 'christian-byrne' }, + { node_id: 'PR_1', head: { sha: 'head-sha' } } + ) + assert.equal(calls.length, 2) + assert.match(calls[1].query, /enablePullRequestAutoMerge/) + assert.match(calls[1].query, /mergeMethod: SQUASH/) + assert.deepEqual(calls[1].variables, { + pullRequestId: 'PR_1', + expectedHeadOid: 'head-sha' + }) +}) + +void test('explicitly enqueues a clean exact head without jumping the queue', async () => { + const calls = [] + const github = { + async graphql(query, variables) { + calls.push({ query, variables }) + if (calls.length === 1) { + return { + node: { + id: 'PR_1', + headRefOid: 'head-sha', + mergeStateStatus: 'CLEAN', + autoMergeRequest: { + enabledAt: '2026-10-06T10:01:00Z', + enabledBy: { login: 'christian-byrne' } + }, + mergeQueueEntry: null + } + } + } + return { enqueuePullRequest: { clientMutationId: null } } + } + } + await armMergeAutomation( + github, + { expectedApprover: 'christian-byrne' }, + { node_id: 'PR_1', head: { sha: 'head-sha' } } + ) + assert.equal(calls.length, 2) + assert.match(calls[1].query, /enqueuePullRequest/) + assert.match(calls[1].query, /jump: false/) + assert.deepEqual(calls[1].variables, { + pullRequestId: 'PR_1', + expectedHeadOid: 'head-sha' + }) +}) + +void test('stops only merge state created after the policy review', async () => { + const calls = [] + const github = { + async graphql(query, variables) { + calls.push({ query, variables }) + if (calls.length === 1) { + return { + node: { + id: 'PR_1', + headRefOid: 'head-sha', + autoMergeRequest: { + enabledAt: '2026-10-06T10:01:00Z', + enabledBy: { login: 'christian-byrne' } + }, + mergeQueueEntry: { + id: 'MQE_1', + enqueuedAt: '2026-10-06T10:02:00Z', + enqueuer: { login: 'christian-byrne' }, + headCommit: { oid: 'head-sha' } + } + } + } + } + return {} + } + } + await stopMergeAutomation( + github, + { expectedApprover: 'christian-byrne' }, + { node_id: 'PR_1', head: { sha: 'head-sha' } }, + { submitted_at: '2026-10-06T10:00:00Z' } + ) + assert.equal(calls.length, 3) + assert.match(calls[1].query, /dequeuePullRequest/) + assert.match(calls[2].query, /disablePullRequestAutoMerge/) +}) + +void test('leaves Christian merge state that predates the workflow review alone', async () => { + const calls = [] + const github = { + async graphql(query, variables) { + calls.push({ query, variables }) + return { + node: { + id: 'PR_1', + headRefOid: 'head-sha', + autoMergeRequest: { + enabledAt: '2026-10-06T09:59:00Z', + enabledBy: { login: 'christian-byrne' } + }, + mergeQueueEntry: null + } + } + } + } + await stopMergeAutomation( + github, + { expectedApprover: 'christian-byrne' }, + { node_id: 'PR_1', head: { sha: 'head-sha' } }, + { submitted_at: '2026-10-06T10:00:00Z' } + ) + assert.equal(calls.length, 1) +}) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 8713ab6252e..96983ff4d7c 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -42,6 +42,18 @@ rejects other base branches and fork pull requests, rechecks the live head, and approve Christian's own pull requests; use another allowlisted author or the fresh-label route on a pull request from a different author. +After exact-head approval, the same Christian credential arms GitHub's native auto-merge with the +repository's only allowed merge method, squash. GitHub moves the pull request into the protected +branch's native merge queue as soon as its remaining requirements pass; no manual merge click or +queue jump is used. Because native auto-merge has not always handed ruleset-protected pull requests +to the queue reliably, the workflow also reconciles after each required Actions workflow and commit +status completes. When GitHub reports the exact head as clean, it explicitly enters that head in the +native queue with `jump: false`; otherwise it leaves native auto-merge armed. The workflow also +listens for human review changes. If a draft, hold, stale +head, mixed path, or active human change request makes the pull request ineligible, it withdraws +Christian's policy approval and disables or dequeues merge state created by Christian's workflow. +Merge state created by another person is left alone. + Approval-label eligibility is provenance-checked against the issue event timeline; the latest matching label event must be from an allowlisted operator and later than the latest commit or force-push event. Every new head therefore diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 9f6e933d087..bbcc9dd2775 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -21,6 +21,16 @@ on: - edited - labeled - unlabeled + pull_request_review: + types: [submitted, dismissed] + workflow_run: + workflows: + - 'CI: Lint Format' + - 'CI: Tests Unit' + - 'CI: Tests E2E' + - 'CI: Website E2E' + types: [completed] + status: permissions: contents: read @@ -28,11 +38,12 @@ permissions: pull-requests: read concurrency: - group: website-auto-approve-${{ github.event.pull_request.number }} + group: website-auto-approve-${{ github.event.pull_request.number || github.event.workflow_run.head_sha || github.event.sha || github.run_id }} cancel-in-progress: true jobs: approve: + if: github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review' environment: website-approval runs-on: ubuntu-latest timeout-minutes: 5 @@ -44,7 +55,7 @@ jobs: persist-credentials: false sparse-checkout: .github/scripts - - name: Approve eligible website pull request + - name: Approve and queue eligible website pull request env: GITHUB_REPOSITORY: ${{ github.repository }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} @@ -59,3 +70,27 @@ jobs: # verifies its latest event came from one of these operators. WEBSITE_AUTO_APPROVE_LABELERS: '["christian-byrne", "DrJKL", "benjcooley"]' run: node .github/scripts/website-auto-approve.mjs + + reconcile-after-check: + if: github.event_name == 'status' || (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request') + environment: website-approval + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout trusted base automation + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + ref: refs/heads/${{ github.event.repository.default_branch }} + persist-credentials: false + sparse-checkout: .github/scripts + + - name: Reconcile approval and native queue state + env: + GITHUB_REPOSITORY: ${{ github.repository }} + PR_HEAD_SHA: ${{ github.event.sha || github.event.workflow_run.head_sha }} + WEBSITE_APPROVAL_BASE_REF: ${{ github.event.repository.default_branch }} + WEBSITE_APPROVAL_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} + WEBSITE_APPROVER_LOGIN: christian-byrne + WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy"]' + WEBSITE_AUTO_APPROVE_LABELERS: '["christian-byrne", "DrJKL", "benjcooley"]' + run: node .github/scripts/website-auto-approve.mjs From 1d4e20d4d0cc16e7f30ff7ccf1d18dfba3c9c509 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 6 Oct 2026 11:27:32 +0000 Subject: [PATCH 23/70] fix: satisfy website queue workflow lint --- .github/scripts/website-auto-approve.mjs | 10 +++++----- .github/scripts/website-auto-approve.test.mjs | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs index de607d5d1cc..acfe2809c78 100644 --- a/.github/scripts/website-auto-approve.mjs +++ b/.github/scripts/website-auto-approve.mjs @@ -453,7 +453,7 @@ export async function stopMergeAutomation(github, config, pull, policyReview) { } } -export async function armMergeAutomation(github, config, pull) { +export async function armMergeAutomation(github, pull) { if (!pull?.node_id) { throw new Error( 'the pull request node id is required to arm merge automation' @@ -559,7 +559,7 @@ async function validateWebsitePaths(github, config, pull, reviews) { return true } -async function revalidatePull(github, config, liveHeadSha) { +async function revalidatePull(github, config) { const recheckedPull = await github.request(`/pulls/${config.prNumber}`) const recheckedReviews = await github.paginate( `/pulls/${config.prNumber}/reviews` @@ -685,7 +685,7 @@ async function main() { const liveHeadSha = pull.head.sha if (!(await validateWebsitePaths(github, config, pull, reviews))) return - const recheckedReviews = await revalidatePull(github, config, liveHeadSha) + const recheckedReviews = await revalidatePull(github, config) if (!recheckedReviews) return const approved = await approveCurrentHead( @@ -697,11 +697,11 @@ async function main() { if (!approved) return const queuePull = await github.request(`/pulls/${config.prNumber}`) - await armMergeAutomation(github, config, queuePull) + await armMergeAutomation(github, queuePull) // Recheck once more after arming. A concurrent hold, new commit, or human // change request must withdraw both the policy approval and merge intent. - await revalidatePull(github, config, liveHeadSha) + await revalidatePull(github, config) } if ( diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index 6ca28051cae..732825270f7 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -331,7 +331,6 @@ void test('arms native auto-merge for the exact head with squash', async () => { } await armMergeAutomation( github, - { expectedApprover: 'christian-byrne' }, { node_id: 'PR_1', head: { sha: 'head-sha' } } ) assert.equal(calls.length, 2) @@ -367,7 +366,6 @@ void test('explicitly enqueues a clean exact head without jumping the queue', as } await armMergeAutomation( github, - { expectedApprover: 'christian-byrne' }, { node_id: 'PR_1', head: { sha: 'head-sha' } } ) assert.equal(calls.length, 2) From f95ed209a62e4b7122b17cb1985757b289fea128 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 6 Oct 2026 11:31:10 +0000 Subject: [PATCH 24/70] [automated] Apply ESLint and Oxfmt fixes --- .github/scripts/website-auto-approve.test.mjs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs index 732825270f7..533ff061515 100644 --- a/.github/scripts/website-auto-approve.test.mjs +++ b/.github/scripts/website-auto-approve.test.mjs @@ -329,10 +329,10 @@ void test('arms native auto-merge for the exact head with squash', async () => { return { enablePullRequestAutoMerge: { clientMutationId: null } } } } - await armMergeAutomation( - github, - { node_id: 'PR_1', head: { sha: 'head-sha' } } - ) + await armMergeAutomation(github, { + node_id: 'PR_1', + head: { sha: 'head-sha' } + }) assert.equal(calls.length, 2) assert.match(calls[1].query, /enablePullRequestAutoMerge/) assert.match(calls[1].query, /mergeMethod: SQUASH/) @@ -364,10 +364,10 @@ void test('explicitly enqueues a clean exact head without jumping the queue', as return { enqueuePullRequest: { clientMutationId: null } } } } - await armMergeAutomation( - github, - { node_id: 'PR_1', head: { sha: 'head-sha' } } - ) + await armMergeAutomation(github, { + node_id: 'PR_1', + head: { sha: 'head-sha' } + }) assert.equal(calls.length, 2) assert.match(calls[1].query, /enqueuePullRequest/) assert.match(calls[1].query, /jump: false/) From f3a40b9ffebbe0ad56f8f2e3bc3c8985be810e0a Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 6 Oct 2026 12:19:17 +0000 Subject: [PATCH 25/70] ci: retain website rollback evidence --- .../validation-website-rollback.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml index 2d850551d33..4957d0be52e 100644 --- a/.github/workflows/validation-website-rollback.yaml +++ b/.github/workflows/validation-website-rollback.yaml @@ -45,6 +45,7 @@ jobs: run: vercel pull --yes --environment=production - name: Verify the captured deployment + id: verify-target env: EXPECTED_SHA: ${{ inputs.expected_sha }} TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} @@ -73,6 +74,7 @@ jobs: echo "::error::Deployment $TARGET_DEPLOYMENT serves $ACTUAL_SHA, expected $EXPECTED_SHA" exit 1 fi + echo "actual-sha=$ACTUAL_SHA" >> "$GITHUB_OUTPUT" { echo "**Validated rollback target:** $TARGET_DEPLOYMENT" echo "**Validated rollback SHA:** $ACTUAL_SHA" @@ -90,6 +92,7 @@ jobs: --scope="$VERCEL_SCOPE" - name: Verify rollback at the canonical hostname + id: verify-canonical if: inputs.perform_rollback env: EXPECTED_SHA: ${{ inputs.expected_sha }} @@ -106,6 +109,8 @@ jobs: jq -r '.deploymentId // empty') || true if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" && "$ALIAS_DEPLOYMENT_ID" == "$TARGET_DEPLOYMENT" ]]; then curl -fsS -o /dev/null https://comfy.org/ + echo "actual-sha=$ACTUAL_SHA" >> "$GITHUB_OUTPUT" + echo "deployment-id=$ALIAS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" exit 0 fi sleep 10 @@ -124,6 +129,7 @@ jobs: --scope="$VERCEL_SCOPE" - name: Verify post-rollback promotion state + id: verify-promotion if: inputs.perform_rollback env: EXPECTED_SHA: ${{ inputs.expected_sha }} @@ -139,8 +145,47 @@ jobs: jq -er '.deploymentId') test "$ACTUAL_SHA" = "$EXPECTED_SHA" test "$ALIAS_DEPLOYMENT_ID" = "$TARGET_DEPLOYMENT" + echo "actual-sha=$ACTUAL_SHA" >> "$GITHUB_OUTPUT" + echo "deployment-id=$ALIAS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" { echo "**Rollback target:** ${{ inputs.deployment_id }}" echo "**Verified canonical SHA:** $ACTUAL_SHA" echo "**Verified canonical deployment:** $ALIAS_DEPLOYMENT_ID" } >> "$GITHUB_STEP_SUMMARY" + + - name: Retain rollback evidence + env: + EXPECTED_SHA: ${{ inputs.expected_sha }} + PERFORM_ROLLBACK: ${{ inputs.perform_rollback }} + POST_PROMOTION_DEPLOYMENT_ID: ${{ steps.verify-promotion.outputs.deployment-id }} + POST_PROMOTION_SHA: ${{ steps.verify-promotion.outputs.actual-sha }} + ROLLBACK_DEPLOYMENT_ID: ${{ steps.verify-canonical.outputs.deployment-id }} + ROLLBACK_SHA: ${{ steps.verify-canonical.outputs.actual-sha }} + TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} + TARGET_VERIFIED_SHA: ${{ steps.verify-target.outputs.actual-sha }} + run: | + mkdir -p temp/website-rollback-result + jq -n \ + --arg targetDeploymentId "$TARGET_DEPLOYMENT" \ + --arg expectedSha "$EXPECTED_SHA" \ + --arg targetVerifiedSha "$TARGET_VERIFIED_SHA" \ + --arg rollbackCanonicalSha "$ROLLBACK_SHA" \ + --arg rollbackCanonicalDeploymentId "$ROLLBACK_DEPLOYMENT_ID" \ + --arg postPromotionCanonicalSha "$POST_PROMOTION_SHA" \ + --arg postPromotionCanonicalDeploymentId "$POST_PROMOTION_DEPLOYMENT_ID" \ + --arg runId "$GITHUB_RUN_ID" \ + --arg runAttempt "$GITHUB_RUN_ATTEMPT" \ + --arg workflowSha "$GITHUB_SHA" \ + --arg actor "$GITHUB_ACTOR" \ + --arg verifiedAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + --argjson performRollback "$PERFORM_ROLLBACK" \ + '{targetDeploymentId: $targetDeploymentId, expectedSha: $expectedSha, targetVerifiedSha: $targetVerifiedSha, performRollback: $performRollback, rollbackCanonicalSha: $rollbackCanonicalSha, rollbackCanonicalDeploymentId: $rollbackCanonicalDeploymentId, postPromotionCanonicalSha: $postPromotionCanonicalSha, postPromotionCanonicalDeploymentId: $postPromotionCanonicalDeploymentId, runId: $runId, runAttempt: $runAttempt, workflowSha: $workflowSha, actor: $actor, verifiedAt: $verifiedAt}' \ + > temp/website-rollback-result/result.json + + - name: Upload rollback evidence + uses: actions/upload-artifact@v6 + with: + name: website-rollback-result + path: temp/website-rollback-result/result.json + retention-days: 7 + if-no-files-found: error From ddf7011202ed8c874606db47203d1a383bfefc6f Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 01:40:02 +0000 Subject: [PATCH 26/70] refactor(ci): make package fast lanes declarative --- .fallowrc.jsonc | 1 - .github/fast-lanes/website.json | 16 + .github/scripts/website-auto-approve.mjs | 715 ------------------ .github/scripts/website-auto-approve.test.mjs | 442 ----------- .github/workflows/README.md | 71 +- .github/workflows/ci-lint-format-queue.yaml | 70 -- .../workflows/pr-website-auto-approve.yaml | 53 +- docs/architecture/package-delivery-lanes.md | 75 ++ .../website-delivery-validation.md | 51 ++ scripts/cicd/fast-lane/automation.test.ts | 241 ++++++ scripts/cicd/fast-lane/automation.ts | 485 ++++++++++++ scripts/cicd/fast-lane/config.ts | 153 ++++ scripts/cicd/fast-lane/github.ts | 113 +++ scripts/cicd/fast-lane/policy.test.ts | 306 ++++++++ scripts/cicd/fast-lane/policy.ts | 178 +++++ scripts/cicd/fast-lane/run.ts | 30 + scripts/cicd/fast-lane/types.ts | 90 +++ 17 files changed, 1770 insertions(+), 1320 deletions(-) create mode 100644 .github/fast-lanes/website.json delete mode 100644 .github/scripts/website-auto-approve.mjs delete mode 100644 .github/scripts/website-auto-approve.test.mjs create mode 100644 docs/architecture/package-delivery-lanes.md create mode 100644 docs/architecture/website-delivery-validation.md create mode 100644 scripts/cicd/fast-lane/automation.test.ts create mode 100644 scripts/cicd/fast-lane/automation.ts create mode 100644 scripts/cicd/fast-lane/config.ts create mode 100644 scripts/cicd/fast-lane/github.ts create mode 100644 scripts/cicd/fast-lane/policy.test.ts create mode 100644 scripts/cicd/fast-lane/policy.ts create mode 100644 scripts/cicd/fast-lane/run.ts create mode 100644 scripts/cicd/fast-lane/types.ts diff --git a/.fallowrc.jsonc b/.fallowrc.jsonc index 2e82f7b7e6f..ff5df294f8a 100644 --- a/.fallowrc.jsonc +++ b/.fallowrc.jsonc @@ -27,7 +27,6 @@ "name": "comfyui-test-entry-points", "enablers": ["@playwright/test"], "entryPoints": [ - ".github/scripts/**/*.test.mjs", "apps/website/src/**/__mocks__/**/*.ts", "browser_tests/global{Setup,Teardown}.ts", "playwright.session.config.ts", diff --git a/.github/fast-lanes/website.json b/.github/fast-lanes/website.json new file mode 100644 index 00000000000..4e4696af36b --- /dev/null +++ b/.github/fast-lanes/website.json @@ -0,0 +1,16 @@ +{ + "schemaVersion": 1, + "id": "website", + "pathPrefixes": ["apps/website/"], + "approval": { + "identity": "christian-byrne", + "trustedAuthors": ["bertfy"], + "approvalLabel": "website-fast-lane:approve", + "trustedLabelers": ["christian-byrne", "DrJKL", "benjcooley"], + "holdLabel": "website-fast-lane:hold" + }, + "merge": { + "mode": "automatic", + "method": "SQUASH" + } +} diff --git a/.github/scripts/website-auto-approve.mjs b/.github/scripts/website-auto-approve.mjs deleted file mode 100644 index acfe2809c78..00000000000 --- a/.github/scripts/website-auto-approve.mjs +++ /dev/null @@ -1,715 +0,0 @@ -import fs from 'node:fs' -import path from 'node:path' -import { fileURLToPath } from 'node:url' - -const API_VERSION = '2022-11-28' -const PAGE_SIZE = 100 -const HOLD_LABEL = 'website-fast-lane:hold' -const APPROVE_LABEL = 'website-fast-lane:approve' -const GRAPHQL_URL = 'https://api.github.com/graphql' -const POLICY_REVIEW_PREFIX = - '[Validation canary] Policy-only automatic approval.' -const DECISIVE_REVIEW_STATES = new Set([ - 'APPROVED', - 'CHANGES_REQUESTED', - 'DISMISSED' -]) - -export function parseApprovedAuthors(raw) { - let authors - try { - authors = JSON.parse(raw) - } catch (error) { - throw new Error( - `WEBSITE_AUTO_APPROVE_AUTHORS must be JSON: ${error.message}`, - { cause: error } - ) - } - - if ( - !Array.isArray(authors) || - authors.some((author) => typeof author !== 'string') - ) { - throw new Error( - 'WEBSITE_AUTO_APPROVE_AUTHORS must be a JSON array of GitHub logins' - ) - } - - return new Set( - authors.map((author) => author.trim().toLowerCase()).filter(Boolean) - ) -} - -export function isWebsiteOnly(paths) { - return ( - paths.length > 0 && - paths.every((changedPath) => changedPath.startsWith('apps/website/')) - ) -} - -export function hasCompleteChangedFileList(files, changedFileCount) { - return ( - Number.isSafeInteger(changedFileCount) && files.length === changedFileCount - ) -} - -export function changedPaths(files) { - const pathGroups = files.map(changedPathGroup) - if (pathGroups.includes(null)) return null - return pathGroups.flat() -} - -function changedPathGroup(file) { - if (typeof file?.filename !== 'string') return null - if (file.previous_filename === undefined) { - if (file.status === 'renamed' || file.status === 'copied') return null - return [file.filename] - } - if (typeof file.previous_filename !== 'string') return null - return [file.filename, file.previous_filename] -} - -export function hasHoldLabel(pull) { - return pull?.labels?.some( - (label) => label?.name?.toLowerCase() === HOLD_LABEL - ) -} - -function hasLabel(pull, expectedLabel) { - return pull?.labels?.some( - (label) => label?.name?.toLowerCase() === expectedLabel - ) -} - -export function hasAuthorizedApprovalLabel(pull, events, approvedLabelers) { - if (!hasLabel(pull, APPROVE_LABEL)) return false - - let latestCodeEvent = -1 - let latestApprovalLabelEvent = -1 - for (let index = events.length - 1; index >= 0; index -= 1) { - const event = events[index] - if ( - latestCodeEvent === -1 && - (event?.event === 'committed' || event?.event === 'head_ref_force_pushed') - ) { - latestCodeEvent = index - } - if ( - latestApprovalLabelEvent === -1 && - event?.label?.name?.toLowerCase() === APPROVE_LABEL - ) { - latestApprovalLabelEvent = index - } - } - - if (latestCodeEvent === -1 || latestApprovalLabelEvent <= latestCodeEvent) { - return false - } - const labelEvent = events[latestApprovalLabelEvent] - const actor = labelEvent?.actor?.login?.toLowerCase() - return labelEvent.event === 'labeled' && approvedLabelers.has(actor) -} - -export function hasActiveChangeRequest(reviews) { - const latestStateByReviewer = new Map() - for (const review of reviews) { - const login = review?.user?.login?.toLowerCase() - if (!login || review.user?.type === 'Bot' || login.endsWith('[bot]')) { - continue - } - if (!DECISIVE_REVIEW_STATES.has(review.state)) continue - latestStateByReviewer.set(login, review.state) - } - return [...latestStateByReviewer.values()].includes('CHANGES_REQUESTED') -} - -export function isSameRepository(pull, repository) { - return pull?.head?.repo?.full_name?.toLowerCase() === repository.toLowerCase() -} - -export function targetsDefaultBranch(pull, repository, defaultBranch) { - return ( - pull?.base?.repo?.full_name?.toLowerCase() === repository.toLowerCase() && - pull?.base?.ref === defaultBranch - ) -} - -export function alreadyApprovedCurrentHead(reviews, approverLogin, headSha) { - const expectedLogin = approverLogin.toLowerCase() - return reviews.some((review) => - isApprovalForHead(review, expectedLogin, headSha) - ) -} - -function isApprovalForHead(review, expectedLogin, headSha) { - if (review?.state !== 'APPROVED') return false - if (review.commit_id !== headSha) return false - return review.user?.login?.toLowerCase() === expectedLogin -} - -function requiredEnv(name) { - const value = process.env[name]?.trim() - if (!value) throw new Error(`${name} is required`) - return value -} - -function optionalPositiveIntegerEnv(name) { - const value = process.env[name]?.trim() - if (!value) return - const number = Number(value) - if (!Number.isSafeInteger(number) || number <= 0) { - throw new Error(`${name} must be positive`) - } - return number -} - -function githubClient(token, repository) { - const root = `https://api.github.com/repos/${repository}` - const headers = { - accept: 'application/vnd.github+json', - authorization: `Bearer ${token}`, - 'x-github-api-version': API_VERSION, - 'user-agent': 'comfy-website-auto-approve/1.0' - } - - async function request(requestPath, options = {}) { - const response = await fetch(apiUrl(root, requestPath), { - ...options, - headers: { ...headers, ...options.headers } - }) - return responseBody(response, options.method, requestPath) - } - - async function paginate(requestPath) { - const rows = [] - for (let page = 1; ; page += 1) { - const body = await request(pagePath(requestPath, page)) - assertArrayResponse(body, requestPath) - rows.push(...body) - if (body.length < PAGE_SIZE) return rows - } - } - - async function graphql(query, variables) { - const body = await request(GRAPHQL_URL, { - method: 'POST', - headers: { 'content-type': 'application/json' }, - body: JSON.stringify({ query, variables }) - }) - if (body?.errors?.length) { - throw new Error( - `GitHub GraphQL failed: ${body.errors - .map((error) => error.message) - .join('; ')}` - ) - } - return body?.data - } - - return { graphql, paginate, request } -} - -function apiUrl(root, requestPath) { - if (requestPath.startsWith('https://')) return requestPath - return `${root}${requestPath}` -} - -async function responseBody(response, method, requestPath) { - if (!response.ok) { - const body = (await response.text()).slice(0, 500) - throw new Error( - `GitHub API ${method ?? 'GET'} ${requestPath} failed: ${response.status} ${body}` - ) - } - if (response.status === 204) return null - return response.json() -} - -function pagePath(requestPath, page) { - const separator = requestPath.includes('?') ? '&' : '?' - return `${requestPath}${separator}per_page=${PAGE_SIZE}&page=${page}` -} - -function assertArrayResponse(body, requestPath) { - if (!Array.isArray(body)) { - throw new Error(`GitHub API ${requestPath} did not return an array`) - } -} - -function summary(message) { - process.stdout.write(`${message}\n`) - if (process.env.GITHUB_STEP_SUMMARY) { - fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${message}\n`) - } -} - -function configuration() { - const config = { - token: requiredEnv('WEBSITE_APPROVAL_TOKEN'), - repository: requiredEnv('GITHUB_REPOSITORY'), - prNumber: optionalPositiveIntegerEnv('PR_NUMBER'), - eventHeadSha: requiredEnv('PR_HEAD_SHA'), - defaultBranch: requiredEnv('WEBSITE_APPROVAL_BASE_REF'), - expectedApprover: requiredEnv('WEBSITE_APPROVER_LOGIN'), - approvedAuthors: parseApprovedAuthors( - requiredEnv('WEBSITE_AUTO_APPROVE_AUTHORS') - ), - approvedLabelers: parseApprovedAuthors( - requiredEnv('WEBSITE_AUTO_APPROVE_LABELERS') - ) - } - return config -} - -async function resolvePullNumber(github, config) { - if (config.prNumber) return config.prNumber - const pulls = await github.request(`/commits/${config.eventHeadSha}/pulls`) - if (!Array.isArray(pulls)) { - throw new Error('GitHub did not return pull requests for the commit') - } - const matches = pulls.filter((pull) => { - return ( - pull?.state === 'open' && - pull?.head?.sha === config.eventHeadSha && - isSameRepository(pull, config.repository) && - targetsDefaultBranch(pull, config.repository, config.defaultBranch) - ) - }) - if (matches.length !== 1) { - summary( - `Skipped: expected one open same-repository pull request for ${config.eventHeadSha.slice(0, 12)}, found ${matches.length}.` - ) - return - } - config.prNumber = matches[0].number - return config.prNumber -} - -function readinessFailure({ pull }) { - if (pull?.state !== 'open') { - return 'Skipped: the pull request is not open and ready for review.' - } - if (pull.draft) { - return 'Skipped: the pull request is not open and ready for review.' - } -} - -function baseFailure({ pull, config }) { - if (targetsDefaultBranch(pull, config.repository, config.defaultBranch)) - return - return `Skipped: website fast-lane approvals apply only to ${config.defaultBranch}.` -} - -function repositoryFailure({ pull, config }) { - if (isSameRepository(pull, config.repository)) return - return 'Skipped: website fast-lane approvals do not apply to fork pull requests.' -} - -function headFailure({ pull, config }) { - if (pull?.head?.sha === config.eventHeadSha) return - return 'Skipped: the pull request head advanced after this workflow started.' -} - -function authorizationFailure({ pull, config, events }) { - const author = pull?.user?.login?.toLowerCase() - if (author && config.approvedAuthors.has(author)) return - if (hasAuthorizedApprovalLabel(pull, events, config.approvedLabelers)) return - return `Skipped: @${author ?? 'unknown'} is not allowlisted and ${APPROVE_LABEL} was not applied by an authorized operator.` -} - -function holdFailure({ pull }) { - if (!hasHoldLabel(pull)) return - return `Skipped: ${HOLD_LABEL} is applied.` -} - -const ELIGIBILITY_CHECKS = [ - readinessFailure, - baseFailure, - repositoryFailure, - headFailure, - authorizationFailure, - holdFailure -] - -function eligibilityFailure(context) { - return ELIGIBILITY_CHECKS.map((check) => check(context)).find(Boolean) -} - -async function assertApproverIdentity(github, expectedApprover) { - const actor = await github.request('https://api.github.com/user') - if (actor?.login?.toLowerCase() !== expectedApprover.toLowerCase()) { - throw new Error( - `WEBSITE_APPROVAL_TOKEN belongs to ${actor?.login ?? 'an unknown account'}, expected ${expectedApprover}` - ) - } -} - -function assertNotSelfApproval(pull, expectedApprover) { - if (pull.user.login.toLowerCase() === expectedApprover.toLowerCase()) { - throw new Error('the approval bot cannot approve its own pull request') - } -} - -function approvalForHead(reviews, approverLogin, headSha) { - const expectedLogin = approverLogin.toLowerCase() - for (let index = reviews.length - 1; index >= 0; index -= 1) { - const review = reviews[index] - if (isApprovalForHead(review, expectedLogin, headSha)) return review - } -} - -function latestPolicyReview(reviews, approverLogin) { - const expectedLogin = approverLogin.toLowerCase() - return [...reviews].reverse().find((review) => { - return ( - review?.user?.login?.toLowerCase() === expectedLogin && - review?.body?.startsWith(POLICY_REVIEW_PREFIX) && - !Number.isNaN(Date.parse(review.submitted_at)) - ) - }) -} - -async function dismissApproval(github, prNumber, review, reason) { - if (!review?.id) return false - await github.request(`/pulls/${prNumber}/reviews/${review.id}/dismissals`, { - method: 'PUT', - headers: { 'content-type': 'application/json' }, - body: JSON.stringify({ message: reason }) - }) - return true -} - -const MERGE_AUTOMATION_STATE = ` - query WebsiteFastLaneMergeState($pullRequestId: ID!) { - node(id: $pullRequestId) { - ... on PullRequest { - id - headRefOid - mergeStateStatus - autoMergeRequest { enabledAt enabledBy { login } } - mergeQueueEntry { - id - enqueuedAt - enqueuer { login } - headCommit { oid } - } - } - } - } -` - -function actorMatches(actor, expectedLogin) { - return actor?.login?.toLowerCase() === expectedLogin.toLowerCase() -} - -async function mergeAutomationState(github, pullRequestId) { - const data = await github.graphql(MERGE_AUTOMATION_STATE, { pullRequestId }) - if (!data?.node?.id) { - throw new Error('GitHub did not return the pull request merge state') - } - return data.node -} - -function atOrAfter(value, floor) { - return Date.parse(value) >= Date.parse(floor) -} - -export async function stopMergeAutomation(github, config, pull, policyReview) { - // Christian may also use native auto-merge manually. Only touch merge state - // created after this workflow's identifiable policy review. - if (!policyReview) return - if (!pull?.node_id) { - throw new Error( - 'the pull request node id is required to stop merge automation' - ) - } - const state = await mergeAutomationState(github, pull.node_id) - const entry = state.mergeQueueEntry - if ( - entry && - actorMatches(entry.enqueuer, config.expectedApprover) && - atOrAfter(entry.enqueuedAt, policyReview.submitted_at) - ) { - await github.graphql( - `mutation WebsiteFastLaneDequeue($id: ID!) { - dequeuePullRequest(input: { id: $id }) { clientMutationId } - }`, - { id: entry.id } - ) - } - if ( - state.autoMergeRequest && - actorMatches(state.autoMergeRequest.enabledBy, config.expectedApprover) && - atOrAfter(state.autoMergeRequest.enabledAt, policyReview.submitted_at) - ) { - await github.graphql( - `mutation WebsiteFastLaneDisableAutoMerge($pullRequestId: ID!) { - disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) { - clientMutationId - } - }`, - { pullRequestId: pull.node_id } - ) - } -} - -export async function armMergeAutomation(github, pull) { - if (!pull?.node_id) { - throw new Error( - 'the pull request node id is required to arm merge automation' - ) - } - const state = await mergeAutomationState(github, pull.node_id) - if (state.headRefOid !== pull.head.sha) { - throw new Error('the pull request head advanced before merge automation') - } - if (state.mergeQueueEntry) { - summary(`Already queued ${pull.head.sha.slice(0, 12)}.`) - return - } - if (state.mergeStateStatus === 'CLEAN') { - await github.graphql( - `mutation WebsiteFastLaneEnqueue( - $pullRequestId: ID! - $expectedHeadOid: GitObjectID! - ) { - enqueuePullRequest(input: { - pullRequestId: $pullRequestId - expectedHeadOid: $expectedHeadOid - jump: false - }) { clientMutationId } - }`, - { - pullRequestId: pull.node_id, - expectedHeadOid: pull.head.sha - } - ) - summary(`Entered the native merge queue for ${pull.head.sha.slice(0, 12)}.`) - return - } - if (state.autoMergeRequest) { - summary(`Auto-merge already armed for ${pull.head.sha.slice(0, 12)}.`) - return - } - await github.graphql( - `mutation WebsiteFastLaneEnableAutoMerge( - $pullRequestId: ID! - $expectedHeadOid: GitObjectID! - ) { - enablePullRequestAutoMerge(input: { - pullRequestId: $pullRequestId - expectedHeadOid: $expectedHeadOid - mergeMethod: SQUASH - }) { clientMutationId } - }`, - { - pullRequestId: pull.node_id, - expectedHeadOid: pull.head.sha - } - ) - summary(`Armed native auto-merge for ${pull.head.sha.slice(0, 12)}.`) -} - -async function stopWithSummary({ github, config, pull, reviews, message }) { - const approval = approvalForHead( - reviews, - config.expectedApprover, - pull?.head?.sha - ) - if (approval) { - await dismissApproval( - github, - config.prNumber, - approval, - `Website fast-lane approval withdrawn: ${message}` - ) - } - await stopMergeAutomation( - github, - config, - pull, - latestPolicyReview(reviews, config.expectedApprover) - ) - summary(message) -} - -async function validateWebsitePaths(github, config, pull, reviews) { - const files = await github.paginate(`/pulls/${config.prNumber}/files`) - if (!hasCompleteChangedFileList(files, pull.changed_files)) { - await stopWithSummary({ - github, - config, - pull, - reviews, - message: 'Skipped: could not enumerate every changed file.' - }) - return false - } - const paths = changedPaths(files) - if (paths === null || !isWebsiteOnly(paths)) { - await stopWithSummary({ - github, - config, - pull, - reviews, - message: 'Skipped: at least one changed file is outside apps/website/**.' - }) - return false - } - return true -} - -async function revalidatePull(github, config) { - const recheckedPull = await github.request(`/pulls/${config.prNumber}`) - const recheckedReviews = await github.paginate( - `/pulls/${config.prNumber}/reviews` - ) - const recheckedEvents = await github.paginate( - `/issues/${config.prNumber}/timeline` - ) - const recheckedFailure = eligibilityFailure({ - pull: recheckedPull, - config, - events: recheckedEvents - }) - if (recheckedFailure) { - await stopWithSummary({ - github, - config, - pull: recheckedPull, - reviews: recheckedReviews, - message: recheckedFailure - }) - return - } - if (hasActiveChangeRequest(recheckedReviews)) { - await stopWithSummary({ - github, - config, - pull: recheckedPull, - reviews: recheckedReviews, - message: 'Skipped: an active reviewer change request is present.' - }) - return - } - return recheckedReviews -} - -export async function approveCurrentHead(github, config, liveHeadSha, reviews) { - if ( - alreadyApprovedCurrentHead(reviews, config.expectedApprover, liveHeadSha) - ) { - summary( - `Already approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` - ) - return true - } - - const createdReview = await github.request( - `/pulls/${config.prNumber}/reviews`, - { - method: 'POST', - headers: { 'content-type': 'application/json' }, - body: JSON.stringify({ - event: 'APPROVE', - commit_id: liveHeadSha, - body: `${POLICY_REVIEW_PREFIX} No diff review was performed; eligibility was bound to a trusted author or authorized approval-label event, the exact head commit, and the \`apps/website/**\` path boundary.` - }) - } - ) - - let verifiedPull - let verifiedReviews - let verifiedEvents - try { - verifiedPull = await github.request(`/pulls/${config.prNumber}`) - verifiedReviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) - verifiedEvents = await github.paginate( - `/issues/${config.prNumber}/timeline` - ) - } catch (error) { - await dismissApproval( - github, - config.prNumber, - createdReview, - 'Website fast-lane approval withdrawn: post-approval verification failed.' - ) - throw error - } - const verificationFailure = eligibilityFailure({ - pull: verifiedPull, - config, - events: verifiedEvents - }) - if (verificationFailure || hasActiveChangeRequest(verifiedReviews)) { - const reason = - verificationFailure ?? - 'Skipped: an active reviewer change request appeared during approval.' - await dismissApproval( - github, - config.prNumber, - createdReview, - `Website fast-lane approval withdrawn: ${reason}` - ) - summary(`Approval withdrawn: ${reason}`) - return false - } - summary( - `Approved ${liveHeadSha.slice(0, 12)} as @${config.expectedApprover}.` - ) - return true -} - -async function main() { - const config = configuration() - const github = githubClient(config.token, config.repository) - await assertApproverIdentity(github, config.expectedApprover) - if (!(await resolvePullNumber(github, config))) return - - const pull = await github.request(`/pulls/${config.prNumber}`) - const reviews = await github.paginate(`/pulls/${config.prNumber}/reviews`) - const events = await github.paginate(`/issues/${config.prNumber}/timeline`) - const failure = eligibilityFailure({ pull, config, events }) - if (failure) { - await stopWithSummary({ - github, - config, - pull, - reviews, - message: failure - }) - return - } - assertNotSelfApproval(pull, config.expectedApprover) - - const liveHeadSha = pull.head.sha - if (!(await validateWebsitePaths(github, config, pull, reviews))) return - - const recheckedReviews = await revalidatePull(github, config) - if (!recheckedReviews) return - - const approved = await approveCurrentHead( - github, - config, - liveHeadSha, - recheckedReviews - ) - if (!approved) return - - const queuePull = await github.request(`/pulls/${config.prNumber}`) - await armMergeAutomation(github, queuePull) - - // Recheck once more after arming. A concurrent hold, new commit, or human - // change request must withdraw both the policy approval and merge intent. - await revalidatePull(github, config) -} - -if ( - process.argv[1] && - fileURLToPath(import.meta.url) === path.resolve(process.argv[1]) -) { - main().catch((error) => { - process.stderr.write(`${error.stack ?? error.message}\n`) - process.exitCode = 1 - }) -} diff --git a/.github/scripts/website-auto-approve.test.mjs b/.github/scripts/website-auto-approve.test.mjs deleted file mode 100644 index 533ff061515..00000000000 --- a/.github/scripts/website-auto-approve.test.mjs +++ /dev/null @@ -1,442 +0,0 @@ -import assert from 'node:assert/strict' -import test from 'node:test' - -import { - armMergeAutomation, - approveCurrentHead, - alreadyApprovedCurrentHead, - changedPaths, - hasActiveChangeRequest, - hasAuthorizedApprovalLabel, - hasCompleteChangedFileList, - hasHoldLabel, - isSameRepository, - isWebsiteOnly, - parseApprovedAuthors, - stopMergeAutomation, - targetsDefaultBranch -} from './website-auto-approve.mjs' - -void test('a failed post-approval verification withdraws the new approval', async () => { - const calls = [] - const verificationError = new Error('verification unavailable') - const github = { - async request(requestPath, options = {}) { - calls.push({ requestPath, method: options.method ?? 'GET' }) - if (options.method === 'POST') return { id: 123 } - if (options.method === 'PUT') return null - throw verificationError - }, - async paginate() { - throw new Error('review verification should not run after pull failure') - } - } - - await assert.rejects( - approveCurrentHead( - github, - { prNumber: 42, expectedApprover: 'christian-byrne' }, - '0123456789abcdef0123456789abcdef01234567', - [] - ), - verificationError - ) - assert.deepEqual(calls, [ - { requestPath: '/pulls/42/reviews', method: 'POST' }, - { requestPath: '/pulls/42', method: 'GET' }, - { requestPath: '/pulls/42/reviews/123/dismissals', method: 'PUT' } - ]) -}) - -void test('requires complete changed-file enumeration', () => { - const files = [{ filename: 'apps/website/a.astro' }] - assert.equal(hasCompleteChangedFileList(files, 1), true) - assert.equal(hasCompleteChangedFileList(files, 2), false) - assert.equal(hasCompleteChangedFileList(files, undefined), false) -}) - -void test('parses and normalizes the explicit author allowlist', () => { - assert.deepEqual( - parseApprovedAuthors('["bertfy", "BERTFY", ""]'), - new Set(['bertfy']) - ) - assert.throws(() => parseApprovedAuthors('bertfy'), /must be JSON/) - assert.throws( - () => parseApprovedAuthors('{"bertfy":true}'), - /must be a JSON array/ - ) -}) - -void test('requires a non-empty website-only path set', () => { - assert.equal(isWebsiteOnly(['apps/website/src/pages/index.astro']), true) - assert.equal( - isWebsiteOnly([ - 'apps/website/src/pages/index.astro', - 'apps/website/public/hero.webp' - ]), - true - ) - assert.equal(isWebsiteOnly([]), false) - assert.equal( - isWebsiteOnly(['apps/website/src/pages/index.astro', 'pnpm-lock.yaml']), - false - ) - assert.equal(isWebsiteOnly(['apps/website-evil/file.ts']), false) -}) - -void test('a rename must stay inside the website on both sides', () => { - assert.deepEqual( - changedPaths([ - { - status: 'renamed', - previous_filename: 'apps/website/old.astro', - filename: 'apps/website/new.astro' - } - ]), - ['apps/website/new.astro', 'apps/website/old.astro'] - ) - const crossBoundaryRename = changedPaths([ - { - status: 'renamed', - previous_filename: 'src/sensitive.ts', - filename: 'apps/website/sensitive.ts' - } - ]) - assert.equal(isWebsiteOnly(crossBoundaryRename), false) - assert.equal( - changedPaths([{ status: 'renamed', filename: 'apps/website/new.astro' }]), - null - ) -}) - -void test('a copied file retains both paths for boundary evaluation', () => { - assert.deepEqual( - changedPaths([ - { - status: 'copied', - previous_filename: 'src/sensitive.ts', - filename: 'apps/website/sensitive.ts' - } - ]), - ['apps/website/sensitive.ts', 'src/sensitive.ts'] - ) -}) - -void test('the explicit hold label stops fast-lane approval', () => { - assert.equal(hasHoldLabel({ labels: [] }), false) - assert.equal( - hasHoldLabel({ labels: [{ name: 'website-fast-lane:hold' }] }), - true - ) - assert.equal( - hasHoldLabel({ labels: [{ name: 'WEBSITE-FAST-LANE:HOLD' }] }), - true - ) -}) - -void test('approval label requires provenance from an authorized operator', () => { - const pull = { labels: [{ name: 'website-fast-lane:approve' }] } - const authorized = new Set(['drjkl']) - assert.equal( - hasAuthorizedApprovalLabel( - pull, - [ - { event: 'committed' }, - { - event: 'labeled', - label: { name: 'website-fast-lane:approve' }, - actor: { login: 'DrJKL' } - } - ], - authorized - ), - true - ) - assert.equal( - hasAuthorizedApprovalLabel( - pull, - [ - { event: 'committed' }, - { - event: 'labeled', - label: { name: 'website-fast-lane:approve' }, - actor: { login: 'not-authorized' } - } - ], - authorized - ), - false - ) - assert.equal( - hasAuthorizedApprovalLabel( - { labels: [] }, - [ - { event: 'committed' }, - { - event: 'labeled', - label: { name: 'website-fast-lane:approve' }, - actor: { login: 'DrJKL' } - } - ], - authorized - ), - false - ) - assert.equal( - hasAuthorizedApprovalLabel( - pull, - [ - { - event: 'labeled', - label: { name: 'website-fast-lane:approve' }, - actor: { login: 'DrJKL' } - }, - { event: 'committed' } - ], - authorized - ), - false - ) -}) - -void test('only each non-app reviewer latest state can actively block', () => { - assert.equal( - hasActiveChangeRequest([ - { - state: 'CHANGES_REQUESTED', - user: { login: 'coderabbitai[bot]', type: 'Bot' } - }, - { - state: 'CHANGES_REQUESTED', - user: { login: 'DrJKL', type: 'User' } - }, - { state: 'APPROVED', user: { login: 'DrJKL', type: 'User' } } - ]), - false - ) - assert.equal( - hasActiveChangeRequest([ - { - state: 'CHANGES_REQUESTED', - user: { login: 'human-reviewer', type: 'User' } - } - ]), - true - ) - assert.equal( - hasActiveChangeRequest([ - { - state: 'CHANGES_REQUESTED', - user: { login: 'DrJKL', type: 'User' } - }, - { state: 'COMMENTED', user: { login: 'DrJKL', type: 'User' } } - ]), - true - ) -}) - -void test('fork pull requests are not eligible', () => { - assert.equal( - isSameRepository( - { head: { repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } } }, - 'comfy-org/comfyui_frontend' - ), - true - ) - assert.equal( - isSameRepository( - { head: { repo: { full_name: 'bertfy/ComfyUI_frontend' } } }, - 'Comfy-Org/ComfyUI_frontend' - ), - false - ) - assert.equal( - isSameRepository({ head: { repo: null } }, 'Comfy-Org/ComfyUI_frontend'), - false - ) -}) - -void test('only pull requests targeting the default branch are eligible', () => { - assert.equal( - targetsDefaultBranch( - { - base: { - ref: 'main', - repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } - } - }, - 'comfy-org/comfyui_frontend', - 'main' - ), - true - ) - assert.equal( - targetsDefaultBranch( - { - base: { - ref: 'release', - repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } - } - }, - 'Comfy-Org/ComfyUI_frontend', - 'main' - ), - false - ) -}) - -void test('idempotency is scoped to Christian and the exact head commit', () => { - const reviews = [ - { state: 'APPROVED', commit_id: 'old', user: { login: 'christian-byrne' } }, - { state: 'APPROVED', commit_id: 'head', user: { login: 'someone-else' } }, - { - state: 'CHANGES_REQUESTED', - commit_id: 'head', - user: { login: 'christian-byrne' } - } - ] - assert.equal( - alreadyApprovedCurrentHead(reviews, 'christian-byrne', 'head'), - false - ) - reviews.push({ - state: 'APPROVED', - commit_id: 'head', - user: { login: 'Christian-Byrne' } - }) - assert.equal( - alreadyApprovedCurrentHead(reviews, 'christian-byrne', 'head'), - true - ) -}) - -void test('arms native auto-merge for the exact head with squash', async () => { - const calls = [] - const github = { - async graphql(query, variables) { - calls.push({ query, variables }) - if (calls.length === 1) { - return { - node: { - id: 'PR_1', - headRefOid: 'head-sha', - mergeStateStatus: 'BLOCKED', - autoMergeRequest: null, - mergeQueueEntry: null - } - } - } - return { enablePullRequestAutoMerge: { clientMutationId: null } } - } - } - await armMergeAutomation(github, { - node_id: 'PR_1', - head: { sha: 'head-sha' } - }) - assert.equal(calls.length, 2) - assert.match(calls[1].query, /enablePullRequestAutoMerge/) - assert.match(calls[1].query, /mergeMethod: SQUASH/) - assert.deepEqual(calls[1].variables, { - pullRequestId: 'PR_1', - expectedHeadOid: 'head-sha' - }) -}) - -void test('explicitly enqueues a clean exact head without jumping the queue', async () => { - const calls = [] - const github = { - async graphql(query, variables) { - calls.push({ query, variables }) - if (calls.length === 1) { - return { - node: { - id: 'PR_1', - headRefOid: 'head-sha', - mergeStateStatus: 'CLEAN', - autoMergeRequest: { - enabledAt: '2026-10-06T10:01:00Z', - enabledBy: { login: 'christian-byrne' } - }, - mergeQueueEntry: null - } - } - } - return { enqueuePullRequest: { clientMutationId: null } } - } - } - await armMergeAutomation(github, { - node_id: 'PR_1', - head: { sha: 'head-sha' } - }) - assert.equal(calls.length, 2) - assert.match(calls[1].query, /enqueuePullRequest/) - assert.match(calls[1].query, /jump: false/) - assert.deepEqual(calls[1].variables, { - pullRequestId: 'PR_1', - expectedHeadOid: 'head-sha' - }) -}) - -void test('stops only merge state created after the policy review', async () => { - const calls = [] - const github = { - async graphql(query, variables) { - calls.push({ query, variables }) - if (calls.length === 1) { - return { - node: { - id: 'PR_1', - headRefOid: 'head-sha', - autoMergeRequest: { - enabledAt: '2026-10-06T10:01:00Z', - enabledBy: { login: 'christian-byrne' } - }, - mergeQueueEntry: { - id: 'MQE_1', - enqueuedAt: '2026-10-06T10:02:00Z', - enqueuer: { login: 'christian-byrne' }, - headCommit: { oid: 'head-sha' } - } - } - } - } - return {} - } - } - await stopMergeAutomation( - github, - { expectedApprover: 'christian-byrne' }, - { node_id: 'PR_1', head: { sha: 'head-sha' } }, - { submitted_at: '2026-10-06T10:00:00Z' } - ) - assert.equal(calls.length, 3) - assert.match(calls[1].query, /dequeuePullRequest/) - assert.match(calls[2].query, /disablePullRequestAutoMerge/) -}) - -void test('leaves Christian merge state that predates the workflow review alone', async () => { - const calls = [] - const github = { - async graphql(query, variables) { - calls.push({ query, variables }) - return { - node: { - id: 'PR_1', - headRefOid: 'head-sha', - autoMergeRequest: { - enabledAt: '2026-10-06T09:59:00Z', - enabledBy: { login: 'christian-byrne' } - }, - mergeQueueEntry: null - } - } - } - } - await stopMergeAutomation( - github, - { expectedApprover: 'christian-byrne' }, - { node_id: 'PR_1', head: { sha: 'head-sha' } }, - { submitted_at: '2026-10-06T10:00:00Z' } - ) - assert.equal(calls.length, 1) -}) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 96983ff4d7c..09d2bb52667 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -23,73 +23,8 @@ The candidate dependency prototype lives in `ci-tests-e2e.yaml`. See for measured runtimes, required-check compatibility, and rollout limits. The required `lint-and-format` context keeps one stable name across pull requests and merge-queue -candidates. Changes confined to `apps/website/**` run website-scoped lint, format, typecheck, and -Knip jobs. Any file outside that directory selects the full repository jobs; pushes to protected -branches always run the full jobs. +candidates. See [Package delivery lanes](../../docs/architecture/package-delivery-lanes.md) for the +path-scoped quality and approval model, and [Website delivery validation](../../docs/architecture/website-delivery-validation.md) +for the current trial and rollback procedure. For GitHub Actions documentation, see [Events that trigger workflows](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows). - -## Website auto-approval - -`pr-website-auto-approve.yaml` removes the human approval wait for explicitly -allowlisted authors, or after an allowlisted operator applies -`website-fast-lane:approve`, when every changed file is under -`apps/website/**`. It runs -from the protected default branch on `pull_request_target`, never executes PR code, -rejects other base branches and fork pull requests, rechecks the live head, and verifies that -`WEBSITE_APPROVAL_TOKEN` belongs to `christian-byrne` before approving. Christian is a member of -`comfy_website_devs`, so the review satisfies the website path reviewer rule. The workflow cannot -approve Christian's own pull requests; use another allowlisted author or the fresh-label route on -a pull request from a different author. - -After exact-head approval, the same Christian credential arms GitHub's native auto-merge with the -repository's only allowed merge method, squash. GitHub moves the pull request into the protected -branch's native merge queue as soon as its remaining requirements pass; no manual merge click or -queue jump is used. Because native auto-merge has not always handed ruleset-protected pull requests -to the queue reliably, the workflow also reconciles after each required Actions workflow and commit -status completes. When GitHub reports the exact head as clean, it explicitly enters that head in the -native queue with `jump: false`; otherwise it leaves native auto-merge armed. The workflow also -listens for human review changes. If a draft, hold, stale -head, mixed path, or active human change request makes the pull request ineligible, it withdraws -Christian's policy approval and disables or dequeues merge state created by Christian's workflow. -Merge state created by another person is left alone. - -Approval-label eligibility is provenance-checked against the issue event -timeline; the latest matching label event must be from an allowlisted operator -and later than the latest commit or force-push event. Every new head therefore -requires a fresh authorized label. Label presence by itself is not authorization. The -`website-fast-lane:hold` label, draft state, an active non-app reviewer change request, a base -or head change, or a path outside `apps/website/**` stops approval and withdraws an existing -current-head policy approval when the trusted workflow evaluates the PR. A human change request -submitted after policy approval blocks merge immediately through GitHub's review rules; the next -trusted PR event reevaluates and withdraws the policy approval. The review body identifies the -verdict as policy-only; it must not be interpreted as a diff review. - -The Stage 1 author allowlist contains `bertfy`. Expand or retain either allowlist only by reviewing -a change to `WEBSITE_AUTO_APPROVE_AUTHORS` or -`WEBSITE_AUTO_APPROVE_LABELERS` in the workflow. A repository administrator -must configure a `website-approval` environment whose deployment branch restriction allows only the -protected default branch, then provide Christian's token as that environment's -`WEBSITE_APPROVAL_TOKEN` secret. Missing or mismatched credentials fail closed. - -## Website production identity and validation rollback - -Every website preview and production build writes a cache-disabled `/__build.json` containing the -repository, exact source SHA, workflow run, attempt, and build time. The deploy workflow verifies -the immutable Vercel URL before it accepts canonical `comfy.org` promotion and retains the prior -and newly deployed IDs/SHA values as a short-lived artifact. - -`validation-website-rollback.yaml` is a manually dispatched validation-only workflow. It accepts -that captured immutable deployment ID and expected SHA. Its safe default validates that the target -belongs to the website project and serves the expected marker without changing production. Setting -`perform_rollback` to true uses Vercel's instant rollback, verifies the canonical marker and public -homepage, then promotes the same known-good deployment to preserve it while resuming normal -automatic production-domain assignment. - -The first production deploy containing `/__build.json` is the rollback bootstrap, not the positive -canary. Before any disposable canary PR is opened or queued, download that deploy's transition -artifact and run `Validation: Website Production Rollback` with its `deployedDeploymentId` and -`deployedSha`, leaving `perform_rollback` false. The positive canary may start only after this -no-mutation preflight is green. This ensures its captured previous deployment is a known-good, -marker-bearing rollback target; an older legacy deployment with an unavailable marker is never -silently accepted as the canary rollback proof. diff --git a/.github/workflows/ci-lint-format-queue.yaml b/.github/workflows/ci-lint-format-queue.yaml index 6265ccbf3ac..139bfd403a0 100644 --- a/.github/workflows/ci-lint-format-queue.yaml +++ b/.github/workflows/ci-lint-format-queue.yaml @@ -32,22 +32,7 @@ env: packages/*/node_modules/.cache/tsbuildinfo jobs: - changes: - runs-on: ubuntu-latest - permissions: - contents: read - outputs: - website-only: ${{ steps.changes.outputs.website-only-changes }} - steps: - - uses: actions/checkout@v7 - - id: changes - uses: ./.github/actions/changes-filter - with: - evaluate-candidate: 'true' - lint: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout ref @@ -77,8 +62,6 @@ jobs: path: ${{ env.LINT_CACHE_PATHS }} typecheck: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout ref @@ -105,8 +88,6 @@ jobs: path: ${{ env.TYPECHECK_CACHE_PATHS }} typecheck-aux: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout ref @@ -133,8 +114,6 @@ jobs: path: ${{ env.TYPECHECK_CACHE_PATHS }} repo-checks: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout ref @@ -151,55 +130,6 @@ jobs: - name: Verify knip, locale integrity and ADR index uses: ./.github/actions/repo-checks - website-lint: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - uses: ./.github/actions/setup-frontend - - - name: Restore lint caches - id: lint-cache - uses: ./.github/actions/tool-cache-restore - with: - scope: website-lint - path: ${{ env.LINT_CACHE_PATHS }} - - - name: Verify website lint and format - run: | - pnpm exec stylelint --cache --cache-strategy content 'apps/website/**/*.{css,vue}' - pnpm exec oxlint apps/website --type-aware - pnpm exec eslint apps/website --cache --cache-strategy content --concurrency auto - pnpm --filter @comfyorg/website format:check - - - name: Save lint caches - if: always() - uses: ./.github/actions/tool-cache-save - with: - cache-key: ${{ steps.lint-cache.outputs.cache-key }} - path: ${{ env.LINT_CACHE_PATHS }} - - website-typecheck: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - uses: ./.github/actions/setup-frontend - - name: Typecheck website - run: pnpm typecheck:website - - website-repo-checks: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - uses: ./.github/actions/setup-frontend - - name: Find unused website files, exports and dependencies - run: pnpm knip --workspace apps/website - # Single stable branch-protection context over the parallel jobs above. lint-and-format: needs: [lint, typecheck, typecheck-aux, repo-checks] diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index bbcc9dd2775..417a94bfca5 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -1,5 +1,4 @@ -# Auto-approve website-only pull requests from explicitly trusted authors or -# after an explicitly trusted operator applies the approval label. +# Run the website package's configured delivery lane. # # Security boundary: # - pull_request_target loads this workflow from the trusted default branch. @@ -8,7 +7,7 @@ # - the script rejects other base branches and forks, re-fetches the live PR, # verifies the exact head SHA, requires every changed path to be under # apps/website/**, and verifies the PAT owner. -name: 'PR: Website Auto-Approve' +name: 'PR: Website Fast Lane' on: pull_request_target: @@ -38,7 +37,7 @@ permissions: pull-requests: read concurrency: - group: website-auto-approve-${{ github.event.pull_request.number || github.event.workflow_run.head_sha || github.event.sha || github.run_id }} + group: website-fast-lane-${{ github.event.pull_request.number || github.event.workflow_run.head_sha || github.event.sha || github.run_id }} cancel-in-progress: true jobs: @@ -49,27 +48,28 @@ jobs: timeout-minutes: 5 steps: - name: Checkout trusted base automation - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + uses: actions/checkout@v7 with: ref: refs/heads/${{ github.event.repository.default_branch }} persist-credentials: false - sparse-checkout: .github/scripts + sparse-checkout: | + .nvmrc + .github/fast-lanes/website.json + scripts/cicd/fast-lane + + - uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc - name: Approve and queue eligible website pull request env: + FAST_LANE_CONFIG: .github/fast-lanes/website.json + FAST_LANE_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} + FAST_LANE_BASE_REF: ${{ github.event.repository.default_branch }} GITHUB_REPOSITORY: ${{ github.repository }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_NUMBER: ${{ github.event.pull_request.number }} - WEBSITE_APPROVAL_BASE_REF: ${{ github.event.repository.default_branch }} - WEBSITE_APPROVAL_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} - WEBSITE_APPROVER_LOGIN: christian-byrne - # This is intentionally checked in: changing who can receive an - # automatic approval must itself pass normal repository review. - WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy"]' - # The label is a second route for a non-allowlisted author. The script - # verifies its latest event came from one of these operators. - WEBSITE_AUTO_APPROVE_LABELERS: '["christian-byrne", "DrJKL", "benjcooley"]' - run: node .github/scripts/website-auto-approve.mjs + run: node --experimental-strip-types scripts/cicd/fast-lane/run.ts reconcile-after-check: if: github.event_name == 'status' || (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request') @@ -78,19 +78,24 @@ jobs: timeout-minutes: 5 steps: - name: Checkout trusted base automation - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + uses: actions/checkout@v7 with: ref: refs/heads/${{ github.event.repository.default_branch }} persist-credentials: false - sparse-checkout: .github/scripts + sparse-checkout: | + .nvmrc + .github/fast-lanes/website.json + scripts/cicd/fast-lane + + - uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc - name: Reconcile approval and native queue state env: + FAST_LANE_CONFIG: .github/fast-lanes/website.json + FAST_LANE_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} + FAST_LANE_BASE_REF: ${{ github.event.repository.default_branch }} GITHUB_REPOSITORY: ${{ github.repository }} PR_HEAD_SHA: ${{ github.event.sha || github.event.workflow_run.head_sha }} - WEBSITE_APPROVAL_BASE_REF: ${{ github.event.repository.default_branch }} - WEBSITE_APPROVAL_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} - WEBSITE_APPROVER_LOGIN: christian-byrne - WEBSITE_AUTO_APPROVE_AUTHORS: '["bertfy"]' - WEBSITE_AUTO_APPROVE_LABELERS: '["christian-byrne", "DrJKL", "benjcooley"]' - run: node .github/scripts/website-auto-approve.mjs + run: node --experimental-strip-types scripts/cicd/fast-lane/run.ts diff --git a/docs/architecture/package-delivery-lanes.md b/docs/architecture/package-delivery-lanes.md new file mode 100644 index 00000000000..149cfa862bf --- /dev/null +++ b/docs/architecture/package-delivery-lanes.md @@ -0,0 +1,75 @@ +# Package delivery lanes + +A package delivery lane lets one part of the monorepo choose its own balance of speed and rigor +without weakening the rest of the repository. A lane has four independent stages: + +1. **Scope:** decide whether every changed path belongs to the package. +2. **Quality:** run the package's checks instead of unrelated repository checks. +3. **Approval:** apply the package's reviewed approval policy to the exact commit. +4. **Delivery:** use the repository's normal merge, deployment, and rollback systems. + +The website is the first lane. The implementation is deliberately package-neutral so another +package can use the same engine with a different checked-in policy. + +## The dials a package owns + +Each lane has a JSON policy in `.github/fast-lanes/`. A policy change receives normal repository +review, so changing a dial is visible in history. + +| Dial | Meaning | +| ----------------- | ------------------------------------------------------------------------------- | +| `pathPrefixes` | The complete set of paths the lane is allowed to change. | +| `trustedAuthors` | Authors who may receive a policy approval without an operator label. | +| `approvalLabel` | An explicit opt-in route for other authors. | +| `trustedLabelers` | Operators allowed to apply that label. | +| `holdLabel` | An immediate stop for the lane. | +| `merge.mode` | `automatic` arms native auto-merge or the queue; `manual` stops after approval. | +| `merge.method` | The repository-supported merge method used by automatic mode. | + +Package-specific quality commands remain in the package's CI jobs. The first routing rule is +simple: a package-only pull request runs that package's checks; a mixed or root-level pull request +runs the full repository checks. Merge-group and protected-branch runs remain full-repository checks +unless a later change proves that a narrower candidate calculation is safe. + +## Fixed safety rules + +These are implementation invariants, not package dials: + +- The workflow and policy are checked out from the protected default branch. Pull request code is + never executed by the approval workflow. +- Forks, drafts, non-default base branches, stale event heads, incomplete file lists, and paths + outside the lane fail closed. +- Every approval is tied to the exact head SHA. A new commit needs a new policy decision. +- Approval-label provenance is verified. The latest matching label event must come from a trusted + operator after the latest commit or force-push event. +- An active human change request blocks the lane. Comments and pending reviews do not count as + change requests. +- The credential's GitHub identity must match the identity declared in the policy, and it cannot + approve its own pull request. +- If post-approval verification fails, the newly created approval is dismissed. +- The lane only disables auto-merge or queue state that its own identity created after its policy + approval. It does not undo another person's merge decision. + +The reusable TypeScript engine lives in `scripts/cicd/fast-lane/`. `policy.ts` contains pure policy +decisions, `github.ts` contains GitHub transport, and `automation.ts` owns the approval and merge +lifecycle. Behavioral tests cover the fixed rules independently of a live repository. + +## Adding a lane + +1. Add a reviewed policy file under `.github/fast-lanes/`. +2. Teach the change classifier to recognize the package-only path set. +3. Add package-scoped lint, format, typecheck, test, and repository checks behind that result. Keep + the full checks as the fallback for mixed changes. +4. Add a thin `pull_request_target` workflow that checks out only `.nvmrc`, the selected policy, + and `scripts/cicd/fast-lane/` from the default branch. Run `run.ts` with Node's TypeScript + stripping; do not install pull request dependencies. +5. Put the approval credential in a package-specific protected environment and restrict that + environment to the protected default branch. +6. Add negative tests for forks, mixed paths, stale heads, self-approval, unauthorized labels, + active change requests, and post-approval failure. +7. Trial the lane with a disposable pull request. Record time from update to checks, approval, + queue entry, production identity, and rollback readiness before expanding its allowlist. + +This process changes package policy, not the repository's underlying protection model. A package +can start with fast feedback and a narrow allowlist, then tighten or relax individual dials using +evidence from its own delivery times and failures. diff --git a/docs/architecture/website-delivery-validation.md b/docs/architecture/website-delivery-validation.md new file mode 100644 index 00000000000..bcfcb88cb3c --- /dev/null +++ b/docs/architecture/website-delivery-validation.md @@ -0,0 +1,51 @@ +# Website delivery validation + +The website trial answers one practical question: can a non-technical owner ship a website-only +change on their timeline while the rest of the monorepo keeps its current safeguards? + +## Current lane + +The checked-in policy is `.github/fast-lanes/website.json`. It allows changes only under +`apps/website/`. Stage 1 includes `bertfy` as a trusted author and also accepts a fresh +`website-fast-lane:approve` label from one of the listed operators. `website-fast-lane:hold`, a +draft, a human change request, a fork, a mixed-path change, or a stale head stops the lane. + +The `website-approval` environment supplies `WEBSITE_APPROVAL_TOKEN`. The credential currently +belongs to `christian-byrne`, whose team membership satisfies the website path review rule. The +workflow verifies that identity before it acts and cannot approve Christian's own pull requests. +After approval it uses squash auto-merge or enters an already-clean exact head in GitHub's native +queue without queue jumping. Later check and review events reconcile the decision. + +For a website-only pull request, the required lint context runs website-scoped lint, format, +typecheck, and unused-code checks. A change outside `apps/website/` falls back to the full repository +jobs. CodeRabbit is excluded from `apps/website/**` for this trial; human change requests still +block the lane. + +## Production identity and rollback + +Each website preview and production build writes a cache-disabled `/__build.json` with the +repository, exact source SHA, workflow run, attempt, and build time. Deployment verifies the +immutable Vercel URL before accepting canonical `comfy.org` promotion and saves the previous and +new deployment IDs and SHAs as a short-lived transition artifact. + +`validation-website-rollback.yaml` accepts an immutable deployment ID and expected SHA. Its default +mode validates the target and marker without changing production. With `perform_rollback` enabled, +it performs an instant rollback, verifies the canonical marker and public homepage, then promotes +the same known-good deployment so normal production assignment can resume. + +The first production deployment containing `/__build.json` is bootstrap evidence, not the positive +canary. Before opening the disposable canary: + +1. Download that deployment's transition artifact. +2. Run `Validation: Website Production Rollback` with its `deployedDeploymentId` and `deployedSha`. +3. Leave `perform_rollback` disabled and require the no-mutation preflight to pass. +4. Run the canary from update through production, then exercise rollback only under the agreed + trial procedure. + +## Evidence to record + +Record timestamps for the contributor update, required checks, policy approval, queue entry, merge, +and verified production SHA. Also record any manual intervention, confusing UI, false-positive +check, or rollback problem. The trial succeeds only if the contributor can follow the path without +developer rescue and production can be tied to the expected commit. The allowlist should not expand +until the canary and rollback evidence are complete. diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts new file mode 100644 index 00000000000..1962afbbdc9 --- /dev/null +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -0,0 +1,241 @@ +import { describe, expect, it, vi } from 'vitest' + +import { + approveCurrentHead, + armMergeAutomation, + stopMergeAutomation +} from './automation.ts' +import type { + GitHubClient, + PullRequest, + ResolvedRuntimeConfig +} from './types.ts' + +const headSha = '0123456789abcdef0123456789abcdef01234567' + +function runtimeConfig(): ResolvedRuntimeConfig { + return { + token: 'not-used-by-tests', + repository: 'Comfy-Org/ComfyUI_frontend', + pullRequestNumber: 42, + eventHeadSha: headSha, + defaultBranch: 'main', + lane: { + schemaVersion: 1, + id: 'website', + pathPrefixes: ['apps/website/'], + approval: { + identity: 'christian-byrne', + trustedAuthors: ['bertfy'], + approvalLabel: 'website-fast-lane:approve', + trustedLabelers: ['drjkl'], + holdLabel: 'website-fast-lane:hold' + }, + merge: { mode: 'automatic', method: 'SQUASH' } + } + } +} + +function pull(): PullRequest { + return { node_id: 'PR_1', head: { sha: headSha } } +} + +function unusedRequest(): Promise { + return Promise.reject(new Error('request was not expected')) +} + +function unusedPaginate(): Promise { + return Promise.reject(new Error('pagination was not expected')) +} + +describe('approval lifecycle', () => { + it('withdraws a new approval when post-approval verification fails', async () => { + const verificationError = new Error('verification unavailable') + const calls: { path: string; method: string }[] = [] + const github: GitHubClient = { + async request(path, options = {}) { + calls.push({ path, method: options.method ?? 'GET' }) + if (options.method === 'POST') return { id: 123 } + if (options.method === 'PUT') return null + throw verificationError + }, + async paginate() { + throw new Error('pagination should not follow a failed pull request') + }, + graphql: unusedRequest + } + + await expect( + approveCurrentHead(github, runtimeConfig(), [], vi.fn()) + ).rejects.toBe(verificationError) + expect(calls).toEqual([ + { path: '/pulls/42/reviews', method: 'POST' }, + { path: '/pulls/42', method: 'GET' }, + { path: '/pulls/42/reviews/123/dismissals', method: 'PUT' } + ]) + }) + + it('does not create a second approval for the same identity and head', async () => { + const summary = vi.fn() + const github: GitHubClient = { + request: unusedRequest, + paginate: unusedPaginate, + graphql: unusedRequest + } + await expect( + approveCurrentHead( + github, + runtimeConfig(), + [ + { + state: 'APPROVED', + commit_id: headSha, + user: { login: 'christian-byrne' } + } + ], + summary + ) + ).resolves.toBe(true) + expect(summary).toHaveBeenCalledWith( + `Already approved ${headSha.slice(0, 12)} as @christian-byrne.` + ) + }) +}) + +describe('merge automation', () => { + it('arms native auto-merge for the exact head and configured method', async () => { + const graphql = vi + .fn() + .mockResolvedValueOnce({ + node: { + id: 'PR_1', + headRefOid: headSha, + mergeStateStatus: 'BLOCKED', + autoMergeRequest: null, + mergeQueueEntry: null + } + }) + .mockResolvedValueOnce({ + enablePullRequestAutoMerge: { clientMutationId: null } + }) + const github: GitHubClient = { + request: unusedRequest, + paginate: unusedPaginate, + graphql + } + + await armMergeAutomation(github, pull(), runtimeConfig(), vi.fn()) + + expect(graphql).toHaveBeenCalledTimes(2) + expect(graphql.mock.calls[1][0]).toContain('enablePullRequestAutoMerge') + expect(graphql.mock.calls[1][1]).toEqual({ + pullRequestId: 'PR_1', + expectedHeadOid: headSha, + mergeMethod: 'SQUASH' + }) + }) + + it('enqueues a clean exact head without queue jumping', async () => { + const graphql = vi + .fn() + .mockResolvedValueOnce({ + node: { + id: 'PR_1', + headRefOid: headSha, + mergeStateStatus: 'CLEAN', + autoMergeRequest: null, + mergeQueueEntry: null + } + }) + .mockResolvedValueOnce({ + enqueuePullRequest: { clientMutationId: null } + }) + const github: GitHubClient = { + request: unusedRequest, + paginate: unusedPaginate, + graphql + } + + await armMergeAutomation(github, pull(), runtimeConfig(), vi.fn()) + + expect(graphql.mock.calls[1][0]).toContain('jump: false') + expect(graphql.mock.calls[1][1]).toEqual({ + pullRequestId: 'PR_1', + expectedHeadOid: headSha + }) + }) + + it('does not mutate merge state in a manual lane', async () => { + const config = runtimeConfig() + config.lane.merge.mode = 'manual' + const graphql = vi.fn() + const github: GitHubClient = { + request: unusedRequest, + paginate: unusedPaginate, + graphql + } + + await armMergeAutomation(github, pull(), config, vi.fn()) + + expect(graphql).not.toHaveBeenCalled() + }) + + it('withdraws only merge state created by the policy identity after its review', async () => { + const graphql = vi + .fn() + .mockResolvedValueOnce({ + node: { + id: 'PR_1', + headRefOid: headSha, + autoMergeRequest: { + enabledAt: '2026-10-06T10:01:00Z', + enabledBy: { login: 'christian-byrne' } + }, + mergeQueueEntry: { + id: 'MQE_1', + enqueuedAt: '2026-10-06T10:02:00Z', + enqueuer: { login: 'christian-byrne' } + } + } + }) + .mockResolvedValue({}) + const github: GitHubClient = { + request: unusedRequest, + paginate: unusedPaginate, + graphql + } + + await stopMergeAutomation(github, pull(), 'christian-byrne', { + submitted_at: '2026-10-06T10:00:00Z' + }) + + expect(graphql).toHaveBeenCalledTimes(3) + expect(graphql.mock.calls[1][0]).toContain('dequeuePullRequest') + expect(graphql.mock.calls[2][0]).toContain('disablePullRequestAutoMerge') + }) + + it('leaves pre-existing merge state alone', async () => { + const graphql = vi.fn().mockResolvedValueOnce({ + node: { + id: 'PR_1', + headRefOid: headSha, + autoMergeRequest: { + enabledAt: '2026-10-06T09:59:00Z', + enabledBy: { login: 'christian-byrne' } + }, + mergeQueueEntry: null + } + }) + const github: GitHubClient = { + request: unusedRequest, + paginate: unusedPaginate, + graphql + } + + await stopMergeAutomation(github, pull(), 'christian-byrne', { + submitted_at: '2026-10-06T10:00:00Z' + }) + + expect(graphql).toHaveBeenCalledTimes(1) + }) +}) diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts new file mode 100644 index 00000000000..95f3a9c6d6e --- /dev/null +++ b/scripts/cicd/fast-lane/automation.ts @@ -0,0 +1,485 @@ +import { + approvalForHead, + changedPaths, + eligibilityFailure, + hasActiveHumanChangeRequest, + hasCompleteChangedFileList, + isApprovalForHead, + isInsideLane, + isSameRepository, + targetsDefaultBranch +} from './policy.ts' +import type { + GitHubClient, + MergeAutomationState, + PullRequest, + PullRequestFile, + PullRequestReview, + ResolvedRuntimeConfig, + RuntimeConfig, + Summary, + TimelineEvent +} from './types.ts' + +const POLICY_REVIEW_PREFIX = '[Package fast lane] Policy-only approval.' + +const MERGE_AUTOMATION_STATE = ` + query PackageFastLaneMergeState($pullRequestId: ID!) { + node(id: $pullRequestId) { + ... on PullRequest { + id + headRefOid + mergeStateStatus + autoMergeRequest { enabledAt enabledBy { login } } + mergeQueueEntry { + id + enqueuedAt + enqueuer { login } + headCommit { oid } + } + } + } + } +` + +function asPullRequest(value: unknown): PullRequest { + if (!value || typeof value !== 'object' || Array.isArray(value)) { + throw new Error('GitHub did not return a pull request') + } + return value +} + +function asReviews(value: unknown[]): PullRequestReview[] { + return value as PullRequestReview[] +} + +function asEvents(value: unknown[]): TimelineEvent[] { + return value as TimelineEvent[] +} + +function asFiles(value: unknown[]): PullRequestFile[] { + return value as PullRequestFile[] +} + +function mergeState(value: unknown): MergeAutomationState { + if (!value || typeof value !== 'object' || Array.isArray(value)) { + throw new Error('GitHub did not return the pull request merge state') + } + const data = value as { node?: MergeAutomationState } + if (!data.node?.id) { + throw new Error('GitHub did not return the pull request merge state') + } + return data.node +} + +function actorMatches( + actor: { login?: string } | undefined, + expectedLogin: string +): boolean { + return actor?.login?.toLowerCase() === expectedLogin.toLowerCase() +} + +function atOrAfter(value: string | undefined, floor: string): boolean { + if (!value) return false + return Date.parse(value) >= Date.parse(floor) +} + +async function readMergeState( + github: GitHubClient, + pullRequestId: string +): Promise { + return mergeState( + await github.graphql(MERGE_AUTOMATION_STATE, { pullRequestId }) + ) +} + +export async function stopMergeAutomation( + github: GitHubClient, + pull: PullRequest, + identity: string, + policyReview: PullRequestReview | undefined +): Promise { + if (!policyReview?.submitted_at) return + if (!pull.node_id) { + throw new Error('the pull request node id is required to stop automation') + } + + const state = await readMergeState(github, pull.node_id) + const entry = state.mergeQueueEntry + if ( + entry?.id && + actorMatches(entry.enqueuer, identity) && + atOrAfter(entry.enqueuedAt, policyReview.submitted_at) + ) { + await github.graphql( + `mutation PackageFastLaneDequeue($id: ID!) { + dequeuePullRequest(input: { id: $id }) { clientMutationId } + }`, + { id: entry.id } + ) + } + + const autoMerge = state.autoMergeRequest + if ( + autoMerge && + actorMatches(autoMerge.enabledBy, identity) && + atOrAfter(autoMerge.enabledAt, policyReview.submitted_at) + ) { + await github.graphql( + `mutation PackageFastLaneDisableAutoMerge($pullRequestId: ID!) { + disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) { + clientMutationId + } + }`, + { pullRequestId: pull.node_id } + ) + } +} + +export async function armMergeAutomation( + github: GitHubClient, + pull: PullRequest, + config: RuntimeConfig, + summary: Summary +): Promise { + if (config.lane.merge.mode === 'manual') return + if (!pull.node_id || !pull.head?.sha) { + throw new Error('the pull request node id and head are required to merge') + } + + const state = await readMergeState(github, pull.node_id) + if (state.headRefOid !== pull.head.sha) { + throw new Error('the pull request head advanced before merge automation') + } + if (state.mergeQueueEntry) { + summary(`Already queued ${pull.head.sha.slice(0, 12)}.`) + return + } + if (state.mergeStateStatus === 'CLEAN') { + await github.graphql( + `mutation PackageFastLaneEnqueue( + $pullRequestId: ID! + $expectedHeadOid: GitObjectID! + ) { + enqueuePullRequest(input: { + pullRequestId: $pullRequestId + expectedHeadOid: $expectedHeadOid + jump: false + }) { clientMutationId } + }`, + { pullRequestId: pull.node_id, expectedHeadOid: pull.head.sha } + ) + summary(`Entered the native merge queue for ${pull.head.sha.slice(0, 12)}.`) + return + } + if (state.autoMergeRequest) { + summary(`Auto-merge already armed for ${pull.head.sha.slice(0, 12)}.`) + return + } + + await github.graphql( + `mutation PackageFastLaneEnableAutoMerge( + $pullRequestId: ID! + $expectedHeadOid: GitObjectID! + $mergeMethod: PullRequestMergeMethod! + ) { + enablePullRequestAutoMerge(input: { + pullRequestId: $pullRequestId + expectedHeadOid: $expectedHeadOid + mergeMethod: $mergeMethod + }) { clientMutationId } + }`, + { + pullRequestId: pull.node_id, + expectedHeadOid: pull.head.sha, + mergeMethod: config.lane.merge.method + } + ) + summary(`Armed native auto-merge for ${pull.head.sha.slice(0, 12)}.`) +} + +function latestPolicyReview( + reviews: PullRequestReview[], + identity: string +): PullRequestReview | undefined { + return reviews.findLast( + (review) => + review.user?.login?.toLowerCase() === identity.toLowerCase() && + review.body?.startsWith(POLICY_REVIEW_PREFIX) && + review.submitted_at !== undefined && + !Number.isNaN(Date.parse(review.submitted_at)) + ) +} + +async function dismissApproval( + github: GitHubClient, + pullRequestNumber: number, + review: PullRequestReview | undefined, + reason: string +): Promise { + if (!review?.id) return + await github.request( + `/pulls/${pullRequestNumber}/reviews/${review.id}/dismissals`, + { + method: 'PUT', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ message: reason }) + } + ) +} + +async function stop( + github: GitHubClient, + config: ResolvedRuntimeConfig, + pull: PullRequest, + reviews: PullRequestReview[], + message: string, + summary: Summary +): Promise { + const identity = config.lane.approval.identity + const headSha = pull.head?.sha + const approval = headSha + ? approvalForHead(reviews, identity, headSha, POLICY_REVIEW_PREFIX) + : undefined + await dismissApproval( + github, + config.pullRequestNumber, + approval, + `Fast-lane approval withdrawn: ${message}` + ) + await stopMergeAutomation( + github, + pull, + identity, + latestPolicyReview(reviews, identity) + ) + summary(message) +} + +async function resolvePullRequestNumber( + github: GitHubClient, + config: RuntimeConfig, + summary: Summary +): Promise { + if (config.pullRequestNumber) return config.pullRequestNumber + const response = await github.request(`/commits/${config.eventHeadSha}/pulls`) + if (!Array.isArray(response)) { + throw new Error('GitHub did not return pull requests for the commit') + } + const matches = response + .map(asPullRequest) + .filter( + (pull) => + pull.state === 'open' && + pull.head?.sha === config.eventHeadSha && + isSameRepository(pull, config.repository) && + targetsDefaultBranch(pull, config.repository, config.defaultBranch) + ) + if (matches.length !== 1 || !matches[0].number) { + summary( + `Skipped: expected one open same-repository pull request for ${config.eventHeadSha.slice(0, 12)}, found ${matches.length}.` + ) + return + } + return matches[0].number +} + +async function readPullState( + github: GitHubClient, + pullRequestNumber: number +): Promise<{ + pull: PullRequest + reviews: PullRequestReview[] + events: TimelineEvent[] +}> { + const [pull, reviews, events] = await Promise.all([ + github.request(`/pulls/${pullRequestNumber}`), + github.paginate(`/pulls/${pullRequestNumber}/reviews`), + github.paginate(`/issues/${pullRequestNumber}/timeline`) + ]) + return { + pull: asPullRequest(pull), + reviews: asReviews(reviews), + events: asEvents(events) + } +} + +async function revalidate( + github: GitHubClient, + config: ResolvedRuntimeConfig, + summary: Summary +): Promise<{ pull: PullRequest; reviews: PullRequestReview[] } | undefined> { + const state = await readPullState(github, config.pullRequestNumber) + const failure = eligibilityFailure({ + pull: state.pull, + lane: config.lane, + repository: config.repository, + defaultBranch: config.defaultBranch, + expectedHeadSha: config.eventHeadSha, + events: state.events + }) + const reason = + failure ?? + (hasActiveHumanChangeRequest(state.reviews) + ? 'Skipped: an active human change request is present.' + : undefined) + if (!reason) return state + + await stop(github, config, state.pull, state.reviews, reason, summary) +} + +export async function approveCurrentHead( + github: GitHubClient, + config: ResolvedRuntimeConfig, + reviews: PullRequestReview[], + summary: Summary +): Promise { + const identity = config.lane.approval.identity + const headSha = config.eventHeadSha + if (reviews.some((review) => isApprovalForHead(review, identity, headSha))) { + summary(`Already approved ${headSha.slice(0, 12)} as @${identity}.`) + return true + } + + const created = asReviews([ + await github.request(`/pulls/${config.pullRequestNumber}/reviews`, { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ + event: 'APPROVE', + commit_id: headSha, + body: `${POLICY_REVIEW_PREFIX} Lane: ${config.lane.id}. No diff review was performed; eligibility was bound to the trusted policy, exact head, and configured path boundary.` + }) + }) + ])[0] + + let verified + try { + verified = await revalidate(github, config, summary) + } catch (error) { + await dismissApproval( + github, + config.pullRequestNumber, + created, + 'Fast-lane approval withdrawn: post-approval verification failed.' + ) + throw error + } + if (!verified) return false + summary(`Approved ${headSha.slice(0, 12)} as @${identity}.`) + return true +} + +async function assertIdentity( + github: GitHubClient, + expectedIdentity: string +): Promise { + const response = await github.request('https://api.github.com/user') + if (!response || typeof response !== 'object' || Array.isArray(response)) { + throw new Error('GitHub did not return the approval identity') + } + const login = (response as { login?: string }).login + if (login?.toLowerCase() !== expectedIdentity) { + throw new Error( + `FAST_LANE_TOKEN belongs to ${login ?? 'an unknown account'}, expected ${expectedIdentity}` + ) + } +} + +async function resolveRuntimeConfig( + github: GitHubClient, + config: RuntimeConfig, + summary: Summary +): Promise { + const pullRequestNumber = await resolvePullRequestNumber( + github, + config, + summary + ) + if (!pullRequestNumber) return + return { ...config, pullRequestNumber } +} + +async function readInitialEligibleState( + github: GitHubClient, + config: ResolvedRuntimeConfig, + summary: Summary +): Promise<{ pull: PullRequest; reviews: PullRequestReview[] } | undefined> { + const state = await revalidate(github, config, summary) + if (!state) return + if (state.pull.user?.login?.toLowerCase() === config.lane.approval.identity) { + throw new Error('the approval identity cannot approve its own pull request') + } + return state +} + +function filesStayInsideLane( + files: PullRequestFile[], + pull: PullRequest, + config: ResolvedRuntimeConfig +): boolean { + if (!hasCompleteChangedFileList(files, pull.changed_files)) return false + const paths = changedPaths(files) + if (!paths) return false + return isInsideLane(paths, config.lane.pathPrefixes) +} + +async function verifyLanePaths( + github: GitHubClient, + config: ResolvedRuntimeConfig, + state: { pull: PullRequest; reviews: PullRequestReview[] }, + summary: Summary +): Promise { + const files = asFiles( + await github.paginate(`/pulls/${config.pullRequestNumber}/files`) + ) + if (filesStayInsideLane(files, state.pull, config)) return true + await stop( + github, + config, + state.pull, + state.reviews, + 'Skipped: the complete changed-file set is not inside the configured lane.', + summary + ) + return false +} + +async function approveAndArm( + github: GitHubClient, + config: ResolvedRuntimeConfig, + summary: Summary +): Promise { + const state = await revalidate(github, config, summary) + if (!state) return + const approved = await approveCurrentHead( + github, + config, + state.reviews, + summary + ) + if (!approved) return + const pull = asPullRequest( + await github.request(`/pulls/${config.pullRequestNumber}`) + ) + await armMergeAutomation(github, pull, config, summary) + await revalidate(github, config, summary) +} + +export async function runFastLane( + github: GitHubClient, + config: RuntimeConfig, + summary: Summary +): Promise { + await assertIdentity(github, config.lane.approval.identity) + const resolved = await resolveRuntimeConfig(github, config, summary) + if (!resolved) return + const initial = await readInitialEligibleState(github, resolved, summary) + if ( + !initial || + !(await verifyLanePaths(github, resolved, initial, summary)) + ) { + return + } + await approveAndArm(github, resolved, summary) +} diff --git a/scripts/cicd/fast-lane/config.ts b/scripts/cicd/fast-lane/config.ts new file mode 100644 index 00000000000..f2a8915e52d --- /dev/null +++ b/scripts/cicd/fast-lane/config.ts @@ -0,0 +1,153 @@ +import fs from 'node:fs' + +import type { FastLaneConfig, RuntimeConfig } from './types.ts' + +const MERGE_METHODS = new Set(['MERGE', 'REBASE', 'SQUASH']) +const MERGE_MODES = new Set(['automatic', 'manual']) + +function requiredString( + record: Record, + key: string, + context: string +): string { + const value = record[key] + if (typeof value !== 'string' || !value.trim()) { + throw new Error(`${context}.${key} must be a non-empty string`) + } + return value.trim() +} + +function stringArray( + record: Record, + key: string, + context: string, + { allowEmpty = false }: { allowEmpty?: boolean } = {} +): string[] { + const value = record[key] + if ( + !Array.isArray(value) || + (!allowEmpty && value.length === 0) || + value.some((item) => typeof item !== 'string' || !item.trim()) + ) { + throw new Error(`${context}.${key} must be an array of non-empty strings`) + } + return [...new Set(value.map((item) => item.trim()))] +} + +function record(value: unknown, context: string): Record { + if (!value || typeof value !== 'object' || Array.isArray(value)) { + throw new Error(`${context} must be an object`) + } + return value as Record +} + +function normalizeLogins(logins: string[]): string[] { + return [...new Set(logins.map((login) => login.toLowerCase()))] +} + +export function parseFastLaneConfig(value: unknown): FastLaneConfig { + const root = record(value, 'fast lane config') + if (root.schemaVersion !== 1) { + throw new Error('fast lane config.schemaVersion must be 1') + } + + const approval = record(root.approval, 'fast lane config.approval') + const merge = record(root.merge, 'fast lane config.merge') + const mode = requiredString(merge, 'mode', 'fast lane config.merge') + const method = requiredString(merge, 'method', 'fast lane config.merge') + if (!MERGE_MODES.has(mode)) { + throw new Error('fast lane config.merge.mode must be automatic or manual') + } + if (!MERGE_METHODS.has(method)) { + throw new Error( + 'fast lane config.merge.method must be MERGE, REBASE, or SQUASH' + ) + } + const pathPrefixes = stringArray(root, 'pathPrefixes', 'fast lane config') + if ( + pathPrefixes.some( + (prefix) => + !prefix.endsWith('/') || + prefix.startsWith('/') || + prefix.split('/').includes('..') + ) + ) { + throw new Error( + 'fast lane config.pathPrefixes must be relative directory prefixes ending in /' + ) + } + + return { + schemaVersion: 1, + id: requiredString(root, 'id', 'fast lane config'), + pathPrefixes, + approval: { + identity: requiredString( + approval, + 'identity', + 'fast lane config.approval' + ).toLowerCase(), + trustedAuthors: normalizeLogins( + stringArray(approval, 'trustedAuthors', 'fast lane config.approval', { + allowEmpty: true + }) + ), + approvalLabel: requiredString( + approval, + 'approvalLabel', + 'fast lane config.approval' + ).toLowerCase(), + trustedLabelers: normalizeLogins( + stringArray(approval, 'trustedLabelers', 'fast lane config.approval', { + allowEmpty: true + }) + ), + holdLabel: requiredString( + approval, + 'holdLabel', + 'fast lane config.approval' + ).toLowerCase() + }, + merge: { + mode: mode as FastLaneConfig['merge']['mode'], + method: method as FastLaneConfig['merge']['method'] + } + } +} + +function requiredEnv(name: string): string { + const value = process.env[name]?.trim() + if (!value) throw new Error(`${name} is required`) + return value +} + +function optionalPositiveIntegerEnv(name: string): number | undefined { + const value = process.env[name]?.trim() + if (!value) return + const parsed = Number(value) + if (!Number.isSafeInteger(parsed) || parsed <= 0) { + throw new Error(`${name} must be a positive integer`) + } + return parsed +} + +export function loadRuntimeConfig(): RuntimeConfig { + const configPath = requiredEnv('FAST_LANE_CONFIG') + let parsed: unknown + try { + parsed = JSON.parse(fs.readFileSync(configPath, 'utf8')) + } catch (error) { + throw new Error(`Could not read ${configPath}: ${String(error)}`, { + cause: error + }) + } + + return { + token: requiredEnv('FAST_LANE_TOKEN'), + repository: requiredEnv('GITHUB_REPOSITORY'), + pullRequestNumber: optionalPositiveIntegerEnv('PR_NUMBER'), + eventHeadSha: requiredEnv('PR_HEAD_SHA'), + defaultBranch: requiredEnv('FAST_LANE_BASE_REF'), + lane: parseFastLaneConfig(parsed) + } +} diff --git a/scripts/cicd/fast-lane/github.ts b/scripts/cicd/fast-lane/github.ts new file mode 100644 index 00000000000..372fb0b7808 --- /dev/null +++ b/scripts/cicd/fast-lane/github.ts @@ -0,0 +1,113 @@ +import type { GitHubClient } from './types.ts' + +const API_VERSION = '2022-11-28' +const PAGE_SIZE = 100 +const GRAPHQL_URL = 'https://api.github.com/graphql' + +function apiUrl(root: string, requestPath: string): string { + return requestPath.startsWith('https://') + ? requestPath + : `${root}${requestPath}` +} + +async function assertSuccessful( + response: Response, + method: string, + requestPath: string +): Promise { + if (response.ok) return + const body = (await response.text()).slice(0, 500) + throw new Error( + `GitHub API ${method} ${requestPath} failed: ${response.status} ${body}` + ) +} + +function arrayPage(value: unknown, requestPath: string): unknown[] { + if (Array.isArray(value)) return value + throw new Error(`GitHub API ${requestPath} did not return an array`) +} + +interface GraphqlEnvelope { + data?: unknown + errors?: { message?: string }[] +} + +function graphqlEnvelope(value: unknown): GraphqlEnvelope { + if (typeof value !== 'object' || value === null) { + throw new Error('GitHub GraphQL returned an invalid response') + } + return value +} + +function graphqlErrorMessage(error: { message?: string }): string { + return error.message ?? 'unknown error' +} + +function graphqlData(value: unknown): unknown { + const envelope = graphqlEnvelope(value) + const errors = envelope.errors ?? [] + if (errors.length === 0) return envelope.data + throw new Error( + `GitHub GraphQL failed: ${errors.map(graphqlErrorMessage).join('; ')}` + ) +} + +export function createGitHubClient( + token: string, + repository: string +): GitHubClient { + const root = `https://api.github.com/repos/${repository}` + const headers = { + accept: 'application/vnd.github+json', + authorization: `Bearer ${token}`, + 'x-github-api-version': API_VERSION, + 'user-agent': 'comfy-package-fast-lane/1.0' + } + + async function request( + requestPath: string, + options: RequestInit = {} + ): Promise { + const requestHeaders = new Headers(headers) + new Headers(options.headers).forEach((value, name) => { + requestHeaders.set(name, value) + }) + const response = await fetch(apiUrl(root, requestPath), { + ...options, + headers: requestHeaders + }) + await assertSuccessful(response, options.method ?? 'GET', requestPath) + if (response.status === 204) return null + return response.json() + } + + async function paginate(requestPath: string): Promise { + const rows: unknown[] = [] + for (let page = 1; ; page += 1) { + const separator = requestPath.includes('?') ? '&' : '?' + const body = arrayPage( + await request( + `${requestPath}${separator}per_page=${PAGE_SIZE}&page=${page}` + ), + requestPath + ) + rows.push(...body) + if (body.length < PAGE_SIZE) return rows + } + } + + async function graphql( + query: string, + variables: Record + ): Promise { + return graphqlData( + await request(GRAPHQL_URL, { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ query, variables }) + }) + ) + } + + return { request, paginate, graphql } +} diff --git a/scripts/cicd/fast-lane/policy.test.ts b/scripts/cicd/fast-lane/policy.test.ts new file mode 100644 index 00000000000..bc7d0f87445 --- /dev/null +++ b/scripts/cicd/fast-lane/policy.test.ts @@ -0,0 +1,306 @@ +import { describe, expect, it } from 'vitest' + +import { parseFastLaneConfig } from './config.ts' +import { + approvalForHead, + changedPaths, + eligibilityFailure, + hasActiveHumanChangeRequest, + hasAuthorizedApprovalLabel, + hasCompleteChangedFileList, + isApprovalForHead, + isInsideLane +} from './policy.ts' +import type { + FastLaneConfig, + PullRequest, + PullRequestReview, + TimelineEvent +} from './types.ts' + +const lane: FastLaneConfig = { + schemaVersion: 1, + id: 'website', + pathPrefixes: ['apps/website/'], + approval: { + identity: 'christian-byrne', + trustedAuthors: ['bertfy'], + approvalLabel: 'website-fast-lane:approve', + trustedLabelers: ['drjkl'], + holdLabel: 'website-fast-lane:hold' + }, + merge: { mode: 'automatic', method: 'SQUASH' } +} + +function eligiblePull(overrides: Partial = {}): PullRequest { + return { + state: 'open', + draft: false, + user: { login: 'bertfy' }, + labels: [], + head: { + sha: 'head-sha', + repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + }, + base: { + ref: 'main', + repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + }, + ...overrides + } +} + +function failure( + pull: PullRequest, + events: TimelineEvent[] = [] +): string | undefined { + return eligibilityFailure({ + pull, + lane, + repository: 'Comfy-Org/ComfyUI_frontend', + defaultBranch: 'main', + expectedHeadSha: 'head-sha', + events + }) +} + +describe('lane configuration', () => { + it('normalizes logins while preserving the reviewed path policy', () => { + expect( + parseFastLaneConfig({ + ...lane, + approval: { + ...lane.approval, + identity: 'Christian-Byrne', + trustedAuthors: ['BertFY', 'bertfy'], + trustedLabelers: ['DrJKL'] + } + }) + ).toEqual(lane) + }) + + it.for([ + { key: 'schema version', value: { ...lane, schemaVersion: 2 } }, + { key: 'empty path policy', value: { ...lane, pathPrefixes: [] } }, + { + key: 'ambiguous path prefix', + value: { ...lane, pathPrefixes: ['apps/website'] } + }, + { + key: 'unknown merge mode', + value: { ...lane, merge: { mode: 'sometimes', method: 'SQUASH' } } + } + ])('rejects $key', ({ value }) => { + expect(() => parseFastLaneConfig(value)).toThrow() + }) +}) + +describe('changed-path boundary', () => { + it('requires a complete, non-empty set inside the configured prefixes', () => { + const files = [{ filename: 'apps/website/src/pages/index.astro' }] + expect(hasCompleteChangedFileList(files, 1)).toBe(true) + expect(hasCompleteChangedFileList(files, 2)).toBe(false) + expect(isInsideLane(changedPaths(files) ?? [], lane.pathPrefixes)).toBe( + true + ) + expect(isInsideLane([], lane.pathPrefixes)).toBe(false) + expect( + isInsideLane( + ['apps/website/src/pages/index.astro', 'pnpm-lock.yaml'], + lane.pathPrefixes + ) + ).toBe(false) + expect(isInsideLane(['apps/website-evil/file.ts'], lane.pathPrefixes)).toBe( + false + ) + }) + + it.for([ + { + name: 'rename into the lane', + file: { + status: 'renamed', + previous_filename: 'src/sensitive.ts', + filename: 'apps/website/sensitive.ts' + }, + expected: ['apps/website/sensitive.ts', 'src/sensitive.ts'] + }, + { + name: 'copy into the lane', + file: { + status: 'copied', + previous_filename: 'src/sensitive.ts', + filename: 'apps/website/sensitive.ts' + }, + expected: ['apps/website/sensitive.ts', 'src/sensitive.ts'] + } + ])('retains both paths for a $name', ({ file, expected }) => { + const paths = changedPaths([file]) + expect(paths).toEqual(expected) + expect(isInsideLane(paths ?? [], lane.pathPrefixes)).toBe(false) + }) + + it('fails closed when a rename omits its previous path', () => { + expect( + changedPaths([{ status: 'renamed', filename: 'apps/website/new.astro' }]) + ).toBeUndefined() + }) +}) + +describe('approval policy', () => { + it('accepts a trusted label event only after the latest code event', () => { + const pull = eligiblePull({ + user: { login: 'someone-else' }, + labels: [{ name: 'website-fast-lane:approve' }] + }) + const events: TimelineEvent[] = [ + { event: 'committed' }, + { + event: 'labeled', + label: { name: 'website-fast-lane:approve' }, + actor: { login: 'DrJKL' } + } + ] + expect(hasAuthorizedApprovalLabel(pull, events, lane)).toBe(true) + expect(hasAuthorizedApprovalLabel(pull, [...events].reverse(), lane)).toBe( + false + ) + }) + + it('keeps a human change request active after a comment-only review', () => { + const reviews: PullRequestReview[] = [ + { + state: 'CHANGES_REQUESTED', + user: { login: 'DrJKL', type: 'User' } + }, + { state: 'COMMENTED', user: { login: 'DrJKL', type: 'User' } } + ] + expect(hasActiveHumanChangeRequest(reviews)).toBe(true) + }) + + it('ignores app reviews and clears a human request only decisively', () => { + expect( + hasActiveHumanChangeRequest([ + { + state: 'CHANGES_REQUESTED', + user: { login: 'coderabbitai[bot]', type: 'Bot' } + }, + { + state: 'CHANGES_REQUESTED', + user: { login: 'DrJKL', type: 'User' } + }, + { state: 'APPROVED', user: { login: 'DrJKL', type: 'User' } } + ]) + ).toBe(false) + }) + + it('binds policy approval to the identity and exact head', () => { + expect( + isApprovalForHead( + { + state: 'APPROVED', + commit_id: 'head-sha', + user: { login: 'Christian-Byrne' } + }, + 'christian-byrne', + 'head-sha' + ) + ).toBe(true) + expect( + isApprovalForHead( + { + state: 'APPROVED', + commit_id: 'old-sha', + user: { login: 'christian-byrne' } + }, + 'christian-byrne', + 'head-sha' + ) + ).toBe(false) + }) + + it('only selects marked policy approvals for withdrawal', () => { + const reviews: PullRequestReview[] = [ + { + id: 1, + state: 'APPROVED', + commit_id: 'head-sha', + body: 'Looks good to me', + user: { login: 'christian-byrne' } + }, + { + id: 2, + state: 'APPROVED', + commit_id: 'head-sha', + body: '[Package fast lane] Policy-only approval. Lane: website.', + user: { login: 'christian-byrne' } + } + ] + const prefix = '[Package fast lane] Policy-only approval.' + + expect( + approvalForHead(reviews, 'christian-byrne', 'head-sha', prefix)?.id + ).toBe(2) + expect( + approvalForHead( + reviews.slice(0, 1), + 'christian-byrne', + 'head-sha', + prefix + ) + ).toBeUndefined() + }) +}) + +describe('fixed eligibility invariants', () => { + it('accepts the configured trusted-author path', () => { + expect(failure(eligiblePull())).toBeUndefined() + }) + + it.for([ + { + name: 'draft', + pull: eligiblePull({ draft: true }), + message: 'not open and ready' + }, + { + name: 'fork', + pull: eligiblePull({ + head: { + sha: 'head-sha', + repo: { full_name: 'bertfy/ComfyUI_frontend' } + } + }), + message: 'fork pull requests' + }, + { + name: 'other base', + pull: eligiblePull({ + base: { + ref: 'release', + repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + } + }), + message: 'applies only to main' + }, + { + name: 'stale head', + pull: eligiblePull({ + head: { + sha: 'new-head', + repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + } + }), + message: 'head advanced' + }, + { + name: 'hold label', + pull: eligiblePull({ + labels: [{ name: 'website-fast-lane:hold' }] + }), + message: 'hold is applied' + } + ])('rejects $name', ({ pull, message }) => { + expect(failure(pull)).toContain(message) + }) +}) diff --git a/scripts/cicd/fast-lane/policy.ts b/scripts/cicd/fast-lane/policy.ts new file mode 100644 index 00000000000..f10f0b4573d --- /dev/null +++ b/scripts/cicd/fast-lane/policy.ts @@ -0,0 +1,178 @@ +import type { + FastLaneConfig, + PullRequest, + PullRequestFile, + PullRequestReview, + TimelineEvent +} from './types.ts' + +const DECISIVE_REVIEW_STATES = new Set([ + 'APPROVED', + 'CHANGES_REQUESTED', + 'DISMISSED' +]) + +export interface EligibilityContext { + pull: PullRequest + lane: FastLaneConfig + repository: string + defaultBranch: string + expectedHeadSha: string + events: TimelineEvent[] +} + +export function changedPaths(files: PullRequestFile[]): string[] | undefined { + const paths: string[] = [] + for (const file of files) { + if (typeof file.filename !== 'string') return + paths.push(file.filename) + + if (file.previous_filename === undefined) { + if (file.status === 'renamed' || file.status === 'copied') return + continue + } + if (typeof file.previous_filename !== 'string') return + paths.push(file.previous_filename) + } + return paths +} + +export function hasCompleteChangedFileList( + files: PullRequestFile[], + expectedCount: number | undefined +): boolean { + return Number.isSafeInteger(expectedCount) && files.length === expectedCount +} + +export function isInsideLane(paths: string[], prefixes: string[]): boolean { + return ( + paths.length > 0 && + paths.every((path) => prefixes.some((prefix) => path.startsWith(prefix))) + ) +} + +function hasLabel(pull: PullRequest, expected: string): boolean { + return Boolean( + pull.labels?.some((label) => label.name?.toLowerCase() === expected) + ) +} + +export function hasAuthorizedApprovalLabel( + pull: PullRequest, + events: TimelineEvent[], + lane: FastLaneConfig +): boolean { + const { approvalLabel, trustedLabelers } = lane.approval + if (!hasLabel(pull, approvalLabel)) return false + + const latestCodeEvent = events.findLastIndex( + (event) => + event.event === 'committed' || event.event === 'head_ref_force_pushed' + ) + const latestLabelEvent = events.findLastIndex( + (event) => event.label?.name?.toLowerCase() === approvalLabel + ) + if (latestCodeEvent < 0 || latestLabelEvent <= latestCodeEvent) return false + + const labelEvent = events[latestLabelEvent] + const actor = labelEvent.actor?.login?.toLowerCase() + return ( + labelEvent.event === 'labeled' && + actor !== undefined && + trustedLabelers.includes(actor) + ) +} + +export function hasActiveHumanChangeRequest( + reviews: PullRequestReview[] +): boolean { + const latestState = new Map() + for (const review of reviews) { + const login = review.user?.login?.toLowerCase() + if ( + !login || + review.user?.type === 'Bot' || + login.endsWith('[bot]') || + !review.state || + !DECISIVE_REVIEW_STATES.has(review.state) + ) { + continue + } + latestState.set(login, review.state) + } + return [...latestState.values()].includes('CHANGES_REQUESTED') +} + +export function isSameRepository( + pull: PullRequest, + repository: string +): boolean { + return pull.head?.repo?.full_name?.toLowerCase() === repository.toLowerCase() +} + +export function targetsDefaultBranch( + pull: PullRequest, + repository: string, + defaultBranch: string +): boolean { + return ( + pull.base?.repo?.full_name?.toLowerCase() === repository.toLowerCase() && + pull.base.ref === defaultBranch + ) +} + +export function eligibilityFailure({ + pull, + lane, + repository, + defaultBranch, + expectedHeadSha, + events +}: EligibilityContext): string | undefined { + if (pull.state !== 'open' || pull.draft) { + return 'Skipped: the pull request is not open and ready for review.' + } + if (!targetsDefaultBranch(pull, repository, defaultBranch)) { + return `Skipped: the ${lane.id} fast lane applies only to ${defaultBranch}.` + } + if (!isSameRepository(pull, repository)) { + return `Skipped: the ${lane.id} fast lane does not apply to fork pull requests.` + } + if (pull.head?.sha !== expectedHeadSha) { + return 'Skipped: the pull request head advanced after this workflow started.' + } + + const author = pull.user?.login?.toLowerCase() + const trustedAuthor = author && lane.approval.trustedAuthors.includes(author) + if (!trustedAuthor && !hasAuthorizedApprovalLabel(pull, events, lane)) { + return `Skipped: @${author ?? 'unknown'} is not trusted and ${lane.approval.approvalLabel} lacks a current authorized event.` + } + if (hasLabel(pull, lane.approval.holdLabel)) { + return `Skipped: ${lane.approval.holdLabel} is applied.` + } +} + +export function isApprovalForHead( + review: PullRequestReview, + identity: string, + headSha: string +): boolean { + return ( + review.state === 'APPROVED' && + review.commit_id === headSha && + review.user?.login?.toLowerCase() === identity.toLowerCase() + ) +} + +export function approvalForHead( + reviews: PullRequestReview[], + identity: string, + headSha: string, + bodyPrefix: string +): PullRequestReview | undefined { + return reviews.findLast( + (review) => + isApprovalForHead(review, identity, headSha) && + review.body?.startsWith(bodyPrefix) + ) +} diff --git a/scripts/cicd/fast-lane/run.ts b/scripts/cicd/fast-lane/run.ts new file mode 100644 index 00000000000..2405aa27016 --- /dev/null +++ b/scripts/cicd/fast-lane/run.ts @@ -0,0 +1,30 @@ +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' + +import { runFastLane } from './automation.ts' +import { loadRuntimeConfig } from './config.ts' +import { createGitHubClient } from './github.ts' + +function summary(message: string): void { + process.stdout.write(`${message}\n`) + const summaryPath = process.env.GITHUB_STEP_SUMMARY + if (summaryPath) fs.appendFileSync(summaryPath, `${message}\n`) +} + +export async function main(): Promise { + const config = loadRuntimeConfig() + const github = createGitHubClient(config.token, config.repository) + await runFastLane(github, config, summary) +} + +if ( + process.argv[1] && + fileURLToPath(import.meta.url) === path.resolve(process.argv[1]) +) { + main().catch((error: unknown) => { + const message = error instanceof Error ? error.stack : String(error) + process.stderr.write(`${message}\n`) + process.exitCode = 1 + }) +} diff --git a/scripts/cicd/fast-lane/types.ts b/scripts/cicd/fast-lane/types.ts new file mode 100644 index 00000000000..02ea883d8e7 --- /dev/null +++ b/scripts/cicd/fast-lane/types.ts @@ -0,0 +1,90 @@ +export interface FastLaneConfig { + schemaVersion: 1 + id: string + pathPrefixes: string[] + approval: { + identity: string + trustedAuthors: string[] + approvalLabel: string + trustedLabelers: string[] + holdLabel: string + } + merge: { + mode: 'automatic' | 'manual' + method: 'MERGE' | 'REBASE' | 'SQUASH' + } +} + +export interface RepositoryRef { + full_name?: string +} + +export interface PullRequest { + number?: number + state?: string + draft?: boolean + node_id?: string + changed_files?: number + user?: { login?: string } + labels?: { name?: string }[] + head?: { sha?: string; repo?: RepositoryRef | null } + base?: { ref?: string; repo?: RepositoryRef | null } +} + +export interface PullRequestFile { + filename?: string + previous_filename?: string + status?: string +} + +export interface PullRequestReview { + id?: number + state?: string + body?: string + commit_id?: string + submitted_at?: string + user?: { login?: string; type?: string } +} + +export interface TimelineEvent { + event?: string + label?: { name?: string } + actor?: { login?: string } +} + +export interface GitHubClient { + request(path: string, options?: RequestInit): Promise + paginate(path: string): Promise + graphql(query: string, variables: Record): Promise +} + +export interface MergeAutomationState { + id: string + headRefOid?: string + mergeStateStatus?: string + autoMergeRequest?: { + enabledAt?: string + enabledBy?: { login?: string } + } | null + mergeQueueEntry?: { + id?: string + enqueuedAt?: string + enqueuer?: { login?: string } + headCommit?: { oid?: string } + } | null +} + +export interface RuntimeConfig { + token: string + repository: string + pullRequestNumber?: number + eventHeadSha: string + defaultBranch: string + lane: FastLaneConfig +} + +export interface ResolvedRuntimeConfig extends RuntimeConfig { + pullRequestNumber: number +} + +export type Summary = (message: string) => void From ef22dfe6396a8f28ac22a5d1d55abef5ea160fd8 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:10:18 +0000 Subject: [PATCH 27/70] fix(ci): stage production-targeted deployments Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332007 --- .github/workflows/ci-vercel-website-preview.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index a6ec1e704dd..90a347457ea 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -282,7 +282,7 @@ jobs: GIT_COMMIT_SHA: ${{ github.sha }} GIT_REPO: ${{ github.repository }} run: | - URL=$(vercel deploy --prebuilt --archive=tgz \ + URL=$(vercel deploy --prebuilt --prod --skip-domain --archive=tgz \ --meta githubCommitSha="$GIT_COMMIT_SHA" \ --meta githubRepo="$GIT_REPO" \ --meta githubRunId="$GITHUB_RUN_ID") From 964f919fa84628119f8d0bf5091528dd4db4d7f5 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:10:32 +0000 Subject: [PATCH 28/70] fix(ci): serialize fast-lane lifecycle runs Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332046 --- .github/workflows/pr-website-auto-approve.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 417a94bfca5..8c8c832c650 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -37,8 +37,11 @@ permissions: pull-requests: read concurrency: - group: website-fast-lane-${{ github.event.pull_request.number || github.event.workflow_run.head_sha || github.event.sha || github.run_id }} - cancel-in-progress: true + # One serialized compensation boundary is safer than SHA-keyed runs that can + # concurrently approve and withdraw the same pull request. The trial cohort + # is intentionally small, so global serialization is acceptable here. + group: website-fast-lane + cancel-in-progress: false jobs: approve: From 0d3763c010e2d1abbde186bd70b0a2eca81a2538 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:11:53 +0000 Subject: [PATCH 29/70] fix(ci): bind label approval to the live head event Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332020 --- .../workflows/pr-website-auto-approve.yaml | 6 ++ scripts/cicd/fast-lane/automation.test.ts | 1 + scripts/cicd/fast-lane/automation.ts | 29 ++++---- scripts/cicd/fast-lane/config.ts | 8 +++ scripts/cicd/fast-lane/policy.test.ts | 71 +++++++++++++------ scripts/cicd/fast-lane/policy.ts | 52 ++++++++------ scripts/cicd/fast-lane/types.ts | 10 ++- 7 files changed, 115 insertions(+), 62 deletions(-) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 8c8c832c650..4458573442f 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -69,6 +69,9 @@ jobs: FAST_LANE_CONFIG: .github/fast-lanes/website.json FAST_LANE_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} FAST_LANE_BASE_REF: ${{ github.event.repository.default_branch }} + FAST_LANE_EVENT_ACTION: ${{ github.event.action }} + FAST_LANE_EVENT_ACTOR: ${{ github.actor }} + FAST_LANE_EVENT_LABEL: ${{ github.event.label.name }} GITHUB_REPOSITORY: ${{ github.repository }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_NUMBER: ${{ github.event.pull_request.number }} @@ -99,6 +102,9 @@ jobs: FAST_LANE_CONFIG: .github/fast-lanes/website.json FAST_LANE_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} FAST_LANE_BASE_REF: ${{ github.event.repository.default_branch }} + FAST_LANE_EVENT_ACTION: ${{ github.event.action }} + FAST_LANE_EVENT_ACTOR: ${{ github.actor }} + FAST_LANE_EVENT_LABEL: ${{ github.event.label.name }} GITHUB_REPOSITORY: ${{ github.repository }} PR_HEAD_SHA: ${{ github.event.sha || github.event.workflow_run.head_sha }} run: node --experimental-strip-types scripts/cicd/fast-lane/run.ts diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index 1962afbbdc9..22217276bf1 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -19,6 +19,7 @@ function runtimeConfig(): ResolvedRuntimeConfig { repository: 'Comfy-Org/ComfyUI_frontend', pullRequestNumber: 42, eventHeadSha: headSha, + eventName: 'pull_request_target', defaultBranch: 'main', lane: { schemaVersion: 1, diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 95f3a9c6d6e..7e21ffd2d86 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -17,8 +17,7 @@ import type { PullRequestReview, ResolvedRuntimeConfig, RuntimeConfig, - Summary, - TimelineEvent + Summary } from './types.ts' const POLICY_REVIEW_PREFIX = '[Package fast lane] Policy-only approval.' @@ -53,10 +52,6 @@ function asReviews(value: unknown[]): PullRequestReview[] { return value as PullRequestReview[] } -function asEvents(value: unknown[]): TimelineEvent[] { - return value as TimelineEvent[] -} - function asFiles(value: unknown[]): PullRequestFile[] { return value as PullRequestFile[] } @@ -290,17 +285,14 @@ async function readPullState( ): Promise<{ pull: PullRequest reviews: PullRequestReview[] - events: TimelineEvent[] }> { - const [pull, reviews, events] = await Promise.all([ + const [pull, reviews] = await Promise.all([ github.request(`/pulls/${pullRequestNumber}`), - github.paginate(`/pulls/${pullRequestNumber}/reviews`), - github.paginate(`/issues/${pullRequestNumber}/timeline`) + github.paginate(`/pulls/${pullRequestNumber}/reviews`) ]) return { pull: asPullRequest(pull), - reviews: asReviews(reviews), - events: asEvents(events) + reviews: asReviews(reviews) } } @@ -316,7 +308,18 @@ async function revalidate( repository: config.repository, defaultBranch: config.defaultBranch, expectedHeadSha: config.eventHeadSha, - events: state.events + hasPolicyApprovalForHead: Boolean( + approvalForHead( + state.reviews, + config.lane.approval.identity, + config.eventHeadSha, + POLICY_REVIEW_PREFIX + ) + ), + eventName: config.eventName, + eventAction: config.eventAction, + eventActor: config.eventActor, + eventLabel: config.eventLabel }) const reason = failure ?? diff --git a/scripts/cicd/fast-lane/config.ts b/scripts/cicd/fast-lane/config.ts index f2a8915e52d..07fb5ab0430 100644 --- a/scripts/cicd/fast-lane/config.ts +++ b/scripts/cicd/fast-lane/config.ts @@ -121,6 +121,10 @@ function requiredEnv(name: string): string { return value } +function optionalEnv(name: string): string | undefined { + return process.env[name]?.trim() || undefined +} + function optionalPositiveIntegerEnv(name: string): number | undefined { const value = process.env[name]?.trim() if (!value) return @@ -147,6 +151,10 @@ export function loadRuntimeConfig(): RuntimeConfig { repository: requiredEnv('GITHUB_REPOSITORY'), pullRequestNumber: optionalPositiveIntegerEnv('PR_NUMBER'), eventHeadSha: requiredEnv('PR_HEAD_SHA'), + eventName: requiredEnv('GITHUB_EVENT_NAME'), + eventAction: optionalEnv('FAST_LANE_EVENT_ACTION'), + eventActor: optionalEnv('FAST_LANE_EVENT_ACTOR'), + eventLabel: optionalEnv('FAST_LANE_EVENT_LABEL'), defaultBranch: requiredEnv('FAST_LANE_BASE_REF'), lane: parseFastLaneConfig(parsed) } diff --git a/scripts/cicd/fast-lane/policy.test.ts b/scripts/cicd/fast-lane/policy.test.ts index bc7d0f87445..02e90280113 100644 --- a/scripts/cicd/fast-lane/policy.test.ts +++ b/scripts/cicd/fast-lane/policy.test.ts @@ -11,12 +11,7 @@ import { isApprovalForHead, isInsideLane } from './policy.ts' -import type { - FastLaneConfig, - PullRequest, - PullRequestReview, - TimelineEvent -} from './types.ts' +import type { FastLaneConfig, PullRequest, PullRequestReview } from './types.ts' const lane: FastLaneConfig = { schemaVersion: 1, @@ -52,7 +47,13 @@ function eligiblePull(overrides: Partial = {}): PullRequest { function failure( pull: PullRequest, - events: TimelineEvent[] = [] + authorization: { + hasPolicyApprovalForHead?: boolean + eventName?: string + eventAction?: string + eventActor?: string + eventLabel?: string + } = {} ): string | undefined { return eligibilityFailure({ pull, @@ -60,7 +61,11 @@ function failure( repository: 'Comfy-Org/ComfyUI_frontend', defaultBranch: 'main', expectedHeadSha: 'head-sha', - events + hasPolicyApprovalForHead: authorization.hasPolicyApprovalForHead ?? false, + eventName: authorization.eventName ?? 'pull_request_target', + eventAction: authorization.eventAction, + eventActor: authorization.eventActor, + eventLabel: authorization.eventLabel }) } @@ -148,23 +153,47 @@ describe('changed-path boundary', () => { }) describe('approval policy', () => { - it('accepts a trusted label event only after the latest code event', () => { + it('accepts only the current trusted label event for a non-trusted author', () => { const pull = eligiblePull({ user: { login: 'someone-else' }, labels: [{ name: 'website-fast-lane:approve' }] }) - const events: TimelineEvent[] = [ - { event: 'committed' }, - { - event: 'labeled', - label: { name: 'website-fast-lane:approve' }, - actor: { login: 'DrJKL' } - } - ] - expect(hasAuthorizedApprovalLabel(pull, events, lane)).toBe(true) - expect(hasAuthorizedApprovalLabel(pull, [...events].reverse(), lane)).toBe( - false - ) + expect( + hasAuthorizedApprovalLabel(pull, lane, { + name: 'pull_request_target', + action: 'labeled', + actor: 'DrJKL', + label: 'website-fast-lane:approve' + }) + ).toBe(true) + expect( + hasAuthorizedApprovalLabel(pull, lane, { + name: 'pull_request_target', + action: 'synchronize', + actor: 'someone-else' + }) + ).toBe(false) + expect( + failure(pull, { + eventName: 'pull_request_target', + eventAction: 'synchronize', + eventActor: 'someone-else' + }) + ).toContain('lacks a current authorized event') + expect( + failure(pull, { + hasPolicyApprovalForHead: true, + eventName: 'workflow_run' + }) + ).toBeUndefined() + expect( + failure(pull, { + eventName: 'pull_request_target', + eventAction: 'labeled', + eventActor: 'DrJKL', + eventLabel: 'website-fast-lane:approve' + }) + ).toBeUndefined() }) it('keeps a human change request active after a comment-only review', () => { diff --git a/scripts/cicd/fast-lane/policy.ts b/scripts/cicd/fast-lane/policy.ts index f10f0b4573d..548c80459a3 100644 --- a/scripts/cicd/fast-lane/policy.ts +++ b/scripts/cicd/fast-lane/policy.ts @@ -2,8 +2,7 @@ import type { FastLaneConfig, PullRequest, PullRequestFile, - PullRequestReview, - TimelineEvent + PullRequestReview } from './types.ts' const DECISIVE_REVIEW_STATES = new Set([ @@ -18,7 +17,11 @@ export interface EligibilityContext { repository: string defaultBranch: string expectedHeadSha: string - events: TimelineEvent[] + hasPolicyApprovalForHead: boolean + eventName: string + eventAction?: string + eventActor?: string + eventLabel?: string } export function changedPaths(files: PullRequestFile[]): string[] | undefined { @@ -59,27 +62,22 @@ function hasLabel(pull: PullRequest, expected: string): boolean { export function hasAuthorizedApprovalLabel( pull: PullRequest, - events: TimelineEvent[], - lane: FastLaneConfig + lane: FastLaneConfig, + event: { + name: string + action?: string + actor?: string + label?: string + } ): boolean { const { approvalLabel, trustedLabelers } = lane.approval if (!hasLabel(pull, approvalLabel)) return false - - const latestCodeEvent = events.findLastIndex( - (event) => - event.event === 'committed' || event.event === 'head_ref_force_pushed' - ) - const latestLabelEvent = events.findLastIndex( - (event) => event.label?.name?.toLowerCase() === approvalLabel - ) - if (latestCodeEvent < 0 || latestLabelEvent <= latestCodeEvent) return false - - const labelEvent = events[latestLabelEvent] - const actor = labelEvent.actor?.login?.toLowerCase() return ( - labelEvent.event === 'labeled' && - actor !== undefined && - trustedLabelers.includes(actor) + event.name === 'pull_request_target' && + event.action === 'labeled' && + event.label?.toLowerCase() === approvalLabel && + event.actor !== undefined && + trustedLabelers.includes(event.actor.toLowerCase()) ) } @@ -127,7 +125,11 @@ export function eligibilityFailure({ repository, defaultBranch, expectedHeadSha, - events + hasPolicyApprovalForHead, + eventName, + eventAction, + eventActor, + eventLabel }: EligibilityContext): string | undefined { if (pull.state !== 'open' || pull.draft) { return 'Skipped: the pull request is not open and ready for review.' @@ -144,7 +146,13 @@ export function eligibilityFailure({ const author = pull.user?.login?.toLowerCase() const trustedAuthor = author && lane.approval.trustedAuthors.includes(author) - if (!trustedAuthor && !hasAuthorizedApprovalLabel(pull, events, lane)) { + const currentLabelEvent = hasAuthorizedApprovalLabel(pull, lane, { + name: eventName, + action: eventAction, + actor: eventActor, + label: eventLabel + }) + if (!trustedAuthor && !hasPolicyApprovalForHead && !currentLabelEvent) { return `Skipped: @${author ?? 'unknown'} is not trusted and ${lane.approval.approvalLabel} lacks a current authorized event.` } if (hasLabel(pull, lane.approval.holdLabel)) { diff --git a/scripts/cicd/fast-lane/types.ts b/scripts/cicd/fast-lane/types.ts index 02ea883d8e7..7238ed2c63c 100644 --- a/scripts/cicd/fast-lane/types.ts +++ b/scripts/cicd/fast-lane/types.ts @@ -46,12 +46,6 @@ export interface PullRequestReview { user?: { login?: string; type?: string } } -export interface TimelineEvent { - event?: string - label?: { name?: string } - actor?: { login?: string } -} - export interface GitHubClient { request(path: string, options?: RequestInit): Promise paginate(path: string): Promise @@ -79,6 +73,10 @@ export interface RuntimeConfig { repository: string pullRequestNumber?: number eventHeadSha: string + eventName: string + eventAction?: string + eventActor?: string + eventLabel?: string defaultBranch: string lane: FastLaneConfig } From 59cd024c27470b3e767c677826fd99b3ae0aa2b2 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:13:11 +0000 Subject: [PATCH 30/70] fix(ci): arm only the approved fast-lane head Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332001 --- scripts/cicd/fast-lane/automation.test.ts | 35 +++++++++++++++++-- scripts/cicd/fast-lane/automation.ts | 41 +++++++++++++++++++---- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index 22217276bf1..24dc4d8d218 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -125,7 +125,7 @@ describe('merge automation', () => { graphql } - await armMergeAutomation(github, pull(), runtimeConfig(), vi.fn()) + await armMergeAutomation(github, pull(), headSha, runtimeConfig(), vi.fn()) expect(graphql).toHaveBeenCalledTimes(2) expect(graphql.mock.calls[1][0]).toContain('enablePullRequestAutoMerge') @@ -157,7 +157,7 @@ describe('merge automation', () => { graphql } - await armMergeAutomation(github, pull(), runtimeConfig(), vi.fn()) + await armMergeAutomation(github, pull(), headSha, runtimeConfig(), vi.fn()) expect(graphql.mock.calls[1][0]).toContain('jump: false') expect(graphql.mock.calls[1][1]).toEqual({ @@ -166,6 +166,35 @@ describe('merge automation', () => { }) }) + it('does not arm a head that advanced after policy approval', async () => { + const advancedSha = 'abcdef0123456789abcdef0123456789abcdef01' + const graphql = vi.fn().mockResolvedValueOnce({ + node: { + id: 'PR_1', + headRefOid: advancedSha, + mergeStateStatus: 'CLEAN', + autoMergeRequest: null, + mergeQueueEntry: null + } + }) + const github: GitHubClient = { + request: unusedRequest, + paginate: unusedPaginate, + graphql + } + + await expect( + armMergeAutomation( + github, + { node_id: 'PR_1', head: { sha: advancedSha } }, + headSha, + runtimeConfig(), + vi.fn() + ) + ).rejects.toThrow('head advanced') + expect(graphql).toHaveBeenCalledTimes(1) + }) + it('does not mutate merge state in a manual lane', async () => { const config = runtimeConfig() config.lane.merge.mode = 'manual' @@ -176,7 +205,7 @@ describe('merge automation', () => { graphql } - await armMergeAutomation(github, pull(), config, vi.fn()) + await armMergeAutomation(github, pull(), headSha, config, vi.fn()) expect(graphql).not.toHaveBeenCalled() }) diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 7e21ffd2d86..28d45805f23 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -134,6 +134,7 @@ export async function stopMergeAutomation( export async function armMergeAutomation( github: GitHubClient, pull: PullRequest, + approvedHeadSha: string, config: RuntimeConfig, summary: Summary ): Promise { @@ -143,7 +144,10 @@ export async function armMergeAutomation( } const state = await readMergeState(github, pull.node_id) - if (state.headRefOid !== pull.head.sha) { + if ( + pull.head.sha !== approvedHeadSha || + state.headRefOid !== approvedHeadSha + ) { throw new Error('the pull request head advanced before merge automation') } if (state.mergeQueueEntry) { @@ -462,11 +466,36 @@ async function approveAndArm( summary ) if (!approved) return - const pull = asPullRequest( - await github.request(`/pulls/${config.pullRequestNumber}`) - ) - await armMergeAutomation(github, pull, config, summary) - await revalidate(github, config, summary) + const verified = await revalidate(github, config, summary) + if (!verified) return + try { + await armMergeAutomation( + github, + verified.pull, + config.eventHeadSha, + config, + summary + ) + await revalidate(github, config, summary) + } catch (error) { + const state = await readPullState(github, config.pullRequestNumber) + try { + await stop( + github, + config, + state.pull, + state.reviews, + 'Merge automation failed; approval and merge state were withdrawn.', + summary + ) + } catch (cleanupError) { + throw new AggregateError( + [error, cleanupError], + 'merge automation and compensation both failed', { cause: cleanupError } + ) + } + throw error + } } export async function runFastLane( From e9559072b052b29adb482bf803829c407dab4e61 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:17:00 +0000 Subject: [PATCH 31/70] fix(ci): preserve compensation failure context Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332001 --- scripts/cicd/fast-lane/automation.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 28d45805f23..e67faa65775 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -489,9 +489,9 @@ async function approveAndArm( summary ) } catch (cleanupError) { - throw new AggregateError( - [error, cleanupError], - 'merge automation and compensation both failed', { cause: cleanupError } + throw new Error( + `Merge automation failed (${String(error)}) and compensation also failed.`, + { cause: cleanupError } ) } throw error From 5d853517ec4cf2b1fa71fd119912ac4ee2baa823 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:17:32 +0000 Subject: [PATCH 32/70] fix(ci): dequeue fast lanes by pull request id Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332032 --- scripts/cicd/fast-lane/automation.test.ts | 1 + scripts/cicd/fast-lane/automation.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index 24dc4d8d218..890d7b31282 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -241,6 +241,7 @@ describe('merge automation', () => { expect(graphql).toHaveBeenCalledTimes(3) expect(graphql.mock.calls[1][0]).toContain('dequeuePullRequest') + expect(graphql.mock.calls[1][1]).toEqual({ pullRequestId: 'PR_1' }) expect(graphql.mock.calls[2][0]).toContain('disablePullRequestAutoMerge') }) diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index e67faa65775..6fe50fc850b 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -107,10 +107,10 @@ export async function stopMergeAutomation( atOrAfter(entry.enqueuedAt, policyReview.submitted_at) ) { await github.graphql( - `mutation PackageFastLaneDequeue($id: ID!) { - dequeuePullRequest(input: { id: $id }) { clientMutationId } + `mutation PackageFastLaneDequeue($pullRequestId: ID!) { + dequeuePullRequest(input: { id: $pullRequestId }) { clientMutationId } }`, - { id: entry.id } + { pullRequestId: pull.node_id } ) } From 6fda68c365b6f293c4d925f8ef8f9f7271d38c96 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:18:17 +0000 Subject: [PATCH 33/70] fix(ci): retain the first fast-lane ownership floor Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332015 --- scripts/cicd/fast-lane/automation.test.ts | 23 ++++++++++++++++++++++ scripts/cicd/fast-lane/automation.ts | 24 ++++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index 890d7b31282..b6f1b4eb53c 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -3,6 +3,7 @@ import { describe, expect, it, vi } from 'vitest' import { approveCurrentHead, armMergeAutomation, + policyReviewFloor, stopMergeAutomation } from './automation.ts' import type { @@ -104,6 +105,28 @@ describe('approval lifecycle', () => { }) describe('merge automation', () => { + it('uses the earliest policy review as the automation ownership floor', () => { + expect( + policyReviewFloor( + [ + { + state: 'APPROVED', + body: '[Package fast lane] Policy-only approval. Later head.', + submitted_at: '2026-10-06T10:03:00Z', + user: { login: 'christian-byrne' } + }, + { + state: 'DISMISSED', + body: '[Package fast lane] Policy-only approval. Earlier head.', + submitted_at: '2026-10-06T10:00:00Z', + user: { login: 'christian-byrne' } + } + ], + 'christian-byrne' + )?.submitted_at + ).toBe('2026-10-06T10:00:00Z') + }) + it('arms native auto-merge for the exact head and configured method', async () => { const graphql = vi .fn() diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 6fe50fc850b..055b7e934ef 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -197,17 +197,23 @@ export async function armMergeAutomation( summary(`Armed native auto-merge for ${pull.head.sha.slice(0, 12)}.`) } -function latestPolicyReview( +export function policyReviewFloor( reviews: PullRequestReview[], identity: string ): PullRequestReview | undefined { - return reviews.findLast( - (review) => - review.user?.login?.toLowerCase() === identity.toLowerCase() && - review.body?.startsWith(POLICY_REVIEW_PREFIX) && - review.submitted_at !== undefined && - !Number.isNaN(Date.parse(review.submitted_at)) - ) + return reviews + .filter( + (review) => + review.user?.login?.toLowerCase() === identity.toLowerCase() && + review.body?.startsWith(POLICY_REVIEW_PREFIX) && + review.submitted_at !== undefined && + !Number.isNaN(Date.parse(review.submitted_at)) + ) + .sort( + (left, right) => + Date.parse(left.submitted_at ?? '') - + Date.parse(right.submitted_at ?? '') + )[0] } async function dismissApproval( @@ -250,7 +256,7 @@ async function stop( github, pull, identity, - latestPolicyReview(reviews, identity) + policyReviewFloor(reviews, identity) ) summary(message) } From cc83981ec07cca730b6f20e72b27269e4401793f Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:18:59 +0000 Subject: [PATCH 34/70] fix(ci): dismiss stale fast-lane policy approvals Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202331996 --- scripts/cicd/fast-lane/automation.test.ts | 33 +++++++++++++++++++++++ scripts/cicd/fast-lane/automation.ts | 30 ++++++++++++++------- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index b6f1b4eb53c..bdeda20c565 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it, vi } from 'vitest' import { + activePolicyApprovals, approveCurrentHead, armMergeAutomation, policyReviewFloor, @@ -51,6 +52,38 @@ function unusedPaginate(): Promise { } describe('approval lifecycle', () => { + it('selects active policy approvals across current and stale heads', () => { + const policyBody = + '[Package fast lane] Policy-only approval. Lane: website.' + expect( + activePolicyApprovals( + [ + { + id: 1, + state: 'APPROVED', + commit_id: 'old-head', + body: policyBody, + user: { login: 'christian-byrne' } + }, + { + id: 2, + state: 'APPROVED', + commit_id: headSha, + body: policyBody, + user: { login: 'christian-byrne' } + }, + { + id: 3, + state: 'DISMISSED', + body: policyBody, + user: { login: 'christian-byrne' } + } + ], + 'christian-byrne' + ).map((review) => review.id) + ).toEqual([1, 2]) + }) + it('withdraws a new approval when post-approval verification fails', async () => { const verificationError = new Error('verification unavailable') const calls: { path: string; method: string }[] = [] diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 055b7e934ef..4b52e5e0655 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -233,6 +233,18 @@ async function dismissApproval( ) } +export function activePolicyApprovals( + reviews: PullRequestReview[], + identity: string +): PullRequestReview[] { + return reviews.filter( + (review) => + review.state === 'APPROVED' && + review.user?.login?.toLowerCase() === identity.toLowerCase() && + review.body?.startsWith(POLICY_REVIEW_PREFIX) + ) +} + async function stop( github: GitHubClient, config: ResolvedRuntimeConfig, @@ -242,16 +254,14 @@ async function stop( summary: Summary ): Promise { const identity = config.lane.approval.identity - const headSha = pull.head?.sha - const approval = headSha - ? approvalForHead(reviews, identity, headSha, POLICY_REVIEW_PREFIX) - : undefined - await dismissApproval( - github, - config.pullRequestNumber, - approval, - `Fast-lane approval withdrawn: ${message}` - ) + for (const approval of activePolicyApprovals(reviews, identity)) { + await dismissApproval( + github, + config.pullRequestNumber, + approval, + `Fast-lane approval withdrawn: ${message}` + ) + } await stopMergeAutomation( github, pull, From 15144ca42b19d257b2c1a1043cd94b1cef8b29db Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:20:34 +0000 Subject: [PATCH 35/70] docs(ci): define revision-bound label events Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332020 --- docs/architecture/package-delivery-lanes.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/architecture/package-delivery-lanes.md b/docs/architecture/package-delivery-lanes.md index 149cfa862bf..53250a1b880 100644 --- a/docs/architecture/package-delivery-lanes.md +++ b/docs/architecture/package-delivery-lanes.md @@ -40,8 +40,10 @@ These are implementation invariants, not package dials: - Forks, drafts, non-default base branches, stale event heads, incomplete file lists, and paths outside the lane fail closed. - Every approval is tied to the exact head SHA. A new commit needs a new policy decision. -- Approval-label provenance is verified. The latest matching label event must come from a trusted - operator after the latest commit or force-push event. +- Approval-label provenance is bound to the current workflow event. A non-allowlisted author is + eligible only on the exact-head `labeled` event from a trusted operator; later events continue + only when that same head already has the policy approval. Commit timestamps are never used as a + proxy for push order. - An active human change request blocks the lane. Comments and pending reviews do not count as change requests. - The credential's GitHub identity must match the identity declared in the policy, and it cannot From d2056fec66afc139767eea9b30b870e4084c1526 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:20:49 +0000 Subject: [PATCH 36/70] fix(ci): make fast-lane compensation fail safe Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202332043 --- docs/architecture/package-delivery-lanes.md | 3 + scripts/cicd/fast-lane/automation.test.ts | 35 ++++++++++ scripts/cicd/fast-lane/automation.ts | 77 ++++++++++++++------- 3 files changed, 90 insertions(+), 25 deletions(-) diff --git a/docs/architecture/package-delivery-lanes.md b/docs/architecture/package-delivery-lanes.md index 53250a1b880..2fe81d27f0d 100644 --- a/docs/architecture/package-delivery-lanes.md +++ b/docs/architecture/package-delivery-lanes.md @@ -49,6 +49,9 @@ These are implementation invariants, not package dials: - The credential's GitHub identity must match the identity declared in the policy, and it cannot approve its own pull request. - If post-approval verification fails, the newly created approval is dismissed. +- Approval, queue, and compensation runs are serialized. Compensation attempts merge-state + teardown and every active policy-review dismissal independently so one API failure cannot skip + the other safety action. - The lane only disables auto-merge or queue state that its own identity created after its policy approval. It does not undo another person's merge decision. diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index bdeda20c565..e73427fb41a 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -325,4 +325,39 @@ describe('merge automation', () => { expect(graphql).toHaveBeenCalledTimes(1) }) + + it('still disables auto-merge when dequeue fails', async () => { + const graphql = vi + .fn() + .mockResolvedValueOnce({ + node: { + id: 'PR_1', + headRefOid: headSha, + autoMergeRequest: { + enabledAt: '2026-10-06T10:01:00Z', + enabledBy: { login: 'christian-byrne' } + }, + mergeQueueEntry: { + id: 'MQE_1', + enqueuedAt: '2026-10-06T10:02:00Z', + enqueuer: { login: 'christian-byrne' } + } + } + }) + .mockRejectedValueOnce(new Error('already dequeued')) + .mockResolvedValueOnce({}) + const github: GitHubClient = { + request: unusedRequest, + paginate: unusedPaginate, + graphql + } + + await expect( + stopMergeAutomation(github, pull(), 'christian-byrne', { + submitted_at: '2026-10-06T10:00:00Z' + }) + ).rejects.toThrow('failed to stop all merge automation') + expect(graphql).toHaveBeenCalledTimes(3) + expect(graphql.mock.calls[2][0]).toContain('disablePullRequestAutoMerge') + }) }) diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 4b52e5e0655..6d6835def02 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -100,18 +100,23 @@ export async function stopMergeAutomation( } const state = await readMergeState(github, pull.node_id) + const errors: unknown[] = [] const entry = state.mergeQueueEntry if ( entry?.id && actorMatches(entry.enqueuer, identity) && atOrAfter(entry.enqueuedAt, policyReview.submitted_at) ) { - await github.graphql( - `mutation PackageFastLaneDequeue($pullRequestId: ID!) { - dequeuePullRequest(input: { id: $pullRequestId }) { clientMutationId } - }`, - { pullRequestId: pull.node_id } - ) + try { + await github.graphql( + `mutation PackageFastLaneDequeue($pullRequestId: ID!) { + dequeuePullRequest(input: { id: $pullRequestId }) { clientMutationId } + }`, + { pullRequestId: pull.node_id } + ) + } catch (error) { + errors.push(error) + } } const autoMerge = state.autoMergeRequest @@ -120,14 +125,21 @@ export async function stopMergeAutomation( actorMatches(autoMerge.enabledBy, identity) && atOrAfter(autoMerge.enabledAt, policyReview.submitted_at) ) { - await github.graphql( - `mutation PackageFastLaneDisableAutoMerge($pullRequestId: ID!) { - disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) { - clientMutationId - } - }`, - { pullRequestId: pull.node_id } - ) + try { + await github.graphql( + `mutation PackageFastLaneDisableAutoMerge($pullRequestId: ID!) { + disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) { + clientMutationId + } + }`, + { pullRequestId: pull.node_id } + ) + } catch (error) { + errors.push(error) + } + } + if (errors.length > 0) { + throw new AggregateError(errors, 'failed to stop all merge automation') } } @@ -254,21 +266,36 @@ async function stop( summary: Summary ): Promise { const identity = config.lane.approval.identity - for (const approval of activePolicyApprovals(reviews, identity)) { - await dismissApproval( + const errors: unknown[] = [] + try { + await stopMergeAutomation( github, - config.pullRequestNumber, - approval, - `Fast-lane approval withdrawn: ${message}` + pull, + identity, + policyReviewFloor(reviews, identity) ) + } catch (error) { + errors.push(error) + } + for (const approval of activePolicyApprovals(reviews, identity)) { + try { + await dismissApproval( + github, + config.pullRequestNumber, + approval, + `Fast-lane approval withdrawn: ${message}` + ) + } catch (error) { + errors.push(error) + } } - await stopMergeAutomation( - github, - pull, - identity, - policyReviewFloor(reviews, identity) - ) summary(message) + if (errors.length > 0) { + throw new AggregateError( + errors, + 'failed to complete fast-lane compensation' + ) + } } async function resolvePullRequestNumber( From 7a01651695aa1b0cb42e21b2f6e8138a9de0b3bb Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:24:04 +0000 Subject: [PATCH 37/70] fix(ci): drop blocked review-event fast-lane runs Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202640154 --- .github/workflows/pr-website-auto-approve.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 4458573442f..a5873257327 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -20,8 +20,6 @@ on: - edited - labeled - unlabeled - pull_request_review: - types: [submitted, dismissed] workflow_run: workflows: - 'CI: Lint Format' From e0b09600d23c7ee2bc4dd5b767f6b2aed376f178 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:24:18 +0000 Subject: [PATCH 38/70] fix(ci): limit approval job to target events Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202640156 --- .github/workflows/pr-website-auto-approve.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index a5873257327..26e279908d4 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -43,7 +43,7 @@ concurrency: jobs: approve: - if: github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review' + if: github.event_name == 'pull_request_target' environment: website-approval runs-on: ubuntu-latest timeout-minutes: 5 From 1acd80e80280748989b5cf167a0191c091118f44 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:24:36 +0000 Subject: [PATCH 39/70] docs(ci): name live fast-lane reconcile events Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202640514 --- docs/architecture/website-delivery-validation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture/website-delivery-validation.md b/docs/architecture/website-delivery-validation.md index bcfcb88cb3c..d3d55f43f07 100644 --- a/docs/architecture/website-delivery-validation.md +++ b/docs/architecture/website-delivery-validation.md @@ -14,7 +14,7 @@ The `website-approval` environment supplies `WEBSITE_APPROVAL_TOKEN`. The creden belongs to `christian-byrne`, whose team membership satisfies the website path review rule. The workflow verifies that identity before it acts and cannot approve Christian's own pull requests. After approval it uses squash auto-merge or enters an already-clean exact head in GitHub's native -queue without queue jumping. Later check and review events reconcile the decision. +queue without queue jumping. Later status and workflow-run events reconcile the decision. For a website-only pull request, the required lint context runs website-scoped lint, format, typecheck, and unused-code checks. A change outside `apps/website/` falls back to the full repository From 877bd263c653549e7367a51efba3d23230d0a74c Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:24:53 +0000 Subject: [PATCH 40/70] fix(ci): retain website locale integrity checks Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202640201 --- .github/workflows/ci-lint-format.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-lint-format.yaml b/.github/workflows/ci-lint-format.yaml index 1e2032eada3..cb5d6dae8e6 100644 --- a/.github/workflows/ci-lint-format.yaml +++ b/.github/workflows/ci-lint-format.yaml @@ -276,5 +276,7 @@ jobs: steps: - uses: actions/checkout@v7 - uses: ./.github/actions/setup-frontend - - name: Find unused website files, exports and dependencies - run: pnpm knip --workspace apps/website + - name: Verify website repository integrity + run: | + pnpm knip --workspace apps/website + pnpm --filter @comfyorg/website locale:check From 5b6eed1a9a2286feee0784e96207f71a5731187e Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:25:25 +0000 Subject: [PATCH 41/70] test(ci): exercise website-only path classification Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202640425 --- scripts/cicd/changes-filter.test.ts | 42 ++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/scripts/cicd/changes-filter.test.ts b/scripts/cicd/changes-filter.test.ts index 182d49e2a0a..28892b3b527 100644 --- a/scripts/cicd/changes-filter.test.ts +++ b/scripts/cicd/changes-filter.test.ts @@ -33,7 +33,11 @@ function evaluateBoolean(expression: string, context: object) { return z.boolean().parse(runInNewContext(javascript, context)) } -function selectChecks(eventName: string, relevant: Record) { +function selectChecks( + eventName: string, + relevant: Record, + filter: Record = {} +) { const root = mkdtempSync(join(tmpdir(), 'changes-filter-')) try { const output = join(root, 'output') @@ -69,7 +73,12 @@ function selectChecks(eventName: string, relevant: Record) { const relevantStep = action.runs.steps.find( (step) => step.id === 'relevant' ) + const filterStep = action.runs.steps.find((step) => step.id === 'filter') + assert.exists(filterStep?.if) assert.exists(relevantStep?.if) + context.steps.filter.outputs = evaluateBoolean(filterStep.if, context) + ? filter + : {} context.steps.relevant.outputs = evaluateBoolean(relevantStep.if, context) ? relevant : {} @@ -162,3 +171,34 @@ it.for([ 'should-run-source': source }) }) + +it.for([ + { + name: 'website-only pull request', + relevant: { + relevant: 'false', + unit: 'false', + e2e: 'false', + source: 'false', + outside_website: 'false' + }, + filter: { app_website: 'true', deps: 'false' }, + expected: true + }, + { + name: 'website plus root pull request', + relevant: { + relevant: 'true', + unit: 'true', + e2e: 'true', + source: 'true', + outside_website: 'true' + }, + filter: { app_website: 'true', deps: 'false' }, + expected: false + } +])('classifies a $name', ({ relevant, filter, expected }) => { + expect( + selectChecks('pull_request', relevant, filter)['website-only-changes'] + ).toBe(expected) +}) From 9e70fdcdb946914700a9ecee08defd1929e1063b Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:26:06 +0000 Subject: [PATCH 42/70] fix(ci): build website previews from the exact PR head Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202640227 --- .github/workflows/ci-vercel-website-preview.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index 90a347457ea..b675a29e12f 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -40,6 +40,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v7 + with: + ref: ${{ github.event.pull_request.head.sha }} - name: Install pnpm uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10 From 9189923ccee092b0f31f407c396f94ca57d3f76f Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:28:10 +0000 Subject: [PATCH 43/70] fix(ci): distinguish policy approvals from human reviews Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202640294 --- scripts/cicd/fast-lane/automation.test.ts | 1 + scripts/cicd/fast-lane/automation.ts | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index e73427fb41a..735b3fde9a5 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -125,6 +125,7 @@ describe('approval lifecycle', () => { { state: 'APPROVED', commit_id: headSha, + body: '[Package fast lane] Policy-only approval. Lane: website.', user: { login: 'christian-byrne' } } ], diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 6d6835def02..9b578cb52cb 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -4,7 +4,6 @@ import { eligibilityFailure, hasActiveHumanChangeRequest, hasCompleteChangedFileList, - isApprovalForHead, isInsideLane, isSameRepository, targetsDefaultBranch @@ -386,7 +385,7 @@ export async function approveCurrentHead( ): Promise { const identity = config.lane.approval.identity const headSha = config.eventHeadSha - if (reviews.some((review) => isApprovalForHead(review, identity, headSha))) { + if (approvalForHead(reviews, identity, headSha, POLICY_REVIEW_PREFIX)) { summary(`Already approved ${headSha.slice(0, 12)} as @${identity}.`) return true } From 6f27166724dc133ab8aee9d2275c5b5ff5f4a0da Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 03:29:24 +0000 Subject: [PATCH 44/70] docs(ci): name trusted fast-lane triggers Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202640330 --- .github/workflows/pr-website-auto-approve.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 26e279908d4..9e2c8ce5c6c 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -1,9 +1,9 @@ # Run the website package's configured delivery lane. # # Security boundary: -# - pull_request_target loads this workflow from the trusted default branch. -# - automation is checked out from the repository's protected default branch; -# pull request code is never executed. +# - pull_request_target, workflow_run, and status load this workflow from the +# default branch. Automation and policy are checked out from the protected +# default branch; pull request code is never executed. # - the script rejects other base branches and forks, re-fetches the live PR, # verifies the exact head SHA, requires every changed path to be under # apps/website/**, and verifies the PAT owner. From f8d2ff098c2662df6d7a11e89983d4d30231db8f Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:04:58 +0000 Subject: [PATCH 45/70] fix(ci): isolate fast-lane lifecycle by pull request Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911157 https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911161 --- .../workflows/pr-website-auto-approve.yaml | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 9e2c8ce5c6c..80e628fdaad 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -34,16 +34,12 @@ permissions: issues: read pull-requests: read -concurrency: - # One serialized compensation boundary is safer than SHA-keyed runs that can - # concurrently approve and withdraw the same pull request. The trial cohort - # is intentionally small, so global serialization is acceptable here. - group: website-fast-lane - cancel-in-progress: false - jobs: approve: if: github.event_name == 'pull_request_target' + concurrency: + group: website-fast-lane-${{ github.event.pull_request.number }} + cancel-in-progress: false environment: website-approval runs-on: ubuntu-latest timeout-minutes: 5 @@ -75,8 +71,43 @@ jobs: PR_NUMBER: ${{ github.event.pull_request.number }} run: node --experimental-strip-types scripts/cicd/fast-lane/run.ts - reconcile-after-check: + resolve-reconcile-pull-request: if: github.event_name == 'status' || (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request') + runs-on: ubuntu-latest + outputs: + pull-request-number: ${{ steps.pull-request.outputs.result }} + steps: + - name: Resolve the exact open pull request + id: pull-request + uses: actions/github-script@v9 + with: + result-encoding: string + script: | + const sha = context.payload.sha ?? context.payload.workflow_run?.head_sha + const { data: pulls } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + ...context.repo, + commit_sha: sha, + }) + const repository = `${context.repo.owner}/${context.repo.repo}` + const matches = pulls.filter((pull) => + pull.state === 'open' && + pull.head.sha === sha && + pull.head.repo?.full_name === repository && + pull.base.ref === context.payload.repository.default_branch && + pull.base.repo.full_name === repository + ) + if (matches.length !== 1) { + core.notice(`Expected one open same-repository pull request for ${sha}; found ${matches.length}.`) + return '' + } + return String(matches[0].number) + + reconcile-after-check: + needs: resolve-reconcile-pull-request + if: needs.resolve-reconcile-pull-request.outputs.pull-request-number != '' + concurrency: + group: website-fast-lane-${{ needs.resolve-reconcile-pull-request.outputs.pull-request-number }} + cancel-in-progress: false environment: website-approval runs-on: ubuntu-latest timeout-minutes: 5 From dd646a2dd307e3b6f24c4b08000d71a37a34740b Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:05:14 +0000 Subject: [PATCH 46/70] fix(ci): authorize label reruns by triggering actor Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911183 --- .github/workflows/pr-website-auto-approve.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 80e628fdaad..d44787a616d 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -64,7 +64,7 @@ jobs: FAST_LANE_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} FAST_LANE_BASE_REF: ${{ github.event.repository.default_branch }} FAST_LANE_EVENT_ACTION: ${{ github.event.action }} - FAST_LANE_EVENT_ACTOR: ${{ github.actor }} + FAST_LANE_EVENT_ACTOR: ${{ github.triggering_actor }} FAST_LANE_EVENT_LABEL: ${{ github.event.label.name }} GITHUB_REPOSITORY: ${{ github.repository }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} From 294038b27d181a6d49933c4d1d76896d0527a09a Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:05:40 +0000 Subject: [PATCH 47/70] fix(ci): revoke lane approval when its label is removed Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911169 --- scripts/cicd/fast-lane/policy.test.ts | 7 +++++++ scripts/cicd/fast-lane/policy.ts | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/cicd/fast-lane/policy.test.ts b/scripts/cicd/fast-lane/policy.test.ts index 02e90280113..a9a46570349 100644 --- a/scripts/cicd/fast-lane/policy.test.ts +++ b/scripts/cicd/fast-lane/policy.test.ts @@ -186,6 +186,13 @@ describe('approval policy', () => { eventName: 'workflow_run' }) ).toBeUndefined() + expect( + failure(eligiblePull({ user: { login: 'someone-else' }, labels: [] }), { + hasPolicyApprovalForHead: true, + eventName: 'pull_request_target', + eventAction: 'unlabeled' + }) + ).toContain('lacks a current authorized event') expect( failure(pull, { eventName: 'pull_request_target', diff --git a/scripts/cicd/fast-lane/policy.ts b/scripts/cicd/fast-lane/policy.ts index 548c80459a3..017a05a39aa 100644 --- a/scripts/cicd/fast-lane/policy.ts +++ b/scripts/cicd/fast-lane/policy.ts @@ -152,7 +152,9 @@ export function eligibilityFailure({ actor: eventActor, label: eventLabel }) - if (!trustedAuthor && !hasPolicyApprovalForHead && !currentLabelEvent) { + const retainedPolicyApproval = + hasPolicyApprovalForHead && hasLabel(pull, lane.approval.approvalLabel) + if (!trustedAuthor && !retainedPolicyApproval && !currentLabelEvent) { return `Skipped: @${author ?? 'unknown'} is not trusted and ${lane.approval.approvalLabel} lacks a current authorized event.` } if (hasLabel(pull, lane.approval.holdLabel)) { From 61ca138646c36fb6f0e9eecf253add3cbfa998db Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:06:16 +0000 Subject: [PATCH 48/70] fix(ci): retain locale source history for website checks Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911195 --- .github/workflows/ci-lint-format.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-lint-format.yaml b/.github/workflows/ci-lint-format.yaml index cb5d6dae8e6..ec17d1b6651 100644 --- a/.github/workflows/ci-lint-format.yaml +++ b/.github/workflows/ci-lint-format.yaml @@ -275,6 +275,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 + with: + fetch-depth: 0 + filter: blob:none - uses: ./.github/actions/setup-frontend - name: Verify website repository integrity run: | From 32fb3e6a7b8c62b25646a1aa95b970f7d5cc378a Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:07:02 +0000 Subject: [PATCH 49/70] test(ci): isolate fast-lane label authorization fields Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911243 --- scripts/cicd/fast-lane/policy.test.ts | 76 +++++++++++++++++++-------- 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/scripts/cicd/fast-lane/policy.test.ts b/scripts/cicd/fast-lane/policy.test.ts index a9a46570349..e5ad292cde4 100644 --- a/scripts/cicd/fast-lane/policy.test.ts +++ b/scripts/cicd/fast-lane/policy.test.ts @@ -153,26 +153,63 @@ describe('changed-path boundary', () => { }) describe('approval policy', () => { - it('accepts only the current trusted label event for a non-trusted author', () => { + const operatorLabelEvent = { + name: 'pull_request_target', + action: 'labeled', + actor: 'DrJKL', + label: 'website-fast-lane:approve' + } + + it.for([ + { + name: 'the trusted operator label event', + labels: ['website-fast-lane:approve'], + event: operatorLabelEvent, + expected: true + }, + { + name: 'an untrusted labeler', + labels: ['website-fast-lane:approve'], + event: { ...operatorLabelEvent, actor: 'someone-else' }, + expected: false + }, + { + name: 'a different label from the operator', + labels: ['website-fast-lane:approve'], + event: { ...operatorLabelEvent, label: 'area:website' }, + expected: false + }, + { + name: 'an unlabeled event', + labels: ['website-fast-lane:approve'], + event: { ...operatorLabelEvent, action: 'unlabeled' }, + expected: false + }, + { + name: 'a pull_request event', + labels: ['website-fast-lane:approve'], + event: { ...operatorLabelEvent, name: 'pull_request' }, + expected: false + }, + { + name: 'a label already removed from the pull request', + labels: [], + event: operatorLabelEvent, + expected: false + } + ])('authorizes $name: $expected', ({ labels, event, expected }) => { + const pull = eligiblePull({ + user: { login: 'someone-else' }, + labels: labels.map((name) => ({ name })) + }) + expect(hasAuthorizedApprovalLabel(pull, lane, event)).toBe(expected) + }) + + it('gates a non-trusted author on a current label event or a head approval', () => { const pull = eligiblePull({ user: { login: 'someone-else' }, labels: [{ name: 'website-fast-lane:approve' }] }) - expect( - hasAuthorizedApprovalLabel(pull, lane, { - name: 'pull_request_target', - action: 'labeled', - actor: 'DrJKL', - label: 'website-fast-lane:approve' - }) - ).toBe(true) - expect( - hasAuthorizedApprovalLabel(pull, lane, { - name: 'pull_request_target', - action: 'synchronize', - actor: 'someone-else' - }) - ).toBe(false) expect( failure(pull, { eventName: 'pull_request_target', @@ -186,13 +223,6 @@ describe('approval policy', () => { eventName: 'workflow_run' }) ).toBeUndefined() - expect( - failure(eligiblePull({ user: { login: 'someone-else' }, labels: [] }), { - hasPolicyApprovalForHead: true, - eventName: 'pull_request_target', - eventAction: 'unlabeled' - }) - ).toContain('lacks a current authorized event') expect( failure(pull, { eventName: 'pull_request_target', From 86fe45ce960d73c4f7370193e20e2788cb6cdaf9 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:07:44 +0000 Subject: [PATCH 50/70] test(ci): cover fail-safe hold compensation Addresses companion review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911249 https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911255 --- scripts/cicd/fast-lane/automation.test.ts | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index 735b3fde9a5..fde81d9f007 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -5,6 +5,7 @@ import { approveCurrentHead, armMergeAutomation, policyReviewFloor, + runFastLane, stopMergeAutomation } from './automation.ts' import type { @@ -110,6 +111,53 @@ describe('approval lifecycle', () => { ]) }) + it('withdraws an existing policy approval on hold even when merge teardown fails', async () => { + const dismissals: string[] = [] + const github: GitHubClient = { + async request(path, options = {}) { + if (path === 'https://api.github.com/user') { + return { login: 'christian-byrne' } + } + if (options.method === 'PUT') { + dismissals.push(path) + return null + } + return { + state: 'open', + node_id: 'PR_1', + user: { login: 'bertfy' }, + labels: [{ name: 'website-fast-lane:hold' }], + head: { + sha: headSha, + repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + }, + base: { + ref: 'main', + repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + } + } + }, + async paginate() { + return [ + { + id: 123, + state: 'APPROVED', + commit_id: headSha, + body: '[Package fast lane] Policy-only approval. Lane: website.', + submitted_at: '2026-10-06T10:00:00Z', + user: { login: 'christian-byrne' } + } + ] + }, + graphql: () => Promise.reject(new Error('merge state unavailable')) + } + + await expect(runFastLane(github, runtimeConfig(), vi.fn())).rejects.toThrow( + 'failed to complete fast-lane compensation' + ) + expect(dismissals).toEqual(['/pulls/42/reviews/123/dismissals']) + }) + it('does not create a second approval for the same identity and head', async () => { const summary = vi.fn() const github: GitHubClient = { From 520de83d0243a59f9ba324dd2547898c97dcf28e Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:08:22 +0000 Subject: [PATCH 51/70] test(ci): distinguish website-plus-docs routing Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911269 --- scripts/cicd/changes-filter.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/cicd/changes-filter.test.ts b/scripts/cicd/changes-filter.test.ts index 28892b3b527..8c2623dd1d7 100644 --- a/scripts/cicd/changes-filter.test.ts +++ b/scripts/cicd/changes-filter.test.ts @@ -186,12 +186,12 @@ it.for([ expected: true }, { - name: 'website plus root pull request', + name: 'website plus docs pull request', relevant: { - relevant: 'true', - unit: 'true', - e2e: 'true', - source: 'true', + relevant: 'false', + unit: 'false', + e2e: 'false', + source: 'false', outside_website: 'true' }, filter: { app_website: 'true', deps: 'false' }, From 1938eac8f9354dc46cb84e2d1ee1afc09f2a4cf5 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:09:00 +0000 Subject: [PATCH 52/70] fix(ci): serialize every production website deployment Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#pullrequestreview-5437462863 --- .github/workflows/ci-vercel-website-preview.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index b675a29e12f..fa7a8829d02 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -25,8 +25,8 @@ env: VERCEL_SCOPE: comfyui concurrency: - group: ${{ github.event_name == 'push' && 'website-production' || format('{0}-{1}', github.workflow, github.ref) }} - cancel-in-progress: ${{ github.event_name != 'push' }} + group: ${{ github.event_name != 'pull_request' && 'website-production' || format('{0}-{1}', github.workflow, github.ref) }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: deploy-preview: From 397cc56e6a4a311221b3d63380bc09b58b047a60 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:11:41 +0000 Subject: [PATCH 53/70] docs(ci): explain fast-lane label revocation Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911176 --- docs/architecture/package-delivery-lanes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/architecture/package-delivery-lanes.md b/docs/architecture/package-delivery-lanes.md index 2fe81d27f0d..9b45e02296a 100644 --- a/docs/architecture/package-delivery-lanes.md +++ b/docs/architecture/package-delivery-lanes.md @@ -42,8 +42,8 @@ These are implementation invariants, not package dials: - Every approval is tied to the exact head SHA. A new commit needs a new policy decision. - Approval-label provenance is bound to the current workflow event. A non-allowlisted author is eligible only on the exact-head `labeled` event from a trusted operator; later events continue - only when that same head already has the policy approval. Commit timestamps are never used as a - proxy for push order. + while that same head has the policy approval and the label remains applied. Removing the label + withdraws the approval. Commit timestamps are never used as a proxy for push order. - An active human change request blocks the lane. Comments and pending reviews do not count as change requests. - The credential's GitHub identity must match the identity declared in the policy, and it cannot From bd0fda66e65fe7d98a73d1a26c46ecb3d16f3eaa Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:11:58 +0000 Subject: [PATCH 54/70] docs(ci): scope fast-lane serialization per pull request Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911167 --- docs/architecture/package-delivery-lanes.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/architecture/package-delivery-lanes.md b/docs/architecture/package-delivery-lanes.md index 9b45e02296a..17ceaab73da 100644 --- a/docs/architecture/package-delivery-lanes.md +++ b/docs/architecture/package-delivery-lanes.md @@ -49,9 +49,9 @@ These are implementation invariants, not package dials: - The credential's GitHub identity must match the identity declared in the policy, and it cannot approve its own pull request. - If post-approval verification fails, the newly created approval is dismissed. -- Approval, queue, and compensation runs are serialized. Compensation attempts merge-state - teardown and every active policy-review dismissal independently so one API failure cannot skip - the other safety action. +- Approval, queue, and compensation runs are serialized per pull request. Compensation attempts + merge-state teardown and every active policy-review dismissal independently so one API failure + cannot skip the other safety action. - The lane only disables auto-merge or queue state that its own identity created after its policy approval. It does not undo another person's merge decision. From 8b2be5250b27bd02f0fe6fcaf8dca9343d3cc1e0 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 7 Oct 2026 07:12:20 +0000 Subject: [PATCH 55/70] fix(ci): report compensation summaries only on success Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#discussion_r4202911206 --- scripts/cicd/fast-lane/automation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 9b578cb52cb..0313345aa83 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -288,13 +288,13 @@ async function stop( errors.push(error) } } - summary(message) if (errors.length > 0) { throw new AggregateError( errors, 'failed to complete fast-lane compensation' ) } + summary(message) } async function resolvePullRequestNumber( From 1a530932ea0feb23d07971c6cbe6bf9508b1e326 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 05:04:15 +0000 Subject: [PATCH 56/70] refactor(ci): resolve every fast-lane event to one per-PR job - Resolve the pull request once and pass it to a single fast-lane job keyed on that pull request's concurrency group; drop the TypeScript resolver - Move change-request and self-approval checks into eligibilityFailure and let a run whose head advanced change nothing - Use one compensation path after approval, return quietly when the head advances before arming, and parse the label event once at ingress - Exercise runFastLane against an in-memory GitHub double Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- .../workflows/pr-website-auto-approve.yaml | 74 +- scripts/cicd/changes-filter.test.ts | 28 + scripts/cicd/fast-lane/automation.test.ts | 693 +++++++++--------- scripts/cicd/fast-lane/automation.ts | 419 +++-------- scripts/cicd/fast-lane/config.test.ts | 128 ++++ scripts/cicd/fast-lane/config.ts | 63 +- scripts/cicd/fast-lane/github.test.ts | 53 ++ scripts/cicd/fast-lane/github.ts | 41 +- scripts/cicd/fast-lane/policy.test.ts | 488 ++++++------ scripts/cicd/fast-lane/policy.ts | 192 +++-- scripts/cicd/fast-lane/run.ts | 13 +- scripts/cicd/fast-lane/types.ts | 26 +- 12 files changed, 1138 insertions(+), 1080 deletions(-) create mode 100644 scripts/cicd/fast-lane/config.test.ts create mode 100644 scripts/cicd/fast-lane/github.test.ts diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index d44787a616d..8ebc45b8910 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -22,8 +22,6 @@ on: - unlabeled workflow_run: workflows: - - 'CI: Lint Format' - - 'CI: Tests Unit' - 'CI: Tests E2E' - 'CI: Website E2E' types: [completed] @@ -31,82 +29,49 @@ on: permissions: contents: read - issues: read pull-requests: read jobs: - approve: - if: github.event_name == 'pull_request_target' - concurrency: - group: website-fast-lane-${{ github.event.pull_request.number }} - cancel-in-progress: false - environment: website-approval + resolve: + if: github.event_name != 'workflow_run' || github.event.workflow_run.event == 'pull_request' runs-on: ubuntu-latest timeout-minutes: 5 - steps: - - name: Checkout trusted base automation - uses: actions/checkout@v7 - with: - ref: refs/heads/${{ github.event.repository.default_branch }} - persist-credentials: false - sparse-checkout: | - .nvmrc - .github/fast-lanes/website.json - scripts/cicd/fast-lane - - - uses: actions/setup-node@v6 - with: - node-version-file: .nvmrc - - - name: Approve and queue eligible website pull request - env: - FAST_LANE_CONFIG: .github/fast-lanes/website.json - FAST_LANE_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} - FAST_LANE_BASE_REF: ${{ github.event.repository.default_branch }} - FAST_LANE_EVENT_ACTION: ${{ github.event.action }} - FAST_LANE_EVENT_ACTOR: ${{ github.triggering_actor }} - FAST_LANE_EVENT_LABEL: ${{ github.event.label.name }} - GITHUB_REPOSITORY: ${{ github.repository }} - PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} - PR_NUMBER: ${{ github.event.pull_request.number }} - run: node --experimental-strip-types scripts/cicd/fast-lane/run.ts - - resolve-reconcile-pull-request: - if: github.event_name == 'status' || (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request') - runs-on: ubuntu-latest outputs: pull-request-number: ${{ steps.pull-request.outputs.result }} steps: - - name: Resolve the exact open pull request + - name: Resolve the pull request for this event id: pull-request uses: actions/github-script@v9 with: result-encoding: string script: | + if (context.payload.pull_request) { + return String(context.payload.pull_request.number) + } const sha = context.payload.sha ?? context.payload.workflow_run?.head_sha const { data: pulls } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ ...context.repo, commit_sha: sha, }) - const repository = `${context.repo.owner}/${context.repo.repo}` + const repository = `${context.repo.owner}/${context.repo.repo}`.toLowerCase() const matches = pulls.filter((pull) => pull.state === 'open' && pull.head.sha === sha && - pull.head.repo?.full_name === repository && + pull.head.repo?.full_name.toLowerCase() === repository && pull.base.ref === context.payload.repository.default_branch && - pull.base.repo.full_name === repository + pull.base.repo.full_name.toLowerCase() === repository ) if (matches.length !== 1) { - core.notice(`Expected one open same-repository pull request for ${sha}; found ${matches.length}.`) + core.info(`Expected one open same-repository pull request for ${sha}; found ${matches.length}.`) return '' } return String(matches[0].number) - reconcile-after-check: - needs: resolve-reconcile-pull-request - if: needs.resolve-reconcile-pull-request.outputs.pull-request-number != '' + fast-lane: + needs: resolve + if: needs.resolve.outputs.pull-request-number != '' concurrency: - group: website-fast-lane-${{ needs.resolve-reconcile-pull-request.outputs.pull-request-number }} + group: website-fast-lane-${{ needs.resolve.outputs.pull-request-number }} cancel-in-progress: false environment: website-approval runs-on: ubuntu-latest @@ -126,14 +91,15 @@ jobs: with: node-version-file: .nvmrc - - name: Reconcile approval and native queue state + - name: Approve, queue, or withdraw the website pull request env: FAST_LANE_CONFIG: .github/fast-lanes/website.json FAST_LANE_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} - FAST_LANE_BASE_REF: ${{ github.event.repository.default_branch }} + FAST_LANE_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} FAST_LANE_EVENT_ACTION: ${{ github.event.action }} - FAST_LANE_EVENT_ACTOR: ${{ github.actor }} + FAST_LANE_EVENT_ACTOR: ${{ github.triggering_actor }} FAST_LANE_EVENT_LABEL: ${{ github.event.label.name }} GITHUB_REPOSITORY: ${{ github.repository }} - PR_HEAD_SHA: ${{ github.event.sha || github.event.workflow_run.head_sha }} - run: node --experimental-strip-types scripts/cicd/fast-lane/run.ts + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.sha || github.event.workflow_run.head_sha }} + PR_NUMBER: ${{ needs.resolve.outputs.pull-request-number }} + run: node scripts/cicd/fast-lane/run.ts diff --git a/scripts/cicd/changes-filter.test.ts b/scripts/cicd/changes-filter.test.ts index 8c2623dd1d7..cbb84eebe18 100644 --- a/scripts/cicd/changes-filter.test.ts +++ b/scripts/cicd/changes-filter.test.ts @@ -202,3 +202,31 @@ it.for([ selectChecks('pull_request', relevant, filter)['website-only-changes'] ).toBe(expected) }) + +it('classifies website-only paths with the fast-lane path policy', () => { + const relevantFilters = z + .object({ + runs: z.object({ + steps: z.array( + z.object({ + id: z.string(), + with: z.object({ filters: z.string() }).optional() + }) + ) + }) + }) + .parse( + parse(readFileSync('.github/actions/changes-filter/action.yaml', 'utf8')) + ) + .runs.steps.find((step) => step.id === 'relevant')?.with?.filters + assert.exists(relevantFilters) + const lane = z + .object({ pathPrefixes: z.array(z.string()) }) + .parse(JSON.parse(readFileSync('.github/fast-lanes/website.json', 'utf8'))) + + expect( + z + .object({ outside_website: z.array(z.string()) }) + .parse(parse(relevantFilters)).outside_website + ).toEqual(['**', ...lane.pathPrefixes.map((prefix) => `!${prefix}**`)]) +}) diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index fde81d9f007..742c2c97254 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -1,28 +1,39 @@ import { describe, expect, it, vi } from 'vitest' -import { - activePolicyApprovals, - approveCurrentHead, - armMergeAutomation, - policyReviewFloor, - runFastLane, - stopMergeAutomation -} from './automation.ts' +import { runFastLane, stopMergeAutomation } from './automation.ts' +import { POLICY_REVIEW_PREFIX } from './policy.ts' import type { GitHubClient, + MergeAutomationState, PullRequest, - ResolvedRuntimeConfig + PullRequestFile, + PullRequestReview, + RuntimeConfig } from './types.ts' const headSha = '0123456789abcdef0123456789abcdef01234567' +const policyBody = `${POLICY_REVIEW_PREFIX} Lane: website.` +const floorTime = '2026-10-06T10:00:00Z' +const afterFloor = '2026-10-06T10:01:00Z' +const beforeFloor = '2026-10-06T09:59:00Z' + +type Write = [operation: string, payload: unknown] + +interface FakeOptions { + viewer?: string + pull?: Partial + reviews?: PullRequestReview[] + files?: PullRequestFile[] + mergeState?: Omit + failingMutations?: string[] + failDismissals?: boolean +} -function runtimeConfig(): ResolvedRuntimeConfig { +function runtimeConfig(overrides: Partial = {}): RuntimeConfig { return { - token: 'not-used-by-tests', repository: 'Comfy-Org/ComfyUI_frontend', pullRequestNumber: 42, eventHeadSha: headSha, - eventName: 'pull_request_target', defaultBranch: 'main', lane: { schemaVersion: 1, @@ -35,378 +46,390 @@ function runtimeConfig(): ResolvedRuntimeConfig { trustedLabelers: ['drjkl'], holdLabel: 'website-fast-lane:hold' }, - merge: { mode: 'automatic', method: 'SQUASH' } - } + merge: { mode: 'automatic', method: 'MERGE' } + }, + ...overrides } } -function pull(): PullRequest { - return { node_id: 'PR_1', head: { sha: headSha } } +function policyApproval( + id: number, + commitId = headSha, + submittedAt = floorTime +): PullRequestReview { + return { + id, + state: 'APPROVED', + commit_id: commitId, + body: policyBody, + submitted_at: submittedAt, + user: { login: 'christian-byrne' } + } } -function unusedRequest(): Promise { - return Promise.reject(new Error('request was not expected')) +function fakeGitHub(options: FakeOptions = {}) { + const writes: Write[] = [] + const pull: PullRequest = { + state: 'open', + draft: false, + node_id: 'PR_1', + changed_files: options.files?.length ?? 1, + user: { login: 'bertfy' }, + labels: [], + head: { sha: headSha, repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } }, + base: { ref: 'main', repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } }, + ...options.pull + } + const reviews = [...(options.reviews ?? [])] + const files = options.files ?? [ + { filename: 'apps/website/src/pages/index.astro' } + ] + + const github: GitHubClient = { + async request(path, init = {}) { + if (path === 'https://api.github.com/user') { + return { login: options.viewer ?? 'christian-byrne' } + } + if (init.method === 'POST') { + const body: PullRequestReview = JSON.parse(String(init.body)) + writes.push([`POST ${path}`, body]) + const created = { + ...policyApproval(900, body.commit_id, afterFloor), + body: body.body + } + reviews.push(created) + return created + } + if (init.method === 'PUT') { + writes.push([`PUT ${path}`, JSON.parse(String(init.body))]) + if (options.failDismissals) throw new Error('dismissal rejected') + return null + } + return pull + }, + async paginate(path) { + return path.endsWith('/files') ? files : reviews + }, + async graphql(query, variables) { + const operation = /(?:query|mutation) (\w+)/.exec(query)?.[1] ?? '' + if (operation === 'PackageFastLaneMergeState') { + return { + node: { + id: 'PR_1', + headRefOid: pull.head?.sha, + ...options.mergeState + } + } + } + writes.push([operation, variables]) + if (options.failingMutations?.includes(operation)) { + throw new Error(`${operation} failed`) + } + return {} + } + } + return { github, writes } } -function unusedPaginate(): Promise { - return Promise.reject(new Error('pagination was not expected')) +const approvalPost: Write = [ + 'POST /pulls/42/reviews', + expect.objectContaining({ event: 'APPROVE', commit_id: headSha }) +] +const enableAutoMerge: Write = [ + 'PackageFastLaneEnableAutoMerge', + { pullRequestId: 'PR_1', expectedHeadOid: headSha, mergeMethod: 'MERGE' } +] +const disableAutoMerge: Write = [ + 'PackageFastLaneDisableAutoMerge', + { pullRequestId: 'PR_1' } +] +const dequeue: Write = ['PackageFastLaneDequeue', { pullRequestId: 'PR_1' }] + +function dismissal(id: number): Write { + return [ + `PUT /pulls/42/reviews/${id}/dismissals`, + { message: expect.stringContaining('Fast-lane approval withdrawn') } + ] } -describe('approval lifecycle', () => { - it('selects active policy approvals across current and stale heads', () => { - const policyBody = - '[Package fast lane] Policy-only approval. Lane: website.' - expect( - activePolicyApprovals( - [ - { - id: 1, - state: 'APPROVED', - commit_id: 'old-head', - body: policyBody, - user: { login: 'christian-byrne' } - }, - { - id: 2, - state: 'APPROVED', - commit_id: headSha, - body: policyBody, - user: { login: 'christian-byrne' } - }, - { - id: 3, - state: 'DISMISSED', - body: policyBody, - user: { login: 'christian-byrne' } - } - ], - 'christian-byrne' - ).map((review) => review.id) - ).toEqual([1, 2]) - }) - - it('withdraws a new approval when post-approval verification fails', async () => { - const verificationError = new Error('verification unavailable') - const calls: { path: string; method: string }[] = [] - const github: GitHubClient = { - async request(path, options = {}) { - calls.push({ path, method: options.method ?? 'GET' }) - if (options.method === 'POST') return { id: 123 } - if (options.method === 'PUT') return null - throw verificationError - }, - async paginate() { - throw new Error('pagination should not follow a failed pull request') - }, - graphql: unusedRequest - } - - await expect( - approveCurrentHead(github, runtimeConfig(), [], vi.fn()) - ).rejects.toBe(verificationError) - expect(calls).toEqual([ - { path: '/pulls/42/reviews', method: 'POST' }, - { path: '/pulls/42', method: 'GET' }, - { path: '/pulls/42/reviews/123/dismissals', method: 'PUT' } - ]) - }) +const armedByLane = { + autoMergeRequest: { + enabledAt: afterFloor, + enabledBy: { login: 'christian-byrne' } + } +} - it('withdraws an existing policy approval on hold even when merge teardown fails', async () => { - const dismissals: string[] = [] - const github: GitHubClient = { - async request(path, options = {}) { - if (path === 'https://api.github.com/user') { - return { login: 'christian-byrne' } - } - if (options.method === 'PUT') { - dismissals.push(path) - return null - } - return { - state: 'open', - node_id: 'PR_1', - user: { login: 'bertfy' }, - labels: [{ name: 'website-fast-lane:hold' }], - head: { - sha: headSha, - repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } - }, - base: { - ref: 'main', - repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } - } +describe('runFastLane', () => { + it.for([ + { + name: 'a trusted author', + options: {}, + config: {}, + writes: [approvalPost, enableAutoMerge] + }, + { + name: 'a non-allowlisted author on the operator label event', + options: { + pull: { + user: { login: 'someone-else' }, + labels: [{ name: 'website-fast-lane:approve' }] } }, - async paginate() { - return [ - { - id: 123, - state: 'APPROVED', - commit_id: headSha, - body: '[Package fast lane] Policy-only approval. Lane: website.', - submitted_at: '2026-10-06T10:00:00Z', - user: { login: 'christian-byrne' } - } + config: { + labelEvent: { actor: 'drjkl', label: 'website-fast-lane:approve' } + }, + writes: [approvalPost, enableAutoMerge] + }, + { + name: 'a head that already has the policy approval', + options: { reviews: [policyApproval(1)] }, + config: {}, + writes: [enableAutoMerge] + }, + { + name: 'a clean head', + options: { mergeState: { mergeStateStatus: 'CLEAN' } }, + config: {}, + writes: [ + approvalPost, + [ + 'PackageFastLaneEnqueue', + { pullRequestId: 'PR_1', expectedHeadOid: headSha } ] + ] + }, + { + name: 'a manual lane', + options: {}, + config: { + lane: { + ...runtimeConfig().lane, + merge: { mode: 'manual', method: 'MERGE' } + } }, - graphql: () => Promise.reject(new Error('merge state unavailable')) + writes: [approvalPost] + }, + { + name: 'a head that advanced before arming', + options: { mergeState: { headRefOid: 'f'.repeat(40) } }, + config: {}, + writes: [approvalPost] } + ] satisfies { + name: string + options: FakeOptions + config: Partial + writes: Write[] + }[])('approves and arms $name', async ({ options, config, writes }) => { + const fake = fakeGitHub(options) - await expect(runFastLane(github, runtimeConfig(), vi.fn())).rejects.toThrow( - 'failed to complete fast-lane compensation' - ) - expect(dismissals).toEqual(['/pulls/42/reviews/123/dismissals']) - }) - - it('does not create a second approval for the same identity and head', async () => { - const summary = vi.fn() - const github: GitHubClient = { - request: unusedRequest, - paginate: unusedPaginate, - graphql: unusedRequest - } - await expect( - approveCurrentHead( - github, - runtimeConfig(), - [ - { - state: 'APPROVED', - commit_id: headSha, - body: '[Package fast lane] Policy-only approval. Lane: website.', - user: { login: 'christian-byrne' } - } - ], - summary - ) - ).resolves.toBe(true) - expect(summary).toHaveBeenCalledWith( - `Already approved ${headSha.slice(0, 12)} as @christian-byrne.` - ) - }) -}) + await runFastLane(fake.github, runtimeConfig(config), vi.fn()) -describe('merge automation', () => { - it('uses the earliest policy review as the automation ownership floor', () => { - expect( - policyReviewFloor( - [ - { - state: 'APPROVED', - body: '[Package fast lane] Policy-only approval. Later head.', - submitted_at: '2026-10-06T10:03:00Z', - user: { login: 'christian-byrne' } - }, - { - state: 'DISMISSED', - body: '[Package fast lane] Policy-only approval. Earlier head.', - submitted_at: '2026-10-06T10:00:00Z', - user: { login: 'christian-byrne' } - } - ], - 'christian-byrne' - )?.submitted_at - ).toBe('2026-10-06T10:00:00Z') + expect(fake.writes).toEqual(writes) }) - it('arms native auto-merge for the exact head and configured method', async () => { - const graphql = vi - .fn() - .mockResolvedValueOnce({ - node: { - id: 'PR_1', - headRefOid: headSha, - mergeStateStatus: 'BLOCKED', - autoMergeRequest: null, - mergeQueueEntry: null + it.for([ + { + name: 'a mixed-path change', + options: { + files: [ + { filename: 'apps/website/src/pages/index.astro' }, + { filename: 'src/main.ts' } + ] + } + }, + { + name: 'a truncated changed-file list', + options: { pull: { changed_files: 2 } } + }, + { + name: 'an active human change request', + options: { + reviews: [ + { state: 'CHANGES_REQUESTED', user: { login: 'DrJKL', type: 'User' } } + ] + } + }, + { + name: 'a pull request authored by the approval identity', + options: { pull: { user: { login: 'christian-byrne' } } } + }, + { + name: 'a non-allowlisted author whose labeled run was replaced', + options: { + pull: { + user: { login: 'someone-else' }, + labels: [{ name: 'website-fast-lane:approve' }] } - }) - .mockResolvedValueOnce({ - enablePullRequestAutoMerge: { clientMutationId: null } - }) - const github: GitHubClient = { - request: unusedRequest, - paginate: unusedPaginate, - graphql + } + }, + { + name: 'a run for a head that has since advanced', + options: { + pull: { head: { sha: 'f'.repeat(40) } }, + reviews: [policyApproval(1, 'f'.repeat(40))], + mergeState: armedByLane + } } + ] satisfies { name: string; options: FakeOptions }[])( + 'writes nothing for $name', + async ({ options }) => { + const fake = fakeGitHub(options) - await armMergeAutomation(github, pull(), headSha, runtimeConfig(), vi.fn()) - - expect(graphql).toHaveBeenCalledTimes(2) - expect(graphql.mock.calls[1][0]).toContain('enablePullRequestAutoMerge') - expect(graphql.mock.calls[1][1]).toEqual({ - pullRequestId: 'PR_1', - expectedHeadOid: headSha, - mergeMethod: 'SQUASH' - }) - }) + await runFastLane(fake.github, runtimeConfig(), vi.fn()) - it('enqueues a clean exact head without queue jumping', async () => { - const graphql = vi - .fn() - .mockResolvedValueOnce({ - node: { - id: 'PR_1', - headRefOid: headSha, - mergeStateStatus: 'CLEAN', - autoMergeRequest: null, - mergeQueueEntry: null - } - }) - .mockResolvedValueOnce({ - enqueuePullRequest: { clientMutationId: null } - }) - const github: GitHubClient = { - request: unusedRequest, - paginate: unusedPaginate, - graphql + expect(fake.writes).toEqual([]) } + ) - await armMergeAutomation(github, pull(), headSha, runtimeConfig(), vi.fn()) - - expect(graphql.mock.calls[1][0]).toContain('jump: false') - expect(graphql.mock.calls[1][1]).toEqual({ - pullRequestId: 'PR_1', - expectedHeadOid: headSha + it('withdraws approval and merge state when the approval label is removed', async () => { + const fake = fakeGitHub({ + pull: { user: { login: 'someone-else' }, labels: [] }, + reviews: [policyApproval(1)], + mergeState: armedByLane }) + + await runFastLane(fake.github, runtimeConfig(), vi.fn()) + + expect(fake.writes).toEqual([disableAutoMerge, dismissal(1)]) }) - it('does not arm a head that advanced after policy approval', async () => { - const advancedSha = 'abcdef0123456789abcdef0123456789abcdef01' - const graphql = vi.fn().mockResolvedValueOnce({ - node: { - id: 'PR_1', - headRefOid: advancedSha, - mergeStateStatus: 'CLEAN', - autoMergeRequest: null, - mergeQueueEntry: null - } - }) - const github: GitHubClient = { - request: unusedRequest, - paginate: unusedPaginate, - graphql - } + it('rejects a token that belongs to another account before writing', async () => { + const fake = fakeGitHub({ viewer: 'someone-else' }) await expect( - armMergeAutomation( - github, - { node_id: 'PR_1', head: { sha: advancedSha } }, - headSha, - runtimeConfig(), - vi.fn() - ) - ).rejects.toThrow('head advanced') - expect(graphql).toHaveBeenCalledTimes(1) + runFastLane(fake.github, runtimeConfig(), vi.fn()) + ).rejects.toThrow('FAST_LANE_TOKEN belongs to someone-else') + expect(fake.writes).toEqual([]) }) - it('does not mutate merge state in a manual lane', async () => { - const config = runtimeConfig() - config.lane.merge.mode = 'manual' - const graphql = vi.fn() - const github: GitHubClient = { - request: unusedRequest, - paginate: unusedPaginate, - graphql - } - - await armMergeAutomation(github, pull(), headSha, config, vi.fn()) + it('withdraws every policy approval on hold even when merge teardown fails', async () => { + const fake = fakeGitHub({ + pull: { labels: [{ name: 'website-fast-lane:hold' }] }, + reviews: [policyApproval(122, 'old-head'), policyApproval(123)], + mergeState: armedByLane, + failingMutations: ['PackageFastLaneDisableAutoMerge'] + }) + const summary = vi.fn() - expect(graphql).not.toHaveBeenCalled() + await expect( + runFastLane(fake.github, runtimeConfig(), summary) + ).rejects.toThrow('failed to complete fast-lane compensation') + expect(fake.writes).toEqual([ + disableAutoMerge, + dismissal(122), + dismissal(123) + ]) + expect(summary).not.toHaveBeenCalled() }) - it('withdraws only merge state created by the policy identity after its review', async () => { - const graphql = vi - .fn() - .mockResolvedValueOnce({ - node: { - id: 'PR_1', - headRefOid: headSha, - autoMergeRequest: { - enabledAt: '2026-10-06T10:01:00Z', - enabledBy: { login: 'christian-byrne' } - }, - mergeQueueEntry: { - id: 'MQE_1', - enqueuedAt: '2026-10-06T10:02:00Z', - enqueuer: { login: 'christian-byrne' } - } - } - }) - .mockResolvedValue({}) - const github: GitHubClient = { - request: unusedRequest, - paginate: unusedPaginate, - graphql - } - - await stopMergeAutomation(github, pull(), 'christian-byrne', { - submitted_at: '2026-10-06T10:00:00Z' + it('withdraws its approval once when arming fails', async () => { + const fake = fakeGitHub({ + failingMutations: ['PackageFastLaneEnableAutoMerge'] }) - expect(graphql).toHaveBeenCalledTimes(3) - expect(graphql.mock.calls[1][0]).toContain('dequeuePullRequest') - expect(graphql.mock.calls[1][1]).toEqual({ pullRequestId: 'PR_1' }) - expect(graphql.mock.calls[2][0]).toContain('disablePullRequestAutoMerge') + await expect( + runFastLane(fake.github, runtimeConfig(), vi.fn()) + ).rejects.toThrow('PackageFastLaneEnableAutoMerge failed') + expect(fake.writes).toEqual([approvalPost, enableAutoMerge, dismissal(900)]) }) +}) - it('leaves pre-existing merge state alone', async () => { - const graphql = vi.fn().mockResolvedValueOnce({ - node: { - id: 'PR_1', - headRefOid: headSha, +describe('stopMergeAutomation', () => { + it.for([ + { + name: 'queue entry and auto-merge created by the lane after its floor', + mergeState: { + ...armedByLane, + mergeQueueEntry: { + id: 'MQE_1', + enqueuedAt: afterFloor, + enqueuer: { login: 'christian-byrne' } + } + }, + writes: [dequeue, disableAutoMerge] + }, + { + name: 'a queue entry by another account', + mergeState: { + ...armedByLane, + mergeQueueEntry: { + id: 'MQE_1', + enqueuedAt: afterFloor, + enqueuer: { login: 'drjkl' } + } + }, + writes: [disableAutoMerge] + }, + { + name: 'a queue entry from before the floor', + mergeState: { + mergeQueueEntry: { + id: 'MQE_1', + enqueuedAt: beforeFloor, + enqueuer: { login: 'christian-byrne' } + } + }, + writes: [] + }, + { + name: 'auto-merge enabled by another account', + mergeState: { + autoMergeRequest: { + enabledAt: afterFloor, + enabledBy: { login: 'drjkl' } + } + }, + writes: [] + }, + { + name: 'auto-merge enabled before the floor', + mergeState: { autoMergeRequest: { - enabledAt: '2026-10-06T09:59:00Z', + enabledAt: beforeFloor, enabledBy: { login: 'christian-byrne' } - }, - mergeQueueEntry: null - } - }) - const github: GitHubClient = { - request: unusedRequest, - paginate: unusedPaginate, - graphql + } + }, + writes: [] } + ] satisfies { + name: string + mergeState: Omit + writes: Write[] + }[])( + 'withdraws only lane-owned state for $name', + async ({ mergeState, writes }) => { + const fake = fakeGitHub({ mergeState }) + + await stopMergeAutomation( + fake.github, + { node_id: 'PR_1' }, + 'christian-byrne', + { submitted_at: floorTime } + ) - await stopMergeAutomation(github, pull(), 'christian-byrne', { - submitted_at: '2026-10-06T10:00:00Z' - }) - - expect(graphql).toHaveBeenCalledTimes(1) - }) + expect(fake.writes).toEqual(writes) + } + ) it('still disables auto-merge when dequeue fails', async () => { - const graphql = vi - .fn() - .mockResolvedValueOnce({ - node: { - id: 'PR_1', - headRefOid: headSha, - autoMergeRequest: { - enabledAt: '2026-10-06T10:01:00Z', - enabledBy: { login: 'christian-byrne' } - }, - mergeQueueEntry: { - id: 'MQE_1', - enqueuedAt: '2026-10-06T10:02:00Z', - enqueuer: { login: 'christian-byrne' } - } + const fake = fakeGitHub({ + mergeState: { + ...armedByLane, + mergeQueueEntry: { + id: 'MQE_1', + enqueuedAt: afterFloor, + enqueuer: { login: 'christian-byrne' } } - }) - .mockRejectedValueOnce(new Error('already dequeued')) - .mockResolvedValueOnce({}) - const github: GitHubClient = { - request: unusedRequest, - paginate: unusedPaginate, - graphql - } + }, + failingMutations: ['PackageFastLaneDequeue'] + }) await expect( - stopMergeAutomation(github, pull(), 'christian-byrne', { - submitted_at: '2026-10-06T10:00:00Z' + stopMergeAutomation(fake.github, { node_id: 'PR_1' }, 'christian-byrne', { + submitted_at: floorTime }) ).rejects.toThrow('failed to stop all merge automation') - expect(graphql).toHaveBeenCalledTimes(3) - expect(graphql.mock.calls[2][0]).toContain('disablePullRequestAutoMerge') + expect(fake.writes).toEqual([dequeue, disableAutoMerge]) }) }) diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index 0313345aa83..a71f7824bdd 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -1,12 +1,11 @@ +import { isRecord } from './github.ts' import { - approvalForHead, - changedPaths, + activePolicyApprovals, eligibilityFailure, - hasActiveHumanChangeRequest, - hasCompleteChangedFileList, - isInsideLane, - isSameRepository, - targetsDefaultBranch + isPolicyApprovalForHead, + pathFailure, + policyReviewFloor, + POLICY_REVIEW_PREFIX } from './policy.ts' import type { GitHubClient, @@ -14,12 +13,15 @@ import type { PullRequest, PullRequestFile, PullRequestReview, - ResolvedRuntimeConfig, RuntimeConfig, + SubmittedReview, Summary } from './types.ts' -const POLICY_REVIEW_PREFIX = '[Package fast lane] Policy-only approval.' +interface PullState { + pull: PullRequest + reviews: PullRequestReview[] +} const MERGE_AUTOMATION_STATE = ` query PackageFastLaneMergeState($pullRequestId: ID!) { @@ -40,37 +42,30 @@ const MERGE_AUTOMATION_STATE = ` } ` -function asPullRequest(value: unknown): PullRequest { - if (!value || typeof value !== 'object' || Array.isArray(value)) { - throw new Error('GitHub did not return a pull request') - } - return value -} - -function asReviews(value: unknown[]): PullRequestReview[] { - return value as PullRequestReview[] +function shortSha(sha: string): string { + return sha.slice(0, 12) } -function asFiles(value: unknown[]): PullRequestFile[] { - return value as PullRequestFile[] +function asPullRequest(value: unknown): PullRequest { + if (!isRecord(value)) throw new Error('GitHub did not return a pull request') + return value } function mergeState(value: unknown): MergeAutomationState { - if (!value || typeof value !== 'object' || Array.isArray(value)) { + const node = isRecord(value) + ? (value as { node?: MergeAutomationState }).node + : undefined + if (!node?.id) { throw new Error('GitHub did not return the pull request merge state') } - const data = value as { node?: MergeAutomationState } - if (!data.node?.id) { - throw new Error('GitHub did not return the pull request merge state') - } - return data.node + return node } function actorMatches( actor: { login?: string } | undefined, - expectedLogin: string + identity: string ): boolean { - return actor?.login?.toLowerCase() === expectedLogin.toLowerCase() + return actor?.login?.toLowerCase() === identity } function atOrAfter(value: string | undefined, floor: string): boolean { @@ -91,9 +86,9 @@ export async function stopMergeAutomation( github: GitHubClient, pull: PullRequest, identity: string, - policyReview: PullRequestReview | undefined + floor: SubmittedReview | undefined ): Promise { - if (!policyReview?.submitted_at) return + if (!floor) return if (!pull.node_id) { throw new Error('the pull request node id is required to stop automation') } @@ -104,7 +99,7 @@ export async function stopMergeAutomation( if ( entry?.id && actorMatches(entry.enqueuer, identity) && - atOrAfter(entry.enqueuedAt, policyReview.submitted_at) + atOrAfter(entry.enqueuedAt, floor.submitted_at) ) { try { await github.graphql( @@ -122,7 +117,7 @@ export async function stopMergeAutomation( if ( autoMerge && actorMatches(autoMerge.enabledBy, identity) && - atOrAfter(autoMerge.enabledAt, policyReview.submitted_at) + atOrAfter(autoMerge.enabledAt, floor.submitted_at) ) { try { await github.graphql( @@ -145,24 +140,22 @@ export async function stopMergeAutomation( export async function armMergeAutomation( github: GitHubClient, pull: PullRequest, - approvedHeadSha: string, config: RuntimeConfig, summary: Summary ): Promise { if (config.lane.merge.mode === 'manual') return - if (!pull.node_id || !pull.head?.sha) { - throw new Error('the pull request node id and head are required to merge') + if (!pull.node_id) { + throw new Error('the pull request node id is required to merge') } + const headSha = config.eventHeadSha const state = await readMergeState(github, pull.node_id) - if ( - pull.head.sha !== approvedHeadSha || - state.headRefOid !== approvedHeadSha - ) { - throw new Error('the pull request head advanced before merge automation') + if (state.headRefOid !== headSha) { + summary('Skipped: the pull request head advanced before merge automation.') + return } if (state.mergeQueueEntry) { - summary(`Already queued ${pull.head.sha.slice(0, 12)}.`) + summary(`Already queued ${shortSha(headSha)}.`) return } if (state.mergeStateStatus === 'CLEAN') { @@ -177,13 +170,13 @@ export async function armMergeAutomation( jump: false }) { clientMutationId } }`, - { pullRequestId: pull.node_id, expectedHeadOid: pull.head.sha } + { pullRequestId: pull.node_id, expectedHeadOid: headSha } ) - summary(`Entered the native merge queue for ${pull.head.sha.slice(0, 12)}.`) + summary(`Entered the native merge queue for ${shortSha(headSha)}.`) return } if (state.autoMergeRequest) { - summary(`Auto-merge already armed for ${pull.head.sha.slice(0, 12)}.`) + summary(`Auto-merge already armed for ${shortSha(headSha)}.`) return } @@ -201,67 +194,37 @@ export async function armMergeAutomation( }`, { pullRequestId: pull.node_id, - expectedHeadOid: pull.head.sha, + expectedHeadOid: headSha, mergeMethod: config.lane.merge.method } ) - summary(`Armed native auto-merge for ${pull.head.sha.slice(0, 12)}.`) -} - -export function policyReviewFloor( - reviews: PullRequestReview[], - identity: string -): PullRequestReview | undefined { - return reviews - .filter( - (review) => - review.user?.login?.toLowerCase() === identity.toLowerCase() && - review.body?.startsWith(POLICY_REVIEW_PREFIX) && - review.submitted_at !== undefined && - !Number.isNaN(Date.parse(review.submitted_at)) - ) - .sort( - (left, right) => - Date.parse(left.submitted_at ?? '') - - Date.parse(right.submitted_at ?? '') - )[0] + summary(`Armed native auto-merge for ${shortSha(headSha)}.`) } async function dismissApproval( github: GitHubClient, pullRequestNumber: number, - review: PullRequestReview | undefined, + review: PullRequestReview, reason: string ): Promise { - if (!review?.id) return + if (!review.id) return await github.request( `/pulls/${pullRequestNumber}/reviews/${review.id}/dismissals`, { method: 'PUT', headers: { 'content-type': 'application/json' }, - body: JSON.stringify({ message: reason }) + body: JSON.stringify({ + message: `Fast-lane approval withdrawn: ${reason}` + }) } ) } -export function activePolicyApprovals( - reviews: PullRequestReview[], - identity: string -): PullRequestReview[] { - return reviews.filter( - (review) => - review.state === 'APPROVED' && - review.user?.login?.toLowerCase() === identity.toLowerCase() && - review.body?.startsWith(POLICY_REVIEW_PREFIX) - ) -} - -async function stop( +async function withdraw( github: GitHubClient, - config: ResolvedRuntimeConfig, - pull: PullRequest, - reviews: PullRequestReview[], - message: string, + config: RuntimeConfig, + { pull, reviews }: PullState, + reason: string, summary: Summary ): Promise { const identity = config.lane.approval.identity @@ -278,12 +241,7 @@ async function stop( } for (const approval of activePolicyApprovals(reviews, identity)) { try { - await dismissApproval( - github, - config.pullRequestNumber, - approval, - `Fast-lane approval withdrawn: ${message}` - ) + await dismissApproval(github, config.pullRequestNumber, approval, reason) } catch (error) { errors.push(error) } @@ -294,129 +252,43 @@ async function stop( 'failed to complete fast-lane compensation' ) } - summary(message) -} - -async function resolvePullRequestNumber( - github: GitHubClient, - config: RuntimeConfig, - summary: Summary -): Promise { - if (config.pullRequestNumber) return config.pullRequestNumber - const response = await github.request(`/commits/${config.eventHeadSha}/pulls`) - if (!Array.isArray(response)) { - throw new Error('GitHub did not return pull requests for the commit') - } - const matches = response - .map(asPullRequest) - .filter( - (pull) => - pull.state === 'open' && - pull.head?.sha === config.eventHeadSha && - isSameRepository(pull, config.repository) && - targetsDefaultBranch(pull, config.repository, config.defaultBranch) - ) - if (matches.length !== 1 || !matches[0].number) { - summary( - `Skipped: expected one open same-repository pull request for ${config.eventHeadSha.slice(0, 12)}, found ${matches.length}.` - ) - return - } - return matches[0].number + summary(`Skipped: ${reason}`) } async function readPullState( github: GitHubClient, pullRequestNumber: number -): Promise<{ - pull: PullRequest - reviews: PullRequestReview[] -}> { +): Promise { const [pull, reviews] = await Promise.all([ github.request(`/pulls/${pullRequestNumber}`), github.paginate(`/pulls/${pullRequestNumber}/reviews`) ]) return { pull: asPullRequest(pull), - reviews: asReviews(reviews) + reviews: reviews as PullRequestReview[] } } -async function revalidate( +async function revalidateOrWithdraw( github: GitHubClient, - config: ResolvedRuntimeConfig, + config: RuntimeConfig, summary: Summary -): Promise<{ pull: PullRequest; reviews: PullRequestReview[] } | undefined> { +): Promise { const state = await readPullState(github, config.pullRequestNumber) - const failure = eligibilityFailure({ + if (state.pull.head?.sha !== config.eventHeadSha) { + summary('Skipped: the pull request head advanced after this run started.') + return + } + const reason = eligibilityFailure({ pull: state.pull, + reviews: state.reviews, lane: config.lane, repository: config.repository, defaultBranch: config.defaultBranch, - expectedHeadSha: config.eventHeadSha, - hasPolicyApprovalForHead: Boolean( - approvalForHead( - state.reviews, - config.lane.approval.identity, - config.eventHeadSha, - POLICY_REVIEW_PREFIX - ) - ), - eventName: config.eventName, - eventAction: config.eventAction, - eventActor: config.eventActor, - eventLabel: config.eventLabel + labelEvent: config.labelEvent }) - const reason = - failure ?? - (hasActiveHumanChangeRequest(state.reviews) - ? 'Skipped: an active human change request is present.' - : undefined) if (!reason) return state - - await stop(github, config, state.pull, state.reviews, reason, summary) -} - -export async function approveCurrentHead( - github: GitHubClient, - config: ResolvedRuntimeConfig, - reviews: PullRequestReview[], - summary: Summary -): Promise { - const identity = config.lane.approval.identity - const headSha = config.eventHeadSha - if (approvalForHead(reviews, identity, headSha, POLICY_REVIEW_PREFIX)) { - summary(`Already approved ${headSha.slice(0, 12)} as @${identity}.`) - return true - } - - const created = asReviews([ - await github.request(`/pulls/${config.pullRequestNumber}/reviews`, { - method: 'POST', - headers: { 'content-type': 'application/json' }, - body: JSON.stringify({ - event: 'APPROVE', - commit_id: headSha, - body: `${POLICY_REVIEW_PREFIX} Lane: ${config.lane.id}. No diff review was performed; eligibility was bound to the trusted policy, exact head, and configured path boundary.` - }) - }) - ])[0] - - let verified - try { - verified = await revalidate(github, config, summary) - } catch (error) { - await dismissApproval( - github, - config.pullRequestNumber, - created, - 'Fast-lane approval withdrawn: post-approval verification failed.' - ) - throw error - } - if (!verified) return false - summary(`Approved ${headSha.slice(0, 12)} as @${identity}.`) - return true + await withdraw(github, config, state, reason, summary) } async function assertIdentity( @@ -424,120 +296,51 @@ async function assertIdentity( expectedIdentity: string ): Promise { const response = await github.request('https://api.github.com/user') - if (!response || typeof response !== 'object' || Array.isArray(response)) { - throw new Error('GitHub did not return the approval identity') - } - const login = (response as { login?: string }).login - if (login?.toLowerCase() !== expectedIdentity) { + const login = isRecord(response) ? response.login : undefined + if (typeof login !== 'string' || login.toLowerCase() !== expectedIdentity) { throw new Error( - `FAST_LANE_TOKEN belongs to ${login ?? 'an unknown account'}, expected ${expectedIdentity}` + `FAST_LANE_TOKEN belongs to ${String(login ?? 'an unknown account')}, expected ${expectedIdentity}` ) } } -async function resolveRuntimeConfig( - github: GitHubClient, - config: RuntimeConfig, - summary: Summary -): Promise { - const pullRequestNumber = await resolvePullRequestNumber( - github, - config, - summary - ) - if (!pullRequestNumber) return - return { ...config, pullRequestNumber } -} - -async function readInitialEligibleState( - github: GitHubClient, - config: ResolvedRuntimeConfig, - summary: Summary -): Promise<{ pull: PullRequest; reviews: PullRequestReview[] } | undefined> { - const state = await revalidate(github, config, summary) - if (!state) return - if (state.pull.user?.login?.toLowerCase() === config.lane.approval.identity) { - throw new Error('the approval identity cannot approve its own pull request') - } - return state -} - -function filesStayInsideLane( - files: PullRequestFile[], - pull: PullRequest, - config: ResolvedRuntimeConfig -): boolean { - if (!hasCompleteChangedFileList(files, pull.changed_files)) return false - const paths = changedPaths(files) - if (!paths) return false - return isInsideLane(paths, config.lane.pathPrefixes) -} - -async function verifyLanePaths( +async function postPolicyApproval( github: GitHubClient, - config: ResolvedRuntimeConfig, - state: { pull: PullRequest; reviews: PullRequestReview[] }, - summary: Summary -): Promise { - const files = asFiles( - await github.paginate(`/pulls/${config.pullRequestNumber}/files`) - ) - if (filesStayInsideLane(files, state.pull, config)) return true - await stop( - github, - config, - state.pull, - state.reviews, - 'Skipped: the complete changed-file set is not inside the configured lane.', - summary - ) - return false + config: RuntimeConfig +): Promise { + await github.request(`/pulls/${config.pullRequestNumber}/reviews`, { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ + event: 'APPROVE', + commit_id: config.eventHeadSha, + body: `${POLICY_REVIEW_PREFIX} Lane: ${config.lane.id}. No diff review was performed; eligibility was bound to the trusted policy, exact head, and configured path boundary.` + }) + }) } -async function approveAndArm( +async function withdrawAfterFailure( github: GitHubClient, - config: ResolvedRuntimeConfig, + config: RuntimeConfig, + error: unknown, summary: Summary -): Promise { - const state = await revalidate(github, config, summary) - if (!state) return - const approved = await approveCurrentHead( - github, - config, - state.reviews, - summary - ) - if (!approved) return - const verified = await revalidate(github, config, summary) - if (!verified) return +): Promise { try { - await armMergeAutomation( + const current = await readPullState(github, config.pullRequestNumber) + await withdraw( github, - verified.pull, - config.eventHeadSha, config, + current, + 'the run failed after approval; approval and merge state were withdrawn.', summary ) - await revalidate(github, config, summary) - } catch (error) { - const state = await readPullState(github, config.pullRequestNumber) - try { - await stop( - github, - config, - state.pull, - state.reviews, - 'Merge automation failed; approval and merge state were withdrawn.', - summary - ) - } catch (cleanupError) { - throw new Error( - `Merge automation failed (${String(error)}) and compensation also failed.`, - { cause: cleanupError } - ) - } - throw error + } catch (cleanupError) { + throw new Error( + `Fast-lane run failed (${String(error)}) and compensation also failed.`, + { cause: cleanupError } + ) } + throw error } export async function runFastLane( @@ -545,15 +348,35 @@ export async function runFastLane( config: RuntimeConfig, summary: Summary ): Promise { - await assertIdentity(github, config.lane.approval.identity) - const resolved = await resolveRuntimeConfig(github, config, summary) - if (!resolved) return - const initial = await readInitialEligibleState(github, resolved, summary) - if ( - !initial || - !(await verifyLanePaths(github, resolved, initial, summary)) - ) { + const { identity } = config.lane.approval + const headSha = config.eventHeadSha + await assertIdentity(github, identity) + const initial = await revalidateOrWithdraw(github, config, summary) + if (!initial) return + + const files = (await github.paginate( + `/pulls/${config.pullRequestNumber}/files` + )) as PullRequestFile[] + const outsideLane = pathFailure(files, initial.pull, config.lane.pathPrefixes) + if (outsideLane) { + await withdraw(github, config, initial, outsideLane, summary) return } - await approveAndArm(github, resolved, summary) + + const alreadyApproved = initial.reviews.some((review) => + isPolicyApprovalForHead(review, identity, headSha) + ) + if (!alreadyApproved) await postPolicyApproval(github, config) + + try { + const verified = await revalidateOrWithdraw(github, config, summary) + if (!verified) return + summary( + `${alreadyApproved ? 'Already approved' : 'Approved'} ${shortSha(headSha)} as @${identity}.` + ) + await armMergeAutomation(github, verified.pull, config, summary) + await revalidateOrWithdraw(github, config, summary) + } catch (error) { + await withdrawAfterFailure(github, config, error, summary) + } } diff --git a/scripts/cicd/fast-lane/config.test.ts b/scripts/cicd/fast-lane/config.test.ts new file mode 100644 index 00000000000..a2aed70d42b --- /dev/null +++ b/scripts/cicd/fast-lane/config.test.ts @@ -0,0 +1,128 @@ +import { readFileSync } from 'node:fs' + +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { loadRuntimeConfig, parseFastLaneConfig } from './config.ts' +import type { FastLaneConfig } from './types.ts' + +const lane: FastLaneConfig = { + schemaVersion: 1, + id: 'website', + pathPrefixes: ['apps/website/'], + approval: { + identity: 'christian-byrne', + trustedAuthors: ['bertfy'], + approvalLabel: 'website-fast-lane:approve', + trustedLabelers: ['drjkl'], + holdLabel: 'website-fast-lane:hold' + }, + merge: { mode: 'automatic', method: 'SQUASH' } +} + +describe('lane configuration', () => { + it('normalizes logins while preserving the reviewed path policy', () => { + expect( + parseFastLaneConfig({ + ...lane, + approval: { + ...lane.approval, + identity: 'Christian-Byrne', + trustedAuthors: ['BertFY', 'bertfy'], + trustedLabelers: ['DrJKL'] + } + }) + ).toEqual(lane) + }) + + it('parses the checked-in website lane', () => { + const shipped: unknown = JSON.parse( + readFileSync('.github/fast-lanes/website.json', 'utf8') + ) + expect(parseFastLaneConfig(shipped).pathPrefixes).toEqual(['apps/website/']) + }) + + it.for([ + { + key: 'schema version', + value: { ...lane, schemaVersion: 2 }, + message: 'schemaVersion must be 1' + }, + { + key: 'empty path policy', + value: { ...lane, pathPrefixes: [] }, + message: 'pathPrefixes must be an array' + }, + { + key: 'ambiguous path prefix', + value: { ...lane, pathPrefixes: ['apps/website'] }, + message: 'relative directory prefixes' + }, + { + key: 'absolute path prefix', + value: { ...lane, pathPrefixes: ['/apps/website/'] }, + message: 'relative directory prefixes' + }, + { + key: 'parent path segment', + value: { ...lane, pathPrefixes: ['apps/website/../'] }, + message: 'relative directory prefixes' + }, + { + key: 'unknown merge mode', + value: { ...lane, merge: { mode: 'sometimes', method: 'SQUASH' } }, + message: 'automatic or manual' + }, + { + key: 'unknown merge method', + value: { ...lane, merge: { mode: 'automatic', method: 'FAST_FORWARD' } }, + message: 'MERGE, REBASE, or SQUASH' + } + ])('rejects $key', ({ value, message }) => { + expect(() => parseFastLaneConfig(value)).toThrow(message) + }) +}) + +describe('runtime configuration', () => { + beforeEach(() => { + vi.stubEnv('FAST_LANE_CONFIG', '.github/fast-lanes/website.json') + vi.stubEnv('GITHUB_REPOSITORY', 'Comfy-Org/ComfyUI_frontend') + vi.stubEnv('PR_NUMBER', '42') + vi.stubEnv('PR_HEAD_SHA', 'head-sha') + vi.stubEnv('FAST_LANE_DEFAULT_BRANCH', 'main') + }) + + it.for([ + { + name: 'an operator label event', + eventName: 'pull_request_target', + action: 'labeled', + expected: { actor: 'drjkl', label: 'website-fast-lane:approve' } + }, + { + name: 'an unlabeled event', + eventName: 'pull_request_target', + action: 'unlabeled', + expected: undefined + }, + { + name: 'a check completion', + eventName: 'workflow_run', + action: 'labeled', + expected: undefined + } + ])( + 'reads $name as label event $expected', + ({ eventName, action, expected }) => { + vi.stubEnv('GITHUB_EVENT_NAME', eventName) + vi.stubEnv('FAST_LANE_EVENT_ACTION', action) + vi.stubEnv('FAST_LANE_EVENT_ACTOR', 'DrJKL') + vi.stubEnv('FAST_LANE_EVENT_LABEL', 'Website-Fast-Lane:Approve') + expect(loadRuntimeConfig().labelEvent).toEqual(expected) + } + ) + + it('requires the resolved pull request number', () => { + vi.stubEnv('PR_NUMBER', '') + expect(() => loadRuntimeConfig()).toThrow('PR_NUMBER is required') + }) +}) diff --git a/scripts/cicd/fast-lane/config.ts b/scripts/cicd/fast-lane/config.ts index 07fb5ab0430..bec7b106293 100644 --- a/scripts/cicd/fast-lane/config.ts +++ b/scripts/cicd/fast-lane/config.ts @@ -1,9 +1,15 @@ import fs from 'node:fs' -import type { FastLaneConfig, RuntimeConfig } from './types.ts' +import { isRecord } from './github.ts' +import { MERGE_METHODS, MERGE_MODES } from './types.ts' +import type { FastLaneConfig, LabelEvent, RuntimeConfig } from './types.ts' -const MERGE_METHODS = new Set(['MERGE', 'REBASE', 'SQUASH']) -const MERGE_MODES = new Set(['automatic', 'manual']) +function isOneOf( + values: readonly T[], + value: string +): value is T { + return values.some((candidate) => candidate === value) +} function requiredString( record: Record, @@ -35,10 +41,8 @@ function stringArray( } function record(value: unknown, context: string): Record { - if (!value || typeof value !== 'object' || Array.isArray(value)) { - throw new Error(`${context} must be an object`) - } - return value as Record + if (!isRecord(value)) throw new Error(`${context} must be an object`) + return value } function normalizeLogins(logins: string[]): string[] { @@ -55,10 +59,10 @@ export function parseFastLaneConfig(value: unknown): FastLaneConfig { const merge = record(root.merge, 'fast lane config.merge') const mode = requiredString(merge, 'mode', 'fast lane config.merge') const method = requiredString(merge, 'method', 'fast lane config.merge') - if (!MERGE_MODES.has(mode)) { + if (!isOneOf(MERGE_MODES, mode)) { throw new Error('fast lane config.merge.mode must be automatic or manual') } - if (!MERGE_METHODS.has(method)) { + if (!isOneOf(MERGE_METHODS, method)) { throw new Error( 'fast lane config.merge.method must be MERGE, REBASE, or SQUASH' ) @@ -108,33 +112,38 @@ export function parseFastLaneConfig(value: unknown): FastLaneConfig { 'fast lane config.approval' ).toLowerCase() }, - merge: { - mode: mode as FastLaneConfig['merge']['mode'], - method: method as FastLaneConfig['merge']['method'] - } + merge: { mode, method } } } -function requiredEnv(name: string): string { +export function requiredEnv(name: string): string { const value = process.env[name]?.trim() if (!value) throw new Error(`${name} is required`) return value } -function optionalEnv(name: string): string | undefined { - return process.env[name]?.trim() || undefined -} - -function optionalPositiveIntegerEnv(name: string): number | undefined { - const value = process.env[name]?.trim() - if (!value) return - const parsed = Number(value) +function positiveIntegerEnv(name: string): number { + const parsed = Number(requiredEnv(name)) if (!Number.isSafeInteger(parsed) || parsed <= 0) { throw new Error(`${name} must be a positive integer`) } return parsed } +function labelEventEnv(): LabelEvent | undefined { + const actor = process.env.FAST_LANE_EVENT_ACTOR?.trim() + const label = process.env.FAST_LANE_EVENT_LABEL?.trim() + if ( + process.env.GITHUB_EVENT_NAME !== 'pull_request_target' || + process.env.FAST_LANE_EVENT_ACTION !== 'labeled' || + !actor || + !label + ) { + return + } + return { actor: actor.toLowerCase(), label: label.toLowerCase() } +} + export function loadRuntimeConfig(): RuntimeConfig { const configPath = requiredEnv('FAST_LANE_CONFIG') let parsed: unknown @@ -147,15 +156,11 @@ export function loadRuntimeConfig(): RuntimeConfig { } return { - token: requiredEnv('FAST_LANE_TOKEN'), repository: requiredEnv('GITHUB_REPOSITORY'), - pullRequestNumber: optionalPositiveIntegerEnv('PR_NUMBER'), + pullRequestNumber: positiveIntegerEnv('PR_NUMBER'), eventHeadSha: requiredEnv('PR_HEAD_SHA'), - eventName: requiredEnv('GITHUB_EVENT_NAME'), - eventAction: optionalEnv('FAST_LANE_EVENT_ACTION'), - eventActor: optionalEnv('FAST_LANE_EVENT_ACTOR'), - eventLabel: optionalEnv('FAST_LANE_EVENT_LABEL'), - defaultBranch: requiredEnv('FAST_LANE_BASE_REF'), + labelEvent: labelEventEnv(), + defaultBranch: requiredEnv('FAST_LANE_DEFAULT_BRANCH'), lane: parseFastLaneConfig(parsed) } } diff --git a/scripts/cicd/fast-lane/github.test.ts b/scripts/cicd/fast-lane/github.test.ts new file mode 100644 index 00000000000..b71b4587509 --- /dev/null +++ b/scripts/cicd/fast-lane/github.test.ts @@ -0,0 +1,53 @@ +import { describe, expect, it, vi } from 'vitest' + +import { createGitHubClient } from './github.ts' + +function jsonResponse(body: unknown): Response { + return new Response(JSON.stringify(body), { + status: 200, + headers: { 'content-type': 'application/json' } + }) +} + +describe('GitHub client', () => { + it('rejects a GraphQL response that reports errors with HTTP 200', async () => { + vi.stubGlobal( + 'fetch', + vi.fn(async () => + jsonResponse({ + data: null, + errors: [{ message: 'Could not resolve to a node' }] + }) + ) + ) + const github = createGitHubClient('token', 'Comfy-Org/ComfyUI_frontend') + + await expect(github.graphql('mutation {}', {})).rejects.toThrow( + 'GitHub GraphQL failed: Could not resolve to a node' + ) + }) + + it('reads every page until a short page', async () => { + const fullPage = Array.from({ length: 100 }, (_, id) => ({ id })) + const fetchPage = vi.fn(async (input) => + jsonResponse(String(input).endsWith('page=1') ? fullPage : [{ id: 100 }]) + ) + vi.stubGlobal('fetch', fetchPage) + const github = createGitHubClient('token', 'Comfy-Org/ComfyUI_frontend') + + await expect(github.paginate('/pulls/42/reviews')).resolves.toHaveLength( + 101 + ) + }) + + it('refuses to send the token to another origin', async () => { + const fetchAny = vi.fn() + vi.stubGlobal('fetch', fetchAny) + const github = createGitHubClient('token', 'Comfy-Org/ComfyUI_frontend') + + await expect(github.request('https://example.com/user')).rejects.toThrow( + 'Refusing to send credentials' + ) + expect(fetchAny).not.toHaveBeenCalled() + }) +}) diff --git a/scripts/cicd/fast-lane/github.ts b/scripts/cicd/fast-lane/github.ts index 372fb0b7808..b191705a0fb 100644 --- a/scripts/cicd/fast-lane/github.ts +++ b/scripts/cicd/fast-lane/github.ts @@ -4,10 +4,16 @@ const API_VERSION = '2022-11-28' const PAGE_SIZE = 100 const GRAPHQL_URL = 'https://api.github.com/graphql' +export function isRecord(value: unknown): value is Record { + return typeof value === 'object' && value !== null && !Array.isArray(value) +} + function apiUrl(root: string, requestPath: string): string { - return requestPath.startsWith('https://') - ? requestPath - : `${root}${requestPath}` + if (!requestPath.startsWith('https://')) return `${root}${requestPath}` + if (new URL(requestPath).origin !== 'https://api.github.com') { + throw new Error(`Refusing to send credentials to ${requestPath}`) + } + return requestPath } async function assertSuccessful( @@ -27,29 +33,18 @@ function arrayPage(value: unknown, requestPath: string): unknown[] { throw new Error(`GitHub API ${requestPath} did not return an array`) } -interface GraphqlEnvelope { - data?: unknown - errors?: { message?: string }[] -} - -function graphqlEnvelope(value: unknown): GraphqlEnvelope { - if (typeof value !== 'object' || value === null) { +function graphqlData(value: unknown): unknown { + if (!isRecord(value)) { throw new Error('GitHub GraphQL returned an invalid response') } - return value -} - -function graphqlErrorMessage(error: { message?: string }): string { - return error.message ?? 'unknown error' -} - -function graphqlData(value: unknown): unknown { - const envelope = graphqlEnvelope(value) - const errors = envelope.errors ?? [] - if (errors.length === 0) return envelope.data - throw new Error( - `GitHub GraphQL failed: ${errors.map(graphqlErrorMessage).join('; ')}` + const errors = Array.isArray(value.errors) ? value.errors : [] + if (errors.length === 0) return value.data + const messages = errors.map((error) => + isRecord(error) && typeof error.message === 'string' + ? error.message + : 'unknown error' ) + throw new Error(`GitHub GraphQL failed: ${messages.join('; ')}`) } export function createGitHubClient( diff --git a/scripts/cicd/fast-lane/policy.test.ts b/scripts/cicd/fast-lane/policy.test.ts index e5ad292cde4..624b5c46938 100644 --- a/scripts/cicd/fast-lane/policy.test.ts +++ b/scripts/cicd/fast-lane/policy.test.ts @@ -1,17 +1,25 @@ import { describe, expect, it } from 'vitest' -import { parseFastLaneConfig } from './config.ts' import { - approvalForHead, + activePolicyApprovals, changedPaths, eligibilityFailure, hasActiveHumanChangeRequest, - hasAuthorizedApprovalLabel, hasCompleteChangedFileList, - isApprovalForHead, - isInsideLane + isAuthorizedLabelEvent, + isInsideLane, + isPolicyApprovalForHead, + POLICY_REVIEW_PREFIX, + policyReviewFloor } from './policy.ts' -import type { FastLaneConfig, PullRequest, PullRequestReview } from './types.ts' +import type { + FastLaneConfig, + LabelEvent, + PullRequest, + PullRequestReview +} from './types.ts' + +const policyBody = `${POLICY_REVIEW_PREFIX} Lane: website.` const lane: FastLaneConfig = { schemaVersion: 1, @@ -27,6 +35,18 @@ const lane: FastLaneConfig = { merge: { mode: 'automatic', method: 'SQUASH' } } +const operatorLabelEvent: LabelEvent = { + actor: 'drjkl', + label: 'website-fast-lane:approve' +} + +const headApproval: PullRequestReview = { + state: 'APPROVED', + commit_id: 'head-sha', + body: policyBody, + user: { login: 'christian-byrne' } +} + function eligiblePull(overrides: Partial = {}): PullRequest { return { state: 'open', @@ -45,104 +65,78 @@ function eligiblePull(overrides: Partial = {}): PullRequest { } } +function outsiderPull(labels: string[]): PullRequest { + return eligiblePull({ + user: { login: 'someone-else' }, + labels: labels.map((name) => ({ name })) + }) +} + function failure( pull: PullRequest, - authorization: { - hasPolicyApprovalForHead?: boolean - eventName?: string - eventAction?: string - eventActor?: string - eventLabel?: string - } = {} + { + reviews = [], + labelEvent + }: { reviews?: PullRequestReview[]; labelEvent?: LabelEvent } = {} ): string | undefined { return eligibilityFailure({ pull, + reviews, lane, repository: 'Comfy-Org/ComfyUI_frontend', defaultBranch: 'main', - expectedHeadSha: 'head-sha', - hasPolicyApprovalForHead: authorization.hasPolicyApprovalForHead ?? false, - eventName: authorization.eventName ?? 'pull_request_target', - eventAction: authorization.eventAction, - eventActor: authorization.eventActor, - eventLabel: authorization.eventLabel + labelEvent }) } -describe('lane configuration', () => { - it('normalizes logins while preserving the reviewed path policy', () => { +describe('changed-path boundary', () => { + it.for([ + { name: 'a matching count', expectedCount: 1, expected: true }, + { name: 'a truncated list', expectedCount: 2, expected: false }, + { name: 'an unknown count', expectedCount: undefined, expected: false } + ])('treats $name as complete: $expected', ({ expectedCount, expected }) => { expect( - parseFastLaneConfig({ - ...lane, - approval: { - ...lane.approval, - identity: 'Christian-Byrne', - trustedAuthors: ['BertFY', 'bertfy'], - trustedLabelers: ['DrJKL'] - } - }) - ).toEqual(lane) + hasCompleteChangedFileList( + [{ filename: 'apps/website/src/pages/index.astro' }], + expectedCount + ) + ).toBe(expected) }) it.for([ - { key: 'schema version', value: { ...lane, schemaVersion: 2 } }, - { key: 'empty path policy', value: { ...lane, pathPrefixes: [] } }, { - key: 'ambiguous path prefix', - value: { ...lane, pathPrefixes: ['apps/website'] } + name: 'a lane path', + paths: ['apps/website/src/pages/index.astro'], + expected: true + }, + { name: 'no paths', paths: [], expected: false }, + { + name: 'a lane path and a root file', + paths: ['apps/website/src/pages/index.astro', 'pnpm-lock.yaml'], + expected: false }, { - key: 'unknown merge mode', - value: { ...lane, merge: { mode: 'sometimes', method: 'SQUASH' } } + name: 'a sibling directory sharing the prefix', + paths: ['apps/website-evil/file.ts'], + expected: false } - ])('rejects $key', ({ value }) => { - expect(() => parseFastLaneConfig(value)).toThrow() - }) -}) - -describe('changed-path boundary', () => { - it('requires a complete, non-empty set inside the configured prefixes', () => { - const files = [{ filename: 'apps/website/src/pages/index.astro' }] - expect(hasCompleteChangedFileList(files, 1)).toBe(true) - expect(hasCompleteChangedFileList(files, 2)).toBe(false) - expect(isInsideLane(changedPaths(files) ?? [], lane.pathPrefixes)).toBe( - true - ) - expect(isInsideLane([], lane.pathPrefixes)).toBe(false) - expect( - isInsideLane( - ['apps/website/src/pages/index.astro', 'pnpm-lock.yaml'], - lane.pathPrefixes - ) - ).toBe(false) - expect(isInsideLane(['apps/website-evil/file.ts'], lane.pathPrefixes)).toBe( - false - ) + ])('treats $name as inside the lane: $expected', ({ paths, expected }) => { + expect(isInsideLane(paths, lane.pathPrefixes)).toBe(expected) }) it.for([ - { - name: 'rename into the lane', - file: { - status: 'renamed', - previous_filename: 'src/sensitive.ts', - filename: 'apps/website/sensitive.ts' - }, - expected: ['apps/website/sensitive.ts', 'src/sensitive.ts'] - }, - { - name: 'copy into the lane', - file: { - status: 'copied', - previous_filename: 'src/sensitive.ts', - filename: 'apps/website/sensitive.ts' - }, - expected: ['apps/website/sensitive.ts', 'src/sensitive.ts'] - } - ])('retains both paths for a $name', ({ file, expected }) => { - const paths = changedPaths([file]) - expect(paths).toEqual(expected) - expect(isInsideLane(paths ?? [], lane.pathPrefixes)).toBe(false) + { name: 'rename', status: 'renamed' }, + { name: 'copy', status: 'copied' } + ])('retains both paths for a $name into the lane', ({ status }) => { + expect( + changedPaths([ + { + status, + previous_filename: 'src/sensitive.ts', + filename: 'apps/website/sensitive.ts' + } + ]) + ).toEqual(['apps/website/sensitive.ts', 'src/sensitive.ts']) }) it('fails closed when a rename omits its previous path', () => { @@ -152,175 +146,44 @@ describe('changed-path boundary', () => { }) }) -describe('approval policy', () => { - const operatorLabelEvent = { - name: 'pull_request_target', - action: 'labeled', - actor: 'DrJKL', - label: 'website-fast-lane:approve' - } - +describe('approval label events', () => { it.for([ { name: 'the trusted operator label event', - labels: ['website-fast-lane:approve'], event: operatorLabelEvent, expected: true }, { name: 'an untrusted labeler', - labels: ['website-fast-lane:approve'], event: { ...operatorLabelEvent, actor: 'someone-else' }, expected: false }, { name: 'a different label from the operator', - labels: ['website-fast-lane:approve'], event: { ...operatorLabelEvent, label: 'area:website' }, expected: false }, + { name: 'a run without a label event', event: undefined, expected: false } + ])('authorizes $name: $expected', ({ event, expected }) => { + expect(isAuthorizedLabelEvent(lane, event)).toBe(expected) + }) +}) + +describe('eligibility', () => { + it.for([ + { name: 'a trusted author', pull: eligiblePull() }, { - name: 'an unlabeled event', - labels: ['website-fast-lane:approve'], - event: { ...operatorLabelEvent, action: 'unlabeled' }, - expected: false - }, - { - name: 'a pull_request event', - labels: ['website-fast-lane:approve'], - event: { ...operatorLabelEvent, name: 'pull_request' }, - expected: false + name: 'a non-allowlisted author on the operator label event', + pull: outsiderPull(['website-fast-lane:approve']), + labelEvent: operatorLabelEvent }, { - name: 'a label already removed from the pull request', - labels: [], - event: operatorLabelEvent, - expected: false + name: 'a non-allowlisted author whose head approval and label remain', + pull: outsiderPull(['website-fast-lane:approve']), + reviews: [headApproval] } - ])('authorizes $name: $expected', ({ labels, event, expected }) => { - const pull = eligiblePull({ - user: { login: 'someone-else' }, - labels: labels.map((name) => ({ name })) - }) - expect(hasAuthorizedApprovalLabel(pull, lane, event)).toBe(expected) - }) - - it('gates a non-trusted author on a current label event or a head approval', () => { - const pull = eligiblePull({ - user: { login: 'someone-else' }, - labels: [{ name: 'website-fast-lane:approve' }] - }) - expect( - failure(pull, { - eventName: 'pull_request_target', - eventAction: 'synchronize', - eventActor: 'someone-else' - }) - ).toContain('lacks a current authorized event') - expect( - failure(pull, { - hasPolicyApprovalForHead: true, - eventName: 'workflow_run' - }) - ).toBeUndefined() - expect( - failure(pull, { - eventName: 'pull_request_target', - eventAction: 'labeled', - eventActor: 'DrJKL', - eventLabel: 'website-fast-lane:approve' - }) - ).toBeUndefined() - }) - - it('keeps a human change request active after a comment-only review', () => { - const reviews: PullRequestReview[] = [ - { - state: 'CHANGES_REQUESTED', - user: { login: 'DrJKL', type: 'User' } - }, - { state: 'COMMENTED', user: { login: 'DrJKL', type: 'User' } } - ] - expect(hasActiveHumanChangeRequest(reviews)).toBe(true) - }) - - it('ignores app reviews and clears a human request only decisively', () => { - expect( - hasActiveHumanChangeRequest([ - { - state: 'CHANGES_REQUESTED', - user: { login: 'coderabbitai[bot]', type: 'Bot' } - }, - { - state: 'CHANGES_REQUESTED', - user: { login: 'DrJKL', type: 'User' } - }, - { state: 'APPROVED', user: { login: 'DrJKL', type: 'User' } } - ]) - ).toBe(false) - }) - - it('binds policy approval to the identity and exact head', () => { - expect( - isApprovalForHead( - { - state: 'APPROVED', - commit_id: 'head-sha', - user: { login: 'Christian-Byrne' } - }, - 'christian-byrne', - 'head-sha' - ) - ).toBe(true) - expect( - isApprovalForHead( - { - state: 'APPROVED', - commit_id: 'old-sha', - user: { login: 'christian-byrne' } - }, - 'christian-byrne', - 'head-sha' - ) - ).toBe(false) - }) - - it('only selects marked policy approvals for withdrawal', () => { - const reviews: PullRequestReview[] = [ - { - id: 1, - state: 'APPROVED', - commit_id: 'head-sha', - body: 'Looks good to me', - user: { login: 'christian-byrne' } - }, - { - id: 2, - state: 'APPROVED', - commit_id: 'head-sha', - body: '[Package fast lane] Policy-only approval. Lane: website.', - user: { login: 'christian-byrne' } - } - ] - const prefix = '[Package fast lane] Policy-only approval.' - - expect( - approvalForHead(reviews, 'christian-byrne', 'head-sha', prefix)?.id - ).toBe(2) - expect( - approvalForHead( - reviews.slice(0, 1), - 'christian-byrne', - 'head-sha', - prefix - ) - ).toBeUndefined() - }) -}) - -describe('fixed eligibility invariants', () => { - it('accepts the configured trusted-author path', () => { - expect(failure(eligiblePull())).toBeUndefined() + ])('accepts $name', ({ pull, reviews, labelEvent }) => { + expect(failure(pull, { reviews, labelEvent })).toBeUndefined() }) it.for([ @@ -330,14 +193,9 @@ describe('fixed eligibility invariants', () => { message: 'not open and ready' }, { - name: 'fork', - pull: eligiblePull({ - head: { - sha: 'head-sha', - repo: { full_name: 'bertfy/ComfyUI_frontend' } - } - }), - message: 'fork pull requests' + name: 'closed pull request', + pull: eligiblePull({ state: 'closed' }), + message: 'not open and ready' }, { name: 'other base', @@ -350,23 +208,157 @@ describe('fixed eligibility invariants', () => { message: 'applies only to main' }, { - name: 'stale head', + name: 'fork', pull: eligiblePull({ head: { - sha: 'new-head', - repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + sha: 'head-sha', + repo: { full_name: 'bertfy/ComfyUI_frontend' } } }), - message: 'head advanced' + message: 'fork pull requests' + }, + { + name: 'pull request authored by the approval identity', + pull: eligiblePull({ user: { login: 'Christian-Byrne' } }), + message: 'cannot approve its own pull request' + }, + { + name: 'non-allowlisted author without the label', + pull: outsiderPull([]), + message: 'is not applied' + }, + { + name: 'non-allowlisted author whose label was removed after approval', + pull: outsiderPull([]), + reviews: [headApproval], + message: 'is not applied' + }, + { + name: 'non-allowlisted author with the label but no current event', + pull: outsiderPull(['website-fast-lane:approve']), + message: 'lacks a current authorized event' }, { name: 'hold label', - pull: eligiblePull({ - labels: [{ name: 'website-fast-lane:hold' }] - }), + pull: eligiblePull({ labels: [{ name: 'website-fast-lane:hold' }] }), message: 'hold is applied' + }, + { + name: 'human change request', + pull: eligiblePull(), + reviews: [ + { state: 'CHANGES_REQUESTED', user: { login: 'DrJKL', type: 'User' } } + ], + message: 'active human change request' + } + ])('rejects $name', ({ pull, reviews, message }) => { + expect(failure(pull, { reviews })).toContain(message) + }) +}) + +describe('human change requests', () => { + it.for([ + { + name: 'a change request followed by a comment', + reviews: [ + { state: 'CHANGES_REQUESTED', user: { login: 'DrJKL', type: 'User' } }, + { state: 'COMMENTED', user: { login: 'DrJKL', type: 'User' } } + ], + expected: true + }, + { + name: 'an app change request and a later human approval', + reviews: [ + { + state: 'CHANGES_REQUESTED', + user: { login: 'coderabbitai[bot]', type: 'Bot' } + }, + { state: 'CHANGES_REQUESTED', user: { login: 'DrJKL', type: 'User' } }, + { state: 'APPROVED', user: { login: 'DrJKL', type: 'User' } } + ], + expected: false + }, + { + name: 'a change request that was dismissed', + reviews: [{ state: 'DISMISSED', user: { login: 'DrJKL', type: 'User' } }], + expected: false + } + ])('treats $name as active: $expected', ({ reviews, expected }) => { + expect(hasActiveHumanChangeRequest(reviews)).toBe(expected) + }) +}) + +describe('policy reviews', () => { + it.for([ + { + name: 'the identity on the head in any case', + review: { ...headApproval, user: { login: 'Christian-Byrne' } }, + expected: true + }, + { + name: 'an older head', + review: { ...headApproval, commit_id: 'old-sha' }, + expected: false + }, + { + name: 'another reviewer', + review: { ...headApproval, user: { login: 'drjkl' } }, + expected: false + }, + { + name: 'a dismissed approval of the head', + review: { ...headApproval, state: 'DISMISSED' }, + expected: false + }, + { + name: 'an unmarked approval by the identity', + review: { ...headApproval, body: 'Looks good to me' }, + expected: false } - ])('rejects $name', ({ pull, message }) => { - expect(failure(pull)).toContain(message) + ])( + 'treats $name as the head policy approval: $expected', + ({ review, expected }) => { + expect( + isPolicyApprovalForHead(review, 'christian-byrne', 'head-sha') + ).toBe(expected) + } + ) + + it('selects active policy approvals across heads', () => { + expect( + activePolicyApprovals( + [ + { ...headApproval, id: 1, commit_id: 'old-head' }, + { ...headApproval, id: 2 }, + { ...headApproval, id: 3, state: 'DISMISSED' }, + { ...headApproval, id: 4, body: 'Looks good to me' } + ], + 'christian-byrne' + ).map((review) => review.id) + ).toEqual([1, 2]) + }) + + it('uses the earliest policy review as the automation ownership floor', () => { + expect( + policyReviewFloor( + [ + { + ...headApproval, + submitted_at: '2026-10-06T10:03:00Z' + }, + { + ...headApproval, + state: 'DISMISSED', + submitted_at: '2026-10-06T10:00:00Z' + }, + { + ...headApproval, + body: 'Looks good to me.', + submitted_at: '2026-10-06T09:00:00Z' + } + ], + 'christian-byrne' + )?.submitted_at + ).toBe('2026-10-06T10:00:00Z') }) }) diff --git a/scripts/cicd/fast-lane/policy.ts b/scripts/cicd/fast-lane/policy.ts index 017a05a39aa..f3b6d074724 100644 --- a/scripts/cicd/fast-lane/policy.ts +++ b/scripts/cicd/fast-lane/policy.ts @@ -1,10 +1,14 @@ import type { FastLaneConfig, + LabelEvent, PullRequest, PullRequestFile, - PullRequestReview + PullRequestReview, + SubmittedReview } from './types.ts' +export const POLICY_REVIEW_PREFIX = '[Package fast lane] Policy-only approval.' + const DECISIVE_REVIEW_STATES = new Set([ 'APPROVED', 'CHANGES_REQUESTED', @@ -13,15 +17,11 @@ const DECISIVE_REVIEW_STATES = new Set([ export interface EligibilityContext { pull: PullRequest + reviews: PullRequestReview[] lane: FastLaneConfig repository: string defaultBranch: string - expectedHeadSha: string - hasPolicyApprovalForHead: boolean - eventName: string - eventAction?: string - eventActor?: string - eventLabel?: string + labelEvent?: LabelEvent } export function changedPaths(files: PullRequestFile[]): string[] | undefined { @@ -54,30 +54,36 @@ export function isInsideLane(paths: string[], prefixes: string[]): boolean { ) } +export function pathFailure( + files: PullRequestFile[], + pull: PullRequest, + prefixes: string[] +): string | undefined { + const paths = hasCompleteChangedFileList(files, pull.changed_files) + ? changedPaths(files) + : undefined + if (!paths || !isInsideLane(paths, prefixes)) { + return 'the complete changed-file set is not inside the configured lane.' + } +} + function hasLabel(pull: PullRequest, expected: string): boolean { return Boolean( pull.labels?.some((label) => label.name?.toLowerCase() === expected) ) } -export function hasAuthorizedApprovalLabel( - pull: PullRequest, +function isLogin(user: { login?: string } | undefined, login: string): boolean { + return user?.login?.toLowerCase() === login +} + +export function isAuthorizedLabelEvent( lane: FastLaneConfig, - event: { - name: string - action?: string - actor?: string - label?: string - } + labelEvent: LabelEvent | undefined ): boolean { - const { approvalLabel, trustedLabelers } = lane.approval - if (!hasLabel(pull, approvalLabel)) return false return ( - event.name === 'pull_request_target' && - event.action === 'labeled' && - event.label?.toLowerCase() === approvalLabel && - event.actor !== undefined && - trustedLabelers.includes(event.actor.toLowerCase()) + labelEvent?.label === lane.approval.approvalLabel && + lane.approval.trustedLabelers.includes(labelEvent.actor) ) } @@ -119,70 +125,108 @@ export function targetsDefaultBranch( ) } -export function eligibilityFailure({ - pull, - lane, - repository, - defaultBranch, - expectedHeadSha, - hasPolicyApprovalForHead, - eventName, - eventAction, - eventActor, - eventLabel -}: EligibilityContext): string | undefined { - if (pull.state !== 'open' || pull.draft) { - return 'Skipped: the pull request is not open and ready for review.' - } - if (!targetsDefaultBranch(pull, repository, defaultBranch)) { - return `Skipped: the ${lane.id} fast lane applies only to ${defaultBranch}.` - } - if (!isSameRepository(pull, repository)) { - return `Skipped: the ${lane.id} fast lane does not apply to fork pull requests.` - } - if (pull.head?.sha !== expectedHeadSha) { - return 'Skipped: the pull request head advanced after this workflow started.' - } - - const author = pull.user?.login?.toLowerCase() - const trustedAuthor = author && lane.approval.trustedAuthors.includes(author) - const currentLabelEvent = hasAuthorizedApprovalLabel(pull, lane, { - name: eventName, - action: eventAction, - actor: eventActor, - label: eventLabel - }) - const retainedPolicyApproval = - hasPolicyApprovalForHead && hasLabel(pull, lane.approval.approvalLabel) - if (!trustedAuthor && !retainedPolicyApproval && !currentLabelEvent) { - return `Skipped: @${author ?? 'unknown'} is not trusted and ${lane.approval.approvalLabel} lacks a current authorized event.` - } - if (hasLabel(pull, lane.approval.holdLabel)) { - return `Skipped: ${lane.approval.holdLabel} is applied.` - } +export function isPolicyReview( + review: PullRequestReview, + identity: string +): boolean { + return ( + isLogin(review.user, identity) && + review.body?.startsWith(POLICY_REVIEW_PREFIX) === true + ) } -export function isApprovalForHead( +export function isPolicyApprovalForHead( review: PullRequestReview, identity: string, headSha: string ): boolean { return ( + isPolicyReview(review, identity) && review.state === 'APPROVED' && - review.commit_id === headSha && - review.user?.login?.toLowerCase() === identity.toLowerCase() + review.commit_id === headSha ) } -export function approvalForHead( +export function activePolicyApprovals( + reviews: PullRequestReview[], + identity: string +): PullRequestReview[] { + return reviews.filter( + (review) => isPolicyReview(review, identity) && review.state === 'APPROVED' + ) +} + +export function policyReviewFloor( + reviews: PullRequestReview[], + identity: string +): SubmittedReview | undefined { + return reviews + .filter( + (review): review is SubmittedReview => + isPolicyReview(review, identity) && + review.submitted_at !== undefined && + !Number.isNaN(Date.parse(review.submitted_at)) + ) + .sort( + (left, right) => + Date.parse(left.submitted_at) - Date.parse(right.submitted_at) + )[0] +} + +function hasHeadPolicyApproval( reviews: PullRequestReview[], identity: string, - headSha: string, - bodyPrefix: string -): PullRequestReview | undefined { - return reviews.findLast( - (review) => - isApprovalForHead(review, identity, headSha) && - review.body?.startsWith(bodyPrefix) + headSha: string | undefined +): boolean { + return ( + headSha !== undefined && + reviews.some((review) => isPolicyApprovalForHead(review, identity, headSha)) ) } + +function authorizationFailure({ + pull, + reviews, + lane, + labelEvent +}: EligibilityContext): string | undefined { + const { identity, trustedAuthors, approvalLabel } = lane.approval + const author = pull.user?.login?.toLowerCase() ?? 'unknown' + if (author === identity) { + return 'the approval identity cannot approve its own pull request.' + } + if (trustedAuthors.includes(author)) return + if (!hasLabel(pull, approvalLabel)) { + return `@${author} is not trusted and ${approvalLabel} is not applied.` + } + if ( + isAuthorizedLabelEvent(lane, labelEvent) || + hasHeadPolicyApproval(reviews, identity, pull.head?.sha) + ) { + return + } + return `@${author} is not trusted and ${approvalLabel} lacks a current authorized event; re-run the cancelled labeled run or re-apply the label.` +} + +export function eligibilityFailure( + context: EligibilityContext +): string | undefined { + const { pull, reviews, lane, repository, defaultBranch } = context + if (pull.state !== 'open' || pull.draft) { + return 'the pull request is not open and ready for review.' + } + if (!targetsDefaultBranch(pull, repository, defaultBranch)) { + return `the ${lane.id} fast lane applies only to ${defaultBranch}.` + } + if (!isSameRepository(pull, repository)) { + return `the ${lane.id} fast lane does not apply to fork pull requests.` + } + const authorization = authorizationFailure(context) + if (authorization) return authorization + if (hasLabel(pull, lane.approval.holdLabel)) { + return `${lane.approval.holdLabel} is applied.` + } + if (hasActiveHumanChangeRequest(reviews)) { + return 'an active human change request is present.' + } +} diff --git a/scripts/cicd/fast-lane/run.ts b/scripts/cicd/fast-lane/run.ts index 2405aa27016..0246d785c3b 100644 --- a/scripts/cicd/fast-lane/run.ts +++ b/scripts/cicd/fast-lane/run.ts @@ -3,7 +3,7 @@ import path from 'node:path' import { fileURLToPath } from 'node:url' import { runFastLane } from './automation.ts' -import { loadRuntimeConfig } from './config.ts' +import { loadRuntimeConfig, requiredEnv } from './config.ts' import { createGitHubClient } from './github.ts' function summary(message: string): void { @@ -14,7 +14,10 @@ function summary(message: string): void { export async function main(): Promise { const config = loadRuntimeConfig() - const github = createGitHubClient(config.token, config.repository) + const github = createGitHubClient( + requiredEnv('FAST_LANE_TOKEN'), + config.repository + ) await runFastLane(github, config, summary) } @@ -22,9 +25,5 @@ if ( process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1]) ) { - main().catch((error: unknown) => { - const message = error instanceof Error ? error.stack : String(error) - process.stderr.write(`${message}\n`) - process.exitCode = 1 - }) + await main() } diff --git a/scripts/cicd/fast-lane/types.ts b/scripts/cicd/fast-lane/types.ts index 7238ed2c63c..163b35f0045 100644 --- a/scripts/cicd/fast-lane/types.ts +++ b/scripts/cicd/fast-lane/types.ts @@ -1,3 +1,6 @@ +export const MERGE_MODES = ['automatic', 'manual'] as const +export const MERGE_METHODS = ['MERGE', 'REBASE', 'SQUASH'] as const + export interface FastLaneConfig { schemaVersion: 1 id: string @@ -10,8 +13,8 @@ export interface FastLaneConfig { holdLabel: string } merge: { - mode: 'automatic' | 'manual' - method: 'MERGE' | 'REBASE' | 'SQUASH' + mode: (typeof MERGE_MODES)[number] + method: (typeof MERGE_METHODS)[number] } } @@ -46,6 +49,8 @@ export interface PullRequestReview { user?: { login?: string; type?: string } } +export type SubmittedReview = PullRequestReview & { submitted_at: string } + export interface GitHubClient { request(path: string, options?: RequestInit): Promise paginate(path: string): Promise @@ -68,21 +73,18 @@ export interface MergeAutomationState { } | null } +export interface LabelEvent { + actor: string + label: string +} + export interface RuntimeConfig { - token: string repository: string - pullRequestNumber?: number + pullRequestNumber: number eventHeadSha: string - eventName: string - eventAction?: string - eventActor?: string - eventLabel?: string + labelEvent?: LabelEvent defaultBranch: string lane: FastLaneConfig } -export interface ResolvedRuntimeConfig extends RuntimeConfig { - pullRequestNumber: number -} - export type Summary = (message: string) => void From ceadf967243a7b543b0a87373af279853484edef Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 05:04:38 +0000 Subject: [PATCH 57/70] ci: run website fixers inside the lint job Select the fixer commands by website-only scope instead of copying the lint job, merge the website typecheck and repository checks into one job, and drop the needs.changes.result guard that the implicit success() already applies. Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- .github/workflows/ci-lint-format.yaml | 96 +++++---------------------- package.json | 1 + 2 files changed, 18 insertions(+), 79 deletions(-) diff --git a/.github/workflows/ci-lint-format.yaml b/.github/workflows/ci-lint-format.yaml index ec17d1b6651..6e22ae75ba0 100644 --- a/.github/workflows/ci-lint-format.yaml +++ b/.github/workflows/ci-lint-format.yaml @@ -1,7 +1,8 @@ # Description: Linting and code formatting validation for pull requests. # Work is split across parallel jobs so wall time is the slowest job rather -# than the sum. The `lint` job runs the fixers; every fixer exits non-zero -# when unfixable problems remain, so no second verify-only lint pass runs. +# than the sum. The `lint` job runs the fixers, scoped to apps/website when +# every changed file is there; every fixer exits non-zero when unfixable +# problems remain, so no second verify-only lint pass runs. name: 'CI: Lint Format' on: @@ -37,7 +38,6 @@ jobs: lint: needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} runs-on: ubuntu-latest steps: - name: Checkout PR @@ -61,14 +61,21 @@ jobs: path: ${{ env.LINT_CACHE_PATHS }} - name: Run ESLint with auto-fix + if: needs.changes.outputs.website-only != 'true' run: pnpm lint:fix:ci - name: Run Stylelint with auto-fix + if: needs.changes.outputs.website-only != 'true' run: pnpm stylelint:fix - name: Run oxfmt with auto-format + if: needs.changes.outputs.website-only != 'true' run: pnpm -r --include-workspace-root format + - name: Run website lint and format fixes + if: needs.changes.outputs.website-only == 'true' + run: pnpm lint:fix:website + - name: Check for changes id: verify-changed-files run: | @@ -125,7 +132,7 @@ jobs: typecheck: needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} + if: needs.changes.outputs.website-only != 'true' runs-on: ubuntu-latest steps: - name: Checkout PR @@ -153,7 +160,7 @@ jobs: typecheck-aux: needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} + if: needs.changes.outputs.website-only != 'true' runs-on: ubuntu-latest steps: - name: Checkout PR @@ -181,7 +188,7 @@ jobs: repo-checks: needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only != 'true' }} + if: needs.changes.outputs.website-only != 'true' runs-on: ubuntu-latest steps: - name: Checkout PR @@ -198,80 +205,9 @@ jobs: - name: Verify knip, locale integrity and ADR index uses: ./.github/actions/repo-checks - website-lint: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} - runs-on: ubuntu-latest - steps: - - name: Checkout PR - uses: actions/checkout@v7 - with: - ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || github.ref }} - token: ${{ !github.event.pull_request.head.repo.fork && secrets.PR_GH_TOKEN || github.token }} - - - name: Setup frontend - uses: ./.github/actions/setup-frontend - with: - node_cache: 'false' - - - name: Restore lint caches - id: lint-cache - uses: ./.github/actions/tool-cache-restore - with: - scope: website-lint - path: ${{ env.LINT_CACHE_PATHS }} - - - name: Apply website lint and format fixes - run: | - pnpm exec stylelint --cache --cache-strategy content --fix 'apps/website/**/*.{css,vue}' - pnpm exec oxlint apps/website --type-aware --fix - pnpm exec eslint apps/website --cache --cache-strategy content --concurrency auto --fix - pnpm --filter @comfyorg/website format - - - name: Check for changes - id: verify-changed-files - run: | - if [ -n "$(git status --porcelain)" ]; then - echo "changed=true" >> "$GITHUB_OUTPUT" - else - echo "changed=false" >> "$GITHUB_OUTPUT" - fi - - - name: Commit changes - if: steps.verify-changed-files.outputs.changed == 'true' && github.event.pull_request.head.repo.full_name == github.repository - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add apps/website - git commit -m "[automated] Apply website lint and format fixes" - git push - - - name: Fail for fork PRs with unfixed lint or format issues - if: steps.verify-changed-files.outputs.changed == 'true' && github.event.pull_request.head.repo.full_name != github.repository - run: | - echo "::error::Website linting or formatting issues found. Run the website checks locally and push the changes." - exit 1 - - - name: Save lint caches - if: always() - uses: ./.github/actions/tool-cache-save - with: - cache-key: ${{ steps.lint-cache.outputs.cache-key }} - path: ${{ env.LINT_CACHE_PATHS }} - - website-typecheck: - needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - uses: ./.github/actions/setup-frontend - - name: Typecheck website - run: pnpm typecheck:website - - website-repo-checks: + website-checks: needs: changes - if: ${{ needs.changes.result == 'success' && needs.changes.outputs.website-only == 'true' }} + if: needs.changes.outputs.website-only == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -279,6 +215,8 @@ jobs: fetch-depth: 0 filter: blob:none - uses: ./.github/actions/setup-frontend + - name: Typecheck website + run: pnpm typecheck:website - name: Verify website repository integrity run: | pnpm knip --workspace apps/website diff --git a/package.json b/package.json index 8a4e197eaf2..7daac1cebf9 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "knip": "knip --cache", "lint:fix:no-cache": "pnpm oxlint --fix && eslint --concurrency auto --fix", "lint:fix:ci": "pnpm lint:fix --cache-strategy content", + "lint:fix:website": "stylelint --cache --cache-strategy content --fix 'apps/website/**/*.{css,vue}' && oxlint apps/website --type-aware --fix && eslint apps/website --cache --cache-strategy content --concurrency auto --fix && pnpm --filter @comfyorg/website format", "lint:fix": "pnpm oxlint --fix && eslint --cache --concurrency auto --fix", "lint:no-cache": "pnpm exec stylelint '{apps,packages,src}/**/*.{css,vue}' && pnpm oxlint && eslint --concurrency auto", "lint:unstaged:fix": "tsx scripts/lint-unstaged.ts --fix", From fcb15c31c8ee11c9499fc931e0bc19475c75fa6b Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 05:04:41 +0000 Subject: [PATCH 58/70] ci: tidy rollback inputs and the website-only output description Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- .coderabbit.yaml | 3 --- .github/actions/changes-filter/action.yaml | 2 +- .github/workflows/validation-website-rollback.yaml | 9 +++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index 2fc4a4c09af..68117a76e68 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -5,9 +5,6 @@ reviews: profile: assertive high_level_summary: false request_changes_workflow: true - # Website PRs use the dedicated Christian-identity approval fast lane. - # Keep CodeRabbit on mixed PRs by reviewing every non-website file, but do - # not let website-only changes generate an independent request-changes loop. path_filters: - '!apps/website/**' # Without this, a review that never happened (rate limit, internal error) diff --git a/.github/actions/changes-filter/action.yaml b/.github/actions/changes-filter/action.yaml index 342868f112a..feb778696b9 100644 --- a/.github/actions/changes-filter/action.yaml +++ b/.github/actions/changes-filter/action.yaml @@ -73,7 +73,7 @@ outputs: description: 'Root `.nvmrc`, `package.json`, `pnpm-lock.yaml`, or `pnpm-workspace.yaml` changed.' value: ${{ steps.mode.outputs.evaluate != 'true' || steps.filter.outputs.deps == 'true' }} website-only-changes: - description: 'Every changed file is under `apps/website/**`.' + description: 'Pull requests only: every changed file is under `apps/website/**`. Always false for other events.' value: ${{ steps.mode.outputs.evaluate == 'true' && steps.filter.outputs.app_website == 'true' && steps.relevant.outputs.outside_website != 'true' }} runs: diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml index 4957d0be52e..6621e95f58d 100644 --- a/.github/workflows/validation-website-rollback.yaml +++ b/.github/workflows/validation-website-rollback.yaml @@ -4,11 +4,11 @@ on: workflow_dispatch: inputs: deployment_id: - description: 'Immutable Vercel deployment ID captured before the canary deploy' + description: 'Immutable Vercel deployment ID to validate or restore (from the transition artifact)' required: true type: string expected_sha: - description: 'Source SHA expected at the canonical hostname after rollback' + description: 'Source SHA the target deployment must serve in /__build.json' required: true type: string perform_rollback: @@ -48,6 +48,7 @@ jobs: id: verify-target env: EXPECTED_SHA: ${{ inputs.expected_sha }} + PERFORM_ROLLBACK: ${{ inputs.perform_rollback }} TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} run: | if [[ ! "$TARGET_DEPLOYMENT" =~ ^dpl_[A-Za-z0-9]+$ ]]; then @@ -78,7 +79,7 @@ jobs: { echo "**Validated rollback target:** $TARGET_DEPLOYMENT" echo "**Validated rollback SHA:** $ACTUAL_SHA" - echo "**Production mutation requested:** ${{ inputs.perform_rollback }}" + echo "**Production mutation requested:** $PERFORM_ROLLBACK" } >> "$GITHUB_STEP_SUMMARY" - name: Roll back to the captured deployment @@ -148,7 +149,7 @@ jobs: echo "actual-sha=$ACTUAL_SHA" >> "$GITHUB_OUTPUT" echo "deployment-id=$ALIAS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" { - echo "**Rollback target:** ${{ inputs.deployment_id }}" + echo "**Rollback target:** $TARGET_DEPLOYMENT" echo "**Verified canonical SHA:** $ACTUAL_SHA" echo "**Verified canonical deployment:** $ALIAS_DEPLOYMENT_ID" } >> "$GITHUB_STEP_SUMMARY" From 6644fd5a0b84a053c6bd36deff5d12d0e564f83c Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 05:04:44 +0000 Subject: [PATCH 59/70] docs: record the fast-lane ADR and operator procedures Add CI-FAST-LANE-0041, correct the lane and trial docs against the engine, document recovery after a cancelled label run or a hold, and list the validation- workflow prefix. Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- .github/workflows/README.md | 15 ++-- ...-0041-path-scoped-policy-approval-lanes.md | 79 +++++++++++++++++++ docs/adr/README.md | 1 + docs/architecture/package-delivery-lanes.md | 56 +++++++------ .../website-delivery-validation.md | 21 +++-- 5 files changed, 135 insertions(+), 37 deletions(-) create mode 100644 docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 09d2bb52667..19dc97cc389 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -6,13 +6,14 @@ Workflow files follow a consistent naming pattern: `-. ### Category Prefixes -| Prefix | Purpose | Example | -| ---------- | ----------------------------------- | ------------------------------------ | -| `ci-` | Testing, linting, validation | `ci-tests-e2e.yaml` | -| `release-` | Version management, publishing | `release-version-bump.yaml` | -| `pr-` | PR automation (triggered by labels) | `pr-claude-review.yaml` | -| `api-` | External Api type generation | `api-update-registry-api-types.yaml` | -| `i18n-` | Internationalization updates | `i18n-update-core.yaml` | +| Prefix | Purpose | Example | +| ------------- | ----------------------------------------- | ------------------------------------ | +| `ci-` | Testing, linting, validation | `ci-tests-e2e.yaml` | +| `release-` | Version management, publishing | `release-version-bump.yaml` | +| `pr-` | PR automation (triggered by labels) | `pr-claude-review.yaml` | +| `api-` | External Api type generation | `api-update-registry-api-types.yaml` | +| `i18n-` | Internationalization updates | `i18n-update-core.yaml` | +| `validation-` | Manually dispatched production validation | `validation-website-rollback.yaml` | ## Documentation diff --git a/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md b/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md new file mode 100644 index 00000000000..f2a01edb387 --- /dev/null +++ b/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md @@ -0,0 +1,79 @@ +# ADR-CI-FAST-LANE-0041: Path-Scoped Policy Approval Lanes + +Date: 2026-10-08 + +## Status + +Proposed + +## Context + +Website changes live in this monorepo, so a copy edit under `apps/website/` waits for the same +full-repository checks and human review as a change to the editor. The website's owners want to +ship website-only changes on their own timeline without weakening the safeguards for the rest of +the repository. + +The `main` ruleset requires one approval, a `comfy_website_devs` approval for `apps/website/**`, +and the `lint-and-format`, `test`, `e2e-status`, and `website-e2e` checks. It dismisses stale +approvals on push and merges through the native merge queue. + +## Decision + +Introduce path-scoped delivery lanes, starting with the website: + +- Each lane has a reviewed JSON policy under `.github/fast-lanes/` that names its path prefixes, + trusted authors, operator label, trusted labelers, hold label, and merge mode. +- A website-only pull request runs website-scoped lint, format, typecheck, unused-code, and locale + checks inside the existing `lint-and-format` context. Mixed pull requests and merge-queue + candidates keep the full checks. +- `pr-website-auto-approve.yaml` runs `scripts/cicd/fast-lane/` from the default branch. For an + eligible same-repository pull request whose complete changed-file set is inside the lane, it + posts a policy-only approval bound to the exact head with a credential held in a + `main`-restricted environment, then arms native auto-merge or enters the queue. Every later run + re-reads live state and withdraws lane-owned approvals and merge state when the pull request + stops being eligible. +- A non-allowlisted author is eligible only on a trusted operator's `labeled` event for the + current head, and stays eligible only while the label remains applied. +- CodeRabbit skips `apps/website/**` for the trial; human change requests still block the lane. +- Website production deploys are staged, verified through `/__build.json`, then promoted; a + manual workflow validates or performs rollback. + +### Alternatives not chosen + +- **A GitHub App or bot identity instead of a personal token.** The trial uses an identity whose + team membership already satisfies the website review rule; moving to an App identity needs that + rule changed first. +- **A ruleset bypass list or CODEOWNERS change.** Either removes review for whole paths instead of + binding each approval to a policy decision on an exact head that can be withdrawn. +- **Keeping CodeRabbit on website files with `request_changes_workflow` disabled.** Its change + requests would still need a human to clear them on every website pull request. +- **Label freshness from timeline order.** Commit timeline entries carry author-controlled dates, + so a backdated push could sort before an older label. +- **One global concurrency group, or groups keyed by commit SHA.** A global group lets unrelated + pull requests cancel a pending hold or label run; SHA-keyed groups let two runs approve and + withdraw the same pull request at once. Runs are grouped per pull request instead. + +## Consequences + +### Positive + +- A trusted author's website-only change can reach the merge queue without waiting for a human + reviewer, and every approval is tied to one head and can be withdrawn. +- The rest of the repository keeps its checks, review rule, and merge queue unchanged. +- Another package can add a lane with its own policy, classifier output, and scoped checks. + +### Negative + +- No human reviews a fast-laned diff, and `apps/website/**` includes build configuration and code + that the production build runs with deployment secrets. +- Policy approvals come from a personal account; that account's own manual merge actions after its + first policy review are treated as lane-owned. +- GitHub keeps only the newest pending run per concurrency group, so a pending `labeled` run can be + cancelled by another event on the same pull request; the operator re-runs it or re-applies the + label. +- The trial adds a workflow, an engine, and a rollback procedure that operators must maintain. + +## Notes + +- Engine and operator model: [Package delivery lanes](../architecture/package-delivery-lanes.md). +- Trial runbook: [Website delivery validation](../architecture/website-delivery-validation.md). diff --git a/docs/adr/README.md b/docs/adr/README.md index 64f74e27647..89c03fc5680 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -34,6 +34,7 @@ An Architecture Decision Record captures an important architectural decision mad | [CANVAS-SELECTION-0028](CANVAS-SELECTION-0028-single-selection-store.md) | Single Selection Store | Proposed | 2026-09-04 | | [CANVAS-SELECTION-0031](CANVAS-SELECTION-0031-ordered-set-storage.md) | Ordered Set Storage for Selection | Proposed | 2026-09-15 | | [CANVAS-VIEWPORT-0009](CANVAS-VIEWPORT-0009-canvas-viewport-system.md) | Canvas Viewport System | Proposed | 2026-09-28 | +| [CI-FAST-LANE-0041](CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md) | Path-Scoped Policy Approval Lanes | Proposed | 2026-10-08 | | [CI-PREREQUISITES-0038](CI-PREREQUISITES-0038-gate-expensive-candidate-tests.md) | Gate expensive candidate tests | Proposed | 2026-09-25 | | [CRDT-AUTHORITY-0035](CRDT-AUTHORITY-0035-human-canvas-authority-and-draft-reconciliation.md) | Human Canvas Authority and Draft Reconciliation | Proposed | 2026-09-19 | | [CRDT-FOLLOWER-0025](CRDT-FOLLOWER-0025-in-app-agent-crdt-follower-and-distribution-resolved-boundaries.md) | In-App Agent CRDT Follower and Distribution-Resolved Boundaries | Accepted | 2026-08-21 | diff --git a/docs/architecture/package-delivery-lanes.md b/docs/architecture/package-delivery-lanes.md index 17ceaab73da..53994a11cee 100644 --- a/docs/architecture/package-delivery-lanes.md +++ b/docs/architecture/package-delivery-lanes.md @@ -8,23 +8,24 @@ without weakening the rest of the repository. A lane has four independent stages 3. **Approval:** apply the package's reviewed approval policy to the exact commit. 4. **Delivery:** use the repository's normal merge, deployment, and rollback systems. -The website is the first lane. The implementation is deliberately package-neutral so another -package can use the same engine with a different checked-in policy. +The website is the first lane. The approval engine in `scripts/cicd/fast-lane/` is package-neutral; +the change classifier output, the scoped CI jobs, and the workflow are per lane. ## The dials a package owns Each lane has a JSON policy in `.github/fast-lanes/`. A policy change receives normal repository review, so changing a dial is visible in history. -| Dial | Meaning | -| ----------------- | ------------------------------------------------------------------------------- | -| `pathPrefixes` | The complete set of paths the lane is allowed to change. | -| `trustedAuthors` | Authors who may receive a policy approval without an operator label. | -| `approvalLabel` | An explicit opt-in route for other authors. | -| `trustedLabelers` | Operators allowed to apply that label. | -| `holdLabel` | An immediate stop for the lane. | -| `merge.mode` | `automatic` arms native auto-merge or the queue; `manual` stops after approval. | -| `merge.method` | The repository-supported merge method used by automatic mode. | +| Dial | Meaning | +| -------------------------- | -------------------------------------------------------------------------------------------- | +| `pathPrefixes` | The complete set of paths the lane is allowed to change. | +| `approval.identity` | The GitHub account whose token posts policy approvals; verified before the lane acts. | +| `approval.trustedAuthors` | Authors who may receive a policy approval without an operator label. | +| `approval.approvalLabel` | An explicit opt-in route for other authors. | +| `approval.trustedLabelers` | Operators allowed to apply that label. | +| `approval.holdLabel` | Stops the lane at its next run: dismisses lane approvals and disarms lane-owned merge state. | +| `merge.mode` | `automatic` arms native auto-merge or the queue; `manual` stops after approval. | +| `merge.method` | The repository-supported merge method used by automatic mode. | Package-specific quality commands remain in the package's CI jobs. The first routing rule is simple: a package-only pull request runs that package's checks; a mixed or root-level pull request @@ -48,26 +49,37 @@ These are implementation invariants, not package dials: change requests. - The credential's GitHub identity must match the identity declared in the policy, and it cannot approve its own pull request. -- If post-approval verification fails, the newly created approval is dismissed. -- Approval, queue, and compensation runs are serialized per pull request. Compensation attempts - merge-state teardown and every active policy-review dismissal independently so one API failure - cannot skip the other safety action. -- The lane only disables auto-merge or queue state that its own identity created after its policy - approval. It does not undo another person's merge decision. +- If verification or arming fails after the policy approval, every active policy approval is + dismissed. A run whose event head is no longer the pull request head changes nothing; the + repository ruleset dismisses approvals of older heads on push, and the run for the new head + decides again. +- Fast-lane runs for one pull request share a concurrency group, so at most one runs at a time and + GitHub keeps only the newest pending run. Hold and label-removal runs are safe to lose because + every run reads the live labels; a pending `labeled` approval run is not, and the operator + re-runs it or re-applies the label. Compensation attempts merge-state teardown and each active + policy-approval dismissal separately, so one failed API call does not skip the others. +- The lane disables only auto-merge or queue state that its identity enabled at or after its first + policy review on the pull request. Because the identity is a personal account, that includes the + account owner's own merge actions in that window. The reusable TypeScript engine lives in `scripts/cicd/fast-lane/`. `policy.ts` contains pure policy decisions, `github.ts` contains GitHub transport, and `automation.ts` owns the approval and merge -lifecycle. Behavioral tests cover the fixed rules independently of a live repository. +lifecycle. Behavioral tests run `runFastLane` against an in-memory GitHub double and cover each +fixed rule. ## Adding a lane 1. Add a reviewed policy file under `.github/fast-lanes/`. -2. Teach the change classifier to recognize the package-only path set. +2. Add a package-only output to the change classifier (`.github/actions/changes-filter`) and a + test that ties it to the policy's `pathPrefixes`. 3. Add package-scoped lint, format, typecheck, test, and repository checks behind that result. Keep the full checks as the fallback for mixed changes. -4. Add a thin `pull_request_target` workflow that checks out only `.nvmrc`, the selected policy, - and `scripts/cicd/fast-lane/` from the default branch. Run `run.ts` with Node's TypeScript - stripping; do not install pull request dependencies. +4. Add a workflow like `pr-website-auto-approve.yaml`: `pull_request_target`, `status`, and + `workflow_run` triggers; a resolver job that finds the pull request; and one lane job keyed on + that pull request's concurrency group. The lane job sparse-checks out `.nvmrc`, the selected + policy, and `scripts/cicd/fast-lane/` from the default branch (cone mode also includes + root-level files) and runs `node scripts/cicd/fast-lane/run.ts` without installing + dependencies. 5. Put the approval credential in a package-specific protected environment and restrict that environment to the protected default branch. 6. Add negative tests for forks, mixed paths, stale heads, self-approval, unauthorized labels, diff --git a/docs/architecture/website-delivery-validation.md b/docs/architecture/website-delivery-validation.md index d3d55f43f07..1a35c286fb3 100644 --- a/docs/architecture/website-delivery-validation.md +++ b/docs/architecture/website-delivery-validation.md @@ -6,9 +6,13 @@ change on their timeline while the rest of the monorepo keeps its current safegu ## Current lane The checked-in policy is `.github/fast-lanes/website.json`. It allows changes only under -`apps/website/`. Stage 1 includes `bertfy` as a trusted author and also accepts a fresh -`website-fast-lane:approve` label from one of the listed operators. `website-fast-lane:hold`, a -draft, a human change request, a fork, a mixed-path change, or a stale head stops the lane. +`apps/website/`. `bertfy` is a trusted author. For other authors, a listed operator adds +`website-fast-lane:approve` to the current head; removing it withdraws the approval. +`website-fast-lane:hold`, a draft, a human change request, a fork, or a mixed-path change stops the +lane. A hold does not undo a merge that already happened. To resume after a hold, remove +`website-fast-lane:hold`; for an author who is not in the allowlist, also remove and re-apply +`website-fast-lane:approve`. If the run for an approval label shows as cancelled, a listed operator +re-runs it or re-applies the label; a re-run works only while the head is unchanged. The `website-approval` environment supplies `WEBSITE_APPROVAL_TOKEN`. The credential currently belongs to `christian-byrne`, whose team membership satisfies the website path review rule. The @@ -33,14 +37,15 @@ mode validates the target and marker without changing production. With `perform_ it performs an instant rollback, verifies the canonical marker and public homepage, then promotes the same known-good deployment so normal production assignment can resume. -The first production deployment containing `/__build.json` is bootstrap evidence, not the positive -canary. Before opening the disposable canary: +The first production deployment containing `/__build.json` is bootstrap evidence, not the canary. +Before opening the canary: -1. Download that deployment's transition artifact. +1. Within 7 days, download that deployment's transition artifact (the same IDs appear in the run's + step summary). 2. Run `Validation: Website Production Rollback` with its `deployedDeploymentId` and `deployedSha`. 3. Leave `perform_rollback` disabled and require the no-mutation preflight to pass. -4. Run the canary from update through production, then exercise rollback only under the agreed - trial procedure. +4. Run the canary from update through production. A real rollback (`perform_rollback: true`) + changes production, so run it only when the operators running the trial agree to it. ## Evidence to record From eab7e2d3d5690ff3109acb4e4169338fd5803992 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 05:40:50 +0000 Subject: [PATCH 60/70] refactor(ci): share website deployment identity checks Move the build-identity writer, Vercel alias and deployment lookups, and the five identity polls from the preview, production, and rollback jobs into scripts/cicd/website-deployment.sh, tested with a stubbed curl. Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- .../workflows/ci-vercel-website-preview.yaml | 119 ++--------- .../validation-website-rollback.yaml | 80 +------ .../website-delivery-validation.md | 3 +- scripts/cicd/website-deployment.sh | 99 +++++++++ scripts/cicd/website-deployment.test.ts | 197 ++++++++++++++++++ 5 files changed, 323 insertions(+), 175 deletions(-) create mode 100755 scripts/cicd/website-deployment.sh create mode 100644 scripts/cicd/website-deployment.test.ts diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index fa7a8829d02..54a7fb92113 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -59,19 +59,8 @@ jobs: - name: Write preview build identity env: - BUILD_REPOSITORY: ${{ github.repository }} BUILD_SHA: ${{ github.event.pull_request.head.sha }} - BUILD_RUN_ID: ${{ github.run_id }} - BUILD_RUN_ATTEMPT: ${{ github.run_attempt }} - run: | - jq -n \ - --arg repository "$BUILD_REPOSITORY" \ - --arg sha "$BUILD_SHA" \ - --arg runId "$BUILD_RUN_ID" \ - --arg runAttempt "$BUILD_RUN_ATTEMPT" \ - --arg builtAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ - '{repository: $repository, sha: $sha, runId: $runId, runAttempt: $runAttempt, builtAt: $builtAt}' \ - > apps/website/public/__build.json + run: scripts/cicd/website-deployment.sh write-build-identity "$BUILD_SHA" - name: Build project artifacts env: @@ -123,18 +112,8 @@ jobs: DEPLOY_URL: ${{ steps.deploy.outputs.url }} EXPECTED_SHA: ${{ github.event.pull_request.head.sha }} run: | - for attempt in {1..30}; do - ACTUAL_SHA=$(curl -fsS \ - -H 'Cache-Control: no-cache' \ - "$DEPLOY_URL/__build.json?run=$GITHUB_RUN_ID-$attempt" | - jq -r '.sha // empty') || true - if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" ]]; then - exit 0 - fi - sleep 5 - done - echo "::error::Immutable preview did not serve expected SHA $EXPECTED_SHA" - exit 1 + scripts/cicd/website-deployment.sh verify-identity \ + --host "$DEPLOY_URL" --sha "$EXPECTED_SHA" --attempts 30 --interval 5 - name: Alias deployment to stable PR hostname id: alias-set @@ -203,40 +182,14 @@ jobs: - name: Capture the current production deployment id: previous-production run: | - ALIAS=$(curl -fsS --retry 3 \ - -H "Authorization: Bearer $VERCEL_TOKEN" \ - "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID") - PREVIOUS_DEPLOYMENT_ID=$(jq -er '.deploymentId' <<< "$ALIAS") - DEPLOYMENT=$(curl -fsS --retry 3 \ - -H "Authorization: Bearer $VERCEL_TOKEN" \ - "https://api.vercel.com/v13/deployments/$PREVIOUS_DEPLOYMENT_ID?teamId=$VERCEL_ORG_ID") - PREVIOUS_DEPLOYMENT_URL=$(jq -er \ - --arg deploymentId "$PREVIOUS_DEPLOYMENT_ID" \ - --arg projectId "$VERCEL_PROJECT_ID" \ - 'select(.id == $deploymentId and (.projectId // .project.id) == $projectId) | .url' \ - <<< "$DEPLOYMENT") - PREVIOUS_SHA=$(curl -fsS \ - -H 'Cache-Control: no-cache' \ - "https://$PREVIOUS_DEPLOYMENT_URL/__build.json?before=$GITHUB_RUN_ID" | - jq -r '.sha // empty') || true + PREVIOUS_DEPLOYMENT_ID=$(scripts/cicd/website-deployment.sh alias-deployment-id) + PREVIOUS_DEPLOYMENT_URL=$(scripts/cicd/website-deployment.sh deployment "$PREVIOUS_DEPLOYMENT_ID" url) + PREVIOUS_SHA=$(scripts/cicd/website-deployment.sh marker-sha "$PREVIOUS_DEPLOYMENT_URL") || true echo "deployment-id=$PREVIOUS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" echo "sha=${PREVIOUS_SHA:-unavailable}" >> "$GITHUB_OUTPUT" - name: Write production build identity - env: - BUILD_REPOSITORY: ${{ github.repository }} - BUILD_SHA: ${{ github.sha }} - BUILD_RUN_ID: ${{ github.run_id }} - BUILD_RUN_ATTEMPT: ${{ github.run_attempt }} - run: | - jq -n \ - --arg repository "$BUILD_REPOSITORY" \ - --arg sha "$BUILD_SHA" \ - --arg runId "$BUILD_RUN_ID" \ - --arg runAttempt "$BUILD_RUN_ATTEMPT" \ - --arg builtAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ - '{repository: $repository, sha: $sha, runId: $runId, runAttempt: $runAttempt, builtAt: $builtAt}' \ - > apps/website/public/__build.json + run: scripts/cicd/website-deployment.sh write-build-identity "$GITHUB_SHA" - name: Verify WEBSITE_CLOUD_API_KEY is present for production build env: @@ -300,39 +253,16 @@ jobs: echo "::error::Unexpected immutable deployment URL: $DEPLOY_URL" exit 1 fi - DEPLOYMENT=$(curl -fsS --retry 3 \ - -H "Authorization: Bearer $VERCEL_TOKEN" \ - "https://api.vercel.com/v13/deployments/$DEPLOYMENT_HOST?teamId=$VERCEL_ORG_ID") - DEPLOYED_DEPLOYMENT_ID=$(jq -er \ - --arg projectId "$VERCEL_PROJECT_ID" \ - 'select((.projectId // .project.id) == $projectId) | .id' \ - <<< "$DEPLOYMENT") + DEPLOYED_DEPLOYMENT_ID=$(scripts/cicd/website-deployment.sh deployment "$DEPLOYMENT_HOST" id) echo "deployment-id=$DEPLOYED_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" - name: Verify staged production identity env: DEPLOY_URL: ${{ steps.deploy.outputs.url }} - EXPECTED_RUN_ATTEMPT: ${{ github.run_attempt }} - EXPECTED_RUN_ID: ${{ github.run_id }} - EXPECTED_SHA: ${{ github.sha }} timeout-minutes: 12 run: | - for attempt in {1..30}; do - if MARKER=$(curl -fsS \ - -H 'Cache-Control: no-cache' \ - "${DEPLOY_URL%/}/__build.json?staged=$GITHUB_RUN_ID-$attempt") && - jq -e \ - --arg sha "$EXPECTED_SHA" \ - --arg runId "$EXPECTED_RUN_ID" \ - --arg runAttempt "$EXPECTED_RUN_ATTEMPT" \ - '.sha == $sha and .runId == $runId and .runAttempt == $runAttempt' \ - <<< "$MARKER" >/dev/null; then - exit 0 - fi - sleep 5 - done - echo "::error::Staged deployment did not serve expected build identity" - exit 1 + scripts/cicd/website-deployment.sh verify-identity \ + --host "$DEPLOY_URL" --sha "$GITHUB_SHA" --this-run --attempts 30 --interval 5 - name: Retain production transition evidence env: @@ -380,33 +310,12 @@ jobs: - name: Verify canonical production identity env: EXPECTED_DEPLOYMENT_ID: ${{ steps.deployed-production.outputs.deployment-id }} - EXPECTED_RUN_ATTEMPT: ${{ github.run_attempt }} - EXPECTED_RUN_ID: ${{ github.run_id }} - EXPECTED_SHA: ${{ github.sha }} timeout-minutes: 12 run: | - for attempt in {1..60}; do - MARKER=$(curl -fsS \ - -H 'Cache-Control: no-cache' \ - "https://comfy.org/__build.json?promoted=$GITHUB_RUN_ID-$attempt") || MARKER='{}' - ALIAS_DEPLOYMENT_ID=$(curl -fsS --retry 3 \ - -H "Authorization: Bearer $VERCEL_TOKEN" \ - "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" | - jq -r '.deploymentId // empty') || true - if jq -e \ - --arg sha "$EXPECTED_SHA" \ - --arg runId "$EXPECTED_RUN_ID" \ - --arg runAttempt "$EXPECTED_RUN_ATTEMPT" \ - '.sha == $sha and .runId == $runId and .runAttempt == $runAttempt' \ - <<< "$MARKER" >/dev/null && - [[ "$ALIAS_DEPLOYMENT_ID" == "$EXPECTED_DEPLOYMENT_ID" ]]; then - curl -fsS -o /dev/null https://comfy.org/ - exit 0 - fi - sleep 10 - done - echo "::error::Canonical production did not serve the promoted deployment identity" - exit 1 + scripts/cicd/website-deployment.sh verify-identity \ + --canonical-deployment "$EXPECTED_DEPLOYMENT_ID" --sha "$GITHUB_SHA" --this-run \ + --attempts 60 --interval 10 + - name: Notify IndexNow of changed pages continue-on-error: true timeout-minutes: 5 diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml index 6621e95f58d..f45c6dba062 100644 --- a/.github/workflows/validation-website-rollback.yaml +++ b/.github/workflows/validation-website-rollback.yaml @@ -45,7 +45,6 @@ jobs: run: vercel pull --yes --environment=production - name: Verify the captured deployment - id: verify-target env: EXPECTED_SHA: ${{ inputs.expected_sha }} PERFORM_ROLLBACK: ${{ inputs.perform_rollback }} @@ -59,26 +58,11 @@ jobs: echo "::error::Expected SHA must be a full lowercase Git commit SHA" exit 1 fi - DEPLOYMENT=$(curl -fsS --retry 3 \ - -H "Authorization: Bearer $VERCEL_TOKEN" \ - "https://api.vercel.com/v13/deployments/$TARGET_DEPLOYMENT?teamId=$VERCEL_ORG_ID") - TARGET_URL=$(jq -er \ - --arg deploymentId "$TARGET_DEPLOYMENT" \ - --arg projectId "$VERCEL_PROJECT_ID" \ - 'select(.id == $deploymentId and (.projectId // .project.id) == $projectId) | .url' \ - <<< "$DEPLOYMENT") - ACTUAL_SHA=$(curl -fsS \ - -H 'Cache-Control: no-cache' \ - "https://$TARGET_URL/__build.json?preflight=$GITHUB_RUN_ID" | - jq -er '.sha') - if [[ "$ACTUAL_SHA" != "$EXPECTED_SHA" ]]; then - echo "::error::Deployment $TARGET_DEPLOYMENT serves $ACTUAL_SHA, expected $EXPECTED_SHA" - exit 1 - fi - echo "actual-sha=$ACTUAL_SHA" >> "$GITHUB_OUTPUT" + TARGET_URL=$(scripts/cicd/website-deployment.sh deployment "$TARGET_DEPLOYMENT" url) + scripts/cicd/website-deployment.sh verify-identity --host "$TARGET_URL" --sha "$EXPECTED_SHA" { echo "**Validated rollback target:** $TARGET_DEPLOYMENT" - echo "**Validated rollback SHA:** $ACTUAL_SHA" + echo "**Validated rollback SHA:** $EXPECTED_SHA" echo "**Production mutation requested:** $PERFORM_ROLLBACK" } >> "$GITHUB_STEP_SUMMARY" @@ -93,31 +77,14 @@ jobs: --scope="$VERCEL_SCOPE" - name: Verify rollback at the canonical hostname - id: verify-canonical if: inputs.perform_rollback env: EXPECTED_SHA: ${{ inputs.expected_sha }} TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} run: | - for attempt in {1..60}; do - ACTUAL_SHA=$(curl -fsS \ - -H 'Cache-Control: no-cache' \ - "https://comfy.org/__build.json?rollback=$GITHUB_RUN_ID-$attempt" | - jq -r '.sha // empty') || true - ALIAS_DEPLOYMENT_ID=$(curl -fsS --retry 3 \ - -H "Authorization: Bearer $VERCEL_TOKEN" \ - "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" | - jq -r '.deploymentId // empty') || true - if [[ "$ACTUAL_SHA" == "$EXPECTED_SHA" && "$ALIAS_DEPLOYMENT_ID" == "$TARGET_DEPLOYMENT" ]]; then - curl -fsS -o /dev/null https://comfy.org/ - echo "actual-sha=$ACTUAL_SHA" >> "$GITHUB_OUTPUT" - echo "deployment-id=$ALIAS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" - exit 0 - fi - sleep 10 - done - echo "::error::Canonical production did not return to expected SHA $EXPECTED_SHA" - exit 1 + scripts/cicd/website-deployment.sh verify-identity \ + --canonical-deployment "$TARGET_DEPLOYMENT" --sha "$EXPECTED_SHA" \ + --attempts 60 --interval 10 - name: Preserve the rolled-back deployment and resume automatic promotion if: inputs.perform_rollback @@ -130,57 +97,32 @@ jobs: --scope="$VERCEL_SCOPE" - name: Verify post-rollback promotion state - id: verify-promotion if: inputs.perform_rollback env: EXPECTED_SHA: ${{ inputs.expected_sha }} TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} run: | - ACTUAL_SHA=$(curl -fsS \ - -H 'Cache-Control: no-cache' \ - "https://comfy.org/__build.json?promote=$GITHUB_RUN_ID" | - jq -r '.sha // empty') - ALIAS_DEPLOYMENT_ID=$(curl -fsS --retry 3 \ - -H "Authorization: Bearer $VERCEL_TOKEN" \ - "https://api.vercel.com/v4/aliases/comfy.org?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" | - jq -er '.deploymentId') - test "$ACTUAL_SHA" = "$EXPECTED_SHA" - test "$ALIAS_DEPLOYMENT_ID" = "$TARGET_DEPLOYMENT" - echo "actual-sha=$ACTUAL_SHA" >> "$GITHUB_OUTPUT" - echo "deployment-id=$ALIAS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" - { - echo "**Rollback target:** $TARGET_DEPLOYMENT" - echo "**Verified canonical SHA:** $ACTUAL_SHA" - echo "**Verified canonical deployment:** $ALIAS_DEPLOYMENT_ID" - } >> "$GITHUB_STEP_SUMMARY" + scripts/cicd/website-deployment.sh verify-identity \ + --canonical-deployment "$TARGET_DEPLOYMENT" --sha "$EXPECTED_SHA" + echo "**Verified canonical deployment:** $TARGET_DEPLOYMENT at $EXPECTED_SHA" >> "$GITHUB_STEP_SUMMARY" - name: Retain rollback evidence env: EXPECTED_SHA: ${{ inputs.expected_sha }} PERFORM_ROLLBACK: ${{ inputs.perform_rollback }} - POST_PROMOTION_DEPLOYMENT_ID: ${{ steps.verify-promotion.outputs.deployment-id }} - POST_PROMOTION_SHA: ${{ steps.verify-promotion.outputs.actual-sha }} - ROLLBACK_DEPLOYMENT_ID: ${{ steps.verify-canonical.outputs.deployment-id }} - ROLLBACK_SHA: ${{ steps.verify-canonical.outputs.actual-sha }} TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} - TARGET_VERIFIED_SHA: ${{ steps.verify-target.outputs.actual-sha }} run: | mkdir -p temp/website-rollback-result jq -n \ --arg targetDeploymentId "$TARGET_DEPLOYMENT" \ --arg expectedSha "$EXPECTED_SHA" \ - --arg targetVerifiedSha "$TARGET_VERIFIED_SHA" \ - --arg rollbackCanonicalSha "$ROLLBACK_SHA" \ - --arg rollbackCanonicalDeploymentId "$ROLLBACK_DEPLOYMENT_ID" \ - --arg postPromotionCanonicalSha "$POST_PROMOTION_SHA" \ - --arg postPromotionCanonicalDeploymentId "$POST_PROMOTION_DEPLOYMENT_ID" \ + --argjson performRollback "$PERFORM_ROLLBACK" \ --arg runId "$GITHUB_RUN_ID" \ --arg runAttempt "$GITHUB_RUN_ATTEMPT" \ --arg workflowSha "$GITHUB_SHA" \ --arg actor "$GITHUB_ACTOR" \ --arg verifiedAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ - --argjson performRollback "$PERFORM_ROLLBACK" \ - '{targetDeploymentId: $targetDeploymentId, expectedSha: $expectedSha, targetVerifiedSha: $targetVerifiedSha, performRollback: $performRollback, rollbackCanonicalSha: $rollbackCanonicalSha, rollbackCanonicalDeploymentId: $rollbackCanonicalDeploymentId, postPromotionCanonicalSha: $postPromotionCanonicalSha, postPromotionCanonicalDeploymentId: $postPromotionCanonicalDeploymentId, runId: $runId, runAttempt: $runAttempt, workflowSha: $workflowSha, actor: $actor, verifiedAt: $verifiedAt}' \ + '{$targetDeploymentId, $expectedSha, $performRollback, $runId, $runAttempt, $workflowSha, $actor, $verifiedAt}' \ > temp/website-rollback-result/result.json - name: Upload rollback evidence diff --git a/docs/architecture/website-delivery-validation.md b/docs/architecture/website-delivery-validation.md index 1a35c286fb3..26eba062f0d 100644 --- a/docs/architecture/website-delivery-validation.md +++ b/docs/architecture/website-delivery-validation.md @@ -30,7 +30,8 @@ block the lane. Each website preview and production build writes a cache-disabled `/__build.json` with the repository, exact source SHA, workflow run, attempt, and build time. Deployment verifies the immutable Vercel URL before accepting canonical `comfy.org` promotion and saves the previous and -new deployment IDs and SHAs as a short-lived transition artifact. +new deployment IDs and SHAs as a short-lived transition artifact. Both deployment workflows use +`scripts/cicd/website-deployment.sh` for the build identity, Vercel lookups, and identity checks. `validation-website-rollback.yaml` accepts an immutable deployment ID and expected SHA. Its default mode validates the target and marker without changing production. With `perform_rollback` enabled, diff --git a/scripts/cicd/website-deployment.sh b/scripts/cicd/website-deployment.sh new file mode 100755 index 00000000000..a8c97089ab1 --- /dev/null +++ b/scripts/cicd/website-deployment.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +set -euo pipefail + +readonly CANONICAL_HOST=comfy.org +readonly BUILD_IDENTITY_PATH=apps/website/public/__build.json + +vercel_api() { + curl -fsS --retry 3 \ + -H "Authorization: Bearer ${VERCEL_TOKEN:?VERCEL_TOKEN is required}" \ + "https://api.vercel.com/$1" +} + +write_build_identity() { + jq -n \ + --arg repository "${GITHUB_REPOSITORY:?}" \ + --arg sha "${1:?usage: write-build-identity }" \ + --arg runId "${GITHUB_RUN_ID:?}" \ + --arg runAttempt "${GITHUB_RUN_ATTEMPT:?}" \ + --arg builtAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + '{$repository, $sha, $runId, $runAttempt, $builtAt}' \ + >"$BUILD_IDENTITY_PATH" +} + +alias_deployment_id() { + vercel_api "v4/aliases/$CANONICAL_HOST?projectId=${VERCEL_PROJECT_ID:?}&teamId=${VERCEL_ORG_ID:?}" | + jq -er '.deploymentId' +} + +deployment_field() { + local ref=${1:?usage: deployment } + local field=${2:?usage: deployment } + vercel_api "v13/deployments/$ref?teamId=${VERCEL_ORG_ID:?}" | + jq -er --arg ref "$ref" --arg field "$field" --arg projectId "${VERCEL_PROJECT_ID:?}" \ + 'select((.projectId // .project.id) == $projectId and (.id == $ref or ($ref | startswith("dpl_") | not))) | .[$field]' +} + +host_of() { + local host=${1#https://} + printf '%s' "${host%/}" +} + +build_identity() { + curl -fsS -H 'Cache-Control: no-cache' \ + "https://$(host_of "$1")/__build.json?probe=${GITHUB_RUN_ID:-local}-${GITHUB_RUN_ATTEMPT:-0}-$2" +} + +marker_sha() { + build_identity "${1:?usage: marker-sha }" 0 | jq -r '.sha // empty' +} + +verify_identity() { + local host='' sha='' deployment='' this_run=false attempts=1 interval=0 + while (($#)); do + case $1 in + --host) host=$2 ;; + --sha) sha=$2 ;; + --canonical-deployment) deployment=$2 host=$CANONICAL_HOST ;; + --attempts) attempts=$2 ;; + --interval) interval=$2 ;; + --this-run) this_run=true && shift && continue ;; + *) echo "unknown option: $1" >&2 && return 2 ;; + esac + shift 2 + done + : "${host:?--host or --canonical-deployment is required}" "${sha:?--sha is required}" + + for ((attempt = 1; attempt <= attempts; attempt++)); do + if serves_identity "$attempt"; then return 0; fi + if ((attempt < attempts)); then sleep "$interval"; fi + done + echo "::error::$(host_of "$host") did not serve $sha${deployment:+ from $deployment}" + return 1 +} + +serves_identity() { + local identity + identity=$(build_identity "$host" "$1") || return 1 + jq -e \ + --arg sha "$sha" \ + --argjson thisRun "$this_run" \ + --arg runId "${GITHUB_RUN_ID:-}" \ + --arg runAttempt "${GITHUB_RUN_ATTEMPT:-}" \ + '.sha == $sha and (($thisRun | not) or (.runId == $runId and .runAttempt == $runAttempt))' \ + <<<"$identity" >/dev/null || return 1 + [[ -z $deployment ]] && return 0 + [[ $(alias_deployment_id || true) == "$deployment" ]] || return 1 + curl -fsS -o /dev/null "https://$CANONICAL_HOST/" +} + +command=${1:?usage: website-deployment.sh [args]} +shift +case $command in + write-build-identity) write_build_identity "$@" ;; + alias-deployment-id) alias_deployment_id ;; + deployment) deployment_field "$@" ;; + marker-sha) marker_sha "$@" ;; + verify-identity) verify_identity "$@" ;; + *) echo "unknown command: $command" >&2 && exit 2 ;; +esac diff --git a/scripts/cicd/website-deployment.test.ts b/scripts/cicd/website-deployment.test.ts new file mode 100644 index 00000000000..4a4403d63df --- /dev/null +++ b/scripts/cicd/website-deployment.test.ts @@ -0,0 +1,197 @@ +import { spawnSync } from 'node:child_process' +import fs from 'node:fs' +import os from 'node:os' +import path from 'node:path' + +import { afterEach, beforeEach, describe, expect, it } from 'vitest' + +const SCRIPT = path.join(import.meta.dirname, 'website-deployment.sh') +const SHA = 'a'.repeat(40) +const PROJECT = 'prj_website' +const DEPLOYMENT = 'dpl_new' + +const ownIdentity = { sha: SHA, runId: '7', runAttempt: '2' } + +const fakeCurl = `#!/usr/bin/env bash +for url; do :; done +printf '%s\\n' "$url" >> "$FAKE_DIR/calls.log" +case $url in + https://api.vercel.com/v4/aliases/*) file=alias.json ;; + https://api.vercel.com/v13/deployments/*) file=deployment.json ;; + */__build.json*) host=\${url#https://}; file=identity-\${host%%/*}.json ;; + https://comfy.org/) exit 0 ;; +esac +[[ -n \${file:-} && -f $FAKE_DIR/$file ]] || exit 22 +cat "$FAKE_DIR/$file" +` + +let dir: string + +beforeEach(() => { + dir = fs.mkdtempSync(path.join(os.tmpdir(), 'website-deployment-')) + fs.mkdirSync(path.join(dir, 'bin')) + fs.mkdirSync(path.join(dir, 'apps/website/public'), { recursive: true }) + fs.writeFileSync(path.join(dir, 'bin/curl'), fakeCurl, { mode: 0o755 }) +}) + +afterEach(() => { + fs.rmSync(dir, { recursive: true, force: true }) +}) + +function serve(responses: Record) { + for (const [file, body] of Object.entries(responses)) { + fs.writeFileSync(path.join(dir, file), JSON.stringify(body)) + } +} + +function run(...args: string[]) { + const result = spawnSync('bash', [SCRIPT, ...args], { + cwd: dir, + encoding: 'utf8', + env: { + PATH: `${path.join(dir, 'bin')}:${process.env.PATH ?? ''}`, + FAKE_DIR: dir, + GITHUB_REPOSITORY: 'Comfy-Org/ComfyUI_frontend', + GITHUB_RUN_ID: '7', + GITHUB_RUN_ATTEMPT: '2', + VERCEL_ORG_ID: 'team_comfy', + VERCEL_PROJECT_ID: PROJECT, + VERCEL_TOKEN: 'token' + } + }) + const log = path.join(dir, 'calls.log') + return { + status: result.status, + stdout: result.stdout.trim(), + calls: fs.existsSync(log) + ? fs.readFileSync(log, 'utf8').trim().split('\n') + : [] + } +} + +describe('website deployment identity', () => { + it('writes the build identity for the current run', () => { + expect(run('write-build-identity', SHA).status).toBe(0) + + expect( + JSON.parse( + fs.readFileSync( + path.join(dir, 'apps/website/public/__build.json'), + 'utf8' + ) + ) + ).toMatchObject({ + repository: 'Comfy-Org/ComfyUI_frontend', + ...ownIdentity + }) + }) + + it.for([ + { + name: 'the URL of its own deployment', + args: [DEPLOYMENT, 'url'], + deployment: { id: DEPLOYMENT, projectId: PROJECT, url: 'new.vercel.app' }, + expected: 'new.vercel.app' + }, + { + name: 'the id of its own deployment host', + args: ['new.vercel.app', 'id'], + deployment: { id: DEPLOYMENT, project: { id: PROJECT } }, + expected: DEPLOYMENT + }, + { + name: 'nothing for another project', + args: [DEPLOYMENT, 'url'], + deployment: { id: DEPLOYMENT, projectId: 'prj_other', url: 'x' }, + expected: undefined + }, + { + name: 'nothing for a different deployment id', + args: [DEPLOYMENT, 'url'], + deployment: { id: 'dpl_other', projectId: PROJECT, url: 'x' }, + expected: undefined + } + ])('resolves $name', ({ args, deployment, expected }) => { + serve({ 'deployment.json': deployment }) + + const result = run('deployment', ...args) + + expect(result.status === 0 ? result.stdout : undefined).toBe(expected) + }) + + it.for([ + { + name: 'a matching preview', + args: ['--host', 'https://new.vercel.app/'], + identity: { sha: SHA }, + ok: true + }, + { + name: 'a preview serving another commit', + args: ['--host', 'new.vercel.app'], + identity: { sha: 'b'.repeat(40) }, + ok: false + }, + { + name: 'a staged build from this run', + args: ['--host', 'new.vercel.app', '--this-run'], + identity: ownIdentity, + ok: true + }, + { + name: 'a staged build from an earlier attempt', + args: ['--host', 'new.vercel.app', '--this-run'], + identity: { ...ownIdentity, runAttempt: '1' }, + ok: false + }, + { + name: 'a canonical host on the expected deployment', + args: ['--canonical-deployment', DEPLOYMENT], + identity: { sha: SHA }, + ok: true + }, + { + name: 'a canonical host aliased to another deployment', + args: ['--canonical-deployment', 'dpl_old'], + identity: { sha: SHA }, + ok: false + } + ])('verifies $name: $ok', ({ args, identity, ok }) => { + serve({ + 'identity-new.vercel.app.json': identity, + 'identity-comfy.org.json': identity, + 'alias.json': { deploymentId: DEPLOYMENT } + }) + + const result = run('verify-identity', '--sha', SHA, ...args) + + expect(result.status === 0).toBe(ok) + }) + + it('retries until the attempts are exhausted', () => { + serve({ 'identity-new.vercel.app.json': { sha: 'b'.repeat(40) } }) + + const result = run( + 'verify-identity', + '--host', + 'new.vercel.app', + '--sha', + SHA, + '--attempts', + '3' + ) + + expect(result.status).toBe(1) + expect(result.calls).toHaveLength(3) + }) + + it('reads the deployment aliased to comfy.org', () => { + serve({ 'alias.json': { deploymentId: 'dpl_live' } }) + + expect(run('alias-deployment-id').stdout).toBe('dpl_live') + }) + + it('reports an empty marker SHA when the deployment has no identity', () => { + expect(run('marker-sha', 'old.vercel.app').stdout).toBe('') + }) +}) From cbf77d9dac4933f88fca32b3ba09ac45a6a153ac Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 05:41:06 +0000 Subject: [PATCH 61/70] refactor(ci): remove duplicated fast-lane logic Share login, repository, and merge-state checks; run every compensation step through one collector; share the lane, pull request, and policy approval test fixtures; reuse the parsed changes-filter action. Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- .../workflows/pr-website-auto-approve.yaml | 4 +- scripts/cicd/changes-filter.test.ts | 50 ++---- scripts/cicd/fast-lane/__fixtures__/lane.ts | 63 +++++++ scripts/cicd/fast-lane/automation.test.ts | 101 ++++------- scripts/cicd/fast-lane/automation.ts | 169 +++++++++--------- scripts/cicd/fast-lane/config.test.ts | 18 +- scripts/cicd/fast-lane/config.ts | 45 ++--- scripts/cicd/fast-lane/policy.test.ts | 106 ++++------- scripts/cicd/fast-lane/policy.ts | 30 ++-- 9 files changed, 260 insertions(+), 326 deletions(-) create mode 100644 scripts/cicd/fast-lane/__fixtures__/lane.ts diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 8ebc45b8910..0f085314dc1 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -4,9 +4,7 @@ # - pull_request_target, workflow_run, and status load this workflow from the # default branch. Automation and policy are checked out from the protected # default branch; pull request code is never executed. -# - the script rejects other base branches and forks, re-fetches the live PR, -# verifies the exact head SHA, requires every changed path to be under -# apps/website/**, and verifies the PAT owner. +# - Eligibility rules: docs/architecture/package-delivery-lanes.md. name: 'PR: Website Fast Lane' on: diff --git a/scripts/cicd/changes-filter.test.ts b/scripts/cicd/changes-filter.test.ts index cbb84eebe18..5a95ea18f01 100644 --- a/scripts/cicd/changes-filter.test.ts +++ b/scripts/cicd/changes-filter.test.ts @@ -17,7 +17,8 @@ const action = z id: z.string(), if: z.string().optional(), run: z.string().optional(), - env: z.object({ EVALUATE: z.string() }).optional() + env: z.object({ EVALUATE: z.string() }).optional(), + with: z.object({ filters: z.string() }).optional() }) ) }) @@ -175,50 +176,33 @@ it.for([ it.for([ { name: 'website-only pull request', - relevant: { - relevant: 'false', - unit: 'false', - e2e: 'false', - source: 'false', - outside_website: 'false' - }, - filter: { app_website: 'true', deps: 'false' }, + outsideWebsite: 'false', expected: true }, { name: 'website plus docs pull request', - relevant: { - relevant: 'false', - unit: 'false', - e2e: 'false', - source: 'false', - outside_website: 'true' - }, - filter: { app_website: 'true', deps: 'false' }, + outsideWebsite: 'true', expected: false } -])('classifies a $name', ({ relevant, filter, expected }) => { +])('classifies a $name', ({ outsideWebsite, expected }) => { + const relevant = { + relevant: 'false', + unit: 'false', + e2e: 'false', + source: 'false', + outside_website: outsideWebsite + } + const filter = { app_website: 'true', deps: 'false' } + expect( selectChecks('pull_request', relevant, filter)['website-only-changes'] ).toBe(expected) }) it('classifies website-only paths with the fast-lane path policy', () => { - const relevantFilters = z - .object({ - runs: z.object({ - steps: z.array( - z.object({ - id: z.string(), - with: z.object({ filters: z.string() }).optional() - }) - ) - }) - }) - .parse( - parse(readFileSync('.github/actions/changes-filter/action.yaml', 'utf8')) - ) - .runs.steps.find((step) => step.id === 'relevant')?.with?.filters + const relevantFilters = action.runs.steps.find( + (step) => step.id === 'relevant' + )?.with?.filters assert.exists(relevantFilters) const lane = z .object({ pathPrefixes: z.array(z.string()) }) diff --git a/scripts/cicd/fast-lane/__fixtures__/lane.ts b/scripts/cicd/fast-lane/__fixtures__/lane.ts new file mode 100644 index 00000000000..f42f23cd4ee --- /dev/null +++ b/scripts/cicd/fast-lane/__fixtures__/lane.ts @@ -0,0 +1,63 @@ +import { POLICY_REVIEW_PREFIX } from '../policy.ts' +import type { + FastLaneConfig, + PullRequest, + PullRequestReview +} from '../types.ts' + +export const repository = 'Comfy-Org/ComfyUI_frontend' +export const headSha = '0123456789abcdef0123456789abcdef01234567' +export const floorTime = '2026-10-06T10:00:00Z' + +export const lane: FastLaneConfig = { + schemaVersion: 1, + id: 'website', + pathPrefixes: ['apps/website/'], + approval: { + identity: 'christian-byrne', + trustedAuthors: ['bertfy'], + approvalLabel: 'website-fast-lane:approve', + trustedLabelers: ['drjkl'], + holdLabel: 'website-fast-lane:hold' + }, + merge: { mode: 'automatic', method: 'SQUASH' } +} + +export const operatorLabelEvent = { + actor: 'drjkl', + label: 'website-fast-lane:approve' +} + +export function pullRequest(overrides: Partial = {}): PullRequest { + return { + state: 'open', + draft: false, + node_id: 'PR_1', + changed_files: 1, + user: { login: 'bertfy' }, + labels: [], + head: { sha: headSha, repo: { full_name: repository } }, + base: { ref: 'main', repo: { full_name: repository } }, + ...overrides + } +} + +export function outsider(labels: string[]): Partial { + return { + user: { login: 'someone-else' }, + labels: labels.map((name) => ({ name })) + } +} + +export function policyApproval( + overrides: Partial = {} +): PullRequestReview { + return { + state: 'APPROVED', + commit_id: headSha, + body: `${POLICY_REVIEW_PREFIX} Lane: website.`, + submitted_at: floorTime, + user: { login: 'christian-byrne' }, + ...overrides + } +} diff --git a/scripts/cicd/fast-lane/automation.test.ts b/scripts/cicd/fast-lane/automation.test.ts index 742c2c97254..b31e349fd04 100644 --- a/scripts/cicd/fast-lane/automation.test.ts +++ b/scripts/cicd/fast-lane/automation.test.ts @@ -1,7 +1,16 @@ import { describe, expect, it, vi } from 'vitest' +import { + floorTime, + headSha, + lane, + operatorLabelEvent, + outsider, + policyApproval, + pullRequest, + repository +} from './__fixtures__/lane.ts' import { runFastLane, stopMergeAutomation } from './automation.ts' -import { POLICY_REVIEW_PREFIX } from './policy.ts' import type { GitHubClient, MergeAutomationState, @@ -11,9 +20,6 @@ import type { RuntimeConfig } from './types.ts' -const headSha = '0123456789abcdef0123456789abcdef01234567' -const policyBody = `${POLICY_REVIEW_PREFIX} Lane: website.` -const floorTime = '2026-10-06T10:00:00Z' const afterFloor = '2026-10-06T10:01:00Z' const beforeFloor = '2026-10-06T09:59:00Z' @@ -31,55 +37,21 @@ interface FakeOptions { function runtimeConfig(overrides: Partial = {}): RuntimeConfig { return { - repository: 'Comfy-Org/ComfyUI_frontend', + repository, pullRequestNumber: 42, eventHeadSha: headSha, defaultBranch: 'main', - lane: { - schemaVersion: 1, - id: 'website', - pathPrefixes: ['apps/website/'], - approval: { - identity: 'christian-byrne', - trustedAuthors: ['bertfy'], - approvalLabel: 'website-fast-lane:approve', - trustedLabelers: ['drjkl'], - holdLabel: 'website-fast-lane:hold' - }, - merge: { mode: 'automatic', method: 'MERGE' } - }, + lane, ...overrides } } -function policyApproval( - id: number, - commitId = headSha, - submittedAt = floorTime -): PullRequestReview { - return { - id, - state: 'APPROVED', - commit_id: commitId, - body: policyBody, - submitted_at: submittedAt, - user: { login: 'christian-byrne' } - } -} - function fakeGitHub(options: FakeOptions = {}) { const writes: Write[] = [] - const pull: PullRequest = { - state: 'open', - draft: false, - node_id: 'PR_1', + const pull = pullRequest({ changed_files: options.files?.length ?? 1, - user: { login: 'bertfy' }, - labels: [], - head: { sha: headSha, repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } }, - base: { ref: 'main', repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } }, ...options.pull - } + }) const reviews = [...(options.reviews ?? [])] const files = options.files ?? [ { filename: 'apps/website/src/pages/index.astro' } @@ -93,10 +65,12 @@ function fakeGitHub(options: FakeOptions = {}) { if (init.method === 'POST') { const body: PullRequestReview = JSON.parse(String(init.body)) writes.push([`POST ${path}`, body]) - const created = { - ...policyApproval(900, body.commit_id, afterFloor), + const created = policyApproval({ + id: 900, + commit_id: body.commit_id, + submitted_at: afterFloor, body: body.body - } + }) reviews.push(created) return created } @@ -137,7 +111,7 @@ const approvalPost: Write = [ ] const enableAutoMerge: Write = [ 'PackageFastLaneEnableAutoMerge', - { pullRequestId: 'PR_1', expectedHeadOid: headSha, mergeMethod: 'MERGE' } + { pullRequestId: 'PR_1', expectedHeadOid: headSha, mergeMethod: 'SQUASH' } ] const disableAutoMerge: Write = [ 'PackageFastLaneDisableAutoMerge', @@ -169,20 +143,13 @@ describe('runFastLane', () => { }, { name: 'a non-allowlisted author on the operator label event', - options: { - pull: { - user: { login: 'someone-else' }, - labels: [{ name: 'website-fast-lane:approve' }] - } - }, - config: { - labelEvent: { actor: 'drjkl', label: 'website-fast-lane:approve' } - }, + options: { pull: outsider(['website-fast-lane:approve']) }, + config: { labelEvent: operatorLabelEvent }, writes: [approvalPost, enableAutoMerge] }, { name: 'a head that already has the policy approval', - options: { reviews: [policyApproval(1)] }, + options: { reviews: [policyApproval({ id: 1 })] }, config: {}, writes: [enableAutoMerge] }, @@ -203,8 +170,8 @@ describe('runFastLane', () => { options: {}, config: { lane: { - ...runtimeConfig().lane, - merge: { mode: 'manual', method: 'MERGE' } + ...lane, + merge: { mode: 'manual', method: 'SQUASH' } } }, writes: [approvalPost] @@ -256,18 +223,13 @@ describe('runFastLane', () => { }, { name: 'a non-allowlisted author whose labeled run was replaced', - options: { - pull: { - user: { login: 'someone-else' }, - labels: [{ name: 'website-fast-lane:approve' }] - } - } + options: { pull: outsider(['website-fast-lane:approve']) } }, { name: 'a run for a head that has since advanced', options: { pull: { head: { sha: 'f'.repeat(40) } }, - reviews: [policyApproval(1, 'f'.repeat(40))], + reviews: [policyApproval({ id: 1, commit_id: 'f'.repeat(40) })], mergeState: armedByLane } } @@ -284,8 +246,8 @@ describe('runFastLane', () => { it('withdraws approval and merge state when the approval label is removed', async () => { const fake = fakeGitHub({ - pull: { user: { login: 'someone-else' }, labels: [] }, - reviews: [policyApproval(1)], + pull: outsider([]), + reviews: [policyApproval({ id: 1 })], mergeState: armedByLane }) @@ -306,7 +268,10 @@ describe('runFastLane', () => { it('withdraws every policy approval on hold even when merge teardown fails', async () => { const fake = fakeGitHub({ pull: { labels: [{ name: 'website-fast-lane:hold' }] }, - reviews: [policyApproval(122, 'old-head'), policyApproval(123)], + reviews: [ + policyApproval({ id: 122, commit_id: 'old-head' }), + policyApproval({ id: 123 }) + ], mergeState: armedByLane, failingMutations: ['PackageFastLaneDisableAutoMerge'] }) diff --git a/scripts/cicd/fast-lane/automation.ts b/scripts/cicd/fast-lane/automation.ts index a71f7824bdd..d4751c7ab2e 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/scripts/cicd/fast-lane/automation.ts @@ -2,6 +2,7 @@ import { isRecord } from './github.ts' import { activePolicyApprovals, eligibilityFailure, + isLogin, isPolicyApprovalForHead, pathFailure, policyReviewFloor, @@ -61,13 +62,6 @@ function mergeState(value: unknown): MergeAutomationState { return node } -function actorMatches( - actor: { login?: string } | undefined, - identity: string -): boolean { - return actor?.login?.toLowerCase() === identity -} - function atOrAfter(value: string | undefined, floor: string): boolean { if (!value) return false return Date.parse(value) >= Date.parse(floor) @@ -75,13 +69,31 @@ function atOrAfter(value: string | undefined, floor: string): boolean { async function readMergeState( github: GitHubClient, - pullRequestId: string + pull: PullRequest ): Promise { + if (!pull.node_id) throw new Error('the pull request node id is required') return mergeState( - await github.graphql(MERGE_AUTOMATION_STATE, { pullRequestId }) + await github.graphql(MERGE_AUTOMATION_STATE, { + pullRequestId: pull.node_id + }) ) } +async function attemptAll( + tasks: (() => Promise)[], + message: string +): Promise { + const errors: unknown[] = [] + for (const task of tasks) { + try { + await task() + } catch (error) { + errors.push(error) + } + } + if (errors.length > 0) throw new AggregateError(errors, message) +} + export async function stopMergeAutomation( github: GitHubClient, pull: PullRequest, @@ -89,52 +101,45 @@ export async function stopMergeAutomation( floor: SubmittedReview | undefined ): Promise { if (!floor) return - if (!pull.node_id) { - throw new Error('the pull request node id is required to stop automation') - } + const { id, mergeQueueEntry, autoMergeRequest } = await readMergeState( + github, + pull + ) + const ownedSinceFloor = ( + actor: { login?: string } | undefined, + at: string | undefined + ) => isLogin(actor, identity) && atOrAfter(at, floor.submitted_at) - const state = await readMergeState(github, pull.node_id) - const errors: unknown[] = [] - const entry = state.mergeQueueEntry - if ( - entry?.id && - actorMatches(entry.enqueuer, identity) && - atOrAfter(entry.enqueuedAt, floor.submitted_at) - ) { - try { - await github.graphql( - `mutation PackageFastLaneDequeue($pullRequestId: ID!) { - dequeuePullRequest(input: { id: $pullRequestId }) { clientMutationId } - }`, - { pullRequestId: pull.node_id } - ) - } catch (error) { - errors.push(error) - } - } + const dequeue = () => + github.graphql( + `mutation PackageFastLaneDequeue($pullRequestId: ID!) { + dequeuePullRequest(input: { id: $pullRequestId }) { clientMutationId } + }`, + { pullRequestId: id } + ) + const disableAutoMerge = () => + github.graphql( + `mutation PackageFastLaneDisableAutoMerge($pullRequestId: ID!) { + disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) { + clientMutationId + } + }`, + { pullRequestId: id } + ) - const autoMerge = state.autoMergeRequest - if ( - autoMerge && - actorMatches(autoMerge.enabledBy, identity) && - atOrAfter(autoMerge.enabledAt, floor.submitted_at) - ) { - try { - await github.graphql( - `mutation PackageFastLaneDisableAutoMerge($pullRequestId: ID!) { - disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) { - clientMutationId - } - }`, - { pullRequestId: pull.node_id } - ) - } catch (error) { - errors.push(error) - } - } - if (errors.length > 0) { - throw new AggregateError(errors, 'failed to stop all merge automation') - } + await attemptAll( + [ + ...(mergeQueueEntry?.id && + ownedSinceFloor(mergeQueueEntry.enqueuer, mergeQueueEntry.enqueuedAt) + ? [dequeue] + : []), + ...(autoMergeRequest && + ownedSinceFloor(autoMergeRequest.enabledBy, autoMergeRequest.enabledAt) + ? [disableAutoMerge] + : []) + ], + 'failed to stop all merge automation' + ) } export async function armMergeAutomation( @@ -144,12 +149,9 @@ export async function armMergeAutomation( summary: Summary ): Promise { if (config.lane.merge.mode === 'manual') return - if (!pull.node_id) { - throw new Error('the pull request node id is required to merge') - } const headSha = config.eventHeadSha - const state = await readMergeState(github, pull.node_id) + const state = await readMergeState(github, pull) if (state.headRefOid !== headSha) { summary('Skipped: the pull request head advanced before merge automation.') return @@ -170,7 +172,7 @@ export async function armMergeAutomation( jump: false }) { clientMutationId } }`, - { pullRequestId: pull.node_id, expectedHeadOid: headSha } + { pullRequestId: state.id, expectedHeadOid: headSha } ) summary(`Entered the native merge queue for ${shortSha(headSha)}.`) return @@ -193,7 +195,7 @@ export async function armMergeAutomation( }) { clientMutationId } }`, { - pullRequestId: pull.node_id, + pullRequestId: state.id, expectedHeadOid: headSha, mergeMethod: config.lane.merge.method } @@ -228,30 +230,22 @@ async function withdraw( summary: Summary ): Promise { const identity = config.lane.approval.identity - const errors: unknown[] = [] - try { - await stopMergeAutomation( - github, - pull, - identity, - policyReviewFloor(reviews, identity) - ) - } catch (error) { - errors.push(error) - } - for (const approval of activePolicyApprovals(reviews, identity)) { - try { - await dismissApproval(github, config.pullRequestNumber, approval, reason) - } catch (error) { - errors.push(error) - } - } - if (errors.length > 0) { - throw new AggregateError( - errors, - 'failed to complete fast-lane compensation' - ) - } + await attemptAll( + [ + () => + stopMergeAutomation( + github, + pull, + identity, + policyReviewFloor(reviews, identity) + ), + ...activePolicyApprovals(reviews, identity).map( + (approval) => () => + dismissApproval(github, config.pullRequestNumber, approval, reason) + ) + ], + 'failed to complete fast-lane compensation' + ) summary(`Skipped: ${reason}`) } @@ -296,10 +290,13 @@ async function assertIdentity( expectedIdentity: string ): Promise { const response = await github.request('https://api.github.com/user') - const login = isRecord(response) ? response.login : undefined - if (typeof login !== 'string' || login.toLowerCase() !== expectedIdentity) { + const login = + isRecord(response) && typeof response.login === 'string' + ? response.login + : undefined + if (!isLogin({ login }, expectedIdentity)) { throw new Error( - `FAST_LANE_TOKEN belongs to ${String(login ?? 'an unknown account')}, expected ${expectedIdentity}` + `FAST_LANE_TOKEN belongs to ${login ?? 'an unknown account'}, expected ${expectedIdentity}` ) } } diff --git a/scripts/cicd/fast-lane/config.test.ts b/scripts/cicd/fast-lane/config.test.ts index a2aed70d42b..3f79ed25f9b 100644 --- a/scripts/cicd/fast-lane/config.test.ts +++ b/scripts/cicd/fast-lane/config.test.ts @@ -2,22 +2,8 @@ import { readFileSync } from 'node:fs' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { lane, operatorLabelEvent } from './__fixtures__/lane.ts' import { loadRuntimeConfig, parseFastLaneConfig } from './config.ts' -import type { FastLaneConfig } from './types.ts' - -const lane: FastLaneConfig = { - schemaVersion: 1, - id: 'website', - pathPrefixes: ['apps/website/'], - approval: { - identity: 'christian-byrne', - trustedAuthors: ['bertfy'], - approvalLabel: 'website-fast-lane:approve', - trustedLabelers: ['drjkl'], - holdLabel: 'website-fast-lane:hold' - }, - merge: { mode: 'automatic', method: 'SQUASH' } -} describe('lane configuration', () => { it('normalizes logins while preserving the reviewed path policy', () => { @@ -96,7 +82,7 @@ describe('runtime configuration', () => { name: 'an operator label event', eventName: 'pull_request_target', action: 'labeled', - expected: { actor: 'drjkl', label: 'website-fast-lane:approve' } + expected: operatorLabelEvent }, { name: 'an unlabeled event', diff --git a/scripts/cicd/fast-lane/config.ts b/scripts/cicd/fast-lane/config.ts index bec7b106293..1796bb5da9e 100644 --- a/scripts/cicd/fast-lane/config.ts +++ b/scripts/cicd/fast-lane/config.ts @@ -37,7 +37,7 @@ function stringArray( ) { throw new Error(`${context}.${key} must be an array of non-empty strings`) } - return [...new Set(value.map((item) => item.trim()))] + return value.map((item) => item.trim()) } function record(value: unknown, context: string): Record { @@ -45,10 +45,6 @@ function record(value: unknown, context: string): Record { return value } -function normalizeLogins(logins: string[]): string[] { - return [...new Set(logins.map((login) => login.toLowerCase()))] -} - export function parseFastLaneConfig(value: unknown): FastLaneConfig { const root = record(value, 'fast lane config') if (root.schemaVersion !== 1) { @@ -56,6 +52,15 @@ export function parseFastLaneConfig(value: unknown): FastLaneConfig { } const approval = record(root.approval, 'fast lane config.approval') + const approvalName = (key: string) => + requiredString(approval, key, 'fast lane config.approval').toLowerCase() + const approvalLogins = (key: string) => [ + ...new Set( + stringArray(approval, key, 'fast lane config.approval', { + allowEmpty: true + }).map((login) => login.toLowerCase()) + ) + ] const merge = record(root.merge, 'fast lane config.merge') const mode = requiredString(merge, 'mode', 'fast lane config.merge') const method = requiredString(merge, 'method', 'fast lane config.merge') @@ -86,31 +91,11 @@ export function parseFastLaneConfig(value: unknown): FastLaneConfig { id: requiredString(root, 'id', 'fast lane config'), pathPrefixes, approval: { - identity: requiredString( - approval, - 'identity', - 'fast lane config.approval' - ).toLowerCase(), - trustedAuthors: normalizeLogins( - stringArray(approval, 'trustedAuthors', 'fast lane config.approval', { - allowEmpty: true - }) - ), - approvalLabel: requiredString( - approval, - 'approvalLabel', - 'fast lane config.approval' - ).toLowerCase(), - trustedLabelers: normalizeLogins( - stringArray(approval, 'trustedLabelers', 'fast lane config.approval', { - allowEmpty: true - }) - ), - holdLabel: requiredString( - approval, - 'holdLabel', - 'fast lane config.approval' - ).toLowerCase() + identity: approvalName('identity'), + trustedAuthors: approvalLogins('trustedAuthors'), + approvalLabel: approvalName('approvalLabel'), + trustedLabelers: approvalLogins('trustedLabelers'), + holdLabel: approvalName('holdLabel') }, merge: { mode, method } } diff --git a/scripts/cicd/fast-lane/policy.test.ts b/scripts/cicd/fast-lane/policy.test.ts index 624b5c46938..b278ebb4144 100644 --- a/scripts/cicd/fast-lane/policy.test.ts +++ b/scripts/cicd/fast-lane/policy.test.ts @@ -1,5 +1,14 @@ import { describe, expect, it } from 'vitest' +import { + headSha, + lane, + operatorLabelEvent, + outsider, + policyApproval, + pullRequest, + repository +} from './__fixtures__/lane.ts' import { activePolicyApprovals, changedPaths, @@ -9,67 +18,14 @@ import { isAuthorizedLabelEvent, isInsideLane, isPolicyApprovalForHead, - POLICY_REVIEW_PREFIX, policyReviewFloor } from './policy.ts' -import type { - FastLaneConfig, - LabelEvent, - PullRequest, - PullRequestReview -} from './types.ts' - -const policyBody = `${POLICY_REVIEW_PREFIX} Lane: website.` +import type { LabelEvent, PullRequest, PullRequestReview } from './types.ts' -const lane: FastLaneConfig = { - schemaVersion: 1, - id: 'website', - pathPrefixes: ['apps/website/'], - approval: { - identity: 'christian-byrne', - trustedAuthors: ['bertfy'], - approvalLabel: 'website-fast-lane:approve', - trustedLabelers: ['drjkl'], - holdLabel: 'website-fast-lane:hold' - }, - merge: { mode: 'automatic', method: 'SQUASH' } -} - -const operatorLabelEvent: LabelEvent = { - actor: 'drjkl', - label: 'website-fast-lane:approve' -} - -const headApproval: PullRequestReview = { - state: 'APPROVED', - commit_id: 'head-sha', - body: policyBody, - user: { login: 'christian-byrne' } -} - -function eligiblePull(overrides: Partial = {}): PullRequest { - return { - state: 'open', - draft: false, - user: { login: 'bertfy' }, - labels: [], - head: { - sha: 'head-sha', - repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } - }, - base: { - ref: 'main', - repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } - }, - ...overrides - } -} +const headApproval = policyApproval() function outsiderPull(labels: string[]): PullRequest { - return eligiblePull({ - user: { login: 'someone-else' }, - labels: labels.map((name) => ({ name })) - }) + return pullRequest(outsider(labels)) } function failure( @@ -83,7 +39,7 @@ function failure( pull, reviews, lane, - repository: 'Comfy-Org/ComfyUI_frontend', + repository, defaultBranch: 'main', labelEvent }) @@ -171,7 +127,7 @@ describe('approval label events', () => { describe('eligibility', () => { it.for([ - { name: 'a trusted author', pull: eligiblePull() }, + { name: 'a trusted author', pull: pullRequest() }, { name: 'a non-allowlisted author on the operator label event', pull: outsiderPull(['website-fast-lane:approve']), @@ -189,37 +145,41 @@ describe('eligibility', () => { it.for([ { name: 'draft', - pull: eligiblePull({ draft: true }), + pull: pullRequest({ draft: true }), message: 'not open and ready' }, { name: 'closed pull request', - pull: eligiblePull({ state: 'closed' }), + pull: pullRequest({ state: 'closed' }), message: 'not open and ready' }, { name: 'other base', - pull: eligiblePull({ + pull: pullRequest({ base: { ref: 'release', - repo: { full_name: 'Comfy-Org/ComfyUI_frontend' } + repo: { full_name: repository } } }), message: 'applies only to main' }, + { + name: 'base in another repository', + pull: pullRequest({ + base: { ref: 'main', repo: { full_name: 'bertfy/ComfyUI_frontend' } } + }), + message: 'applies only to main' + }, { name: 'fork', - pull: eligiblePull({ - head: { - sha: 'head-sha', - repo: { full_name: 'bertfy/ComfyUI_frontend' } - } + pull: pullRequest({ + head: { sha: headSha, repo: { full_name: 'bertfy/ComfyUI_frontend' } } }), message: 'fork pull requests' }, { name: 'pull request authored by the approval identity', - pull: eligiblePull({ user: { login: 'Christian-Byrne' } }), + pull: pullRequest({ user: { login: 'Christian-Byrne' } }), message: 'cannot approve its own pull request' }, { @@ -240,12 +200,12 @@ describe('eligibility', () => { }, { name: 'hold label', - pull: eligiblePull({ labels: [{ name: 'website-fast-lane:hold' }] }), + pull: pullRequest({ labels: [{ name: 'website-fast-lane:hold' }] }), message: 'hold is applied' }, { name: 'human change request', - pull: eligiblePull(), + pull: pullRequest(), reviews: [ { state: 'CHANGES_REQUESTED', user: { login: 'DrJKL', type: 'User' } } ], @@ -318,9 +278,9 @@ describe('policy reviews', () => { ])( 'treats $name as the head policy approval: $expected', ({ review, expected }) => { - expect( - isPolicyApprovalForHead(review, 'christian-byrne', 'head-sha') - ).toBe(expected) + expect(isPolicyApprovalForHead(review, 'christian-byrne', headSha)).toBe( + expected + ) } ) diff --git a/scripts/cicd/fast-lane/policy.ts b/scripts/cicd/fast-lane/policy.ts index f3b6d074724..869b25aaeba 100644 --- a/scripts/cicd/fast-lane/policy.ts +++ b/scripts/cicd/fast-lane/policy.ts @@ -4,6 +4,7 @@ import type { PullRequest, PullRequestFile, PullRequestReview, + RepositoryRef, SubmittedReview } from './types.ts' @@ -73,7 +74,10 @@ function hasLabel(pull: PullRequest, expected: string): boolean { ) } -function isLogin(user: { login?: string } | undefined, login: string): boolean { +export function isLogin( + user: { login?: string } | undefined, + login: string +): boolean { return user?.login?.toLowerCase() === login } @@ -107,22 +111,11 @@ export function hasActiveHumanChangeRequest( return [...latestState.values()].includes('CHANGES_REQUESTED') } -export function isSameRepository( - pull: PullRequest, +function isRepository( + repo: RepositoryRef | null | undefined, repository: string ): boolean { - return pull.head?.repo?.full_name?.toLowerCase() === repository.toLowerCase() -} - -export function targetsDefaultBranch( - pull: PullRequest, - repository: string, - defaultBranch: string -): boolean { - return ( - pull.base?.repo?.full_name?.toLowerCase() === repository.toLowerCase() && - pull.base.ref === defaultBranch - ) + return repo?.full_name?.toLowerCase() === repository.toLowerCase() } export function isPolicyReview( @@ -215,10 +208,13 @@ export function eligibilityFailure( if (pull.state !== 'open' || pull.draft) { return 'the pull request is not open and ready for review.' } - if (!targetsDefaultBranch(pull, repository, defaultBranch)) { + if ( + !isRepository(pull.base?.repo, repository) || + pull.base?.ref !== defaultBranch + ) { return `the ${lane.id} fast lane applies only to ${defaultBranch}.` } - if (!isSameRepository(pull, repository)) { + if (!isRepository(pull.head?.repo, repository)) { return `the ${lane.id} fast lane does not apply to fork pull requests.` } const authorization = authorizationFailure(context) From 23d3d2924a34d53144dfee602207d58837fdcb71 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 05:42:35 +0000 Subject: [PATCH 62/70] refactor(ci): keep only verified fields in the website build identity Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- docs/architecture/website-delivery-validation.md | 4 ++-- scripts/cicd/website-deployment.sh | 4 +--- scripts/cicd/website-deployment.test.ts | 6 +----- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/architecture/website-delivery-validation.md b/docs/architecture/website-delivery-validation.md index 26eba062f0d..6a9b9bc6575 100644 --- a/docs/architecture/website-delivery-validation.md +++ b/docs/architecture/website-delivery-validation.md @@ -27,8 +27,8 @@ block the lane. ## Production identity and rollback -Each website preview and production build writes a cache-disabled `/__build.json` with the -repository, exact source SHA, workflow run, attempt, and build time. Deployment verifies the +Each website preview and production build writes a cache-disabled `/__build.json` with the exact +source SHA, workflow run, and attempt. Deployment verifies the immutable Vercel URL before accepting canonical `comfy.org` promotion and saves the previous and new deployment IDs and SHAs as a short-lived transition artifact. Both deployment workflows use `scripts/cicd/website-deployment.sh` for the build identity, Vercel lookups, and identity checks. diff --git a/scripts/cicd/website-deployment.sh b/scripts/cicd/website-deployment.sh index a8c97089ab1..c68ab5168af 100755 --- a/scripts/cicd/website-deployment.sh +++ b/scripts/cicd/website-deployment.sh @@ -12,12 +12,10 @@ vercel_api() { write_build_identity() { jq -n \ - --arg repository "${GITHUB_REPOSITORY:?}" \ --arg sha "${1:?usage: write-build-identity }" \ --arg runId "${GITHUB_RUN_ID:?}" \ --arg runAttempt "${GITHUB_RUN_ATTEMPT:?}" \ - --arg builtAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ - '{$repository, $sha, $runId, $runAttempt, $builtAt}' \ + '{$sha, $runId, $runAttempt}' \ >"$BUILD_IDENTITY_PATH" } diff --git a/scripts/cicd/website-deployment.test.ts b/scripts/cicd/website-deployment.test.ts index 4a4403d63df..c9cffa376c8 100644 --- a/scripts/cicd/website-deployment.test.ts +++ b/scripts/cicd/website-deployment.test.ts @@ -51,7 +51,6 @@ function run(...args: string[]) { env: { PATH: `${path.join(dir, 'bin')}:${process.env.PATH ?? ''}`, FAKE_DIR: dir, - GITHUB_REPOSITORY: 'Comfy-Org/ComfyUI_frontend', GITHUB_RUN_ID: '7', GITHUB_RUN_ATTEMPT: '2', VERCEL_ORG_ID: 'team_comfy', @@ -80,10 +79,7 @@ describe('website deployment identity', () => { 'utf8' ) ) - ).toMatchObject({ - repository: 'Comfy-Org/ComfyUI_frontend', - ...ownIdentity - }) + ).toEqual(ownIdentity) }) it.for([ From d1ede074402ecd784bff8bf21a77d3a08b739684 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 06:14:47 +0000 Subject: [PATCH 63/70] refactor(ci): move the fast-lane engine into tools/cicd/fast-lane Give the engine its own private workspace, following tools/test-recorder: its package format scripts own the files, knip checks it as a workspace, and typecheck:tools and the tooling Vitest project already cover tools/**. Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- .github/workflows/pr-website-auto-approve.yaml | 4 ++-- ...LANE-0041-path-scoped-policy-approval-lanes.md | 2 +- docs/architecture/package-delivery-lanes.md | 8 ++++---- knip.config.ts | 3 +++ package.json | 4 ++-- pnpm-lock.yaml | 9 +++++++++ tools/cicd/fast-lane/package.json | 15 +++++++++++++++ .../cicd/fast-lane/src}/__fixtures__/lane.ts | 0 .../cicd/fast-lane/src}/automation.test.ts | 0 .../cicd/fast-lane/src}/automation.ts | 2 +- .../cicd/fast-lane/src}/config.test.ts | 0 .../cicd/fast-lane/src}/config.ts | 0 .../cicd/fast-lane/src}/github.test.ts | 0 .../cicd/fast-lane/src}/github.ts | 0 .../cicd/fast-lane/src}/policy.test.ts | 0 .../cicd/fast-lane/src}/policy.ts | 5 +---- .../fast-lane => tools/cicd/fast-lane/src}/run.ts | 0 .../cicd/fast-lane/src}/types.ts | 0 18 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 tools/cicd/fast-lane/package.json rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/__fixtures__/lane.ts (100%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/automation.test.ts (100%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/automation.ts (99%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/config.test.ts (100%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/config.ts (100%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/github.test.ts (100%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/github.ts (100%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/policy.test.ts (100%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/policy.ts (98%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/run.ts (100%) rename {scripts/cicd/fast-lane => tools/cicd/fast-lane/src}/types.ts (100%) diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index 0f085314dc1..f4708d60db9 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -83,7 +83,7 @@ jobs: sparse-checkout: | .nvmrc .github/fast-lanes/website.json - scripts/cicd/fast-lane + tools/cicd/fast-lane - uses: actions/setup-node@v6 with: @@ -100,4 +100,4 @@ jobs: GITHUB_REPOSITORY: ${{ github.repository }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.sha || github.event.workflow_run.head_sha }} PR_NUMBER: ${{ needs.resolve.outputs.pull-request-number }} - run: node scripts/cicd/fast-lane/run.ts + run: node tools/cicd/fast-lane/src/run.ts diff --git a/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md b/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md index f2a01edb387..a5528abe0fb 100644 --- a/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md +++ b/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md @@ -26,7 +26,7 @@ Introduce path-scoped delivery lanes, starting with the website: - A website-only pull request runs website-scoped lint, format, typecheck, unused-code, and locale checks inside the existing `lint-and-format` context. Mixed pull requests and merge-queue candidates keep the full checks. -- `pr-website-auto-approve.yaml` runs `scripts/cicd/fast-lane/` from the default branch. For an +- `pr-website-auto-approve.yaml` runs the `tools/cicd/fast-lane/` workspace from the default branch. For an eligible same-repository pull request whose complete changed-file set is inside the lane, it posts a policy-only approval bound to the exact head with a credential held in a `main`-restricted environment, then arms native auto-merge or enters the queue. Every later run diff --git a/docs/architecture/package-delivery-lanes.md b/docs/architecture/package-delivery-lanes.md index 53994a11cee..9936b5f7161 100644 --- a/docs/architecture/package-delivery-lanes.md +++ b/docs/architecture/package-delivery-lanes.md @@ -8,7 +8,7 @@ without weakening the rest of the repository. A lane has four independent stages 3. **Approval:** apply the package's reviewed approval policy to the exact commit. 4. **Delivery:** use the repository's normal merge, deployment, and rollback systems. -The website is the first lane. The approval engine in `scripts/cicd/fast-lane/` is package-neutral; +The website is the first lane. The approval engine in the `tools/cicd/fast-lane/` workspace is package-neutral; the change classifier output, the scoped CI jobs, and the workflow are per lane. ## The dials a package owns @@ -62,7 +62,7 @@ These are implementation invariants, not package dials: policy review on the pull request. Because the identity is a personal account, that includes the account owner's own merge actions in that window. -The reusable TypeScript engine lives in `scripts/cicd/fast-lane/`. `policy.ts` contains pure policy +The reusable TypeScript engine lives in `tools/cicd/fast-lane/src/`. `policy.ts` contains pure policy decisions, `github.ts` contains GitHub transport, and `automation.ts` owns the approval and merge lifecycle. Behavioral tests run `runFastLane` against an in-memory GitHub double and cover each fixed rule. @@ -77,8 +77,8 @@ fixed rule. 4. Add a workflow like `pr-website-auto-approve.yaml`: `pull_request_target`, `status`, and `workflow_run` triggers; a resolver job that finds the pull request; and one lane job keyed on that pull request's concurrency group. The lane job sparse-checks out `.nvmrc`, the selected - policy, and `scripts/cicd/fast-lane/` from the default branch (cone mode also includes - root-level files) and runs `node scripts/cicd/fast-lane/run.ts` without installing + policy, and `tools/cicd/fast-lane/` from the default branch (cone mode also includes + root-level files) and runs `node tools/cicd/fast-lane/src/run.ts` without installing dependencies. 5. Put the approval credential in a package-specific protected environment and restrict that environment to the protected default branch. diff --git a/knip.config.ts b/knip.config.ts index f33754a1e36..2a867cdc4df 100644 --- a/knip.config.ts +++ b/knip.config.ts @@ -54,6 +54,9 @@ const config: KnipConfig = { // Executed by models-snippets.test.ts inside the generated Node examples. ignoreDependencies: ['mime-types'] }, + 'tools/cicd/fast-lane': { + project: ['src/**/*.ts'] + }, 'tools/test-recorder': { project: ['src/**/*.ts'] } diff --git a/package.json b/package.json index 7daac1cebf9..195178b362f 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,8 @@ "devtools:pycheck": "python3 -m compileall -q tools/devtools", "fallow": "fallow", "fallow:audit": "fallow audit", - "format:check": "oxfmt --check \"!apps/**\" \"!packages/**\" \"!tools/test-recorder/**\"", - "format": "oxfmt --write \"!apps/**\" \"!packages/**\" \"!tools/test-recorder/**\"", + "format:check": "oxfmt --check \"!apps/**\" \"!packages/**\" \"!tools/test-recorder/**\" \"!tools/cicd/fast-lane/**\"", + "format": "oxfmt --write \"!apps/**\" \"!packages/**\" \"!tools/test-recorder/**\" \"!tools/cicd/fast-lane/**\"", "json-schema": "tsx scripts/generate-json-schema.ts", "deps:audit": "depcruise src", "knip:no-cache": "knip", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5e827aed600..1888cdebe82 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1466,6 +1466,15 @@ importers: specifier: 'catalog:' version: 6.0.3 + tools/cicd/fast-lane: + devDependencies: + '@types/node': + specifier: 'catalog:' + version: 25.9.5 + vitest: + specifier: 'catalog:' + version: 5.0.2(@types/node@25.9.5)(@vitest/coverage-v8@5.0.2)(@vitest/ui@5.0.2)(happy-dom@20.14.5)(jsdom@29.1.1)(vite@8.2.2(@types/node@25.9.5)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(tsx@4.23.1)(yaml@2.9.0)) + tools/test-recorder: dependencies: '@clack/prompts': diff --git a/tools/cicd/fast-lane/package.json b/tools/cicd/fast-lane/package.json new file mode 100644 index 00000000000..57dea3cb276 --- /dev/null +++ b/tools/cicd/fast-lane/package.json @@ -0,0 +1,15 @@ +{ + "name": "@comfyorg/fast-lane", + "version": "0.1.0", + "private": true, + "description": "Path-scoped policy approval and merge automation for package delivery lanes", + "type": "module", + "scripts": { + "format": "oxfmt --write", + "format:check": "oxfmt --check" + }, + "devDependencies": { + "@types/node": "catalog:", + "vitest": "catalog:" + } +} diff --git a/scripts/cicd/fast-lane/__fixtures__/lane.ts b/tools/cicd/fast-lane/src/__fixtures__/lane.ts similarity index 100% rename from scripts/cicd/fast-lane/__fixtures__/lane.ts rename to tools/cicd/fast-lane/src/__fixtures__/lane.ts diff --git a/scripts/cicd/fast-lane/automation.test.ts b/tools/cicd/fast-lane/src/automation.test.ts similarity index 100% rename from scripts/cicd/fast-lane/automation.test.ts rename to tools/cicd/fast-lane/src/automation.test.ts diff --git a/scripts/cicd/fast-lane/automation.ts b/tools/cicd/fast-lane/src/automation.ts similarity index 99% rename from scripts/cicd/fast-lane/automation.ts rename to tools/cicd/fast-lane/src/automation.ts index d4751c7ab2e..09ae20e373f 100644 --- a/scripts/cicd/fast-lane/automation.ts +++ b/tools/cicd/fast-lane/src/automation.ts @@ -142,7 +142,7 @@ export async function stopMergeAutomation( ) } -export async function armMergeAutomation( +async function armMergeAutomation( github: GitHubClient, pull: PullRequest, config: RuntimeConfig, diff --git a/scripts/cicd/fast-lane/config.test.ts b/tools/cicd/fast-lane/src/config.test.ts similarity index 100% rename from scripts/cicd/fast-lane/config.test.ts rename to tools/cicd/fast-lane/src/config.test.ts diff --git a/scripts/cicd/fast-lane/config.ts b/tools/cicd/fast-lane/src/config.ts similarity index 100% rename from scripts/cicd/fast-lane/config.ts rename to tools/cicd/fast-lane/src/config.ts diff --git a/scripts/cicd/fast-lane/github.test.ts b/tools/cicd/fast-lane/src/github.test.ts similarity index 100% rename from scripts/cicd/fast-lane/github.test.ts rename to tools/cicd/fast-lane/src/github.test.ts diff --git a/scripts/cicd/fast-lane/github.ts b/tools/cicd/fast-lane/src/github.ts similarity index 100% rename from scripts/cicd/fast-lane/github.ts rename to tools/cicd/fast-lane/src/github.ts diff --git a/scripts/cicd/fast-lane/policy.test.ts b/tools/cicd/fast-lane/src/policy.test.ts similarity index 100% rename from scripts/cicd/fast-lane/policy.test.ts rename to tools/cicd/fast-lane/src/policy.test.ts diff --git a/scripts/cicd/fast-lane/policy.ts b/tools/cicd/fast-lane/src/policy.ts similarity index 98% rename from scripts/cicd/fast-lane/policy.ts rename to tools/cicd/fast-lane/src/policy.ts index 869b25aaeba..020759aa29b 100644 --- a/scripts/cicd/fast-lane/policy.ts +++ b/tools/cicd/fast-lane/src/policy.ts @@ -118,10 +118,7 @@ function isRepository( return repo?.full_name?.toLowerCase() === repository.toLowerCase() } -export function isPolicyReview( - review: PullRequestReview, - identity: string -): boolean { +function isPolicyReview(review: PullRequestReview, identity: string): boolean { return ( isLogin(review.user, identity) && review.body?.startsWith(POLICY_REVIEW_PREFIX) === true diff --git a/scripts/cicd/fast-lane/run.ts b/tools/cicd/fast-lane/src/run.ts similarity index 100% rename from scripts/cicd/fast-lane/run.ts rename to tools/cicd/fast-lane/src/run.ts diff --git a/scripts/cicd/fast-lane/types.ts b/tools/cicd/fast-lane/src/types.ts similarity index 100% rename from scripts/cicd/fast-lane/types.ts rename to tools/cicd/fast-lane/src/types.ts From c1b1a6405473e08789345070989d8aa5ea9408e5 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 06:50:16 +0000 Subject: [PATCH 64/70] refactor(ci): replace custom website CI plumbing with native tools - Production records a GitHub deployment instead of a build marker, staged promotion, transition artifact, and rollback workflow; rollback uses Vercel Instant Rollback. - Website-only pull requests run the standard lint and typecheck jobs; the scoped jobs did not shorten the time to merge. - The fast-lane workflow reads the pull request from the event instead of a resolver job, and drops the repo-wide status trigger. Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- .github/actions/changes-filter/action.yaml | 6 - .github/fast-lanes/website.json | 16 -- .github/workflows/README.md | 20 +- .github/workflows/ci-lint-format.yaml | 48 +---- .../workflows/ci-vercel-website-preview.yaml | 115 +---------- .../workflows/pr-website-auto-approve.yaml | 57 +----- .../validation-website-rollback.yaml | 134 ------------ apps/website/vercel.json | 13 -- package.json | 1 - scripts/cicd/changes-filter.test.ts | 59 +----- scripts/cicd/website-deployment.sh | 97 --------- scripts/cicd/website-deployment.test.ts | 193 ------------------ 12 files changed, 26 insertions(+), 733 deletions(-) delete mode 100644 .github/fast-lanes/website.json delete mode 100644 .github/workflows/validation-website-rollback.yaml delete mode 100755 scripts/cicd/website-deployment.sh delete mode 100644 scripts/cicd/website-deployment.test.ts diff --git a/.github/actions/changes-filter/action.yaml b/.github/actions/changes-filter/action.yaml index feb778696b9..7fdb1198ff7 100644 --- a/.github/actions/changes-filter/action.yaml +++ b/.github/actions/changes-filter/action.yaml @@ -72,9 +72,6 @@ outputs: dependency-changes: description: 'Root `.nvmrc`, `package.json`, `pnpm-lock.yaml`, or `pnpm-workspace.yaml` changed.' value: ${{ steps.mode.outputs.evaluate != 'true' || steps.filter.outputs.deps == 'true' }} - website-only-changes: - description: 'Pull requests only: every changed file is under `apps/website/**`. Always false for other events.' - value: ${{ steps.mode.outputs.evaluate == 'true' && steps.filter.outputs.app_website == 'true' && steps.relevant.outputs.outside_website != 'true' }} runs: using: composite @@ -145,6 +142,3 @@ runs: - *unit - '!**/*.test.ts' - '!**/__mocks__/**' - outside_website: - - '**' - - '!apps/website/**' diff --git a/.github/fast-lanes/website.json b/.github/fast-lanes/website.json deleted file mode 100644 index 4e4696af36b..00000000000 --- a/.github/fast-lanes/website.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "schemaVersion": 1, - "id": "website", - "pathPrefixes": ["apps/website/"], - "approval": { - "identity": "christian-byrne", - "trustedAuthors": ["bertfy"], - "approvalLabel": "website-fast-lane:approve", - "trustedLabelers": ["christian-byrne", "DrJKL", "benjcooley"], - "holdLabel": "website-fast-lane:hold" - }, - "merge": { - "mode": "automatic", - "method": "SQUASH" - } -} diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 19dc97cc389..c2398a00abe 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -6,14 +6,13 @@ Workflow files follow a consistent naming pattern: `-. ### Category Prefixes -| Prefix | Purpose | Example | -| ------------- | ----------------------------------------- | ------------------------------------ | -| `ci-` | Testing, linting, validation | `ci-tests-e2e.yaml` | -| `release-` | Version management, publishing | `release-version-bump.yaml` | -| `pr-` | PR automation (triggered by labels) | `pr-claude-review.yaml` | -| `api-` | External Api type generation | `api-update-registry-api-types.yaml` | -| `i18n-` | Internationalization updates | `i18n-update-core.yaml` | -| `validation-` | Manually dispatched production validation | `validation-website-rollback.yaml` | +| Prefix | Purpose | Example | +| ---------- | ----------------------------------- | ------------------------------------ | +| `ci-` | Testing, linting, validation | `ci-tests-e2e.yaml` | +| `release-` | Version management, publishing | `release-version-bump.yaml` | +| `pr-` | PR automation (triggered by labels) | `pr-claude-review.yaml` | +| `api-` | External Api type generation | `api-update-registry-api-types.yaml` | +| `i18n-` | Internationalization updates | `i18n-update-core.yaml` | ## Documentation @@ -23,9 +22,4 @@ The candidate dependency prototype lives in `ci-tests-e2e.yaml`. See [CI-PREREQUISITES-0038](../../docs/adr/CI-PREREQUISITES-0038-gate-expensive-candidate-tests.md) for measured runtimes, required-check compatibility, and rollout limits. -The required `lint-and-format` context keeps one stable name across pull requests and merge-queue -candidates. See [Package delivery lanes](../../docs/architecture/package-delivery-lanes.md) for the -path-scoped quality and approval model, and [Website delivery validation](../../docs/architecture/website-delivery-validation.md) -for the current trial and rollback procedure. - For GitHub Actions documentation, see [Events that trigger workflows](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows). diff --git a/.github/workflows/ci-lint-format.yaml b/.github/workflows/ci-lint-format.yaml index 6e22ae75ba0..6434861bbf6 100644 --- a/.github/workflows/ci-lint-format.yaml +++ b/.github/workflows/ci-lint-format.yaml @@ -1,8 +1,7 @@ # Description: Linting and code formatting validation for pull requests. # Work is split across parallel jobs so wall time is the slowest job rather -# than the sum. The `lint` job runs the fixers, scoped to apps/website when -# every changed file is there; every fixer exits non-zero when unfixable -# problems remain, so no second verify-only lint pass runs. +# than the sum. The `lint` job runs the fixers; every fixer exits non-zero +# when unfixable problems remain, so no second verify-only lint pass runs. name: 'CI: Lint Format' on: @@ -24,20 +23,7 @@ env: packages/*/node_modules/.cache/tsbuildinfo jobs: - changes: - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: read - outputs: - website-only: ${{ steps.changes.outputs.website-only-changes }} - steps: - - uses: actions/checkout@v7 - - id: changes - uses: ./.github/actions/changes-filter - lint: - needs: changes runs-on: ubuntu-latest steps: - name: Checkout PR @@ -61,21 +47,14 @@ jobs: path: ${{ env.LINT_CACHE_PATHS }} - name: Run ESLint with auto-fix - if: needs.changes.outputs.website-only != 'true' run: pnpm lint:fix:ci - name: Run Stylelint with auto-fix - if: needs.changes.outputs.website-only != 'true' run: pnpm stylelint:fix - name: Run oxfmt with auto-format - if: needs.changes.outputs.website-only != 'true' run: pnpm -r --include-workspace-root format - - name: Run website lint and format fixes - if: needs.changes.outputs.website-only == 'true' - run: pnpm lint:fix:website - - name: Check for changes id: verify-changed-files run: | @@ -131,8 +110,6 @@ jobs: path: ${{ env.LINT_CACHE_PATHS }} typecheck: - needs: changes - if: needs.changes.outputs.website-only != 'true' runs-on: ubuntu-latest steps: - name: Checkout PR @@ -159,8 +136,6 @@ jobs: path: ${{ env.TYPECHECK_CACHE_PATHS }} typecheck-aux: - needs: changes - if: needs.changes.outputs.website-only != 'true' runs-on: ubuntu-latest steps: - name: Checkout PR @@ -187,8 +162,6 @@ jobs: path: ${{ env.TYPECHECK_CACHE_PATHS }} repo-checks: - needs: changes - if: needs.changes.outputs.website-only != 'true' runs-on: ubuntu-latest steps: - name: Checkout PR @@ -204,20 +177,3 @@ jobs: - name: Verify knip, locale integrity and ADR index uses: ./.github/actions/repo-checks - - website-checks: - needs: changes - if: needs.changes.outputs.website-only == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 0 - filter: blob:none - - uses: ./.github/actions/setup-frontend - - name: Typecheck website - run: pnpm typecheck:website - - name: Verify website repository integrity - run: | - pnpm knip --workspace apps/website - pnpm --filter @comfyorg/website locale:check diff --git a/.github/workflows/ci-vercel-website-preview.yaml b/.github/workflows/ci-vercel-website-preview.yaml index 54a7fb92113..f0121cd933d 100644 --- a/.github/workflows/ci-vercel-website-preview.yaml +++ b/.github/workflows/ci-vercel-website-preview.yaml @@ -25,8 +25,8 @@ env: VERCEL_SCOPE: comfyui concurrency: - group: ${{ github.event_name != 'pull_request' && 'website-production' || format('{0}-{1}', github.workflow, github.ref) }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: deploy-preview: @@ -40,8 +40,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v7 - with: - ref: ${{ github.event.pull_request.head.sha }} - name: Install pnpm uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10 @@ -57,11 +55,6 @@ jobs: - name: Pull Vercel environment information run: vercel pull --yes --environment=preview - - name: Write preview build identity - env: - BUILD_SHA: ${{ github.event.pull_request.head.sha }} - run: scripts/cicd/website-deployment.sh write-build-identity "$BUILD_SHA" - - name: Build project artifacts env: WEBSITE_ASHBY_API_KEY: ${{ secrets.WEBSITE_ASHBY_API_KEY }} @@ -107,14 +100,6 @@ jobs: --meta githubRepo="$GIT_REPO") echo "url=$URL" >> "$GITHUB_OUTPUT" - - name: Verify immutable preview identity - env: - DEPLOY_URL: ${{ steps.deploy.outputs.url }} - EXPECTED_SHA: ${{ github.event.pull_request.head.sha }} - run: | - scripts/cicd/website-deployment.sh verify-identity \ - --host "$DEPLOY_URL" --sha "$EXPECTED_SHA" --attempts 30 --interval 5 - - name: Alias deployment to stable PR hostname id: alias-set continue-on-error: true @@ -161,6 +146,9 @@ jobs: deploy-production: if: github.event_name == 'push' runs-on: ubuntu-latest + environment: + name: website-production + url: ${{ steps.deploy.outputs.url }} steps: - name: Checkout repository uses: actions/checkout@v7 @@ -179,18 +167,6 @@ jobs: - name: Pull Vercel environment information run: vercel pull --yes --environment=production - - name: Capture the current production deployment - id: previous-production - run: | - PREVIOUS_DEPLOYMENT_ID=$(scripts/cicd/website-deployment.sh alias-deployment-id) - PREVIOUS_DEPLOYMENT_URL=$(scripts/cicd/website-deployment.sh deployment "$PREVIOUS_DEPLOYMENT_ID" url) - PREVIOUS_SHA=$(scripts/cicd/website-deployment.sh marker-sha "$PREVIOUS_DEPLOYMENT_URL") || true - echo "deployment-id=$PREVIOUS_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" - echo "sha=${PREVIOUS_SHA:-unavailable}" >> "$GITHUB_OUTPUT" - - - name: Write production build identity - run: scripts/cicd/website-deployment.sh write-build-identity "$GITHUB_SHA" - - name: Verify WEBSITE_CLOUD_API_KEY is present for production build env: WEBSITE_CLOUD_API_KEY: ${{ secrets.WEBSITE_CLOUD_API_KEY }} @@ -233,89 +209,10 @@ jobs: - name: Deploy project artifacts to Vercel id: deploy - env: - GIT_COMMIT_SHA: ${{ github.sha }} - GIT_REPO: ${{ github.repository }} run: | - URL=$(vercel deploy --prebuilt --prod --skip-domain --archive=tgz \ - --meta githubCommitSha="$GIT_COMMIT_SHA" \ - --meta githubRepo="$GIT_REPO" \ - --meta githubRunId="$GITHUB_RUN_ID") + URL=$(vercel deploy --prebuilt --prod --archive=tgz) echo "url=$URL" >> "$GITHUB_OUTPUT" - - name: Capture staged deployment identity - id: deployed-production - env: - DEPLOY_URL: ${{ steps.deploy.outputs.url }} - run: | - DEPLOYMENT_HOST=${DEPLOY_URL#https://} - if [[ ! "$DEPLOYMENT_HOST" =~ ^[A-Za-z0-9.-]+\.vercel\.app$ ]]; then - echo "::error::Unexpected immutable deployment URL: $DEPLOY_URL" - exit 1 - fi - DEPLOYED_DEPLOYMENT_ID=$(scripts/cicd/website-deployment.sh deployment "$DEPLOYMENT_HOST" id) - echo "deployment-id=$DEPLOYED_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT" - - - name: Verify staged production identity - env: - DEPLOY_URL: ${{ steps.deploy.outputs.url }} - timeout-minutes: 12 - run: | - scripts/cicd/website-deployment.sh verify-identity \ - --host "$DEPLOY_URL" --sha "$GITHUB_SHA" --this-run --attempts 30 --interval 5 - - - name: Retain production transition evidence - env: - DEPLOY_URL: ${{ steps.deploy.outputs.url }} - DEPLOYED_DEPLOYMENT_ID: ${{ steps.deployed-production.outputs.deployment-id }} - PREVIOUS_DEPLOYMENT_ID: ${{ steps.previous-production.outputs.deployment-id }} - PREVIOUS_SHA: ${{ steps.previous-production.outputs.sha }} - DEPLOYED_SHA: ${{ github.sha }} - run: | - mkdir -p temp/website-production-transition - jq -n \ - --arg previousDeploymentId "$PREVIOUS_DEPLOYMENT_ID" \ - --arg previousSha "$PREVIOUS_SHA" \ - --arg deployedDeploymentId "$DEPLOYED_DEPLOYMENT_ID" \ - --arg deploymentUrl "$DEPLOY_URL" \ - --arg deployedSha "$DEPLOYED_SHA" \ - --arg runId "$GITHUB_RUN_ID" \ - '{previousDeploymentId: $previousDeploymentId, previousSha: $previousSha, deployedDeploymentId: $deployedDeploymentId, deploymentUrl: $deploymentUrl, deployedSha: $deployedSha, runId: $runId}' \ - > temp/website-production-transition/transition.json - { - echo "**Production:** $DEPLOY_URL" - echo "**Deployment ID:** $DEPLOYED_DEPLOYMENT_ID" - echo "**Deployed SHA:** $DEPLOYED_SHA" - echo "**Previous deployment:** $PREVIOUS_DEPLOYMENT_ID" - echo "**Previous SHA:** $PREVIOUS_SHA" - } >> "$GITHUB_STEP_SUMMARY" - - - name: Upload production transition evidence - uses: actions/upload-artifact@v6 - with: - name: website-production-transition - path: temp/website-production-transition/transition.json - retention-days: 7 - if-no-files-found: error - - - name: Promote the staged deployment to production - env: - DEPLOY_URL: ${{ steps.deploy.outputs.url }} - run: | - vercel promote "$DEPLOY_URL" \ - --timeout=10m \ - --non-interactive \ - --scope="$VERCEL_SCOPE" - - - name: Verify canonical production identity - env: - EXPECTED_DEPLOYMENT_ID: ${{ steps.deployed-production.outputs.deployment-id }} - timeout-minutes: 12 - run: | - scripts/cicd/website-deployment.sh verify-identity \ - --canonical-deployment "$EXPECTED_DEPLOYMENT_ID" --sha "$GITHUB_SHA" --this-run \ - --attempts 60 --interval 10 - - name: Notify IndexNow of changed pages continue-on-error: true timeout-minutes: 5 diff --git a/.github/workflows/pr-website-auto-approve.yaml b/.github/workflows/pr-website-auto-approve.yaml index f4708d60db9..90e816527de 100644 --- a/.github/workflows/pr-website-auto-approve.yaml +++ b/.github/workflows/pr-website-auto-approve.yaml @@ -1,10 +1,8 @@ # Run the website package's configured delivery lane. # -# Security boundary: -# - pull_request_target, workflow_run, and status load this workflow from the -# default branch. Automation and policy are checked out from the protected -# default branch; pull request code is never executed. -# - Eligibility rules: docs/architecture/package-delivery-lanes.md. +# Security boundary: pull_request_target and workflow_run load this workflow, +# the policy, and the engine from the default branch; pull request code is +# never executed. Eligibility rules: docs/architecture/package-delivery-lanes.md. name: 'PR: Website Fast Lane' on: @@ -23,53 +21,15 @@ on: - 'CI: Tests E2E' - 'CI: Website E2E' types: [completed] - status: permissions: contents: read - pull-requests: read jobs: - resolve: - if: github.event_name != 'workflow_run' || github.event.workflow_run.event == 'pull_request' - runs-on: ubuntu-latest - timeout-minutes: 5 - outputs: - pull-request-number: ${{ steps.pull-request.outputs.result }} - steps: - - name: Resolve the pull request for this event - id: pull-request - uses: actions/github-script@v9 - with: - result-encoding: string - script: | - if (context.payload.pull_request) { - return String(context.payload.pull_request.number) - } - const sha = context.payload.sha ?? context.payload.workflow_run?.head_sha - const { data: pulls } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ - ...context.repo, - commit_sha: sha, - }) - const repository = `${context.repo.owner}/${context.repo.repo}`.toLowerCase() - const matches = pulls.filter((pull) => - pull.state === 'open' && - pull.head.sha === sha && - pull.head.repo?.full_name.toLowerCase() === repository && - pull.base.ref === context.payload.repository.default_branch && - pull.base.repo.full_name.toLowerCase() === repository - ) - if (matches.length !== 1) { - core.info(`Expected one open same-repository pull request for ${sha}; found ${matches.length}.`) - return '' - } - return String(matches[0].number) - fast-lane: - needs: resolve - if: needs.resolve.outputs.pull-request-number != '' + if: github.event.pull_request || github.event.workflow_run.pull_requests[0] concurrency: - group: website-fast-lane-${{ needs.resolve.outputs.pull-request-number }} + group: website-fast-lane-${{ github.event.pull_request.number || github.event.workflow_run.pull_requests[0].number }} cancel-in-progress: false environment: website-approval runs-on: ubuntu-latest @@ -82,7 +42,6 @@ jobs: persist-credentials: false sparse-checkout: | .nvmrc - .github/fast-lanes/website.json tools/cicd/fast-lane - uses: actions/setup-node@v6 @@ -91,13 +50,13 @@ jobs: - name: Approve, queue, or withdraw the website pull request env: - FAST_LANE_CONFIG: .github/fast-lanes/website.json + FAST_LANE: website FAST_LANE_TOKEN: ${{ secrets.WEBSITE_APPROVAL_TOKEN }} FAST_LANE_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} FAST_LANE_EVENT_ACTION: ${{ github.event.action }} FAST_LANE_EVENT_ACTOR: ${{ github.triggering_actor }} FAST_LANE_EVENT_LABEL: ${{ github.event.label.name }} GITHUB_REPOSITORY: ${{ github.repository }} - PR_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.sha || github.event.workflow_run.head_sha }} - PR_NUMBER: ${{ needs.resolve.outputs.pull-request-number }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha }} + PR_NUMBER: ${{ github.event.pull_request.number || github.event.workflow_run.pull_requests[0].number }} run: node tools/cicd/fast-lane/src/run.ts diff --git a/.github/workflows/validation-website-rollback.yaml b/.github/workflows/validation-website-rollback.yaml deleted file mode 100644 index f45c6dba062..00000000000 --- a/.github/workflows/validation-website-rollback.yaml +++ /dev/null @@ -1,134 +0,0 @@ -name: 'Validation: Website Production Rollback' - -on: - workflow_dispatch: - inputs: - deployment_id: - description: 'Immutable Vercel deployment ID to validate or restore (from the transition artifact)' - required: true - type: string - expected_sha: - description: 'Source SHA the target deployment must serve in /__build.json' - required: true - type: string - perform_rollback: - description: 'Change production after target validation; false performs a safe preflight only' - required: true - default: false - type: boolean - -permissions: - contents: read - -concurrency: - group: website-production - cancel-in-progress: false - -env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_WEBSITE_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_WEBSITE_PROJECT_ID }} - VERCEL_TOKEN: ${{ secrets.VERCEL_WEBSITE_TOKEN }} - VERCEL_SCOPE: comfyui - -jobs: - rollback: - if: github.repository == 'Comfy-Org/ComfyUI_frontend' - runs-on: ubuntu-latest - timeout-minutes: 25 - steps: - - uses: actions/checkout@v7 - - - name: Install Vercel CLI - run: npm install --global vercel@latest - - - name: Pull Vercel project information - run: vercel pull --yes --environment=production - - - name: Verify the captured deployment - env: - EXPECTED_SHA: ${{ inputs.expected_sha }} - PERFORM_ROLLBACK: ${{ inputs.perform_rollback }} - TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} - run: | - if [[ ! "$TARGET_DEPLOYMENT" =~ ^dpl_[A-Za-z0-9]+$ ]]; then - echo "::error::Invalid Vercel deployment ID" - exit 1 - fi - if [[ ! "$EXPECTED_SHA" =~ ^[0-9a-f]{40}$ ]]; then - echo "::error::Expected SHA must be a full lowercase Git commit SHA" - exit 1 - fi - TARGET_URL=$(scripts/cicd/website-deployment.sh deployment "$TARGET_DEPLOYMENT" url) - scripts/cicd/website-deployment.sh verify-identity --host "$TARGET_URL" --sha "$EXPECTED_SHA" - { - echo "**Validated rollback target:** $TARGET_DEPLOYMENT" - echo "**Validated rollback SHA:** $EXPECTED_SHA" - echo "**Production mutation requested:** $PERFORM_ROLLBACK" - } >> "$GITHUB_STEP_SUMMARY" - - - name: Roll back to the captured deployment - if: inputs.perform_rollback - env: - TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} - run: | - vercel rollback "$TARGET_DEPLOYMENT" \ - --timeout=10m \ - --non-interactive \ - --scope="$VERCEL_SCOPE" - - - name: Verify rollback at the canonical hostname - if: inputs.perform_rollback - env: - EXPECTED_SHA: ${{ inputs.expected_sha }} - TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} - run: | - scripts/cicd/website-deployment.sh verify-identity \ - --canonical-deployment "$TARGET_DEPLOYMENT" --sha "$EXPECTED_SHA" \ - --attempts 60 --interval 10 - - - name: Preserve the rolled-back deployment and resume automatic promotion - if: inputs.perform_rollback - env: - TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} - run: | - vercel promote "$TARGET_DEPLOYMENT" \ - --timeout=10m \ - --non-interactive \ - --scope="$VERCEL_SCOPE" - - - name: Verify post-rollback promotion state - if: inputs.perform_rollback - env: - EXPECTED_SHA: ${{ inputs.expected_sha }} - TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} - run: | - scripts/cicd/website-deployment.sh verify-identity \ - --canonical-deployment "$TARGET_DEPLOYMENT" --sha "$EXPECTED_SHA" - echo "**Verified canonical deployment:** $TARGET_DEPLOYMENT at $EXPECTED_SHA" >> "$GITHUB_STEP_SUMMARY" - - - name: Retain rollback evidence - env: - EXPECTED_SHA: ${{ inputs.expected_sha }} - PERFORM_ROLLBACK: ${{ inputs.perform_rollback }} - TARGET_DEPLOYMENT: ${{ inputs.deployment_id }} - run: | - mkdir -p temp/website-rollback-result - jq -n \ - --arg targetDeploymentId "$TARGET_DEPLOYMENT" \ - --arg expectedSha "$EXPECTED_SHA" \ - --argjson performRollback "$PERFORM_ROLLBACK" \ - --arg runId "$GITHUB_RUN_ID" \ - --arg runAttempt "$GITHUB_RUN_ATTEMPT" \ - --arg workflowSha "$GITHUB_SHA" \ - --arg actor "$GITHUB_ACTOR" \ - --arg verifiedAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ - '{$targetDeploymentId, $expectedSha, $performRollback, $runId, $runAttempt, $workflowSha, $actor, $verifiedAt}' \ - > temp/website-rollback-result/result.json - - - name: Upload rollback evidence - uses: actions/upload-artifact@v6 - with: - name: website-rollback-result - path: temp/website-rollback-result/result.json - retention-days: 7 - if-no-files-found: error diff --git a/apps/website/vercel.json b/apps/website/vercel.json index c31a917fef9..9828c816dcd 100644 --- a/apps/website/vercel.json +++ b/apps/website/vercel.json @@ -8,19 +8,6 @@ "enabled": false }, "headers": [ - { - "source": "/__build.json", - "headers": [ - { - "key": "Cache-Control", - "value": "no-store, max-age=0" - }, - { - "key": "X-Robots-Tag", - "value": "noindex" - } - ] - }, { "source": "/(.*)", "has": [ diff --git a/package.json b/package.json index 195178b362f..340531ef69c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "knip": "knip --cache", "lint:fix:no-cache": "pnpm oxlint --fix && eslint --concurrency auto --fix", "lint:fix:ci": "pnpm lint:fix --cache-strategy content", - "lint:fix:website": "stylelint --cache --cache-strategy content --fix 'apps/website/**/*.{css,vue}' && oxlint apps/website --type-aware --fix && eslint apps/website --cache --cache-strategy content --concurrency auto --fix && pnpm --filter @comfyorg/website format", "lint:fix": "pnpm oxlint --fix && eslint --cache --concurrency auto --fix", "lint:no-cache": "pnpm exec stylelint '{apps,packages,src}/**/*.{css,vue}' && pnpm oxlint && eslint --concurrency auto", "lint:unstaged:fix": "tsx scripts/lint-unstaged.ts --fix", diff --git a/scripts/cicd/changes-filter.test.ts b/scripts/cicd/changes-filter.test.ts index 5a95ea18f01..131ed3f592f 100644 --- a/scripts/cicd/changes-filter.test.ts +++ b/scripts/cicd/changes-filter.test.ts @@ -17,8 +17,7 @@ const action = z id: z.string(), if: z.string().optional(), run: z.string().optional(), - env: z.object({ EVALUATE: z.string() }).optional(), - with: z.object({ filters: z.string() }).optional() + env: z.object({ EVALUATE: z.string() }).optional() }) ) }) @@ -34,11 +33,7 @@ function evaluateBoolean(expression: string, context: object) { return z.boolean().parse(runInNewContext(javascript, context)) } -function selectChecks( - eventName: string, - relevant: Record, - filter: Record = {} -) { +function selectChecks(eventName: string, relevant: Record) { const root = mkdtempSync(join(tmpdir(), 'changes-filter-')) try { const output = join(root, 'output') @@ -74,12 +69,7 @@ function selectChecks( const relevantStep = action.runs.steps.find( (step) => step.id === 'relevant' ) - const filterStep = action.runs.steps.find((step) => step.id === 'filter') - assert.exists(filterStep?.if) assert.exists(relevantStep?.if) - context.steps.filter.outputs = evaluateBoolean(filterStep.if, context) - ? filter - : {} context.steps.relevant.outputs = evaluateBoolean(relevantStep.if, context) ? relevant : {} @@ -145,8 +135,7 @@ it.for(['merge_group', 'push', 'workflow_dispatch'])( 'packages-changes': true, 'storybook-changes': true, 'docs-changes': true, - 'dependency-changes': true, - 'website-only-changes': false + 'dependency-changes': true }) } ) @@ -172,45 +161,3 @@ it.for([ 'should-run-source': source }) }) - -it.for([ - { - name: 'website-only pull request', - outsideWebsite: 'false', - expected: true - }, - { - name: 'website plus docs pull request', - outsideWebsite: 'true', - expected: false - } -])('classifies a $name', ({ outsideWebsite, expected }) => { - const relevant = { - relevant: 'false', - unit: 'false', - e2e: 'false', - source: 'false', - outside_website: outsideWebsite - } - const filter = { app_website: 'true', deps: 'false' } - - expect( - selectChecks('pull_request', relevant, filter)['website-only-changes'] - ).toBe(expected) -}) - -it('classifies website-only paths with the fast-lane path policy', () => { - const relevantFilters = action.runs.steps.find( - (step) => step.id === 'relevant' - )?.with?.filters - assert.exists(relevantFilters) - const lane = z - .object({ pathPrefixes: z.array(z.string()) }) - .parse(JSON.parse(readFileSync('.github/fast-lanes/website.json', 'utf8'))) - - expect( - z - .object({ outside_website: z.array(z.string()) }) - .parse(parse(relevantFilters)).outside_website - ).toEqual(['**', ...lane.pathPrefixes.map((prefix) => `!${prefix}**`)]) -}) diff --git a/scripts/cicd/website-deployment.sh b/scripts/cicd/website-deployment.sh deleted file mode 100755 index c68ab5168af..00000000000 --- a/scripts/cicd/website-deployment.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -readonly CANONICAL_HOST=comfy.org -readonly BUILD_IDENTITY_PATH=apps/website/public/__build.json - -vercel_api() { - curl -fsS --retry 3 \ - -H "Authorization: Bearer ${VERCEL_TOKEN:?VERCEL_TOKEN is required}" \ - "https://api.vercel.com/$1" -} - -write_build_identity() { - jq -n \ - --arg sha "${1:?usage: write-build-identity }" \ - --arg runId "${GITHUB_RUN_ID:?}" \ - --arg runAttempt "${GITHUB_RUN_ATTEMPT:?}" \ - '{$sha, $runId, $runAttempt}' \ - >"$BUILD_IDENTITY_PATH" -} - -alias_deployment_id() { - vercel_api "v4/aliases/$CANONICAL_HOST?projectId=${VERCEL_PROJECT_ID:?}&teamId=${VERCEL_ORG_ID:?}" | - jq -er '.deploymentId' -} - -deployment_field() { - local ref=${1:?usage: deployment } - local field=${2:?usage: deployment } - vercel_api "v13/deployments/$ref?teamId=${VERCEL_ORG_ID:?}" | - jq -er --arg ref "$ref" --arg field "$field" --arg projectId "${VERCEL_PROJECT_ID:?}" \ - 'select((.projectId // .project.id) == $projectId and (.id == $ref or ($ref | startswith("dpl_") | not))) | .[$field]' -} - -host_of() { - local host=${1#https://} - printf '%s' "${host%/}" -} - -build_identity() { - curl -fsS -H 'Cache-Control: no-cache' \ - "https://$(host_of "$1")/__build.json?probe=${GITHUB_RUN_ID:-local}-${GITHUB_RUN_ATTEMPT:-0}-$2" -} - -marker_sha() { - build_identity "${1:?usage: marker-sha }" 0 | jq -r '.sha // empty' -} - -verify_identity() { - local host='' sha='' deployment='' this_run=false attempts=1 interval=0 - while (($#)); do - case $1 in - --host) host=$2 ;; - --sha) sha=$2 ;; - --canonical-deployment) deployment=$2 host=$CANONICAL_HOST ;; - --attempts) attempts=$2 ;; - --interval) interval=$2 ;; - --this-run) this_run=true && shift && continue ;; - *) echo "unknown option: $1" >&2 && return 2 ;; - esac - shift 2 - done - : "${host:?--host or --canonical-deployment is required}" "${sha:?--sha is required}" - - for ((attempt = 1; attempt <= attempts; attempt++)); do - if serves_identity "$attempt"; then return 0; fi - if ((attempt < attempts)); then sleep "$interval"; fi - done - echo "::error::$(host_of "$host") did not serve $sha${deployment:+ from $deployment}" - return 1 -} - -serves_identity() { - local identity - identity=$(build_identity "$host" "$1") || return 1 - jq -e \ - --arg sha "$sha" \ - --argjson thisRun "$this_run" \ - --arg runId "${GITHUB_RUN_ID:-}" \ - --arg runAttempt "${GITHUB_RUN_ATTEMPT:-}" \ - '.sha == $sha and (($thisRun | not) or (.runId == $runId and .runAttempt == $runAttempt))' \ - <<<"$identity" >/dev/null || return 1 - [[ -z $deployment ]] && return 0 - [[ $(alias_deployment_id || true) == "$deployment" ]] || return 1 - curl -fsS -o /dev/null "https://$CANONICAL_HOST/" -} - -command=${1:?usage: website-deployment.sh [args]} -shift -case $command in - write-build-identity) write_build_identity "$@" ;; - alias-deployment-id) alias_deployment_id ;; - deployment) deployment_field "$@" ;; - marker-sha) marker_sha "$@" ;; - verify-identity) verify_identity "$@" ;; - *) echo "unknown command: $command" >&2 && exit 2 ;; -esac diff --git a/scripts/cicd/website-deployment.test.ts b/scripts/cicd/website-deployment.test.ts deleted file mode 100644 index c9cffa376c8..00000000000 --- a/scripts/cicd/website-deployment.test.ts +++ /dev/null @@ -1,193 +0,0 @@ -import { spawnSync } from 'node:child_process' -import fs from 'node:fs' -import os from 'node:os' -import path from 'node:path' - -import { afterEach, beforeEach, describe, expect, it } from 'vitest' - -const SCRIPT = path.join(import.meta.dirname, 'website-deployment.sh') -const SHA = 'a'.repeat(40) -const PROJECT = 'prj_website' -const DEPLOYMENT = 'dpl_new' - -const ownIdentity = { sha: SHA, runId: '7', runAttempt: '2' } - -const fakeCurl = `#!/usr/bin/env bash -for url; do :; done -printf '%s\\n' "$url" >> "$FAKE_DIR/calls.log" -case $url in - https://api.vercel.com/v4/aliases/*) file=alias.json ;; - https://api.vercel.com/v13/deployments/*) file=deployment.json ;; - */__build.json*) host=\${url#https://}; file=identity-\${host%%/*}.json ;; - https://comfy.org/) exit 0 ;; -esac -[[ -n \${file:-} && -f $FAKE_DIR/$file ]] || exit 22 -cat "$FAKE_DIR/$file" -` - -let dir: string - -beforeEach(() => { - dir = fs.mkdtempSync(path.join(os.tmpdir(), 'website-deployment-')) - fs.mkdirSync(path.join(dir, 'bin')) - fs.mkdirSync(path.join(dir, 'apps/website/public'), { recursive: true }) - fs.writeFileSync(path.join(dir, 'bin/curl'), fakeCurl, { mode: 0o755 }) -}) - -afterEach(() => { - fs.rmSync(dir, { recursive: true, force: true }) -}) - -function serve(responses: Record) { - for (const [file, body] of Object.entries(responses)) { - fs.writeFileSync(path.join(dir, file), JSON.stringify(body)) - } -} - -function run(...args: string[]) { - const result = spawnSync('bash', [SCRIPT, ...args], { - cwd: dir, - encoding: 'utf8', - env: { - PATH: `${path.join(dir, 'bin')}:${process.env.PATH ?? ''}`, - FAKE_DIR: dir, - GITHUB_RUN_ID: '7', - GITHUB_RUN_ATTEMPT: '2', - VERCEL_ORG_ID: 'team_comfy', - VERCEL_PROJECT_ID: PROJECT, - VERCEL_TOKEN: 'token' - } - }) - const log = path.join(dir, 'calls.log') - return { - status: result.status, - stdout: result.stdout.trim(), - calls: fs.existsSync(log) - ? fs.readFileSync(log, 'utf8').trim().split('\n') - : [] - } -} - -describe('website deployment identity', () => { - it('writes the build identity for the current run', () => { - expect(run('write-build-identity', SHA).status).toBe(0) - - expect( - JSON.parse( - fs.readFileSync( - path.join(dir, 'apps/website/public/__build.json'), - 'utf8' - ) - ) - ).toEqual(ownIdentity) - }) - - it.for([ - { - name: 'the URL of its own deployment', - args: [DEPLOYMENT, 'url'], - deployment: { id: DEPLOYMENT, projectId: PROJECT, url: 'new.vercel.app' }, - expected: 'new.vercel.app' - }, - { - name: 'the id of its own deployment host', - args: ['new.vercel.app', 'id'], - deployment: { id: DEPLOYMENT, project: { id: PROJECT } }, - expected: DEPLOYMENT - }, - { - name: 'nothing for another project', - args: [DEPLOYMENT, 'url'], - deployment: { id: DEPLOYMENT, projectId: 'prj_other', url: 'x' }, - expected: undefined - }, - { - name: 'nothing for a different deployment id', - args: [DEPLOYMENT, 'url'], - deployment: { id: 'dpl_other', projectId: PROJECT, url: 'x' }, - expected: undefined - } - ])('resolves $name', ({ args, deployment, expected }) => { - serve({ 'deployment.json': deployment }) - - const result = run('deployment', ...args) - - expect(result.status === 0 ? result.stdout : undefined).toBe(expected) - }) - - it.for([ - { - name: 'a matching preview', - args: ['--host', 'https://new.vercel.app/'], - identity: { sha: SHA }, - ok: true - }, - { - name: 'a preview serving another commit', - args: ['--host', 'new.vercel.app'], - identity: { sha: 'b'.repeat(40) }, - ok: false - }, - { - name: 'a staged build from this run', - args: ['--host', 'new.vercel.app', '--this-run'], - identity: ownIdentity, - ok: true - }, - { - name: 'a staged build from an earlier attempt', - args: ['--host', 'new.vercel.app', '--this-run'], - identity: { ...ownIdentity, runAttempt: '1' }, - ok: false - }, - { - name: 'a canonical host on the expected deployment', - args: ['--canonical-deployment', DEPLOYMENT], - identity: { sha: SHA }, - ok: true - }, - { - name: 'a canonical host aliased to another deployment', - args: ['--canonical-deployment', 'dpl_old'], - identity: { sha: SHA }, - ok: false - } - ])('verifies $name: $ok', ({ args, identity, ok }) => { - serve({ - 'identity-new.vercel.app.json': identity, - 'identity-comfy.org.json': identity, - 'alias.json': { deploymentId: DEPLOYMENT } - }) - - const result = run('verify-identity', '--sha', SHA, ...args) - - expect(result.status === 0).toBe(ok) - }) - - it('retries until the attempts are exhausted', () => { - serve({ 'identity-new.vercel.app.json': { sha: 'b'.repeat(40) } }) - - const result = run( - 'verify-identity', - '--host', - 'new.vercel.app', - '--sha', - SHA, - '--attempts', - '3' - ) - - expect(result.status).toBe(1) - expect(result.calls).toHaveLength(3) - }) - - it('reads the deployment aliased to comfy.org', () => { - serve({ 'alias.json': { deploymentId: 'dpl_live' } }) - - expect(run('alias-deployment-id').stdout).toBe('dpl_live') - }) - - it('reports an empty marker SHA when the deployment has no identity', () => { - expect(run('marker-sha', 'old.vercel.app').stdout).toBe('') - }) -}) From 91e8072c2fb0f7339dc5cedac40e3cc4b0e235a8 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 06:50:49 +0000 Subject: [PATCH 65/70] refactor(ci): keep fast-lane policies in a typed module Replace the JSON policy, its hand-written parser, schema version, and the unused manual merge mode with lanes.ts; a test keeps entries lowercase and prefixes relative. Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- tools/cicd/fast-lane/src/__fixtures__/lane.ts | 4 +- tools/cicd/fast-lane/src/automation.test.ts | 11 -- tools/cicd/fast-lane/src/automation.ts | 4 +- tools/cicd/fast-lane/src/config.test.ts | 85 +++---------- tools/cicd/fast-lane/src/config.ts | 118 +----------------- tools/cicd/fast-lane/src/lanes.ts | 15 +++ tools/cicd/fast-lane/src/types.ts | 8 -- 7 files changed, 41 insertions(+), 204 deletions(-) create mode 100644 tools/cicd/fast-lane/src/lanes.ts diff --git a/tools/cicd/fast-lane/src/__fixtures__/lane.ts b/tools/cicd/fast-lane/src/__fixtures__/lane.ts index f42f23cd4ee..eebe549c2e9 100644 --- a/tools/cicd/fast-lane/src/__fixtures__/lane.ts +++ b/tools/cicd/fast-lane/src/__fixtures__/lane.ts @@ -10,7 +10,6 @@ export const headSha = '0123456789abcdef0123456789abcdef01234567' export const floorTime = '2026-10-06T10:00:00Z' export const lane: FastLaneConfig = { - schemaVersion: 1, id: 'website', pathPrefixes: ['apps/website/'], approval: { @@ -19,8 +18,7 @@ export const lane: FastLaneConfig = { approvalLabel: 'website-fast-lane:approve', trustedLabelers: ['drjkl'], holdLabel: 'website-fast-lane:hold' - }, - merge: { mode: 'automatic', method: 'SQUASH' } + } } export const operatorLabelEvent = { diff --git a/tools/cicd/fast-lane/src/automation.test.ts b/tools/cicd/fast-lane/src/automation.test.ts index b31e349fd04..897458526b3 100644 --- a/tools/cicd/fast-lane/src/automation.test.ts +++ b/tools/cicd/fast-lane/src/automation.test.ts @@ -165,17 +165,6 @@ describe('runFastLane', () => { ] ] }, - { - name: 'a manual lane', - options: {}, - config: { - lane: { - ...lane, - merge: { mode: 'manual', method: 'SQUASH' } - } - }, - writes: [approvalPost] - }, { name: 'a head that advanced before arming', options: { mergeState: { headRefOid: 'f'.repeat(40) } }, diff --git a/tools/cicd/fast-lane/src/automation.ts b/tools/cicd/fast-lane/src/automation.ts index 09ae20e373f..49329d61271 100644 --- a/tools/cicd/fast-lane/src/automation.ts +++ b/tools/cicd/fast-lane/src/automation.ts @@ -148,8 +148,6 @@ async function armMergeAutomation( config: RuntimeConfig, summary: Summary ): Promise { - if (config.lane.merge.mode === 'manual') return - const headSha = config.eventHeadSha const state = await readMergeState(github, pull) if (state.headRefOid !== headSha) { @@ -197,7 +195,7 @@ async function armMergeAutomation( { pullRequestId: state.id, expectedHeadOid: headSha, - mergeMethod: config.lane.merge.method + mergeMethod: 'SQUASH' } ) summary(`Armed native auto-merge for ${shortSha(headSha)}.`) diff --git a/tools/cicd/fast-lane/src/config.test.ts b/tools/cicd/fast-lane/src/config.test.ts index 3f79ed25f9b..6ea4213f1d1 100644 --- a/tools/cicd/fast-lane/src/config.test.ts +++ b/tools/cicd/fast-lane/src/config.test.ts @@ -1,76 +1,22 @@ -import { readFileSync } from 'node:fs' - import { beforeEach, describe, expect, it, vi } from 'vitest' -import { lane, operatorLabelEvent } from './__fixtures__/lane.ts' -import { loadRuntimeConfig, parseFastLaneConfig } from './config.ts' - -describe('lane configuration', () => { - it('normalizes logins while preserving the reviewed path policy', () => { - expect( - parseFastLaneConfig({ - ...lane, - approval: { - ...lane.approval, - identity: 'Christian-Byrne', - trustedAuthors: ['BertFY', 'bertfy'], - trustedLabelers: ['DrJKL'] - } - }) - ).toEqual(lane) - }) - - it('parses the checked-in website lane', () => { - const shipped: unknown = JSON.parse( - readFileSync('.github/fast-lanes/website.json', 'utf8') - ) - expect(parseFastLaneConfig(shipped).pathPrefixes).toEqual(['apps/website/']) - }) +import { operatorLabelEvent } from './__fixtures__/lane.ts' +import { loadRuntimeConfig } from './config.ts' +import { lanes } from './lanes.ts' - it.for([ - { - key: 'schema version', - value: { ...lane, schemaVersion: 2 }, - message: 'schemaVersion must be 1' - }, - { - key: 'empty path policy', - value: { ...lane, pathPrefixes: [] }, - message: 'pathPrefixes must be an array' - }, - { - key: 'ambiguous path prefix', - value: { ...lane, pathPrefixes: ['apps/website'] }, - message: 'relative directory prefixes' - }, - { - key: 'absolute path prefix', - value: { ...lane, pathPrefixes: ['/apps/website/'] }, - message: 'relative directory prefixes' - }, - { - key: 'parent path segment', - value: { ...lane, pathPrefixes: ['apps/website/../'] }, - message: 'relative directory prefixes' - }, - { - key: 'unknown merge mode', - value: { ...lane, merge: { mode: 'sometimes', method: 'SQUASH' } }, - message: 'automatic or manual' - }, - { - key: 'unknown merge method', - value: { ...lane, merge: { mode: 'automatic', method: 'FAST_FORWARD' } }, - message: 'MERGE, REBASE, or SQUASH' - } - ])('rejects $key', ({ value, message }) => { - expect(() => parseFastLaneConfig(value)).toThrow(message) - }) +it.for(lanes)('keeps the $id lane in the form the engine compares', (lane) => { + for (const value of Object.values(lane.approval).flat()) { + expect(value).toBe(value.toLowerCase()) + } + for (const prefix of lane.pathPrefixes) { + expect(prefix).toMatch(/\/$/) + expect(prefix).not.toMatch(/^\/|(^|\/)\.\.\//) + } }) describe('runtime configuration', () => { beforeEach(() => { - vi.stubEnv('FAST_LANE_CONFIG', '.github/fast-lanes/website.json') + vi.stubEnv('FAST_LANE', 'website') vi.stubEnv('GITHUB_REPOSITORY', 'Comfy-Org/ComfyUI_frontend') vi.stubEnv('PR_NUMBER', '42') vi.stubEnv('PR_HEAD_SHA', 'head-sha') @@ -107,7 +53,12 @@ describe('runtime configuration', () => { } ) - it('requires the resolved pull request number', () => { + it('rejects an unconfigured lane', () => { + vi.stubEnv('FAST_LANE', 'docs') + expect(() => loadRuntimeConfig()).toThrow('not a configured lane') + }) + + it('requires the pull request number', () => { vi.stubEnv('PR_NUMBER', '') expect(() => loadRuntimeConfig()).toThrow('PR_NUMBER is required') }) diff --git a/tools/cicd/fast-lane/src/config.ts b/tools/cicd/fast-lane/src/config.ts index 1796bb5da9e..134eaa6a773 100644 --- a/tools/cicd/fast-lane/src/config.ts +++ b/tools/cicd/fast-lane/src/config.ts @@ -1,105 +1,5 @@ -import fs from 'node:fs' - -import { isRecord } from './github.ts' -import { MERGE_METHODS, MERGE_MODES } from './types.ts' -import type { FastLaneConfig, LabelEvent, RuntimeConfig } from './types.ts' - -function isOneOf( - values: readonly T[], - value: string -): value is T { - return values.some((candidate) => candidate === value) -} - -function requiredString( - record: Record, - key: string, - context: string -): string { - const value = record[key] - if (typeof value !== 'string' || !value.trim()) { - throw new Error(`${context}.${key} must be a non-empty string`) - } - return value.trim() -} - -function stringArray( - record: Record, - key: string, - context: string, - { allowEmpty = false }: { allowEmpty?: boolean } = {} -): string[] { - const value = record[key] - if ( - !Array.isArray(value) || - (!allowEmpty && value.length === 0) || - value.some((item) => typeof item !== 'string' || !item.trim()) - ) { - throw new Error(`${context}.${key} must be an array of non-empty strings`) - } - return value.map((item) => item.trim()) -} - -function record(value: unknown, context: string): Record { - if (!isRecord(value)) throw new Error(`${context} must be an object`) - return value -} - -export function parseFastLaneConfig(value: unknown): FastLaneConfig { - const root = record(value, 'fast lane config') - if (root.schemaVersion !== 1) { - throw new Error('fast lane config.schemaVersion must be 1') - } - - const approval = record(root.approval, 'fast lane config.approval') - const approvalName = (key: string) => - requiredString(approval, key, 'fast lane config.approval').toLowerCase() - const approvalLogins = (key: string) => [ - ...new Set( - stringArray(approval, key, 'fast lane config.approval', { - allowEmpty: true - }).map((login) => login.toLowerCase()) - ) - ] - const merge = record(root.merge, 'fast lane config.merge') - const mode = requiredString(merge, 'mode', 'fast lane config.merge') - const method = requiredString(merge, 'method', 'fast lane config.merge') - if (!isOneOf(MERGE_MODES, mode)) { - throw new Error('fast lane config.merge.mode must be automatic or manual') - } - if (!isOneOf(MERGE_METHODS, method)) { - throw new Error( - 'fast lane config.merge.method must be MERGE, REBASE, or SQUASH' - ) - } - const pathPrefixes = stringArray(root, 'pathPrefixes', 'fast lane config') - if ( - pathPrefixes.some( - (prefix) => - !prefix.endsWith('/') || - prefix.startsWith('/') || - prefix.split('/').includes('..') - ) - ) { - throw new Error( - 'fast lane config.pathPrefixes must be relative directory prefixes ending in /' - ) - } - - return { - schemaVersion: 1, - id: requiredString(root, 'id', 'fast lane config'), - pathPrefixes, - approval: { - identity: approvalName('identity'), - trustedAuthors: approvalLogins('trustedAuthors'), - approvalLabel: approvalName('approvalLabel'), - trustedLabelers: approvalLogins('trustedLabelers'), - holdLabel: approvalName('holdLabel') - }, - merge: { mode, method } - } -} +import { lanes } from './lanes.ts' +import type { LabelEvent, RuntimeConfig } from './types.ts' export function requiredEnv(name: string): string { const value = process.env[name]?.trim() @@ -130,15 +30,9 @@ function labelEventEnv(): LabelEvent | undefined { } export function loadRuntimeConfig(): RuntimeConfig { - const configPath = requiredEnv('FAST_LANE_CONFIG') - let parsed: unknown - try { - parsed = JSON.parse(fs.readFileSync(configPath, 'utf8')) - } catch (error) { - throw new Error(`Could not read ${configPath}: ${String(error)}`, { - cause: error - }) - } + const laneId = requiredEnv('FAST_LANE') + const lane = lanes.find((candidate) => candidate.id === laneId) + if (!lane) throw new Error(`FAST_LANE ${laneId} is not a configured lane`) return { repository: requiredEnv('GITHUB_REPOSITORY'), @@ -146,6 +40,6 @@ export function loadRuntimeConfig(): RuntimeConfig { eventHeadSha: requiredEnv('PR_HEAD_SHA'), labelEvent: labelEventEnv(), defaultBranch: requiredEnv('FAST_LANE_DEFAULT_BRANCH'), - lane: parseFastLaneConfig(parsed) + lane } } diff --git a/tools/cicd/fast-lane/src/lanes.ts b/tools/cicd/fast-lane/src/lanes.ts new file mode 100644 index 00000000000..ad38e288551 --- /dev/null +++ b/tools/cicd/fast-lane/src/lanes.ts @@ -0,0 +1,15 @@ +import type { FastLaneConfig } from './types.ts' + +export const lanes: FastLaneConfig[] = [ + { + id: 'website', + pathPrefixes: ['apps/website/'], + approval: { + identity: 'christian-byrne', + trustedAuthors: ['bertfy'], + approvalLabel: 'website-fast-lane:approve', + trustedLabelers: ['christian-byrne', 'drjkl', 'benjcooley'], + holdLabel: 'website-fast-lane:hold' + } + } +] diff --git a/tools/cicd/fast-lane/src/types.ts b/tools/cicd/fast-lane/src/types.ts index 163b35f0045..9025271550f 100644 --- a/tools/cicd/fast-lane/src/types.ts +++ b/tools/cicd/fast-lane/src/types.ts @@ -1,8 +1,4 @@ -export const MERGE_MODES = ['automatic', 'manual'] as const -export const MERGE_METHODS = ['MERGE', 'REBASE', 'SQUASH'] as const - export interface FastLaneConfig { - schemaVersion: 1 id: string pathPrefixes: string[] approval: { @@ -12,10 +8,6 @@ export interface FastLaneConfig { trustedLabelers: string[] holdLabel: string } - merge: { - mode: (typeof MERGE_MODES)[number] - method: (typeof MERGE_METHODS)[number] - } } export interface RepositoryRef { From b387448260bcfc293d3348812f87bec776523d93 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 8 Oct 2026 06:50:55 +0000 Subject: [PATCH 66/70] docs: describe the simplified fast lane and website rollback Amp-Thread-ID: https://ampcode.com/threads/T-01a11431-3124-76d9-85a5-01290adae734 --- ...-0041-path-scoped-policy-approval-lanes.md | 26 ++++----- docs/architecture/package-delivery-lanes.md | 54 ++++++------------- .../website-delivery-validation.md | 40 +++++--------- 3 files changed, 43 insertions(+), 77 deletions(-) diff --git a/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md b/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md index a5528abe0fb..ebe63f61ee5 100644 --- a/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md +++ b/docs/adr/CI-FAST-LANE-0041-path-scoped-policy-approval-lanes.md @@ -21,22 +21,19 @@ approvals on push and merges through the native merge queue. Introduce path-scoped delivery lanes, starting with the website: -- Each lane has a reviewed JSON policy under `.github/fast-lanes/` that names its path prefixes, - trusted authors, operator label, trusted labelers, hold label, and merge mode. -- A website-only pull request runs website-scoped lint, format, typecheck, unused-code, and locale - checks inside the existing `lint-and-format` context. Mixed pull requests and merge-queue - candidates keep the full checks. -- `pr-website-auto-approve.yaml` runs the `tools/cicd/fast-lane/` workspace from the default branch. For an - eligible same-repository pull request whose complete changed-file set is inside the lane, it - posts a policy-only approval bound to the exact head with a credential held in a +- Each lane is a reviewed entry in `tools/cicd/fast-lane/src/lanes.ts` that names its path + prefixes, trusted authors, operator label, trusted labelers, and hold label. +- `pr-website-auto-approve.yaml` runs the `tools/cicd/fast-lane/` workspace from the default + branch. For an eligible same-repository pull request whose complete changed-file set is inside + the lane, it posts a policy-only approval bound to the exact head with a credential held in a `main`-restricted environment, then arms native auto-merge or enters the queue. Every later run re-reads live state and withdraws lane-owned approvals and merge state when the pull request stops being eligible. - A non-allowlisted author is eligible only on a trusted operator's `labeled` event for the current head, and stays eligible only while the label remains applied. - CodeRabbit skips `apps/website/**` for the trial; human change requests still block the lane. -- Website production deploys are staged, verified through `/__build.json`, then promoted; a - manual workflow validates or performs rollback. +- Production deploys record a GitHub deployment for their commit; rollback uses Vercel's Instant + Rollback. ### Alternatives not chosen @@ -52,6 +49,11 @@ Introduce path-scoped delivery lanes, starting with the website: - **One global concurrency group, or groups keyed by commit SHA.** A global group lets unrelated pull requests cancel a pending hold or label run; SHA-keyed groups let two runs approve and withdraw the same pull request at once. Runs are grouped per pull request instead. +- **Website-scoped lint and typecheck jobs.** The full typecheck (about 6 minutes) finishes before + the website unit and browser suites, so scoping it does not shorten the time to merge. +- **A deployment marker, staged promotion, and a rollback workflow.** The GitHub deployment record + and Vercel's deployment history already tie production to a commit, and Vercel's Instant Rollback + restores a known deployment. ## Consequences @@ -60,7 +62,7 @@ Introduce path-scoped delivery lanes, starting with the website: - A trusted author's website-only change can reach the merge queue without waiting for a human reviewer, and every approval is tied to one head and can be withdrawn. - The rest of the repository keeps its checks, review rule, and merge queue unchanged. -- Another package can add a lane with its own policy, classifier output, and scoped checks. +- Another package can add a lane with one entry and a copy of the workflow. ### Negative @@ -71,7 +73,7 @@ Introduce path-scoped delivery lanes, starting with the website: - GitHub keeps only the newest pending run per concurrency group, so a pending `labeled` run can be cancelled by another event on the same pull request; the operator re-runs it or re-applies the label. -- The trial adds a workflow, an engine, and a rollback procedure that operators must maintain. +- The trial adds a workflow and an engine that operators must maintain. ## Notes diff --git a/docs/architecture/package-delivery-lanes.md b/docs/architecture/package-delivery-lanes.md index 9936b5f7161..cee3fc4166b 100644 --- a/docs/architecture/package-delivery-lanes.md +++ b/docs/architecture/package-delivery-lanes.md @@ -1,20 +1,17 @@ # Package delivery lanes A package delivery lane lets one part of the monorepo choose its own balance of speed and rigor -without weakening the rest of the repository. A lane has four independent stages: +without weakening the rest of the repository. A lane decides whether every changed path belongs to +the package, applies the package's reviewed approval policy to the exact commit, and then hands the +pull request to the repository's normal checks, merge queue, deployment, and rollback. -1. **Scope:** decide whether every changed path belongs to the package. -2. **Quality:** run the package's checks instead of unrelated repository checks. -3. **Approval:** apply the package's reviewed approval policy to the exact commit. -4. **Delivery:** use the repository's normal merge, deployment, and rollback systems. - -The website is the first lane. The approval engine in the `tools/cicd/fast-lane/` workspace is package-neutral; -the change classifier output, the scoped CI jobs, and the workflow are per lane. +The website is the first lane. The approval engine in the `tools/cicd/fast-lane/` workspace is +package-neutral; the lane entry and the workflow are per lane. ## The dials a package owns -Each lane has a JSON policy in `.github/fast-lanes/`. A policy change receives normal repository -review, so changing a dial is visible in history. +Each lane is an entry in `tools/cicd/fast-lane/src/lanes.ts`, written in lowercase. A policy change +receives normal repository review, so changing a dial is visible in history. | Dial | Meaning | | -------------------------- | -------------------------------------------------------------------------------------------- | @@ -24,13 +21,6 @@ review, so changing a dial is visible in history. | `approval.approvalLabel` | An explicit opt-in route for other authors. | | `approval.trustedLabelers` | Operators allowed to apply that label. | | `approval.holdLabel` | Stops the lane at its next run: dismisses lane approvals and disarms lane-owned merge state. | -| `merge.mode` | `automatic` arms native auto-merge or the queue; `manual` stops after approval. | -| `merge.method` | The repository-supported merge method used by automatic mode. | - -Package-specific quality commands remain in the package's CI jobs. The first routing rule is -simple: a package-only pull request runs that package's checks; a mixed or root-level pull request -runs the full repository checks. Merge-group and protected-branch runs remain full-repository checks -unless a later change proves that a narrower candidate calculation is safe. ## Fixed safety rules @@ -62,30 +52,20 @@ These are implementation invariants, not package dials: policy review on the pull request. Because the identity is a personal account, that includes the account owner's own merge actions in that window. -The reusable TypeScript engine lives in `tools/cicd/fast-lane/src/`. `policy.ts` contains pure policy -decisions, `github.ts` contains GitHub transport, and `automation.ts` owns the approval and merge -lifecycle. Behavioral tests run `runFastLane` against an in-memory GitHub double and cover each -fixed rule. +The reusable TypeScript engine lives in `tools/cicd/fast-lane/src/`. `lanes.ts` holds the policies, +`policy.ts` the pure policy decisions, `github.ts` the GitHub transport, and `automation.ts` the +approval and merge lifecycle. Behavioral tests run `runFastLane` against an in-memory GitHub double +and cover each fixed rule. ## Adding a lane -1. Add a reviewed policy file under `.github/fast-lanes/`. -2. Add a package-only output to the change classifier (`.github/actions/changes-filter`) and a - test that ties it to the policy's `pathPrefixes`. -3. Add package-scoped lint, format, typecheck, test, and repository checks behind that result. Keep - the full checks as the fallback for mixed changes. -4. Add a workflow like `pr-website-auto-approve.yaml`: `pull_request_target`, `status`, and - `workflow_run` triggers; a resolver job that finds the pull request; and one lane job keyed on - that pull request's concurrency group. The lane job sparse-checks out `.nvmrc`, the selected - policy, and `tools/cicd/fast-lane/` from the default branch (cone mode also includes - root-level files) and runs `node tools/cicd/fast-lane/src/run.ts` without installing - dependencies. -5. Put the approval credential in a package-specific protected environment and restrict that +1. Add the lane to `tools/cicd/fast-lane/src/lanes.ts`. +2. Copy `pr-website-auto-approve.yaml` and point it at the new lane and at the workflows whose + completion should re-run the lane. +3. Put the approval credential in a package-specific protected environment and restrict that environment to the protected default branch. -6. Add negative tests for forks, mixed paths, stale heads, self-approval, unauthorized labels, - active change requests, and post-approval failure. -7. Trial the lane with a disposable pull request. Record time from update to checks, approval, - queue entry, production identity, and rollback readiness before expanding its allowlist. +4. Trial the lane with a disposable pull request. Record time from update to checks, approval, + queue entry, and production deployment before expanding its allowlist. This process changes package policy, not the repository's underlying protection model. A package can start with fast feedback and a narrow allowlist, then tighten or relax individual dials using diff --git a/docs/architecture/website-delivery-validation.md b/docs/architecture/website-delivery-validation.md index 6a9b9bc6575..c8d4f3925a0 100644 --- a/docs/architecture/website-delivery-validation.md +++ b/docs/architecture/website-delivery-validation.md @@ -5,8 +5,8 @@ change on their timeline while the rest of the monorepo keeps its current safegu ## Current lane -The checked-in policy is `.github/fast-lanes/website.json`. It allows changes only under -`apps/website/`. `bertfy` is a trusted author. For other authors, a listed operator adds +The `website` entry in `tools/cicd/fast-lane/src/lanes.ts` is the policy. It allows changes only +under `apps/website/`. `bertfy` is a trusted author. For other authors, a listed operator adds `website-fast-lane:approve` to the current head; removing it withdraws the approval. `website-fast-lane:hold`, a draft, a human change request, a fork, or a mixed-path change stops the lane. A hold does not undo a merge that already happened. To resume after a hold, remove @@ -18,40 +18,24 @@ The `website-approval` environment supplies `WEBSITE_APPROVAL_TOKEN`. The creden belongs to `christian-byrne`, whose team membership satisfies the website path review rule. The workflow verifies that identity before it acts and cannot approve Christian's own pull requests. After approval it uses squash auto-merge or enters an already-clean exact head in GitHub's native -queue without queue jumping. Later status and workflow-run events reconcile the decision. +queue without queue jumping. Each `CI: Tests E2E` or `CI: Website E2E` completion re-runs the lane +for its pull request in case native auto-merge did not hand the head to the queue. -For a website-only pull request, the required lint context runs website-scoped lint, format, -typecheck, and unused-code checks. A change outside `apps/website/` falls back to the full repository -jobs. CodeRabbit is excluded from `apps/website/**` for this trial; human change requests still -block the lane. +Website-only pull requests run the normal required checks; the core unit and browser suites already +skip when nothing outside `apps/` changed. CodeRabbit is excluded from `apps/website/**` for this +trial; human change requests still block the lane. ## Production identity and rollback -Each website preview and production build writes a cache-disabled `/__build.json` with the exact -source SHA, workflow run, and attempt. Deployment verifies the -immutable Vercel URL before accepting canonical `comfy.org` promotion and saves the previous and -new deployment IDs and SHAs as a short-lived transition artifact. Both deployment workflows use -`scripts/cicd/website-deployment.sh` for the build identity, Vercel lookups, and identity checks. - -`validation-website-rollback.yaml` accepts an immutable deployment ID and expected SHA. Its default -mode validates the target and marker without changing production. With `perform_rollback` enabled, -it performs an instant rollback, verifies the canonical marker and public homepage, then promotes -the same known-good deployment so normal production assignment can resume. - -The first production deployment containing `/__build.json` is bootstrap evidence, not the canary. -Before opening the canary: - -1. Within 7 days, download that deployment's transition artifact (the same IDs appear in the run's - step summary). -2. Run `Validation: Website Production Rollback` with its `deployedDeploymentId` and `deployedSha`. -3. Leave `perform_rollback` disabled and require the no-mutation preflight to pass. -4. Run the canary from update through production. A real rollback (`perform_rollback: true`) - changes production, so run it only when the operators running the trial agree to it. +Each production deploy records a `website-production` GitHub deployment for its commit, with the +immutable Vercel URL. To roll back, use Vercel's Instant Rollback on the last good production +deployment (dashboard or `vercel rollback `). Vercel then stops assigning new production +deployments, so once the fix has merged, use Undo Rollback (or `vercel promote `) on it. ## Evidence to record Record timestamps for the contributor update, required checks, policy approval, queue entry, merge, -and verified production SHA. Also record any manual intervention, confusing UI, false-positive +and production deployment. Also record any manual intervention, confusing UI, false-positive check, or rollback problem. The trial succeeds only if the contributor can follow the path without developer rescue and production can be tied to the expected commit. The allowlist should not expand until the canary and rollback evidence are complete. From 10e178ba13185eff9a4843105cb0330263f65668 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 8 Oct 2026 22:48:21 +0000 Subject: [PATCH 67/70] fix: repair pnpm lockfile --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b2dc4bb14be..2dc361c4c7b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -598,7 +598,7 @@ importers: version: 14.4.0(vue@3.5.42(typescript@6.0.3)) '@vueuse/integrations': specifier: 'catalog:' - version: 14.4.0(axios@1.18.1(debug@4.4.3))(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3)) + version: 14.4.0(axios@1.18.1)(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3)) '@vueuse/router': specifier: ^14.4.0 version: 14.4.0(vue-router@5.2.0(@vue/compiler-sfc@3.5.42)(esbuild@0.28.1)(pinia@4.0.2(@vue/devtools-api@8.1.5)(typescript@6.0.3)(vue@3.5.42(typescript@6.0.3)))(rolldown@1.2.6)(vite@8.2.2(@types/node@25.9.5)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(tsx@4.23.1)(yaml@2.9.0))(vue@3.5.42(typescript@6.0.3)))(vue@3.5.42(typescript@6.0.3)) @@ -13838,7 +13838,7 @@ snapshots: '@vueuse/shared': 14.4.0(vue@3.5.42(typescript@6.0.3)) vue: 3.5.42(typescript@6.0.3) - '@vueuse/integrations@14.4.0(axios@1.18.1(debug@4.4.3))(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3))': + '@vueuse/integrations@14.4.0(axios@1.18.1)(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3))': dependencies: '@vueuse/core': 14.4.0(vue@3.5.42(typescript@6.0.3)) '@vueuse/shared': 14.4.0(vue@3.5.42(typescript@6.0.3)) From 50953ba394e37776e0bd053dbd6549801ab3b87c Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 11 Oct 2026 05:49:20 +0000 Subject: [PATCH 68/70] fix: keep staged server-fact checks merge-aware --- scripts/server-fact-gate.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/server-fact-gate.ts b/scripts/server-fact-gate.ts index 7c032143669..ad6d9b8315e 100644 --- a/scripts/server-fact-gate.ts +++ b/scripts/server-fact-gate.ts @@ -15,14 +15,16 @@ function git(args: string[]): string { }) } -function diffArgs(argv: string[]): string[] { - if (argv.includes('--staged')) { - try { - return ['--cached', git(['rev-parse', '--verify', 'MERGE_HEAD']).trim()] - } catch { - return ['--cached'] - } +function stagedDiffArgs(): string[] { + try { + return ['--cached', git(['rev-parse', '--verify', 'MERGE_HEAD']).trim()] + } catch { + return ['--cached'] } +} + +function diffArgs(argv: string[]): string[] { + if (argv.includes('--staged')) return stagedDiffArgs() const baseIndex = argv.indexOf('--base') const base = baseIndex === -1 ? undefined : argv.at(baseIndex + 1) if (base === undefined) { From d4fbd612d6eb8e92d69e8a689e4b28e07f98046f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 11 Oct 2026 05:51:37 +0000 Subject: [PATCH 69/70] fix: repair pnpm lockfile --- pnpm-lock.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da48ada0908..fbba18758cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1490,15 +1490,6 @@ importers: specifier: 'catalog:' version: 5.0.2(@types/node@25.9.5)(@vitest/coverage-v8@5.0.2)(@vitest/ui@5.0.2)(happy-dom@20.14.5)(jsdom@29.1.1)(vite@8.2.2(@types/node@25.9.5)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(tsx@4.23.1)(yaml@2.9.0)) - tools/cicd/fast-lane: - devDependencies: - '@types/node': - specifier: 'catalog:' - version: 25.9.5 - vitest: - specifier: 'catalog:' - version: 5.0.2(@types/node@25.9.5)(@vitest/coverage-v8@5.0.2)(@vitest/ui@5.0.2)(happy-dom@20.14.5)(jsdom@29.1.1)(vite@8.2.2(@types/node@25.9.5)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(tsx@4.23.1)(yaml@2.9.0)) - tools/architecture: dependencies: typescript: @@ -1515,6 +1506,15 @@ importers: specifier: 'catalog:' version: 5.0.2(@types/node@25.9.5)(@vitest/coverage-v8@5.0.2)(@vitest/ui@5.0.2)(happy-dom@20.14.5)(jsdom@29.1.1)(vite@8.2.2(@types/node@25.9.5)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(tsx@4.23.1)(yaml@2.9.0)) + tools/cicd/fast-lane: + devDependencies: + '@types/node': + specifier: 'catalog:' + version: 25.9.5 + vitest: + specifier: 'catalog:' + version: 5.0.2(@types/node@25.9.5)(@vitest/coverage-v8@5.0.2)(@vitest/ui@5.0.2)(happy-dom@20.14.5)(jsdom@29.1.1)(vite@8.2.2(@types/node@25.9.5)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(tsx@4.23.1)(yaml@2.9.0)) + tools/test-recorder: dependencies: '@clack/prompts': From a39b0845a7378bf4f992358f8d423a82fa5fdd35 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 11 Oct 2026 06:26:13 +0000 Subject: [PATCH 70/70] test: make merge regression fixture exercise server facts Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/20155#pullrequestreview-5482099877 --- scripts/server-fact-gate.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/server-fact-gate.test.ts b/scripts/server-fact-gate.test.ts index d2c6d2a905a..a98840304ed 100644 --- a/scripts/server-fact-gate.test.ts +++ b/scripts/server-fact-gate.test.ts @@ -237,7 +237,8 @@ describe('server-fact gate on a real diff', () => { run('branch', 'feature') writeFileSync( path.join(dir, gatedFile), - 'export const canInvite = canInviteMembers.value || isPlanEnded.value\n' + 'const { canInviteMembers } = useBillingCapabilities()\n' + + 'export const canInvite = canInviteMembers.value || isPlanEnded.value\n' ) run('add', gatedFile) run('commit', '-q', '-m', 'upstream finding')