Skip to content

Commit c888b2c

Browse files
committed
test(review): close 2 coverage gaps surfaced by the #4514 rebase-merge
getEffectiveSubmitterReputation's getRepository().catch() needed a real read-failure test (added); its isConfirmedOfficialMiner().catch() is unreachable (that function already catches every internal failure point itself) and getSubmitterReputationAcrossInstall's results ?? [] fallback is the same "D1 always populates results" case already v8-ignored elsewhere in this codebase -- both marked accordingly.
1 parent 8d44b10 commit c888b2c

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/review/reputation-wire.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export async function getEffectiveSubmitterReputation(
7878
if (shouldDowngradeToDeterministic(perRepo)) return perRepo;
7979
const submitter = args.submitter?.trim();
8080
if (!submitter) return perRepo;
81+
/* v8 ignore next -- isConfirmedOfficialMiner already catches every internal failure point itself and never rejects; this guards only a future implementation change. */
8182
const isMiner = await isConfirmedOfficialMiner(env, submitter).catch(() => false);
8283
if (!isMiner) return perRepo;
8384
const repo = await getRepository(env, args.repoFullName).catch(() => null);

src/review/submitter-reputation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ export async function getSubmitterReputationAcrossInstall(
339339
)
340340
.bind(installationId, submitter, `-${cfg.windowDays} days`, REPUTATION_WINDOW_ROW_CAP)
341341
.all<{ status: string; reasonCode: string | null }>();
342+
/* v8 ignore next -- D1's .all() always populates results; the fallback only protects a driver anomaly. */
342343
const rows = result?.results ?? [];
343344
signal = signalFromCounts(countOutcomes(rows), cfg);
344345
} catch {

test/unit/reputation-wiring.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,23 @@ describe("getEffectiveSubmitterReputation (#4513, install-wide for a confirmed m
352352
vi.unstubAllGlobals();
353353
}
354354
});
355+
356+
it("fails safe to the per-repo result, without throwing, when the getRepository read itself errors", async () => {
357+
const env = createTestEnv();
358+
await seedReviewTarget(env, { project: "org/repo-a", repo: "org/repo-a", number: 1, installationId: 999, submitter: "farmer99", status: "closed", reasonCode: "dual_review_declined" });
359+
vi.stubGlobal("fetch", stubMinerFetch("farmer99"));
360+
const realPrepare = env.DB.prepare.bind(env.DB);
361+
env.DB.prepare = ((sql: string) => {
362+
if (/FROM.*"?repositories"?/i.test(sql)) throw new Error("d1 down");
363+
return realPrepare(sql);
364+
}) as typeof env.DB.prepare;
365+
try {
366+
const rep = await getEffectiveSubmitterReputation(env, { repoFullName: "org/repo-a", submitter: "farmer99" });
367+
expect(rep.signal).toBe("neutral");
368+
} finally {
369+
vi.unstubAllGlobals();
370+
}
371+
});
355372
});
356373

357374
describe("processGitHubWebhook records the reputation outcome on a terminal PR (flag-ON call site)", () => {

0 commit comments

Comments
 (0)