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 3bcd55dc210..580bca98a4c 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,51 @@ 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 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. +# +# GitHub compares group names case-insensitively, so two branches that differ +# only by letter case - feature/a and feature/A, which two forks can hold at +# the same commit - do share a group. That is accepted instead of fought: the +# resolver below compares head branches case-insensitively as well, so +# whichever run survives reconciles every PR the group stands for rather than +# only the one whose spelling happened to arrive first. +# +# 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.id }} + group: >- + 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: @@ -63,11 +104,17 @@ jobs: // Resolve which PRs the completed run targeted. Review runs // backfill pull_requests empty for fork PRs, and the head // owner is not recoverable from head_repository, so the - // fallback lists open PRs and matches the exact head branch, - // SHA, and base repository. The workflow_run branch of - // label-pr-review-state.yml keeps an owner-and-branch query - // instead: its runs are CI runs triggered by pull_request, - // whose head_repository is the real fork. + // fallback lists open PRs and matches the head branch + // case-insensitively, the head SHA, and the base repository. + // Group names are compared case-insensitively above, so a + // case-sensitive match here would let the run that survived the + // shared group reconcile only its own branch's PR and drop the + // other target - the failure the key exists to avoid. GitHub's + // own identity comparisons (usernames, the base repository + // below) are case-insensitive too. + // The workflow_run branch of label-pr-review-state.yml keeps an + // owner-and-branch query instead: its runs are CI runs triggered + // by pull_request, whose head_repository is the real fork. let prNumbers = []; if (run.pull_requests?.length > 0) { prNumbers = run.pull_requests.map(pr => pr.number); @@ -82,13 +129,13 @@ jobs: prNumbers = candidates .filter(pr => pr.head?.sha === run.head_sha && - pr.head?.ref === run.head_branch && + pr.head?.ref?.toLowerCase() === run.head_branch?.toLowerCase() && pr.base?.repo?.full_name?.toLowerCase() === baseRepository ) .map(pr => pr.number); core.info( `Resolved workflow_run ${run.id ?? '(unknown)'} to ` + - `${prNumbers.length} PR(s) by exact head branch, SHA, and base repository` + `${prNumbers.length} PR(s) by case-insensitive head branch, SHA, and base repository` ); } diff --git a/.github/workflows/label-pr-review-state.yml b/.github/workflows/label-pr-review-state.yml index 459dcf50bd4..1d8adbd220a 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 }} diff --git a/src/services/__tests__/fork-review-followup-workflow.test.ts b/src/services/__tests__/fork-review-followup-workflow.test.ts index b681e4d7d9a..7b3f1c3f934 100644 --- a/src/services/__tests__/fork-review-followup-workflow.test.ts +++ b/src/services/__tests__/fork-review-followup-workflow.test.ts @@ -24,7 +24,7 @@ const OLD_SHA = "b".repeat(40) interface HarnessOptions { workflowRunEvent?: string associatedPrNumbers?: number[] - fallback?: "match" | "sha-mismatch" | "ref-mismatch" | "base-mismatch" | "none" + fallback?: "match" | "sha-mismatch" | "ref-mismatch" | "case-variant" | "base-mismatch" | "none" headBranch?: string | null headSha?: string | null failDispatchFor?: number @@ -49,6 +49,12 @@ async function runFollowup(options: HarnessOptions = {}) { if (head !== undefined && head !== `fork-owner:${HEAD_BRANCH}`) return [] if (options.fallback === "match") return [pr] if (options.fallback === "sha-mismatch") return [{ ...pr, head: { ...pr.head, sha: OLD_SHA } }] + if (options.fallback === "case-variant") { + // Two forks can carry one commit on branches whose names differ only by + // letter case, and GitHub's case-insensitive group comparison puts both + // targets in a single concurrency group for this workflow. + return [pr, { ...pr, number: 1663, head: { ...pr.head, ref: HEAD_BRANCH.toUpperCase() } }] + } if (options.fallback === "ref-mismatch") { return [{ ...pr, head: { ...pr.head, ref: "some-other-branch" } }] } @@ -133,7 +139,7 @@ describe("fork review follow-up workflow (#2046, #2086, #2133)", () => { it("dispatches a privileged reconciliation for the fork PR a read-only review run targeted", async () => { // Fork runs backfill pull_requests empty, and head_repository is the // base repository (issue #2133), so the follow-up resolves the PR by - // exact head branch, SHA, and base repository. + // case-insensitive head branch, the head SHA, and the base repository. const result = await runFollowup({ associatedPrNumbers: [], fallback: "match" }) expect(result.listPullRequests).toHaveBeenCalledWith({ @@ -207,6 +213,22 @@ describe("fork review follow-up workflow (#2046, #2086, #2133)", () => { } }) + it("dispatches both PRs when one commit sits on branches differing only by case", async () => { + // GitHub compares this workflow's concurrency group names case-insensitively, so + // `feature/a` and `feature/A` are one group and only one completion survives. + // A case-sensitive resolver would reconcile only the PR whose spelling matched + // the payload and silently drop the other target, which is the very loss the + // branch-keyed group was added to prevent. + const result = await runFollowup({ fallback: "case-variant", headBranch: HEAD_BRANCH }) + + expect(result.listPullRequests).toHaveBeenCalledTimes(1) + expect(result.createWorkflowDispatch).toHaveBeenCalledTimes(2) + expect( + result.createWorkflowDispatch.mock.calls.map(([args]) => args.inputs.pull_request_number).sort(), + ).toEqual(["1662", "1663"]) + expect(result.setFailed).not.toHaveBeenCalled() + }) + it("dispatches nothing when the matching PR targets another base repository", async () => { const result = await runFollowup({ fallback: "base-mismatch" }) diff --git a/src/services/__tests__/pr-review-state-workflow.test.ts b/src/services/__tests__/pr-review-state-workflow.test.ts index af8ad70f3d0..60722ee1fc6 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,247 @@ 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, 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, + // owner: null models a payload with no head repository at all. + head_repository: + options.owner === null ? null : { 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("collapses branches that differ only by case, as GitHub compares group names", () => { + // GitHub's scheduler compares concurrency group names case-insensitively, so + // `feature/a` and `feature/A` are one group no matter how the key is spelled: + // the two strings below differ, and folded to one case they are equal. The + // group being shared is accepted, not fought, because the resolver the key + // points at compares head branches case-insensitively too, so the run that + // survives reconciles both targets rather than the one whose spelling won. + const lower = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA })) + const upper = followupGroupFor(forkRun({ branch: "feature/A", sha: SHA })) + + expect(lower.toLowerCase()).toBe(upper.toLowerCase()) + expect(lower).not.toBe(upper) + }) + + 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 })) + + 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$/) + }) + }) })