From 91af502372eb71485c1708daf3636b38d8cf703b Mon Sep 17 00:00:00 2001 From: JSONbored <49853598+JSONbored@users.noreply.github.com> Date: Sun, 5 Jul 2026 01:49:32 -0700 Subject: [PATCH 1/2] test(review): cover the markAiReviewPublished write-failure fail-open path #3461 added markAiReviewPublished alongside the existing markPullRequestSurfacePublished stamp but only tested the latter's failure path, leaving the new call's own catch/console.error branch without a regression test (codecov/patch flagged it after merge). Mirrors the existing "over-publish dedup" test for the sibling stamp. --- test/unit/queue.test.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/unit/queue.test.ts b/test/unit/queue.test.ts index 094e938a72..4774b42479 100644 --- a/test/unit/queue.test.ts +++ b/test/unit/queue.test.ts @@ -2949,6 +2949,46 @@ describe("queue processors", () => { stampSpy.mockRestore(); }); + it("#regate-churn: a failing markAiReviewPublished stamp is swallowed (fail-open) — the publish still completes", async () => { + const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem() }); + await upsertRepositoryFromGitHub(env, { name: "gittensory", full_name: "JSONbored/gittensory", private: false, owner: { login: "JSONbored" } }, 123); + await upsertRepositorySettings(env, { repoFullName: "JSONbored/gittensory", commentMode: "all_prs", publicSurface: "comment_only", autoLabelEnabled: false, checkRunMode: "off", gateCheckMode: "enabled", aiReviewMode: "off", gatePack: "oss-anti-slop" }); + const markSpy = vi.spyOn(repositoriesModule, "markAiReviewPublished").mockRejectedValueOnce(new Error("D1 stamp failed")); + let commentPosted = false; + vi.stubGlobal("fetch", async (input: RequestInfo | URL, init?: RequestInit) => { + const url = input.toString(); + const method = init?.method ?? "GET"; + if (url.includes("/access_tokens")) return Response.json({ token: "installation-token" }); + if (url.includes("/pulls/7/files")) return Response.json([{ filename: "src/a.ts", status: "modified", additions: 1, deletions: 0, changes: 1, patch: "@@\n+export const ok = true;" }]); + if (url.endsWith("/pulls/7")) return Response.json({ number: 7, title: "Clean PR", state: "open", user: { login: "contributor" }, head: { sha: "a7" }, labels: [], body: "Closes #1" }); + if (url.includes("/commits/a7/check-runs")) return Response.json({ total_count: 0, check_runs: [] }); + if (url.includes("/commits/a7/status")) return Response.json({ state: "success", statuses: [] }); + if (url.includes("/issues/1")) return Response.json({ number: 1, title: "Issue", state: "open", labels: [], user: { login: "reporter" } }); + if (url.includes("/issues/7/comments") && method === "GET") return Response.json([]); + if (url.includes("/issues/7/comments") && method === "POST") { commentPosted = true; return Response.json({ id: 1 }, { status: 201 }); } + if (url.includes("/branches/")) return Response.json({ protected: false, protection: { required_status_checks: { contexts: [] } } }); + return Response.json({}); + }); + + await expect( + processJob(env, { + type: "github-webhook", + deliveryId: "ai-review-published-stamp-failopen", + eventName: "pull_request", + payload: { + action: "opened", + installation: { id: 123, account: { login: "JSONbored", id: 1, type: "User" } }, + repository: { name: "gittensory", full_name: "JSONbored/gittensory", private: false, owner: { login: "JSONbored" } }, + pull_request: { number: 7, title: "Clean PR", state: "open", user: { login: "contributor" }, head: { sha: "a7" }, labels: [], body: "Closes #1" }, + }, + }), + ).resolves.toBeUndefined(); + + expect(commentPosted).toBe(true); // the surface published despite the ai_review_cache marker write throwing + expect(markSpy).toHaveBeenCalled(); + markSpy.mockRestore(); + }); + describe("#regate-churn: scheduled re-gate idempotency", () => { async function seedRegateChurnRepo(env: Env, overrides: Partial[1]> = {}) { await persistRegistrySnapshot( From 85a201c42150ba5b97c4d9cbf25c8578b48523f8 Mon Sep 17 00:00:00 2001 From: JSONbored <49853598+JSONbored@users.noreply.github.com> Date: Sun, 5 Jul 2026 01:58:47 -0700 Subject: [PATCH 2/2] test(review): assert the exact stamp identity in the fail-open regression Addresses the gate review's nit on #3477: the markAiReviewPublished spy assertion only checked that it was called, not with which repo/PR/head, so a wrong-identity call would have passed silently. --- test/unit/queue.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/queue.test.ts b/test/unit/queue.test.ts index 4774b42479..bbc2ded361 100644 --- a/test/unit/queue.test.ts +++ b/test/unit/queue.test.ts @@ -2985,7 +2985,7 @@ describe("queue processors", () => { ).resolves.toBeUndefined(); expect(commentPosted).toBe(true); // the surface published despite the ai_review_cache marker write throwing - expect(markSpy).toHaveBeenCalled(); + expect(markSpy).toHaveBeenCalledWith(env, "JSONbored/gittensory", 7, "a7"); // ties this regression to the real write path, not any call markSpy.mockRestore(); });