From 07c7eb41ea9aedb28c4e05d1853a71a88323887f Mon Sep 17 00:00:00 2001 From: "user.email" <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:20:26 +0800 Subject: [PATCH 1/4] ci(label-review-state): stop reconcile workflow self-amplification Measured on 2026-11-18 between 01:00Z and 02:18Z: this repo created 678 Actions runs; 243 were runs of the fork review follow-up and 126 parent reconcile runs came from issue_comment, while each real PR CI workflow ran 6 times. Three changes, both only in these two workflow files: 1. Reconcile no longer runs when the event is only its own label write. The reconciliation writes the labels it listens for, so each mutating run started one more run through the labeled/unlabeled pull_request_target events it caused itself. The guard skips a labeled/unlabeled event only when github-actions[bot] authored it and the label is one this workflow manages; human edits and other bots still reconcile. 2. The fork review follow-up coalesces per PR (or per head SHA for fork runs whose pull_requests GitHub leaves empty) instead of per triggering run. Keying by workflow_run.id gave every completion its own group, so nothing coalesced and a burst of six required checks completing for one PR queued six identical dispatches. 3. workflow_run is trimmed to the two workflows whose completion can change a required status check: Code QA Roo Code (check-translations, compile, knip, both platform-unit-test rows) and E2E Tests (Mocked) (e2e-mock). Webview Visual Regression never matched any workflow (the display name is Visual Regression), and CodeQL Advanced publishes none of the six required checks. --- ...l-pr-review-state-fork-review-followup.yml | 20 +++++++++-- .github/workflows/label-pr-review-state.yml | 35 +++++++++++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/.github/workflows/label-pr-review-state-fork-review-followup.yml b/.github/workflows/label-pr-review-state-fork-review-followup.yml index 3bcd55dc21..391de46d08 100644 --- a/.github/workflows/label-pr-review-state-fork-review-followup.yml +++ b/.github/workflows/label-pr-review-state-fork-review-followup.yml @@ -20,10 +20,24 @@ permissions: actions: write pull-requests: read -# Each completed run gets its own group: one run can resolve several PRs, and -# a shared key would let an unrelated completion supersede queued dispatches. +# Coalesce by target, not by triggering run (2026-11-18 storm: this workflow +# started 243 runs in 78 minutes and dispatched 73 of them). Keying per +# triggering run id gave every completion its own group, so nothing ever +# coalesced: the six required checks of one PR all completing at the same head +# meant six queued dispatches of the same work. GitHub keeps at most one +# running plus one pending run per group, so keying by the PR the completed run +# evaluated (or, for fork runs whose pull_requests GitHub leaves empty, by the +# head SHA, which resolves to the same PR set) collapses a burst into a single +# dispatch of the freshest state. Two PRs never share a PR number, and two +# distinct commits never share a head SHA, so an unrelated PR still keeps its +# own group and its queued dispatch is never superseded. cancel-in-progress +# stays false: a running dispatch must finish every PR it resolved. The run id +# stays as the fallback so a payload with neither a PR number nor a head SHA +# keeps a unique group instead of every such run colliding on one key. concurrency: - group: label-pr-review-state-fork-review-followup-${{ github.event.workflow_run.id }} + group: >- + label-pr-review-state-fork-review-followup-${{ github.event.workflow_run.pull_requests[0].number + || github.event.workflow_run.head_sha || github.event.workflow_run.id }} cancel-in-progress: false jobs: diff --git a/.github/workflows/label-pr-review-state.yml b/.github/workflows/label-pr-review-state.yml index 459dcf50bd..1d8adbd220 100644 --- a/.github/workflows/label-pr-review-state.yml +++ b/.github/workflows/label-pr-review-state.yml @@ -41,8 +41,24 @@ on: # writes (issue #2046). The privileged follow-up for those runs lives in # label-pr-review-state-fork-review-followup.yml: GitHub rejects a workflow # that lists itself in workflow_run.workflows (issue #2086). + # + # A workflow belongs in this list only when its completion can change the + # answer for a required status check, because the reconcile below reads + # only the required checks from the branch ruleset and never inspects which + # workflow completed, its conclusion, or its outputs. "Code QA Roo Code" + # publishes check-translations, compile, knip and both platform-unit-test + # rows; "E2E Tests (Mocked)" publishes e2e-mock. Those six are the entire + # required set on main, so no completion of any other workflow can change a + # label this workflow writes. + # + # "Webview Visual Regression" was in this list but no workflow has that + # display name: the visual workflow is "Visual Regression" + # (visual-regression.yml), so the entry never matched anything and only + # looked like coverage. "CodeQL Advanced" does run, but it publishes none of + # the six required checks, so each of its completions started a full + # reconciliation that could only recompute the labels already written. workflow_run: - workflows: ["Code QA Roo Code", "E2E Tests (Mocked)", "Webview Visual Regression", "CodeQL Advanced"] + workflows: ["Code QA Roo Code", "E2E Tests (Mocked)"] types: [completed] permissions: @@ -94,9 +110,22 @@ concurrency: jobs: resolve: name: Zoo Code / resolve PRs to reconcile + # Loop guard (self-triggered label writes): the reconciliation writes the + # labels it also listens for, so every mutating run used to start one + # more run through the labeled/unlabeled pull_request_target events it + # caused itself. Reconciliation is idempotent, so a run woken only by + # this workflow's own label write would recompute the state it just + # wrote and write it again; skipping it breaks that loop. Only label + # events authored by github-actions[bot] for a label this workflow + # manages are skipped: a human edit to one of those labels, and any + # other bot or workflow label write, still reconciles. if: >- - github.event_name != 'issue_comment' || - (github.event.issue.pull_request && github.event.comment.user.login == 'coderabbitai[bot]') + (github.event_name != 'issue_comment' || + (github.event.issue.pull_request && github.event.comment.user.login == 'coderabbitai[bot]')) && + !(github.event_name == 'pull_request_target' && + contains(fromJSON('["labeled", "unlabeled"]'), github.event.action) && + github.event.sender.login == 'github-actions[bot]' && + contains(fromJSON('["awaiting-author", "awaiting-coderabbit", "awaiting-ready", "awaiting-maintainer", "awaiting-review", "coderabbit-review-active", "community-approved", "has-conflicts", "stale-inactive", "stale-awaiting-author"]'), github.event.label.name)) runs-on: ubuntu-latest outputs: pr_numbers: ${{ steps.resolve.outputs.pr_numbers }} From 12aec8879ee412134020cb473390fdc9024bd624 Mon Sep 17 00:00:00 2001 From: "user.email" <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:05:56 +0800 Subject: [PATCH 2/4] fix(ci): key the fork review follow-up by branch identity and test the resolve guard CodeRabbit 4608868348: the fork fallback keyed on head_sha alone, but two fork PRs can carry the same commit on different branches (a cherry-picked stack), and the resolver distinguishes them by head branch. A later completion for one branch could then supersede the other branch's pending run, losing that PR's dispatch. The key now uses the resolver's branch identity - head repository owner plus head branch plus head SHA - after the associated PR number, so branches never share a group and repeated completions for one target still coalesce. The file comment no longer claims that distinct commits never share a SHA as the reason branches cannot collide; it states the branch is part of the key and that two branches carrying the same commit intentionally do not coalesce. CodeRabbit 4608868359: the workflow harness executed the embedded scripts but never evaluated jobs.resolve.if, so the new label guard had no coverage. The expression evaluator now supports unary negation, contains, fromJSON and format, and two new describes evaluate the real YAML: 8 tests for the resolve guard (labeled and unlabeled, managed and unrelated labels, github-actions[bot] versus human and other bot senders, events with no label field, plus the issue_comment and other-trigger regressions and a drift guard on both fromJSON lists) and 5 tests for the follow-up key (same commit on two branches, coalescing, PR-number preference, run-id fallback). Negative controls: removing one managed label from the guard fails 2 tests; restoring the SHA-only key fails the branch test. --- ...l-pr-review-state-fork-review-followup.yml | 40 ++- .../pr-review-state-workflow.test.ts | 280 +++++++++++++++++- 2 files changed, 308 insertions(+), 12 deletions(-) diff --git a/.github/workflows/label-pr-review-state-fork-review-followup.yml b/.github/workflows/label-pr-review-state-fork-review-followup.yml index 391de46d08..e3f7235ddb 100644 --- a/.github/workflows/label-pr-review-state-fork-review-followup.yml +++ b/.github/workflows/label-pr-review-state-fork-review-followup.yml @@ -25,19 +25,39 @@ permissions: # triggering run id gave every completion its own group, so nothing ever # coalesced: the six required checks of one PR all completing at the same head # meant six queued dispatches of the same work. GitHub keeps at most one -# running plus one pending run per group, so keying by the PR the completed run -# evaluated (or, for fork runs whose pull_requests GitHub leaves empty, by the -# head SHA, which resolves to the same PR set) collapses a burst into a single -# dispatch of the freshest state. Two PRs never share a PR number, and two -# distinct commits never share a head SHA, so an unrelated PR still keeps its -# own group and its queued dispatch is never superseded. cancel-in-progress -# stays false: a running dispatch must finish every PR it resolved. The run id -# stays as the fallback so a payload with neither a PR number nor a head SHA +# running plus one pending run per group, so keying the group by the target the +# completed run evaluated collapses a burst into a single dispatch of the +# freshest state: first by the PR number GitHub associates with the run, then, +# for fork runs whose pull_requests GitHub leaves empty (issue #2133), by the +# branch identity the resolver below actually matches on. +# +# The fork fallback must include the branch, not just the head SHA. Two fork PRs +# can carry the same commit on different branches (a cherry-picked stack does +# exactly that), and the resolver distinguishes them only by head branch: a +# SHA-only key would put both PRs in one group, so a pending run for the second +# branch would be superseded by a later completion for the first and its +# reconciliation would never dispatch. head_branch, together with the head +# repository owner it belongs to, is the resolver's branch identity, so two +# branches never share a group. Two distinct branches carrying the same commit +# do not coalesce, which is the intended correction: they are different PR +# targets. Repeated completions for one target share branch and SHA and still +# coalesce. +# +# cancel-in-progress stays false: a running dispatch must finish every PR it +# resolved, so only pending duplicates are dropped. The run id is the last +# fallback so a payload with neither an associated PR nor a head branch and SHA # keeps a unique group instead of every such run colliding on one key. concurrency: group: >- - label-pr-review-state-fork-review-followup-${{ github.event.workflow_run.pull_requests[0].number - || github.event.workflow_run.head_sha || github.event.workflow_run.id }} + label-pr-review-state-fork-review-followup-${{ + github.event.workflow_run.pull_requests[0].number || + ((github.event.workflow_run.head_branch && github.event.workflow_run.head_sha) && + format('{0}:{1}@{2}', + github.event.workflow_run.head_repository.owner.login || 'unknown', + github.event.workflow_run.head_branch, + github.event.workflow_run.head_sha)) || + github.event.workflow_run.id + }} cancel-in-progress: false jobs: diff --git a/src/services/__tests__/pr-review-state-workflow.test.ts b/src/services/__tests__/pr-review-state-workflow.test.ts index af8ad70f3d..a64db6fc14 100644 --- a/src/services/__tests__/pr-review-state-workflow.test.ts +++ b/src/services/__tests__/pr-review-state-workflow.test.ts @@ -10,6 +10,12 @@ const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)) const workflow = parse( fs.readFileSync(path.join(repositoryRoot, ".github/workflows/label-pr-review-state.yml"), "utf8"), ) +const forkReviewFollowupWorkflow = parse( + fs.readFileSync( + path.join(repositoryRoot, ".github/workflows/label-pr-review-state-fork-review-followup.yml"), + "utf8", + ), +) const codeRabbitConfig = parse(fs.readFileSync(path.join(repositoryRoot, ".coderabbit.yaml"), "utf8")) const workflowScript = workflow.jobs.reconcile.steps[0].with.script as string const resolveScript = workflow.jobs.resolve.steps[0].with.script as string @@ -3581,9 +3587,19 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { head?: { repo?: { full_name?: string } | null } base?: { repo?: { full_name?: string } | null } } - issue?: { number: number } - workflow_run?: { id?: number; pull_requests?: Array<{ number: number }> } + issue?: { number: number; pull_request?: unknown } + workflow_run?: { + id?: number + pull_requests?: Array<{ number: number }> + head_branch?: string | null + head_sha?: string | null + head_repository?: { owner?: { login?: string } | null } | null + } inputs?: { pull_request_number: number } + action?: string + label?: { name?: string } | null + sender?: { login?: string } | null + comment?: { user?: { login?: string } | null } | null } } @@ -3633,6 +3649,57 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { return left === right } + /** + * Splits a function call's argument source on top-level commas. Strings are + * skipped so a JSON array literal inside fromJSON stays one argument. + */ + function splitArguments(source: string): string[] { + const args: string[] = [] + let depth = 0 + let inString = false + let start = 0 + for (let index = 0; index < source.length; index++) { + const char = source[index] + if (char === "'") { + inString = !inString + } else if (!inString && char === "(") { + depth++ + } else if (!inString && char === ")") { + depth-- + } else if (!inString && depth === 0 && char === ",") { + args.push(source.slice(start, index)) + start = index + 1 + } + } + args.push(source.slice(start)) + return args.map((argument) => argument.trim()).filter((argument) => argument.length > 0) + } + + /** Evaluates the GitHub expression functions the job conditions use. */ + function evaluateFunctionCall(name: string, source: string, roots: ExpressionRoots): unknown { + const args = splitArguments(source).map((argument) => evaluateExpression(argument, roots)) + if (name === "contains") { + const [haystack, needle] = args + if (Array.isArray(haystack)) { + return haystack.some((item) => looseEquals(item, needle)) + } + if (typeof haystack === "string" && typeof needle === "string") { + return haystack.includes(needle) + } + return false + } + if (name === "fromJSON") { + return JSON.parse(String(args[0])) + } + if (name === "format") { + const [template, ...values] = args + return String(template).replace(/\{(\d+)\}/g, (_match, index: string) => + String(values[Number(index)] ?? ""), + ) + } + throw new Error(`Unsupported expression function: ${name}`) + } + function resolvePath(path: string, roots: ExpressionRoots): unknown { let value: unknown = roots for (const segment of path.split(".")) { @@ -3656,6 +3723,10 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { function evaluatePrimary(expression: string, roots: ExpressionRoots): unknown { const current = expression.trim() + // GitHub's unary ! negates loose truthiness, exactly like the && and || chains. + if (current.startsWith("!")) { + return !isTruthy(evaluatePrimary(current.slice(1), roots)) + } if (current.startsWith("(")) { // Strip the parentheses only when the first one wraps the whole expression. let depth = 0 @@ -3682,6 +3753,10 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { if (/^(github|matrix)\./.test(current)) { return resolvePath(current, roots) } + const functionCall = /^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/.exec(current) + if (functionCall) { + return evaluateFunctionCall(functionCall[1], functionCall[2], roots) + } return evaluateExpression(current, roots) } @@ -4144,4 +4219,205 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { "Create label failed", ) }) + + describe("resolve job loop guard on self-triggered label writes", () => { + // Mirrors the labels the reconciliation itself writes. The guard only refuses + // to wake on this workflow's own writes for these labels. + const MANAGED_LABELS = [ + "awaiting-author", + "awaiting-coderabbit", + "awaiting-ready", + "awaiting-maintainer", + "awaiting-review", + "coderabbit-review-active", + "community-approved", + "has-conflicts", + "stale-inactive", + "stale-awaiting-author", + ] + + // GitHub evaluates a job-level if as an expression, without the + // dollar-brace wrapper, so the template evaluator is applied to the raw + // condition. This is the public entry point the harness previously never + // exercised: the embedded scripts were run, the job predicate was not. + function resolveIfFor(github: GithubExpressionContext): boolean { + return isTruthy(evaluateExpression(String(workflow.jobs.resolve.if), { github })) + } + + function labelEvent(options: { action: string; sender: string; labelName?: string }): GithubExpressionContext { + return contextFor({ + event_name: "pull_request_target", + event: { + pull_request: { number: 1664 }, + action: options.action, + sender: { login: options.sender }, + ...(options.labelName === undefined ? {} : { label: { name: options.labelName } }), + }, + }) + } + + it("keeps the guard's actions and label list in sync with the workflow", () => { + // Drift guard: the two fromJSON lists in the condition are the guard's + // whole input vocabulary, so pin them explicitly. + const lists = [...String(workflow.jobs.resolve.if).matchAll(/fromJSON\('(\[[^']*\])'\)/g)].map((match) => + JSON.parse(match[1]), + ) + + expect(lists[0]).toEqual(["labeled", "unlabeled"]) + expect(lists[1]).toEqual(MANAGED_LABELS) + }) + + it("rejects labeled and unlabeled events the reconciliation wrote itself", () => { + for (const action of ["labeled", "unlabeled"]) { + for (const labelName of MANAGED_LABELS) { + expect(resolveIfFor(labelEvent({ action, labelName, sender: "github-actions[bot]" }))).toBe(false) + } + } + }) + + it("accepts those label events when a human or another bot wrote them", () => { + for (const sender of ["edelauna", "MarkSwanson", "coderabbitai[bot]", "codecov[bot]"]) { + for (const action of ["labeled", "unlabeled"]) { + expect(resolveIfFor(labelEvent({ action, labelName: "awaiting-author", sender }))).toBe(true) + } + } + }) + + it("accepts a github-actions label event for a label this workflow does not manage", () => { + for (const labelName of ["dependencies", "bug", "pinned", "do-not-close"]) { + expect(resolveIfFor(labelEvent({ action: "labeled", labelName, sender: "github-actions[bot]" }))).toBe( + true, + ) + } + }) + + it("accepts a labeled event whose payload carries no label name", () => { + // Boundary: an unclassifiable label event must not be rejected, or a + // payload change would silently stop reconciliation. + expect(resolveIfFor(labelEvent({ action: "labeled", sender: "github-actions[bot]" }))).toBe(true) + expect(resolveIfFor(labelEvent({ action: "unlabeled", sender: "github-actions[bot]" }))).toBe(true) + }) + + it("accepts pull_request_target events that carry no label at all", () => { + for (const action of [ + "opened", + "reopened", + "ready_for_review", + "converted_to_draft", + "synchronize", + "review_requested", + "review_request_removed", + ]) { + expect(resolveIfFor(labelEvent({ action, sender: "github-actions[bot]" }))).toBe(true) + } + }) + + it("still gates issue_comment on the CodeRabbit author", () => { + const issueComment = (login: string | null, onPullRequest = true): GithubExpressionContext => + contextFor({ + event_name: "issue_comment", + event: { + issue: { number: 1664, ...(onPullRequest ? { pull_request: {} } : {}) }, + comment: { user: { login } }, + }, + }) + + // GitHub's == is case-insensitive for strings. + expect(resolveIfFor(issueComment("coderabbitai[bot]"))).toBe(true) + expect(resolveIfFor(issueComment("CodeRabbitAI[bot]"))).toBe(true) + expect(resolveIfFor(issueComment("edelauna"))).toBe(false) + expect(resolveIfFor(issueComment("github-actions[bot]"))).toBe(false) + expect(resolveIfFor(issueComment("coderabbitai[bot]", false))).toBe(false) + }) + + it("accepts every other trigger unchanged", () => { + expect(resolveIfFor(contextFor({ event_name: "pull_request_review" }))).toBe(true) + expect( + resolveIfFor( + contextFor({ event_name: "workflow_run", event: { workflow_run: { id: 7, pull_requests: [] } } }), + ), + ).toBe(true) + expect(resolveIfFor(contextFor({ event_name: "schedule" }))).toBe(true) + expect(resolveIfFor(contextFor({ event_name: "push" }))).toBe(true) + expect( + resolveIfFor( + contextFor({ event_name: "workflow_dispatch", event: { inputs: { pull_request_number: 1664 } } }), + ), + ).toBe(true) + }) + }) + + describe("fork review follow-up concurrency key", () => { + // GitHub keeps one running plus one pending run per group, so the group key + // decides which completions coalesce and which may supersede each other. + function followupGroupFor(github: GithubExpressionContext): string { + return evaluateTemplate(String(forkReviewFollowupWorkflow.concurrency.group), { github }) + } + + function forkRun(options: { + branch?: string | null + sha?: string | null + owner?: string | null + associatedPrNumbers?: number[] + runId?: number + }): GithubExpressionContext { + return contextFor({ + event_name: "workflow_run", + run_id: 99000, + event: { + workflow_run: { + id: options.runId ?? 777000111, + pull_requests: (options.associatedPrNumbers ?? []).map((number) => ({ number })), + head_branch: options.branch ?? null, + head_sha: options.sha ?? null, + head_repository: { owner: { login: options.owner ?? "Zoo-Code-Org" } }, + }, + }, + }) + } + + it("keeps cancel-in-progress disabled", () => { + expect(forkReviewFollowupWorkflow.concurrency["cancel-in-progress"]).toBe(false) + }) + + it("keys two branches carrying the same commit to different groups", () => { + // A cherry-picked stack puts one commit on two branches. A SHA-only key + // would put both fork PRs in one group, so a later completion for one + // branch would supersede the other branch's pending dispatch and that + // PR would never be reconciled. + const branchA = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA })) + const branchB = followupGroupFor(forkRun({ branch: "feature/b", sha: SHA })) + + expect(branchA).toContain("feature/a") + expect(branchB).toContain("feature/b") + expect(branchA).not.toBe(branchB) + }) + + it("coalesces repeated completions for the same target onto one group", () => { + const first = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, runId: 1 })) + const second = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, runId: 2 })) + + expect(second).toBe(first) + // A push to the same branch is a new target: its pending dispatch must + // not be cancelled by an older head's queued run. + expect(followupGroupFor(forkRun({ branch: "feature/a", sha: OLD_SHA, runId: 3 }))).not.toBe(first) + }) + + it("prefers the associated PR number over the branch fallback", () => { + const withPr = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, associatedPrNumbers: [1662] })) + expect(withPr).toMatch(/-1662$/) + expect(withPr).not.toContain("feature/a") + expect( + followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, associatedPrNumbers: [1662], runId: 5 })), + ).toBe(withPr) + }) + + it("keeps a unique group when the payload has neither an associated PR nor a branch and SHA", () => { + const missing = followupGroupFor(forkRun({})) + expect(missing).toMatch(/-777000111$/) + expect(followupGroupFor(forkRun({ runId: 777000222 }))).not.toBe(missing) + // Half a pair is not enough: the fallback must not fabricate a target. + expect(followupGroupFor(forkRun({ branch: "feature/a", sha: null }))).toMatch(/-777000111$/) + }) + }) }) From 29b6fd9954b4b47f67e226edc27102306cf1f634 Mon Sep 17 00:00:00 2001 From: "user.email" <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:16:25 +0800 Subject: [PATCH 3/4] test(ci): type the issue-comment helper's login as string The compile job's pnpm check-types failed on the new test at the issue_comment helper: the local signature accepted string or null while the payload type declares login as an optional string, so passing null was not assignable. The helper is only called with real logins, so the parameter is now a plain string; behaviour and coverage are unchanged. --- src/services/__tests__/pr-review-state-workflow.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/__tests__/pr-review-state-workflow.test.ts b/src/services/__tests__/pr-review-state-workflow.test.ts index a64db6fc14..2007ccbf5f 100644 --- a/src/services/__tests__/pr-review-state-workflow.test.ts +++ b/src/services/__tests__/pr-review-state-workflow.test.ts @@ -4313,7 +4313,7 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { }) it("still gates issue_comment on the CodeRabbit author", () => { - const issueComment = (login: string | null, onPullRequest = true): GithubExpressionContext => + const issueComment = (login: string, onPullRequest = true): GithubExpressionContext => contextFor({ event_name: "issue_comment", event: { From cdb27cdbd42177bf70fe1cd1d0942a8bd7776c11 Mon Sep 17 00:00:00 2001 From: "user.email" <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:39:27 +0800 Subject: [PATCH 4/4] test(ci): cover the head owner in the follow-up concurrency key CodeRabbit 4609203178: every concurrency test used the default head owner, so dropping head_repository.owner.login from the group expression or mis-wiring its unknown fallback would not have failed a test. Adds three cases: two owners with the same branch and commit must land in different groups and each group must carry its own owner; a payload with no head repository must use the unknown fallback and must not collide with a known owner; and repeated completions with an unknown owner must still coalesce rather than each getting a unique key. forkRun now models an absent head repository with owner: null. Negative control: dropping the owner component from the format expression fails exactly these two owner tests (2 failed, 331 passed) and the file was restored byte-identically (sha256 f906ee9d). --- .../pr-review-state-workflow.test.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/services/__tests__/pr-review-state-workflow.test.ts b/src/services/__tests__/pr-review-state-workflow.test.ts index 2007ccbf5f..920d0441b6 100644 --- a/src/services/__tests__/pr-review-state-workflow.test.ts +++ b/src/services/__tests__/pr-review-state-workflow.test.ts @@ -4370,7 +4370,9 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { pull_requests: (options.associatedPrNumbers ?? []).map((number) => ({ number })), head_branch: options.branch ?? null, head_sha: options.sha ?? null, - head_repository: { owner: { login: options.owner ?? "Zoo-Code-Org" } }, + // owner: null models a payload with no head repository at all. + head_repository: + options.owner === null ? null : { owner: { login: options.owner ?? "Zoo-Code-Org" } }, }, }, }) @@ -4393,6 +4395,32 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { expect(branchA).not.toBe(branchB) }) + it("includes the head owner in the fallback group", () => { + const upstream = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: "Zoo-Code-Org" })) + const contributor = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: "contributor" })) + + expect(upstream).toContain("Zoo-Code-Org:feature/a") + expect(contributor).toContain("contributor:feature/a") + expect(contributor).not.toBe(upstream) + }) + + it("uses the unknown owner fallback when the payload carries no head repository", () => { + // Review runs report the base repository as head_repository (issue #2133), so + // this covers the key expression's fallback rather than a production split. + const missingOwner = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: null })) + const knownOwner = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: "Zoo-Code-Org" })) + + expect(missingOwner).toContain("unknown:feature/a") + expect(missingOwner).not.toBe(knownOwner) + }) + + it("still coalesces repeated completions when the owner is unknown", () => { + const first = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: null, runId: 11 })) + const second = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: null, runId: 12 })) + + expect(second).toBe(first) + }) + it("coalesces repeated completions for the same target onto one group", () => { const first = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, runId: 1 })) const second = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, runId: 2 }))