Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
1.9 kB · 49 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import { describe, expect, it, vi } from "vitest";import { AuthStorage } from "../src/core/auth-storage.js";import { initTheme } from "../src/modes/interactive/theme/theme.js";import { fetchCodexUsageReports, renderUsageReportText } from "../src/modes/interactive/usage-report.js";
initTheme("dark");
const oauth = (access: string, email: string, accountId: string) => ({ type: "oauth" as const, access, refresh: `refresh-${accountId}`, expires: Date.now() + 60_000, email, accountId,});
describe("usage reports", () => { it("fetches and keeps quota data separate for every Codex account", async () => { const auth = AuthStorage.inMemory({ "openai-codex": [ oauth("access-one", "one@example.com", "account-one"), oauth("access-two", "two@example.com", "account-two"), ], }); const fetchImpl = vi.fn(async (_input: string | URL, init?: RequestInit) => { const account = (init?.headers as Record<string, string>)["ChatGPT-Account-Id"]; return new Response( JSON.stringify({ plan_type: "plus", rate_limit: { primary_window: { used_percent: account === "account-one" ? 20 : 80, limit_window_seconds: 18_000 }, }, }), { status: 200, headers: { "content-type": "application/json" } }, ); }); const reports = await fetchCodexUsageReports(auth, { fetchImpl }); expect(reports).toHaveLength(2); expect(reports.map((report) => report.email)).toEqual(["one@example.com", "two@example.com"]); expect(reports.map((report) => report.limits[0]?.usedPercent)).toEqual([20, 80]); expect(fetchImpl).toHaveBeenCalledTimes(2); });
it("renders a non-empty immediate report while quota refresh is pending", () => { const output = renderUsageReportText([], undefined, 100, { loading: true }); expect(output).toContain("Usage"); expect(output).toContain("background"); });});