From 2009d33a65db70d1d07f05a41694109fe6f640fa Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 25 Oct 2026 02:22:07 +0800 Subject: [PATCH] usage: Gemini 4 Argon's own quota group shows beside Gemini's and Claude's, and keeps Claude's in view (01huadalang on Discord) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 01huadalang: "反重力有 Gemini 4的条子是7天,有没有5h 的条子,而且有 Gemini 4的条子怎么 claude 的条子没有了". Google now reports a third group in retrieveUserQuotaSummary for paid accounts: "Gemini 4 Argon", "For paid Pro plans, Argon quota is separate", with one bucket, gemini-argon-wtu-weekly, window weekly. That shape is agy 1.4.0's own /usage output, recorded in CodexBar #4585 and its test fixture; agy itself shows Gemini 5-hour, Gemini weekly and Gemini 4 Argon weekly, no Argon 5 hours. So there is no 5-hour bar for Argon to show: Google sends none. Claude's bar went because the GUI showed only some pools: - poolLine (an account row on the Providers page) drew pools.slice(0, 2) and put the rest in the tooltip; - the menu bar panel's card drew fam.slice(0, 4) rings; - poolWindows sorted pools by their first word, so "Gemini 4 Argon" ranked with Gemini, before "Claude & GPT". With three pools, Gemini and Gemini 4 Argon took both places and Claude & GPT dropped out of sight. The panel also labelled Argon's ring "Gemini 7d", the same as Gemini's own. And in Go, pools() matched a model to the first group whose name or description holds its family: gemini-4-argon went into Gemini's pool (and its tooltip), and a versioned group listed first with a 5-hour bucket would have taken every Gemini model. Now: - pools(): a group whose name says a version and that a model's name or id begins with ("Gemini 4 Argon") is that model's, whatever its windows; the family-wide match skips versioned groups and, as before (#745), needs the group's 5 hours. - app.js: every pool shows on an account row (the line already wraps) and every pool window on the panel card (a closer gap past four rings); a pool named for a model sorts after the family pools, as agy lists it; its ring reads "Gemini 4 7d" (poolWord); the #745 fallback, which shows a family's own 5 hours before a week-only pool's week, isn't applied to a model's pool. Tests, each red on the old code: - TestAntigravityQuotaModelGroup: the agy groups in agy's order, Argon listed first, and Argon first with a 5-hour bucket. Old code put gemini-4-argon in Gemini, and in the last case gemini-3-flash in Gemini 4 Argon. - quota-pool-model.test.cjs (Chromium, WebKit; en, zh): the Usage page has every group's windows in order; the panel has five rings, Claude's among them, labelled Gemini 5h/7d, Claude 5h/7d, Gemini 4 7d, all fitting; the account row has Gemini, Claude & GPT, Gemini 4 Argon. Chromium was red on the old app.js (order). Run at the pushed head's tree (7b1faf99f plus this change; rebased on 40a0b442c, which touches only internal/cli): - go test -tags nogui -count=1 -timeout 45m ./... under a sandbox HOME: every package ok; - gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui for internal/provider and internal/gui; - GUI, both engines, 76 files (quota-*, panel-usage, panel-quota-*, tray-usage*, usage-accounts*, usage-card-refresh, usage-quota-head, i18n*, old-webkit, click-scroll): 299 of 303 passed. quota-families Chromium zh hit a 180s browser launch timeout at load 75 and passed when rerun. quota-count-wrap (WebKit, 1100px) and quota-reads (WebKit de 360) are red the same way on the untouched 7b1faf99f, already filed as #3404/#2228 and #3406/#2150. Not tried: a real Antigravity account. The Argon group's shape comes from agy's recorded output, not from a call made here. A summary from the cloudcode-pa OAuth endpoint may lack the Argon group (CodexBar saw that); in that case nothing changes. --- internal/gui/assets/app.css | 1 + internal/gui/assets/app.js | 36 ++++-- internal/gui/tests/quota-pool-model.test.cjs | 118 +++++++++++++++++++ internal/provider/google.go | 61 ++++++++-- internal/provider/google_test.go | 69 +++++++++++ 5 files changed, 264 insertions(+), 21 deletions(-) create mode 100644 internal/gui/tests/quota-pool-model.test.cjs diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index c426a8a43..903fdad79 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -1851,6 +1851,7 @@ body.panel .profiles #save { height: 25px; } /* the field's: the line keeps its .pq-sub { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; } .pq-sub.err { color: var(--muted); white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; } .pq-rings { grid-row: 1 / 3; grid-column: 2; display: flex; gap: 12px; } +.pq-rings.many { gap: 7px; } .pq-ring { display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; } .pq-dial { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--fg-2) calc(var(--p) * 1%), color-mix(in srgb, var(--fg) 9%, transparent) 0); } .pq-dial b { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--card); font-size: 9.5px; font-weight: 600; color: var(--fg-2); font-variant-numeric: tabular-nums; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 127124192..bd792cdd3 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -13595,8 +13595,9 @@ function accountQuota(data, user, capFor = () => 0, settable = null) { } // poolLine: an account row's pools, each its name then its 5-hour and -// weekly meters (Gemini 5h ▬ 95% 7d ▬ 75%), two pools on the line and the -// rest in its tooltip. +// weekly meters (Gemini 5h ▬ 95% 7d ▬ 75%), every pool Google reports: +// one left to the tooltip was Claude's once Gemini 4 Argon had its own +// (01huadalang on Discord). The line wraps. function poolLine(line, ws, q, capFor = () => 0, settable = null) { const pools = []; for (const w of ws) { @@ -13604,9 +13605,8 @@ function poolLine(line, ws, q, capFor = () => 0, settable = null) { const p = pools.find((x) => x.k === k); if (p) p.ws.push(w); else pools.push({ k, name: w.members ? w.pool : t(w.name), ws: [w] }); } - line.title = pools.slice(2).map((p) => p.ws.map((w) => t(w.name) + " " + quotaText(w)).join(" · ")).join("\n"); - if (q.asOf) line.title = [line.title, asOfText(q)].filter(Boolean).join("\n"); - for (const p of pools.slice(0, 2)) { + if (q.asOf) line.title = asOfText(q); + for (const p of pools) { const m = el("span", "aq-w aq-pool" + (p.ws.some((w) => w.used >= 90) ? " full" : "")); m.append(el("span", "aq-n", p.name)); for (const w of p.ws) { @@ -14059,6 +14059,12 @@ function familyWindows(ws) { // same, show the 5 hours and the week left a group). The models' windows // in no pool go on as families. const isPool = (w) => w.pool && !w.family; +// poolOfModel: a pool named for one model, its name saying a version +// ("Gemini 4 Argon", apart from the other Gemini models'), not a family's. +const poolOfModel = (p) => /\d/.test(p || ""); +// poolWord: a pool's short name for a ring: its first word, with the +// version after it ("Gemini 4" for Gemini 4 Argon, beside Gemini's own). +const poolWord = (p) => { const [a, b] = p.split(/[ &]+/); return /^\d/.test(b || "") ? a + " " + b : a; }; function poolWindows(ws) { const pools = new Map(); for (const w of ws.filter(isPool)) { @@ -14069,7 +14075,10 @@ function poolWindows(ws) { const m = /^(\d+)\s*(hour|day|week)s?$/i.exec(w.name || ""); return m ? m[1] * { hour: 1, day: 24, week: 168 }[m[2].toLowerCase()] : Infinity; }; - const first = (p) => { const i = FAMILY_FIRST.indexOf(p.split(/[ &]/)[0]); return i < 0 ? FAMILY_FIRST.length : i; }; + // a family's pools first (Gemini, then Claude & GPT), then the rest, and + // a model's own pool ("Gemini 4 Argon", one with a version) after them + // all, as agy's /usage lists it (01huadalang on Discord) + const first = (p) => { const i = FAMILY_FIRST.indexOf(p.split(/[ &]/)[0]); return poolOfModel(p) ? FAMILY_FIRST.length + 1 : i < 0 ? FAMILY_FIRST.length : i; }; const rest = ws.filter((w) => !isPool(w) && !(w.pool && pools.has(w.pool))); let fam = familyWindows(rest); const out = []; @@ -14080,7 +14089,9 @@ function poolWindows(ws) { // windows as families: they go in the pool's place, before its week, // so the card reads in the same order whether or not the summary sent // the 5 hours this time (#860: 5h and 7d swapped after a refresh) - if (!own.some((w) => hours(w) === 5)) { + // (a model's own pool stands for no family: Gemini 4 Argon's week + // takes no Gemini model's 5 hours) + if (!own.some((w) => hours(w) === 5) && !poolOfModel(pool)) { const mine = (w) => { const f = w.tiers ? w.name : w.family; return !!f && pool.toLowerCase().includes(f.toLowerCase()); }; out.push(...fam.filter(mine)); fam = fam.filter((w) => !mine(w)); @@ -14099,7 +14110,7 @@ function poolTip(w) { // ringName: a window's name short enough for a ring: a pool's first word // and its span (Gemini 5h, Claude 7d). function ringName(w) { - return w.window ? w.pool.split(/[ &]/)[0] + " " + shortWindow(w.window) : shortWindow(w.name); + return w.window ? poolWord(w.pool) + " " + shortWindow(w.window) : shortWindow(w.name); } // tiersText: a family's windows, one a line, for its tooltip. @@ -17294,7 +17305,8 @@ function panelQuotaCard(q) { card.title += "\n" + asOfText(q); } const balance = q.balance && balanceRow(q, "What is left on the account besides its windows", false); - // a pool's 5-hour and weekly rings, two pools of them, else three + // a pool's 5-hour and weekly rings, every pool's (a third pool once left + // Claude's out: 01huadalang on Discord), else three const fam = familyWindows(q.windows.filter((w) => !w.unlimited)); if (!fam.length && q.windows.some((w) => w.unlimited)) { const sub = el("span", "pq-sub", t("Unlimited")); @@ -17303,7 +17315,7 @@ function panelQuotaCard(q) { if (balance) card.append(balance); return card; } - const ws = fam.slice(0, fam.some((w) => w.members) ? 4 : 3); + const ws = fam.slice(0, fam.some((w) => w.members) ? Math.max(4, fam.filter((w) => w.members).length) : 3); // when the windows begun start again: the first bare, the others by name const begun = ws.filter((w) => w.resetsAt && w.used > 0); const sub = el("span", "pq-sub", begun.length @@ -17327,7 +17339,7 @@ function panelQuotaCard(q) { // the card's own refresh, as on the Usage page: shown as it's hovered sub.append(quotaRefresh(q)); card.append(sub); - const rings = el("span", "pq-rings"); + const rings = el("span", "pq-rings" + (ws.length > 4 ? " many" : "")); for (const w of ws) { const used = Math.max(0, Math.min(100, w.used)); const r = el("span", "pq-ring" + (used >= 90 ? " full" : "")); @@ -17338,7 +17350,7 @@ function panelQuotaCard(q) { const rn = el("span", "pq-rn", w.window ? undefined : ringName(w)); if (w.window) { rn.classList.add("pq-rn2"); - rn.append(el("span", "", w.pool.split(/[ &]/)[0]), el("span", "", shortWindow(w.window))); + rn.append(el("span", "", poolWord(w.pool)), el("span", "", shortWindow(w.window))); } r.append(dial, rn); r.title = t(w.name) + " · " + quotaText(w) + (w.resetsAt ? "\n" + resetText(new Date(w.resetsAt), new Date(w.resetsAt).toLocaleString(intlLang())) + (new Date(w.resetsAt) > Date.now() ? " · " + untilText(new Date(w.resetsAt)) : "") : "") diff --git a/internal/gui/tests/quota-pool-model.test.cjs b/internal/gui/tests/quota-pool-model.test.cjs new file mode 100644 index 000000000..06ce2b11f --- /dev/null +++ b/internal/gui/tests/quota-pool-model.test.cjs @@ -0,0 +1,118 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Gemini 4 Argon has a quota group of its own beside Gemini's and Claude & +// GPT's, with only a week (agy 1.4.0's /usage: "Gemini 4 Argon", bucket +// gemini-argon-wtu-weekly; CodexBar #4585). 01huadalang on Discord: 反重力 +// 有 Gemini 4 的条子是7天…有 Gemini 4 的条子怎么 claude 的条子没有了. The +// account rows showed two pools and the panel four rings, Gemini's two +// pools first, so Claude & GPT's went out. Now every pool shows, Claude & +// GPT before the model's own pool, which reads "Gemini 4" on its ring, not +// a second "Gemini". English and Chinese, Chromium and WebKit; the API is +// faked here. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const at = (h) => new Date(Date.now() + h * 36e5).toISOString(); +const model = (name, family, pool, used, h) => ({ name, family, pool, used, resetsAt: at(h) }); +const pool = (pool, name, used, h) => ({ name, pool, used, resetsAt: at(h) }); +// as magpie reports it: the models, then each group's windows as Google +// lists the groups, Argon's last with its week alone +const ag = (user) => ({ + provider: "antigravity", name: "Antigravity", icon: "antigravity-color", user, plan: "Google AI Pro", + windows: [ + model("Claude Sonnet 4.6", "Claude", "Claude & GPT", 30, 3), + model("Gemini 3 Flash", "Gemini", "Gemini", 0, 2), + model("Gemini 4 Argon", "Gemini", "Gemini 4 Argon", 47, 150), + pool("Gemini", "7 days", 1, 100), pool("Gemini", "5 hours", 0, 2), + pool("Claude & GPT", "7 days", 40, 90), pool("Claude & GPT", "5 hours", 30, 3), + pool("Gemini 4 Argon", "7 days", 47, 150), + ], +}); +const quotas = [ag("ada@example.com")]; +const logins = [{ user: "ada@example.com", plan: "Google AI Pro", active: true, on: true }]; +const antigravity = { + id: "antigravity", name: "Antigravity", icon: "antigravity-color", chat: "", responses: "", anthropic: "", catalog: "", + models: [{ id: "gemini-3-flash", name: "Gemini 3 Flash", on: true }], agents: [], fallback: [], headers: {}, keyList: [], + account: { agent: "antigravity", agentName: "Antigravity", user: logins[0].user, plan: logins[0].plan, logins }, +}; + +function serve(lang, panel) { + const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" }; + return async (route) => { + const url = new URL(route.request().url()); + const json = (data) => route.fulfill({ json: data }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${!panel}};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings }); + if (url.pathname === "/api/settings") return json(settings); + if (url.pathname === "/api/providers") return json({ providers: [antigravity], presets: [], excluded: [], gateway: { running: true, window: true } }); + if (url.pathname === "/api/usage/quotas") return json(quotas); + if (url.pathname === "/api/login/usage") return json(Object.fromEntries(quotas.map((q) => [q.user, q]))); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); } + }; +} + +const words = { + en: { five: "5 hours", week: "7 days" }, + zh: { five: "5 小时", week: "7 天" }, +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh"]) { + const w = words[lang]; + test(`${engine} ${lang}: a model's own quota group shows beside Gemini's and Claude's`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const errors = []; + const open = async (url, viewport) => { + const page = await (await browser.newContext({ viewport, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, url.includes("mode=panel"))); + await page.goto(url); + return page; + }; + const fill = (loc) => loc.evaluateAll((es) => es.map((e) => Math.round(parseFloat(e.style.width)))); + + // the Usage page: every group's windows, Claude & GPT before Argon + const page = await open("http://magpie.test/?view=usage", { width: 900, height: 700 }); + const box = page.locator(".subscription-card", { hasText: "Antigravity" }).locator(".quota-windows").first(); + await box.waitFor(); + assert.deepEqual(await box.locator(".quota-labels > span:first-child").allTextContents(), + [`Gemini · ${w.five}`, `Gemini · ${w.week}`, `Claude & GPT · ${w.five}`, `Claude & GPT · ${w.week}`, `Gemini 4 Argon · ${w.week}`]); + const tip = await box.locator(".quota").nth(1).getAttribute("title"); + assert(tip.includes("Gemini 3 Flash") && !tip.includes("Gemini 4 Argon"), "Gemini's pool is the other Gemini models': " + tip); + + // the menu bar panel: five rings, Claude's among them, Argon's named for it + const panel = await open("http://magpie.test/?mode=panel", { width: 440, height: 640 }); + await panel.locator('#ptabs [data-ptab="usage"]').click(); + const card = panel.locator(".pq-group", { hasText: "Antigravity" }).locator(".pq-card").first(); + await card.locator(".pq-ring").first().waitFor(); + assert.deepEqual(await card.locator(".pq-rn").evaluateAll((es) => es.map((e) => [...e.children].map((c) => c.textContent).join(" "))), + ["Gemini 5h", "Gemini 7d", "Claude 5h", "Claude 7d", "Gemini 4 7d"]); + assert.deepEqual(await card.locator(".pq-dial b").allTextContents(), ["0%", "1%", "30%", "40%", "47%"]); + assert(await card.locator(".pq-rn > span").evaluateAll((es) => es.every((e) => e.scrollWidth <= e.clientWidth)), "the ring labels fit"); + const fits = await card.evaluate((c) => { const r = c.getBoundingClientRect(); return [...c.querySelectorAll(".pq-ring")].every((x) => x.getBoundingClientRect().right <= r.right + 0.5); }); + assert(fits, "the five rings fit the card"); + assert(await card.locator(".pq-user").evaluate((e) => e.getBoundingClientRect().width >= 80), "the account's name keeps room"); + + // the provider's account row: every pool, Claude & GPT's included + const prov = await open("http://magpie.test/?view=providers", { width: 900, height: 700 }); + await prov.locator(".row.provider", { hasText: "Antigravity" }).click(); + const row = prov.locator(".accts .acc", { hasText: "ada@example.com" }); + await row.locator(".aq-w").first().waitFor(); + assert.deepEqual(await row.locator(".aq-n").allTextContents(), ["Gemini", "Claude & GPT", "Gemini 4 Argon"]); + assert.deepEqual(await row.locator(".aq-k").allTextContents(), ["5h", "7d", "5h", "7d", "7d"]); + assert.deepEqual(await fill(row.locator(".aq-track i")), [0, 1, 30, 40, 47]); + assert.deepEqual(errors, []); + }); + } +} diff --git a/internal/provider/google.go b/internal/provider/google.go index 476d663b1..c40e9842f 100644 --- a/internal/provider/google.go +++ b/internal/provider/google.go @@ -1221,6 +1221,12 @@ func (g googleAccount) quota(ctx context.Context, plan string) SubscriptionQuota // its group's name as its Pool, so the GUI shows one row a group. None // when the summary can't be read: the per-model windows stand alone. They // are Aside: routing goes on reading the per-model windows, as before. +// +// A group named for one model ("Gemini 4 Argon", whose quota is apart +// from the other Gemini models' and has only a week: agy 1.4.0's /usage, +// CodexBar #4585) takes that model, whatever windows it has, and no other +// model of its family: the family-wide group ("Gemini Models") keeps the +// rest, whichever of the two Google lists first (01huadalang on Discord). func (g googleAccount) pools(ctx context.Context, ws []QuotaWindow) []QuotaWindow { p, err := g.project(ctx) if err != nil { @@ -1243,7 +1249,12 @@ func (g googleAccount) pools(ctx context.Context, ws []QuotaWindow) []QuotaWindo if err := g.call(ctx, g.app.base, "retrieveUserQuotaSummary", map[string]any{"project": p.id}, &res, nil); err != nil { return nil } + type group struct { + pool, about string + five bool // has its 5 hours, which stand in for its models' + } var out []QuotaWindow + var groups []group for _, gr := range res.Groups { pool := poolName(gr.DisplayName) if pool == "" { @@ -1281,22 +1292,54 @@ func (g googleAccount) pools(ctx context.Context, ws []QuotaWindow) []QuotaWindo n++ fiveHour = fiveHour || w.Span == modelSpan } - if n == 0 || !fiveHour { - continue // without the group's 5 hours its models' own stand (#745) + if n > 0 { + groups = append(groups, group{pool, strings.ToLower(gr.DisplayName + " " + gr.Description), fiveHour}) } - // a model is in the group its name or description names its - // family in ("Models within this group: Claude Opus, Claude - // Sonnet, GPT-OSS") - about := strings.ToLower(gr.DisplayName + " " + gr.Description) - for i := range ws { - if ws[i].Pool == "" && ws[i].Family != "" && strings.Contains(about, strings.ToLower(ws[i].Family)) { - ws[i].Pool = pool + } + for i := range ws { + if ws[i].Pool != "" || ws[i].Family == "" { + continue + } + if j := slices.IndexFunc(groups, func(gr group) bool { return poolNames(gr.pool, ws[i]) }); j >= 0 { + ws[i].Pool = groups[j].pool + continue + } + // else the group its name or description names its family in + // ("Models within this group: Claude Opus, Claude Sonnet, + // GPT-OSS"), one with its 5 hours: without them its models' own + // stand (#745); a group that says a version ("Gemini 4 Argon") is + // its model's alone, never the family's + for _, gr := range groups { + if gr.five && !versioned(gr.pool) && strings.Contains(gr.about, strings.ToLower(ws[i].Family)) { + ws[i].Pool = gr.pool + break } } } return out } +// poolNames is whether a quota group's name (pool) is a model's own: the +// model's name or id begins with it and it says a version, as "Gemini 4 +// Argon" does Gemini 4 Argon (High)'s; "Gemini" names a family, not a model. +func poolNames(pool string, w QuotaWindow) bool { + if !versioned(pool) { + return false + } + p := strings.ToLower(pool) + for _, s := range []string{w.Name, strings.ReplaceAll(w.Model, "-", " ")} { + s = strings.ToLower(s) + if s == p || strings.HasPrefix(s, p+" ") || strings.HasPrefix(s, p+"(") { + return true + } + } + return false +} + +// versioned is whether a quota group's name says a version, a model's +// group ("Gemini 4 Argon"), not a family's ("Gemini", "Claude & GPT"). +func versioned(pool string) bool { return strings.ContainsAny(pool, "0123456789") } + // modelSpan is the window fetchAvailableModels gives a model of // Antigravity's, its 5 hours, which its window leaves without a Span. const modelSpan = 5 * time.Hour diff --git a/internal/provider/google_test.go b/internal/provider/google_test.go index c06a1d96c..591f24643 100644 --- a/internal/provider/google_test.go +++ b/internal/provider/google_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "io" + "maps" "net/http" "net/http/httptest" "net/url" @@ -821,3 +822,71 @@ func TestAntigravityRetiredModelNamedWithoutTag(t *testing.T) { }) } } + +// Gemini 4 Argon has a quota group of its own, with only a week (agy +// 1.4.0's /usage: "Gemini 4 Argon", bucket gemini-argon-wtu-weekly, "For +// paid Pro plans, Argon quota is separate"; CodexBar #4585). Its model is +// in that group, not Gemini's, and the group never takes the other Gemini +// models, whichever Google lists first and whether or not it has 5 hours +// (01huadalang on Discord: a Gemini 4 bar of 7 days, and Claude's gone). +func TestAntigravityQuotaModelGroup(t *testing.T) { + argon := func(five bool) string { + b := `{"bucketId":"gemini-argon-wtu-weekly","window":"weekly","remainingFraction":0.53,"resetTime":"2099-01-07T00:00:00Z","displayName":"Gemini 4 Argon Weekly Limit"}` + if five { + b += `,{"bucketId":"gemini-argon-5h","window":"5h","remainingFraction":0.8,"resetTime":"2099-01-01T04:00:00Z"}` + } + return `{"displayName":"Gemini 4 Argon","description":"For paid Pro plans, Argon quota is separate.","buckets":[` + b + `]}` + } + gemini := `{"displayName":"Gemini Models","description":"Models within this group: Gemini Flash, Gemini Pro","buckets":[ + {"bucketId":"gemini-weekly","window":"weekly","remainingFraction":0.99,"resetTime":"2099-01-07T00:00:00Z"}, + {"bucketId":"gemini-5h","window":"5h","remainingFraction":1,"resetTime":"2099-01-01T05:00:00Z"}]}` + claude := `{"displayName":"Claude and GPT models","description":"Models within this group: Claude Opus, Claude Sonnet, GPT-OSS","buckets":[ + {"bucketId":"3p-weekly","window":"weekly","remainingFraction":0.6,"resetTime":"2099-01-06T00:00:00Z"}, + {"bucketId":"3p-5h","window":"5h","remainingFraction":0.7,"resetTime":"2099-01-01T03:00:00Z"}]}` + f := &fakeGoogle{ + load: `{"allowedTiers":[{"id":"free-tier","name":"Antigravity","isDefault":true}]}`, + onboard: `{"done":true,"response":{"cloudaicompanionProject":"ag-proj"}}`, + models: `{"models":{ + "gemini-3-flash":{"displayName":"Gemini 3 Flash","quotaInfo":{"remainingFraction":1,"resetTime":"2099-01-01T05:00:00Z"}}, + "gemini-4-argon":{"displayName":"Gemini 4 Argon","quotaInfo":{"remainingFraction":0.53,"resetTime":"2099-01-07T00:00:00Z"}}, + "claude-sonnet-4-6":{"displayName":"Claude Sonnet 4.6","quotaInfo":{"remainingFraction":0.7}}}}`, + } + googleSandbox(t, f) + auth := googleAuth{AccessToken: "tok", RefreshToken: "rt-ag", Expiry: time.Now().Add(time.Hour).UnixMilli()} + if err := addGoogleLogin("antigravity", "ag@example.com", "", auth); err != nil { + t.Fatal(err) + } + for _, c := range []struct { + name, groups string + pooled string + }{ + {"as agy has it", gemini + "," + claude + "," + argon(false), + "Gemini 4 Argon,Gemini · 7 days,Gemini · 5 hours,Claude & GPT · 7 days,Claude & GPT · 5 hours,Gemini 4 Argon · 7 days"}, + {"Argon first", argon(false) + "," + gemini + "," + claude, + "Gemini 4 Argon,Gemini 4 Argon · 7 days,Gemini · 7 days,Gemini · 5 hours,Claude & GPT · 7 days,Claude & GPT · 5 hours"}, + {"Argon first with 5 hours", argon(true) + "," + gemini + "," + claude, + "Gemini 4 Argon · 7 days,Gemini 4 Argon · 5 hours,Gemini · 7 days,Gemini · 5 hours,Claude & GPT · 7 days,Claude & GPT · 5 hours"}, + } { + f.mu.Lock() + f.summary = `{"groups":[` + c.groups + `]}` + f.mu.Unlock() + q := googleLogins("antigravity")[0].acct.quota(context.Background(), "") + pools := map[string]string{} + for _, w := range q.Windows { + if w.Model != "" { + pools[w.Model] = w.Pool + } + } + want := map[string]string{"gemini-3-flash": "Gemini", "gemini-4-argon": "Gemini 4 Argon", "claude-sonnet-4-6": "Claude & GPT"} + if !maps.Equal(pools, want) { + t.Errorf("%s: pools %v, want %v", c.name, pools, want) + } + var names []string + for _, w := range PooledWindows(q.Windows) { + names = append(names, w.Name) + } + if got := strings.Join(names, ","); got != c.pooled { + t.Errorf("%s: pooled\n%s\nwant\n%s", c.name, got, c.pooled) + } + } +}