Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/queue/review-evasion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1365,4 +1365,6 @@ async function closeSynchronizeAmendmentIfPolicyEnabled(
/* v8 ignore next -- fail-safe: an audit write failure never blocks the handler. */
() => undefined,
);
/* v8 ignore next -- best-effort: the guarded CAS update never rejects against a healthy D1, and a cleanup failure here must never block the webhook. */
await terminalizeActiveReviewTracking(env, repoFullName, pr.number, { onlyIfHeadSha: pr.headSha }).catch(() => undefined);
}
18 changes: 18 additions & 0 deletions test/unit/queue-lifecycle-guards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3922,6 +3922,24 @@ describe("review-evasion protection (#review-evasion-protection)", () => {
expect(audit?.detail).toContain("contributor");
});

it("terminalizes the active-review tracking row on enforcement close -- leaves no dangling row for the PR's reviewed headSha, matching the four sibling guards", async () => {
const calls: Array<{ url: string; method: string }> = [];
stubEvasionFetch(calls);
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: generateRsaPrivateKeyPem(), GITHUB_APP_SLUG: "loopover-orb" });
await setupEvasionRepo(env, { reviewEvasionProtection: "off", synchronizeClosePolicy: "close" });
// A review was actively tracked on the PR's head before the author pushed the amending commit; the
// synchronize-amendment close must mark that row terminal, exactly as its four siblings do.
await repositoriesModule.startActiveReviewTracking(env, { repoFullName: "JSONbored/gittensory", pullNumber: 42, headSha: "def456", authorLogin: "contributor", deliveryId: "review-start-sync" });
expect(await repositoriesModule.hasActiveReviewForHeadSha(env, "JSONbored/gittensory", 42, "def456")).toBe(true);

await processJob(env, { type: "github-webhook", deliveryId: "sync-policy-terminalize", eventName: "pull_request", payload: synchronizePayload("contributor") });

expect(calls.some((c) => c.method === "PATCH" && c.url.endsWith("/pulls/42"))).toBe(true);
const audit = await env.DB.prepare("select outcome from audit_events where event_type = ?").bind("github_app.synchronize_amend_closed").first<{ outcome: string }>();
expect(audit?.outcome).toBe("completed");
expect(await repositoriesModule.hasActiveReviewForHeadSha(env, "JSONbored/gittensory", 42, "def456")).toBe(false); // terminalized
});

it("does NOT record a moderation strike -- this is a blanket policy against an ordinary push, not a detected abuse pattern", async () => {
const calls: Array<{ url: string; method: string }> = [];
stubEvasionFetch(calls);
Expand Down