Files
paseo/plugins/antigravity-provider/server/usage.test.ts
T
Mohamed Boudra 7eec266f50 fix(usage): keep window shorthands visible in sidebar usage row (#10274)
* fix(usage): keep window shorthands visible in sidebar usage row

Antigravity usage windows emitted full group names and raw period strings (for example "Gemini Models weekly") in shortLabel, which pushed the measured labels row past the maximum sidebar width. On the app side, choosePinnedUsageLayout dropped every window on the row straight to bare percentages whenever any scoped short label overflowed the row.

Normalize Antigravity shortLabel periods (weekly -> wk, monthly -> mo) and shorten group prefixes, and add a compact period-shorthand tier between full labels and bare percentages in PinnedUsageTrigger so tight sidebar rows keep shorthands like 5h and wk visible instead of collapsing to percentages alone.

* test(usage): expect compact shorthands in usage modal sidebar summary

With the compact period-shorthand tier between full labels and bare percentages, three Weekly windows now render as "31% wk", "20% wk", "12% wk" in the 320px sidebar instead of dropping to bare percentages.
2026-11-20 13:58:45 +07:00

139 lines
5.4 KiB
TypeScript

import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, expect, it } from "vitest";
import { Usage } from "./usage.js";
const directories: string[] = [];
afterEach(async () => {
await Promise.all(directories.splice(0).map((directory) => rm(directory, { recursive: true })));
});
it("discovers the resolved account and maps the CLI's quota buckets", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "paseo-antigravity-usage-"));
directories.push(directory);
const cli = path.join(directory, "cli.cjs");
await writeFile(
cli,
`
if (JSON.stringify(process.argv.slice(2)) !== JSON.stringify(['-p', '/usage', '--output-format', 'json'])) process.exit(2);
console.log(JSON.stringify({ status: 'SUCCESS', command: { name: 'usage', data: { groups: [
{ name: 'Gemini Models', buckets: [
{ id: 'gemini-5h', name: 'Five Hour Limit Remaining', window: '5h', remaining_fraction: 0.25, reset_time: '2026-11-19T14:25:08Z' },
{ id: 'gemini-weekly', name: 'Weekly Limit Remaining', window: 'weekly', remaining_fraction: 0.7 },
{ id: 'disabled', name: 'Weekly', window: 'weekly', disabled: true, remaining_fraction: 1 }
] }
] } } }));
`,
);
const usage = new Usage();
const launch = {
command: process.execPath,
args: [cli, "acp", "--disable-telemetry"],
env: { HOME: directory },
};
const source = usage.registration();
const accounts = await source.discover({ kind: "global", launch });
expect(accounts).toHaveLength(1);
expect(
await source.discover({
kind: "session",
provider: "antigravity",
env: { HOME: directory },
launch,
}),
).toEqual(accounts);
expect(
await source.discover({
kind: "session",
provider: "antigravity",
env: { HOME: `${directory}-other` },
}),
).toEqual([]);
expect(
await source.discover({ kind: "session", provider: "codex", env: { HOME: directory } }),
).toEqual([]);
const otherLaunch = { ...launch, env: { HOME: `${directory}-other` } };
const other = await source.discover({
kind: "session",
provider: "antigravity",
env: otherLaunch.env,
launch: otherLaunch,
});
expect(other[0]?.key).not.toBe(accounts[0]?.key);
expect(other[0]?.input).not.toEqual(accounts[0]?.input);
expect(await source.fetch(accounts[0]!.input)).toMatchObject({
status: "available",
windows: [
{
id: "gemini-5h",
shortLabel: "5h",
usedPct: 75,
remainingPct: 25,
resetsAt: "2026-11-19T14:25:08Z",
},
{ id: "gemini-weekly", shortLabel: "wk", usedPct: expect.closeTo(30), summary: true },
{ id: "disabled", shortLabel: "wk", usedPct: null, remainingPct: null },
],
});
});
it("uses compact group and period shorthands when multiple groups are reported", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "paseo-antigravity-usage-"));
directories.push(directory);
const cli = path.join(directory, "cli.cjs");
await writeFile(
cli,
`
console.log(JSON.stringify({ status: 'SUCCESS', command: { name: 'usage', data: { groups: [
{ name: 'Gemini Models', buckets: [
{ id: 'gemini-weekly', name: 'Weekly Limit Remaining', window: 'weekly', remaining_fraction: 0.9 },
{ id: 'gemini-5h', name: 'Five Hour Limit Remaining', window: '5h', remaining_fraction: 0.8 }
] },
{ name: 'Claude and GPT models', buckets: [
{ id: '3p-weekly', name: 'Weekly Limit Remaining', window: 'weekly', remaining_fraction: 1 }
] }
] } } }));
`,
);
const launch = { command: process.execPath, args: [cli, "acp"], env: { HOME: directory } };
const source = new Usage().registration();
const [account] = await source.discover({ kind: "global", launch });
expect(await source.fetch(account!.input)).toMatchObject({
status: "available",
windows: [
{ id: "gemini-weekly", shortLabel: "Gemini wk" },
{ id: "gemini-5h", shortLabel: "Gemini 5h" },
{ id: "3p-weekly", shortLabel: "Claude and GPT wk" },
],
});
});
it("surfaces CLI errors instead of reporting a successful quota", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "paseo-antigravity-usage-"));
directories.push(directory);
const cli = path.join(directory, "cli.cjs");
await writeFile(
cli,
`console.log(JSON.stringify({ status: 'ERROR', error: 'Authentication required' }));`,
);
const usage = new Usage();
const launch = { command: process.execPath, args: [cli, "acp"], env: { HOME: directory } };
const source = usage.registration();
const [account] = await source.discover({ kind: "global", launch });
await expect(source.fetch(account!.input)).rejects.toThrow("Authentication required");
});
it("reports a failed CLI without exposing its stderr", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "paseo-antigravity-usage-"));
directories.push(directory);
const cli = path.join(directory, "cli.cjs");
await writeFile(cli, `process.stderr.write('authentication token=private'); process.exit(1);`);
const launch = { command: process.execPath, args: [cli, "acp"], env: { HOME: directory } };
const source = new Usage().registration();
const [account] = await source.discover({ kind: "global", launch });
await expect(source.fetch(account!.input)).rejects.toThrow(
"Antigravity usage command failed or timed out. Check that agy is signed in.",
);
});