import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { createTestSession, type TestSession } from "../../../test/harness"; import { __test } from "../index.ts"; describe("quota pi-test-harness", () => { let t: TestSession | undefined; afterEach(() => { t?.dispose(); t = undefined; }); it("loads in real Pi extension runtime", async () => { const extensionPath = path.resolve(import.meta.dirname, "../index.ts"); t = await createTestSession({ extensions: [extensionPath] }); expect(t.session.extensionRunner.extensions).toHaveLength(1); expect(t.session.extensionRunner.extensions[0].path).toBe(extensionPath); }, 15000); it("parses stolen provider quota shapes", () => { expect( __test.parseCopilot({ quota_snapshots: { premium_interactions: { percent_remaining: 75 }, chat: { percent_remaining: 40 }, }, }), ).toMatchObject({ name: "GitHub Copilot", fiveH: { used: 25, total: 100, remaining: 75 }, weekly: { used: 60, total: 100, remaining: 40 }, }); expect( __test.parseGemini({ buckets: [ { modelId: "gemini-pro", remainingFraction: 0.25 }, { modelId: "gemini-flash", remainingFraction: 0.75 }, ], }), ).toMatchObject({ name: "Gemini", fiveH: { used: 75, total: 100, remaining: 25 }, weekly: { used: 25, total: 100, remaining: 75 }, }); expect( __test.parseMinimax({ base_resp: { status_code: 0, status_msg: "" }, model_remains: [ { model_name: "MiniMax-M2", current_interval_total_count: 100, current_interval_usage_count: 30, current_weekly_total_count: 1000, current_weekly_usage_count: 800, }, ], }), ).toMatchObject({ name: "MiniMax", fiveH: { used: 70, total: 100, remaining: 30 }, weekly: { used: 200, total: 1000, remaining: 800 }, }); expect( __test.parseMinimax({ base_resp: { status_code: 0, status_msg: "" }, model_remains: [ { model_name: "general", current_interval_total_count: 0, current_interval_usage_count: 0, current_interval_remaining_percent: 25, current_weekly_total_count: 0, current_weekly_usage_count: 0, current_weekly_remaining_percent: 80, }, ], }), ).toMatchObject({ name: "MiniMax", fiveH: { used: 75, total: 100, remaining: 25 }, weekly: { used: 20, total: 100, remaining: 80 }, }); }); });