Files
OmniRoute/tests/unit/copilot-usage.test.mjs
T
Jack Cowey 5a777bd598 fix(github): correct copilot plan and quota mapping
Normalize GitHub Copilot account tiers from the usage payload and hide misleading unlimited buckets so account type and limits render correctly in the dashboard.

Made-with: Cursor
2026-03-18 12:25:17 +00:00

93 lines
2.8 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
const usageService = await import("../../open-sse/services/usage.ts");
const providerLimitUtils = await import(
"../../src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.tsx"
);
test("github copilot business seats infer business plan and hide unlimited buckets", async () => {
const originalFetch = globalThis.fetch;
globalThis.fetch = async () =>
new Response(
JSON.stringify({
access_type_sku: "copilot_business_seat",
quota_reset_date: "2026-04-01T00:00:00Z",
quota_snapshots: {
chat: { unlimited: true },
completions: { unlimited: true },
premium_interactions: {
entitlement: 300,
remaining: 180,
unlimited: false,
},
},
}),
{
status: 200,
headers: { "content-type": "application/json" },
}
);
try {
const usage = await usageService.getUsageForProvider({
provider: "github",
accessToken: "gho_test",
providerSpecificData: {},
});
assert.equal(usage.plan, "Copilot Business");
assert.deepEqual(Object.keys(usage.quotas), ["premium_interactions"]);
assert.equal(usage.quotas.premium_interactions.total, 300);
assert.equal(usage.quotas.premium_interactions.used, 120);
assert.equal(usage.quotas.premium_interactions.remaining, 180);
assert.equal(usage.quotas.premium_interactions.remainingPercentage, 60);
const parsed = providerLimitUtils.parseQuotaData("github", usage);
assert.equal(parsed.length, 1);
assert.equal(parsed[0].name, "premium_interactions");
assert.equal(parsed[0].remainingPercentage, 60);
assert.equal(providerLimitUtils.normalizePlanTier(usage.plan).key, "business");
} finally {
globalThis.fetch = originalFetch;
}
});
test("github copilot individual paid plans no longer normalize as free", async () => {
const originalFetch = globalThis.fetch;
globalThis.fetch = async () =>
new Response(
JSON.stringify({
copilot_plan: "individual",
quota_reset_date: "2026-04-01T00:00:00Z",
quota_snapshots: {
premium_interactions: {
entitlement: 300,
remaining: 120,
unlimited: false,
},
},
}),
{
status: 200,
headers: { "content-type": "application/json" },
}
);
try {
const usage = await usageService.getUsageForProvider({
provider: "github",
accessToken: "gho_test",
providerSpecificData: {},
});
assert.equal(usage.plan, "Copilot Pro");
assert.equal(providerLimitUtils.normalizePlanTier(usage.plan).key, "pro");
assert.equal(providerLimitUtils.normalizePlanTier("individual").key, "unknown");
} finally {
globalThis.fetch = originalFetch;
}
});