From 9ee68ddac664fde2f5d3156e35e6cf0edf22169a Mon Sep 17 00:00:00 2001 From: RAJVEER42 Date: Fri, 22 May 2026 06:42:35 +0530 Subject: [PATCH] fix(server): confirmation comment only says Re-running scan when a scan is actually queued The issue_comment handler only re-enqueues a scan when the latest check run conclusion is failure. The confirmation comment always ended with Re-running scan... regardless, misleading users when the check run was already success, neutral, or absent. The suffix is now conditional on enqueueScan actually resolving. --- .changeset/silver-hawks-run.md | 12 ++++++++++++ src/__tests__/server.test.ts | 33 +++++++++++++++++++++++++++++++++ src/server.ts | 6 ++++-- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 .changeset/silver-hawks-run.md diff --git a/.changeset/silver-hawks-run.md b/.changeset/silver-hawks-run.md new file mode 100644 index 0000000..0b16353 --- /dev/null +++ b/.changeset/silver-hawks-run.md @@ -0,0 +1,12 @@ +--- +"layne": patch +--- + +fix(server): confirmation comment only says "Re-running scan..." when a scan is actually queued + +The issue_comment handler only re-enqueues a scan when the latest check +run conclusion is 'failure'. However the confirmation comment always +ended with "Re-running scan..." regardless of whether a scan was queued. +Users who approved an exception while the check run was in a success or +neutral state (or when no check run existed) saw a misleading message. +The suffix is now conditional on the scan actually being enqueued. diff --git a/src/__tests__/server.test.ts b/src/__tests__/server.test.ts index bfcdcae..8dcd270 100644 --- a/src/__tests__/server.test.ts +++ b/src/__tests__/server.test.ts @@ -1142,6 +1142,39 @@ describe('issue_comment handler', () => { expect(scanQueue.add).not.toHaveBeenCalled(); }); + it('confirmation comment says "Re-running scan..." when check run is in failure state', async () => { + (getLatestCheckRun as ReturnType).mockResolvedValue({ conclusion: 'failure' }); + + await processWebhookRequest(webhookRequest( + commentPayload(), { event: 'issue_comment' } + )); + + const [call] = (createPrComment as ReturnType).mock.calls as [{ body: string }][]; + expect(call[0].body).toContain('Re-running scan'); + }); + + it('confirmation comment does NOT say "Re-running scan..." when check run did not fail', async () => { + (getLatestCheckRun as ReturnType).mockResolvedValue({ conclusion: 'success' }); + + await processWebhookRequest(webhookRequest( + commentPayload(), { event: 'issue_comment' } + )); + + const [call] = (createPrComment as ReturnType).mock.calls as [{ body: string }][]; + expect(call[0].body).not.toContain('Re-running scan'); + }); + + it('confirmation comment does NOT say "Re-running scan..." when there is no check run', async () => { + (getLatestCheckRun as ReturnType).mockResolvedValue(null); + + await processWebhookRequest(webhookRequest( + commentPayload(), { event: 'issue_comment' } + )); + + const [call] = (createPrComment as ReturnType).mock.calls as [{ body: string }][]; + expect(call[0].body).not.toContain('Re-running scan'); + }); + it('does not store exceptions or enqueue scan when PR is already merged', async () => { (getPullRequest as ReturnType).mockResolvedValueOnce({ state: 'closed', diff --git a/src/server.ts b/src/server.ts index 4d19075..f6d4f1c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -262,6 +262,7 @@ async function handleIssueComment(payload: Record): Promise<{ s }); const checkRunData = checkRun as { conclusion?: string } | null; + let scanEnqueued = false; if (checkRunData?.conclusion === 'failure') { const jobId = getJobId(repo.full_name, issueData.number, headSha); await enqueueScan({ @@ -276,16 +277,17 @@ async function handleIssueComment(payload: Record): Promise<{ s jobId, action: 'issue_comment', triggeredByException: true, - }).catch(err => console.error(`[server] Failed to enqueue scan: ${(err as Error).message}`)); + }).then(() => { scanEnqueued = true; }).catch(err => console.error(`[server] Failed to enqueue scan: ${(err as Error).message}`)); } const idList = parsed.ids.join(', '); + const confirmationSuffix = scanEnqueued ? ' Re-running scan...' : ''; await createPrComment({ installationId: (installation as { id: number }).id, owner: repo.owner.login, repo: repo.name, prNumber: issueData.number, - body: `✅ Exception recorded for ${idList} by @${commenter}: "${parsed.reason}". Re-running scan...`, + body: `✅ Exception recorded for ${idList} by @${commenter}: "${parsed.reason}".${confirmationSuffix}`, }).catch(err => console.error(`[server] Failed to post confirmation: ${(err as Error).message}`)); return { status: 200, body: 'Accepted' };