feat(costs): add billing, quota, and budget control plane

This commit is contained in:
Dotta
2026-03-14 22:00:12 -05:00
parent 656b4659fc
commit 76e6cc08a6
91 changed files with 22406 additions and 769 deletions

View File

@@ -0,0 +1,56 @@
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
vi.mock("../adapters/registry.js", () => ({
listServerAdapters: vi.fn(),
}));
import { listServerAdapters } from "../adapters/registry.js";
import { fetchAllQuotaWindows } from "../services/quota-windows.js";
describe("fetchAllQuotaWindows", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
});
it("returns adapter results without waiting for a slower provider to finish forever", async () => {
vi.mocked(listServerAdapters).mockReturnValue([
{
type: "codex_local",
getQuotaWindows: vi.fn().mockResolvedValue({
provider: "openai",
source: "codex-rpc",
ok: true,
windows: [{ label: "5h limit", usedPercent: 2, resetsAt: null, valueLabel: null, detail: null }],
}),
},
{
type: "claude_local",
getQuotaWindows: vi.fn(() => new Promise(() => {})),
},
] as never);
const promise = fetchAllQuotaWindows();
await vi.advanceTimersByTimeAsync(20_001);
const results = await promise;
expect(results).toEqual([
{
provider: "openai",
source: "codex-rpc",
ok: true,
windows: [{ label: "5h limit", usedPercent: 2, resetsAt: null, valueLabel: null, detail: null }],
},
{
provider: "anthropic",
ok: false,
error: "quota polling timed out after 20s",
windows: [],
},
]);
});
});