fix(antigravity): separate weekly and short-window quotas and clean up redundant rows

- Track both weekly and 5-hour session buckets in parseWeeklyQuotaSummary,
  distinguishing sliding-window limits from multi-day weekly limits
- Preserve disabled session buckets at 0% rather than dropping them when weekly limits are reached
- Target 5-hour session rows (not weekly rows) during family exhaustion reconciliation in getAntigravityUsage
- Suppress synthesized per-model duplicate rows in dashboard normalization when family summaries are present
- Add unit test coverage for multi-bucket extraction, reconciliation isolation, and dashboard deduplication
This commit is contained in:
Christian Gennari
2026-09-21 20:15:11 +07:00
parent 2daf25ffbe
commit be3bc764b1
5 changed files with 281 additions and 92 deletions

View File

@@ -82,17 +82,97 @@ describe("Antigravity dashboard normalization with weekly quotas", () => {
expect(weeklyRows[1].name).toMatch(/Weekly/);
});
it("order: gemini family, claude family, weekly, then other", () => {
const quotas = parseQuotaData("antigravity", data);
it("order: session, weekly, then other models", () => {
const dataWithBoth = {
quotas: {
gemini_session: {
displayName: "Gemini (5h)",
used: 100,
total: 1000,
resetAt: "2026-09-08T05:00:00Z",
remainingPercentage: 90,
},
gemini_weekly: {
displayName: "Gemini (Weekly)",
used: 250,
total: 1000,
resetAt: "2026-09-15T00:00:00Z",
remainingPercentage: 75,
},
claude_gpt_session: {
displayName: "Claude & GPT (5h)",
used: 50,
total: 1000,
resetAt: "2026-09-08T05:00:00Z",
remainingPercentage: 95,
},
claude_gpt_weekly: {
displayName: "Claude & GPT (Weekly)",
used: 500,
total: 1000,
resetAt: "2026-09-14T00:00:00Z",
remainingPercentage: 50,
},
},
};
const quotas = parseQuotaData("antigravity", dataWithBoth);
const keys = quotas.map((q) => q.modelKey);
const geminiIdx = keys.indexOf("gemini");
const claudeIdx = keys.indexOf("claude");
const geminiSessionIdx = keys.indexOf("gemini_session");
const geminiWeeklyIdx = keys.indexOf("gemini_weekly");
const claudeSessionIdx = keys.indexOf("claude_gpt_session");
const claudeWeeklyIdx = keys.indexOf("claude_gpt_weekly");
expect(geminiIdx).toBeLessThan(geminiWeeklyIdx);
expect(claudeIdx).toBeLessThan(claudeWeeklyIdx);
expect(geminiSessionIdx).toBeLessThan(geminiWeeklyIdx);
expect(claudeSessionIdx).toBeLessThan(claudeWeeklyIdx);
});
it("excludes redundant duplicates when individual models mirror weekly reset and summary is present", () => {
// Exact scenario from Christian's account:
const liveLikeData = {
quotas: {
"gemini-3.8-flash-high": { used: 1000, total: 1000, remainingPercentage: 0, resetAt: "2026-09-23T06:00:17Z", displayName: "Gemini 3.8 Flash (High)" },
"claude-sonnet-4-6": { used: 1000, total: 1000, remainingPercentage: 0, resetAt: "2026-09-20T19:00:21Z", displayName: "Claude 3.7 Sonnet" },
"gpt-oss-120b-medium": { used: 1000, total: 1000, remainingPercentage: 0, resetAt: "2026-09-20T19:00:21Z", displayName: "GPT-OSS 120B (Medium)" },
"gemini-3.1-flash-image": { used: 1000, total: 1000, remainingPercentage: 0, resetAt: "2026-09-23T06:00:17Z", displayName: "Gemini 3.1 Flash Image" },
gemini_weekly: {
displayName: "Gemini (Weekly)",
used: 1000,
total: 1000,
resetAt: "2026-09-23T06:00:17Z",
remainingPercentage: 0,
},
claude_gpt_weekly: {
displayName: "Claude & GPT (Weekly)",
used: 807,
total: 1000,
resetAt: "2026-09-24T18:09:46Z",
remainingPercentage: 19.3,
},
claude_gpt_session: {
displayName: "Claude & GPT (5h)",
used: 1000,
total: 1000,
resetAt: "2026-09-20T19:00:21Z",
remainingPercentage: 0,
},
},
};
const quotas = parseQuotaData("antigravity", liveLikeData);
const names = quotas.map((q) => q.name);
// Should contain unique usages:
expect(names).toContain("Claude & GPT (5h)");
expect(names).toContain("Claude & GPT (Weekly)");
expect(names).toContain("Gemini (Weekly)");
expect(names).toContain("Gemini 3.1 Flash Image");
// Should NOT contain redundant duplicate entries:
expect(names).not.toContain("Gemini (Flash / Pro)"); // duplicate of Gemini (Weekly)
expect(names).not.toContain("Claude (Sonnet / Opus)"); // duplicate of Claude & GPT (5h)
expect(names).not.toContain("GPT-OSS 120B (Medium)"); // covered by Claude & GPT family
expect(quotas).toHaveLength(4);
});
it("works with no weekly keys present (backward compat)", () => {

View File

@@ -53,7 +53,7 @@ const NESTED_RESPONSE = {
// — parseWeeklyQuotaSummary ———————————————————————————————
describe("parseWeeklyQuotaSummary", () => {
it("extracts Gemini weekly quota from top-level groups", () => {
it("extracts Gemini weekly and session quotas from top-level groups", () => {
const result = parseWeeklyQuotaSummary(FULL_RESPONSE);
expect(result.gemini_weekly).toMatchObject({
used: 250,
@@ -63,6 +63,14 @@ describe("parseWeeklyQuotaSummary", () => {
unlimited: false,
});
expect(result.gemini_weekly.resetAt).toBe("2026-09-15T00:00:00.000Z");
expect(result.gemini_session).toMatchObject({
used: 100,
total: 1000,
remainingPercentage: 90,
displayName: "Gemini (5h)",
unlimited: false,
});
expect(result.gemini_session.resetAt).toBe("2026-09-09T00:00:00.000Z");
});
it("extracts Claude & GPT weekly quota", () => {
@@ -85,14 +93,14 @@ describe("parseWeeklyQuotaSummary", () => {
expect(result.claude_gpt_weekly.remainingPercentage).toBe(50);
});
it("skips non-weekly buckets", () => {
it("skips unrecognized non-weekly non-session buckets", () => {
const data = {
groups: [{
displayName: "Gemini Models",
buckets: [
{
bucketId: "gemini-daily-bucket",
displayName: "Daily Limit",
bucketId: "gemini-monthly-bucket",
displayName: "Monthly Limit",
remainingFraction: 0.9,
resetTime: "2026-09-09T00:00:00Z",
},
@@ -404,7 +412,7 @@ describe("weekly quota isolation from existing quota", () => {
});
});
it("reconciles weekly quota to 0% when all paid-tier family models are exhausted", async () => {
it("reconciles 5h session quota to 0% when all paid-tier family models are exhausted without clobbering weekly quota", async () => {
proxyAwareFetch.mockImplementation(async (url) => {
if (url.includes(":loadCodeAssist")) {
return {
@@ -421,7 +429,7 @@ describe("weekly quota isolation from existing quota", () => {
models: {
"gemini-3.8-flash-high": {
displayName: "Gemini 3.8 Flash (High)",
// Exhausted model: no remainingFraction, future resetTime
// Exhausted model: no remainingFraction, future resetTime (5h window reset)
quotaInfo: { resetTime: "2026-09-13T12:00:00Z" },
},
},
@@ -435,30 +443,49 @@ describe("weekly quota isolation from existing quota", () => {
json: async () => ({
groups: [{
displayName: "Gemini Models",
buckets: [{
bucketId: "gemini-weekly",
displayName: "Weekly Limit Remaining",
remainingFraction: 1,
resetTime: "2026-09-15T00:00:00Z",
}],
buckets: [
{
bucketId: "gemini-weekly",
displayName: "Weekly Limit Remaining",
window: "weekly",
remainingFraction: 0.75,
resetTime: "2026-09-15T00:00:00Z",
},
{
bucketId: "gemini-5h",
displayName: "Five Hour Limit Remaining",
window: "5h",
remainingFraction: 1,
resetTime: "2026-09-13T11:00:00Z",
},
],
}],
}),
};
}
return { ok: false, status: 404 };
return { ok: true, status: 200, json: async () => ({}) };
});
const { getAntigravityUsage } = await import("../../open-sse/services/usage/google.js");
const result = await getAntigravityUsage("token", {});
const result = await getAntigravityUsage("token-exhausted", null);
// Per-model quota should show exhausted
expect(result.quotas["gemini-3.8-flash-high"].remainingPercentage).toBe(0);
// Weekly quota should be reconciled to 0% with the family reset time
expect(result.quotas.gemini_weekly).toMatchObject({
// 5h session quota should be reconciled to 0% with the family reset time
expect(result.quotas.gemini_session).toMatchObject({
used: 1000,
total: 1000,
remainingPercentage: 0,
resetAt: "2026-09-13T12:00:00.000Z",
});
// Weekly quota should remain intact and NOT be clobbered to 0% or steal the 5h resetAt
expect(result.quotas.gemini_weekly).toMatchObject({
used: 250,
total: 1000,
remainingPercentage: 75,
resetAt: "2026-09-15T00:00:00.000Z",
});
});
});