You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(review): make the review-nag cooldown-cap regression test actually exercise the guard
Gate review: the original regression test seeded an oversized
reviewNagCooldownDays through upsertRepositorySettings, but both
upsertRepositorySettings and getRepositorySettings already clamp that field
on write AND read -- so the value read back inside resolveRepositorySettings
was never actually oversized by the time maybeThrottleReviewNagPing saw it.
The test could pass even with processors.ts's own
Math.min(reviewNagCooldownDays, MAX_REVIEW_NAG_COOLDOWN_DAYS) guard removed
entirely.
Mocks resolveRepositorySettings directly (bypassing the DB/yml clamp layers
entirely, not just the write-time one) to actually deliver an oversized
value to the function under test, then proves the guard's effect
behaviorally: three prior pings 400 days old fall outside the CORRECTLY
capped 365-day window (no cooldown applied), whereas an uncapped
"1-billion-day" window would count them and trip the threshold. Confirmed
by mutation-testing: removing the Math.min throws a real RangeError
(Invalid time value) building the Date.
it("caps an oversized review-nag cooldown before Date arithmetic (regression)", async () => {
11979
+
it("REGRESSION (gate-flagged): caps an oversized review-nag cooldown at MAX_REVIEW_NAG_COOLDOWN_DAYS before Date arithmetic, even when the resolved settings object itself carries an oversized value", async () => {
11980
+
// upsertRepositorySettings/getRepositorySettings both clamp reviewNagCooldownDays on write AND read, so
11981
+
// seeding an oversized value through the normal repository layer (even via a raw DB update bypassing the
11982
+
// write-time clamp) can never actually reach maybeThrottleReviewNagPing uncapped -- the read-time clamp in
11983
+
// getRepositorySettings neutralizes it first. Mock resolveRepositorySettings directly so this test proves
11984
+
// processors.ts's OWN Math.min(reviewNagCooldownDays, MAX_REVIEW_NAG_COOLDOWN_DAYS) guard, not the DB layer.
const pings = await env.DB.prepare("select count(*) as n from audit_events where event_type = 'github_app.review_nag_ping'").first<{ n: number }>();
11998
-
expect(pings?.n).toBe(1);
12015
+
12016
+
// The 400-day-old pings fell outside the CAPPED 365-day window, so this is only the 1st ping this
12017
+
// window — under maxPings=3, never throttled. An uncapped window would have counted all 3 prior pings
12018
+
// (pingCount=4 > maxPings=3) and applied the cooldown instead.
12019
+
const applied = await env.DB.prepare("select count(*) as n from audit_events where event_type = 'github_app.review_nag_cooldown_applied'").first<{ n: number }>();
0 commit comments