test: update markAuthProfileFailure tests for stepped 30s/1m/5m cooldown ladder

Update the auth-profiles.markauthprofilefailure test suite to match the
new stepped cooldown formula (30s → 1m → 5m cap) introduced in the
first commit. The test was still asserting the old exponential backoff
values (1m → 5m → 25m → 1h cap).

Changes:
- calculateAuthProfileCooldownMs assertions: 60s→30s, 5m→1m, 25m→5m,
  1h→5m cap
- 'resets error count when previous cooldown has expired' test: upper
  bound adjusted from 120s to 60s to match 30s base cooldown
- Comments updated to reflect the stepped ladder

Resolves merge-blocker review from @altaywtf.
This commit is contained in:
kiranvk2011 2026-03-18 18:44:50 +00:00
parent 8ea6f5206c
commit ae9ad3c070

View File

@ -230,12 +230,12 @@ describe("markAuthProfileFailure", () => {
const stats = store.usageStats?.["anthropic:default"];
// Error count should reset to 1 (not escalate to 4) because the
// previous cooldown expired. Cooldown should be ~1 min, not ~60 min.
// previous cooldown expired. Cooldown should be ~30s, not ~5 min.
expect(stats?.errorCount).toBe(1);
expect(stats?.failureCounts?.rate_limit).toBe(1);
const cooldownMs = (stats?.cooldownUntil ?? 0) - now;
// calculateAuthProfileCooldownMs(1) = 60_000 (1 minute)
expect(cooldownMs).toBeLessThan(120_000);
// calculateAuthProfileCooldownMs(1) = 30_000 (stepped: 30s → 1m → 5m)
expect(cooldownMs).toBeLessThan(60_000);
expect(cooldownMs).toBeGreaterThan(0);
} finally {
fs.rmSync(agentDir, { recursive: true, force: true });
@ -267,11 +267,11 @@ describe("markAuthProfileFailure", () => {
});
describe("calculateAuthProfileCooldownMs", () => {
it("applies exponential backoff with a 1h cap", () => {
expect(calculateAuthProfileCooldownMs(1)).toBe(60_000);
expect(calculateAuthProfileCooldownMs(2)).toBe(5 * 60_000);
expect(calculateAuthProfileCooldownMs(3)).toBe(25 * 60_000);
expect(calculateAuthProfileCooldownMs(4)).toBe(60 * 60_000);
expect(calculateAuthProfileCooldownMs(5)).toBe(60 * 60_000);
it("applies stepped backoff with a 5-min cap", () => {
expect(calculateAuthProfileCooldownMs(1)).toBe(30_000); // 30 seconds
expect(calculateAuthProfileCooldownMs(2)).toBe(60_000); // 1 minute
expect(calculateAuthProfileCooldownMs(3)).toBe(5 * 60_000); // 5 minutes
expect(calculateAuthProfileCooldownMs(4)).toBe(5 * 60_000); // 5 minutes (cap)
expect(calculateAuthProfileCooldownMs(5)).toBe(5 * 60_000); // 5 minutes (cap)
});
});