From 67767d48348ea7210f8857f02a62e003143707b5 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 29 Oct 2026 06:01:54 +0000 Subject: [PATCH 1/4] test: cover the manual dispatch path of the backport conflict comment The conflict-comment tests injected FORCE_RERUN directly and always ran as pull_request_target, so the step's FORCE_RERUN expression and the workflow_dispatch branch that reads author and merge commit through gh pr view were never exercised. Evaluate the step's real FORCE_RERUN expression (and fail on an unexpected shape), stub gh pr view, and add cases for a manual dispatch with and without force_rerun, force_rerun outside a dispatch, and the author and merge commit read from the PR. --- .../cicd/backport-conflict-comment.test.ts | 66 +++++++++++++++++-- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/scripts/cicd/backport-conflict-comment.test.ts b/scripts/cicd/backport-conflict-comment.test.ts index fb4115c9028..2e9888ea316 100644 --- a/scripts/cicd/backport-conflict-comment.test.ts +++ b/scripts/cicd/backport-conflict-comment.test.ts @@ -34,6 +34,22 @@ if (!commentStep?.run || !commentStep.env) { } const { run: commentRun, env: commentEnv } = commentStep +// The step derives FORCE_RERUN from the event in its env mapping. Evaluate +// that exact expression instead of injecting the variable, so a change to it +// fails here rather than silently skipping the manual path. +const forceRerunExpression = + /^\$\{\{ github\.event_name == '([a-z_]+)' && inputs\.force_rerun \|\| 'false' \}\}$/.exec( + commentEnv.FORCE_RERUN ?? '' + ) +if (!forceRerunExpression) { + throw new Error( + `unexpected FORCE_RERUN expression in pr-backport.yaml: ${commentEnv.FORCE_RERUN}` + ) +} +const forceRerunEvent = forceRerunExpression[1] +const evaluateForceRerun = (eventName: string, forceRerunInput: boolean) => + eventName === forceRerunEvent && forceRerunInput ? 'true' : 'false' + beforeAll(() => { const missing = ['envsubst', 'jq'].filter( (tool) => spawnSync('bash', ['-c', `command -v ${tool}`]).status !== 0 @@ -78,6 +94,11 @@ case "$1 $2" in "issue create") record "$4" "$6" >> "\${FAKE_DIR}/issues.jsonl" ;; + "pr view") + [[ "$3" == "\${FAKE_PR_NUMBER}" && "$4 $5" == "--json author,mergeCommit" ]] || { + echo "unexpected gh pr view invocation: $*" >&2; exit 64; } + jq -cn --arg oid "\${FAKE_MERGE_COMMIT}" '{author: {login: "author"}, mergeCommit: {oid: $oid}}' + ;; "pr list") ;; *) echo "unexpected gh invocation: $*" >&2; exit 64 ;; esac @@ -102,6 +123,7 @@ function createSandbox() { } interface Run { + event?: 'pull_request_target' | 'workflow_dispatch' mergeCommit?: string targetHead?: string failed?: string @@ -114,6 +136,7 @@ interface Run { function reportConflict( sandbox: string, { + event = 'pull_request_target', mergeCommit = firstMergeCommit, targetHead = firstTargetHead, failed = coreConflict, @@ -123,9 +146,9 @@ function reportConflict( prLocked = false }: Run = {} ) { - const event = join(sandbox, 'event.json') + const eventPath = join(sandbox, 'event.json') writeFileSync( - event, + eventPath, JSON.stringify({ pull_request: { number: 21078, @@ -135,7 +158,7 @@ function reportConflict( }) ) const script = commentRun - .replaceAll('${{ github.event_name }}', 'pull_request_target') + .replaceAll('${{ github.event_name }}', event) .replaceAll('${{ inputs.pr_number }}', '21078') .replaceAll('${{ steps.backport.outputs.failed }}', failed) @@ -146,12 +169,14 @@ function reportConflict( BACKPORT_AGENT_PROMPT_TEMPLATE: commentEnv.BACKPORT_AGENT_PROMPT_TEMPLATE, COMMENT_BODY_TEMPLATE: commentEnv.COMMENT_BODY_TEMPLATE, FAKE_DIR: sandbox, + FAKE_MERGE_COMMIT: mergeCommit, + FAKE_PR_NUMBER: '21078', FAKE_LOGIN: login, FAKE_PR_LOCKED: String(prLocked), FAKE_READ: commentsRead, FAKE_TARGET_HEAD: targetHead, - FORCE_RERUN: String(forceRerun), - GITHUB_EVENT_PATH: event, + FORCE_RERUN: evaluateForceRerun(event, forceRerun), + GITHUB_EVENT_PATH: eventPath, GITHUB_REPOSITORY: 'Comfy-Org/ComfyUI_frontend', GITHUB_SERVER_URL: 'https://github.com', PATH: `${sandbox}:${process.env.PATH}` @@ -213,10 +238,20 @@ describe('backport conflict comment', () => { expected: 2 }, { - scenario: 'a manual force rerun', - second: { forceRerun: true }, + scenario: 'a manual dispatch with force_rerun', + second: { event: 'workflow_dispatch', forceRerun: true }, expected: 2 }, + { + scenario: 'a manual dispatch without force_rerun', + second: { event: 'workflow_dispatch' }, + expected: 1 + }, + { + scenario: 'force_rerun set outside a manual dispatch', + second: { forceRerun: true }, + expected: 1 + }, { scenario: 'a failed read of the existing comments', second: { commentsRead: 'error' }, @@ -245,6 +280,23 @@ describe('backport conflict comment', () => { } ) + it('reads the author and merge commit from the PR on a manual dispatch', () => { + const sandbox = createSandbox() + + reportConflict(sandbox, { + event: 'workflow_dispatch', + forceRerun: true, + mergeCommit: secondMergeCommit + }) + + const reports = postedReports(sandbox) + expect(reports).toHaveLength(1) + expect(reports[0]).toContain( + `` + ) + expect(reports[0]).toContain('cc @author') + }) + it('reports the same merge commit once per target', () => { const sandbox = createSandbox() From 9a381e9ffc54073c990079c745d6f290aa3d5e85 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 29 Oct 2026 06:12:14 +0000 Subject: [PATCH 2/4] test: drop an unnecessary nullish fallback flagged by type-aware lint --- scripts/cicd/backport-conflict-comment.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cicd/backport-conflict-comment.test.ts b/scripts/cicd/backport-conflict-comment.test.ts index 2e9888ea316..0f0635c4b2a 100644 --- a/scripts/cicd/backport-conflict-comment.test.ts +++ b/scripts/cicd/backport-conflict-comment.test.ts @@ -39,7 +39,7 @@ const { run: commentRun, env: commentEnv } = commentStep // fails here rather than silently skipping the manual path. const forceRerunExpression = /^\$\{\{ github\.event_name == '([a-z_]+)' && inputs\.force_rerun \|\| 'false' \}\}$/.exec( - commentEnv.FORCE_RERUN ?? '' + commentEnv.FORCE_RERUN ) if (!forceRerunExpression) { throw new Error( From f4e5b9deea8dc1e82df7f49881bbe7b891091cfc Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Wed, 28 Oct 2026 23:43:37 -0700 Subject: [PATCH 3/4] Apply suggestion from @DrJKL --- scripts/cicd/backport-conflict-comment.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/cicd/backport-conflict-comment.test.ts b/scripts/cicd/backport-conflict-comment.test.ts index 0f0635c4b2a..5d68265de7e 100644 --- a/scripts/cicd/backport-conflict-comment.test.ts +++ b/scripts/cicd/backport-conflict-comment.test.ts @@ -34,9 +34,6 @@ if (!commentStep?.run || !commentStep.env) { } const { run: commentRun, env: commentEnv } = commentStep -// The step derives FORCE_RERUN from the event in its env mapping. Evaluate -// that exact expression instead of injecting the variable, so a change to it -// fails here rather than silently skipping the manual path. const forceRerunExpression = /^\$\{\{ github\.event_name == '([a-z_]+)' && inputs\.force_rerun \|\| 'false' \}\}$/.exec( commentEnv.FORCE_RERUN From e26e56965aa87e5c2263eb4f2c50d2208196f644 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 29 Oct 2026 06:52:34 +0000 Subject: [PATCH 4/4] test: give manual dispatch runs a dispatch-shaped event and a distinct PR author A workflow_dispatch event has no pull_request object, and the PR lookup now returns its own author, so a regression that reads the event file instead of gh pr view fails the suite. --- .../cicd/backport-conflict-comment.test.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/cicd/backport-conflict-comment.test.ts b/scripts/cicd/backport-conflict-comment.test.ts index 5d68265de7e..756d16c5af9 100644 --- a/scripts/cicd/backport-conflict-comment.test.ts +++ b/scripts/cicd/backport-conflict-comment.test.ts @@ -94,7 +94,7 @@ case "$1 $2" in "pr view") [[ "$3" == "\${FAKE_PR_NUMBER}" && "$4 $5" == "--json author,mergeCommit" ]] || { echo "unexpected gh pr view invocation: $*" >&2; exit 64; } - jq -cn --arg oid "\${FAKE_MERGE_COMMIT}" '{author: {login: "author"}, mergeCommit: {oid: $oid}}' + jq -cn --arg oid "\${FAKE_MERGE_COMMIT}" '{author: {login: "pr-view-author"}, mergeCommit: {oid: $oid}}' ;; "pr list") ;; *) echo "unexpected gh invocation: $*" >&2; exit 64 ;; @@ -146,13 +146,17 @@ function reportConflict( const eventPath = join(sandbox, 'event.json') writeFileSync( eventPath, - JSON.stringify({ - pull_request: { - number: 21078, - user: { login: 'author' }, - merge_commit_sha: mergeCommit - } - }) + JSON.stringify( + event === 'workflow_dispatch' + ? { inputs: { pr_number: '21078', force_rerun: String(forceRerun) } } + : { + pull_request: { + number: 21078, + user: { login: 'author' }, + merge_commit_sha: mergeCommit + } + } + ) ) const script = commentRun .replaceAll('${{ github.event_name }}', event) @@ -291,7 +295,7 @@ describe('backport conflict comment', () => { expect(reports[0]).toContain( `` ) - expect(reports[0]).toContain('cc @author') + expect(reports[0]).toContain('cc @pr-view-author') }) it('reports the same merge commit once per target', () => {