From 864dd6448c5e5bc8a3b87ad31a27c0c4dfd61c90 Mon Sep 17 00:00:00 2001 From: can1357 Date: Wed, 10 Jun 2026 08:04:34 +0200 Subject: [PATCH] test(ai): pin antigravity ranking contract to bottleneck-as-primary Rebase onto main collided with c9c2da9c8, whose contract test pinned the old strategy shape (bottleneck in secondary, runner-up in primary). The scoped strategy intentionally returns only the bottleneck counter as primary and leaves secondary unset, so every candidate ties on the secondary metrics and the bottleneck decides. Update the contract test to assert the new invariant; the end-to-end ordering cases live in auth-storage-antigravity-selection.test.ts. Addresses review feedback on #2200. --- packages/ai/src/auth-storage.ts | 5 ++++- packages/ai/test/google-antigravity-usage.test.ts | 11 ++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/ai/src/auth-storage.ts b/packages/ai/src/auth-storage.ts index a4abcba8b..d89b18204 100644 --- a/packages/ai/src/auth-storage.ts +++ b/packages/ai/src/auth-storage.ts @@ -3551,7 +3551,10 @@ export class AuthStorage { const message = error instanceof Error ? error.message : typeof error === "string" ? error : undefined; if (message && isUsageLimitError(message)) { return ( - await this.markUsageLimitReached(provider, sessionId, { modelId: options?.modelId, signal: options?.signal }) + await this.markUsageLimitReached(provider, sessionId, { + modelId: options?.modelId, + signal: options?.signal, + }) ).switched; } diff --git a/packages/ai/test/google-antigravity-usage.test.ts b/packages/ai/test/google-antigravity-usage.test.ts index 83bbe8b8c..3db72230b 100644 --- a/packages/ai/test/google-antigravity-usage.test.ts +++ b/packages/ai/test/google-antigravity-usage.test.ts @@ -257,11 +257,12 @@ describe("antigravity ranking strategy", () => { }; } - it("maps the most-pressured counter to secondary because AuthStorage compares secondary first", () => { + it("maps the most-pressured counter to primary and leaves secondary unset", () => { // fetchAntigravityUsage sorts ascending by remainingFraction, so a real // report's limits[0] is always the bottleneck. AuthStorage compares the - // secondary ranking metrics before primary, so Antigravity must put the - // bottleneck there; otherwise [5%, 90%] remaining can beat [40%, 40%] + // secondary ranking metrics before primary; leaving secondary unset makes + // every Antigravity candidate tie there, so the bottleneck counter in + // primary decides — otherwise [5%, 90%] remaining can beat [40%, 40%] // because the runner-up counter looks healthier. const report = { provider: "google-antigravity" as const, @@ -269,8 +270,8 @@ describe("antigravity ranking strategy", () => { limits: [makeLimit(0.05, "Anthropic"), makeLimit(0.4, "Google"), makeLimit(0.9, "OpenAI")], }; const { primary, secondary } = antigravityRankingStrategy.findWindowLimits(report); - expect(secondary?.label).toBe("Anthropic"); - expect(primary?.label).toBe("Google"); + expect(primary?.label).toBe("Anthropic"); + expect(secondary).toBeUndefined(); }); it("returns undefined windows when the credential has no usage limits", () => {