mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* chore(usage): extract crof, nanogpt, qoder, opencode, deepseek, bailian, vertex, xiaomi-mimo, xai, github usage fetchers into usage/* leaves Decompose services/usage.ts (god-file phase 1): move the remaining per-provider usage fetcher/parser logic into co-located leaves under open-sse/services/usage/ so usage.ts becomes a thin dispatcher (imports + USAGE_FETCHER_PROVIDERS + getUsageForProvider switch + __testing re-exports). New leaves (each a pure data transform or independent fetcher, no orchestration): - usage/github.ts getGitHubUsage, formatGitHubQuotaSnapshot, inferGitHubPlanName, shouldDisplayGitHubQuota - usage/crof.ts getCrofUsage - usage/nanogpt.ts getNanoGptUsage - usage/qoder.ts getQoderUsage, parseQoderUserStatusUsage - usage/opencode.ts getOpencodeUsage - usage/deepseek.ts getDeepseekUsage - usage/bailian.ts getBailianCodingPlanUsage - usage/vertex.ts getVertexUsage - usage/xiaomi-mimo.ts getXiaomiMimoUsage - usage/xai.ts getXaiUsage usage.ts re-exports parseQoderUserStatusUsage (named) and threads every helper the existing __testing contract exposes (usage-utils / usage-service-hardening / qoder-usage-quota / xiaomi-mimo-selftrack / xai-usage / vertex-spend suites read them from services/usage). External importers unchanged. open-sse/services/usage.ts: 1065 -> 256 lines (cap 800). npm run check:file-size: OK. typecheck:core: OK. eslint: clean. check:cycles: OK. Added characterization tests (tests/unit/usage-<provider>-split.test.ts) that import each leaf directly and pin its export surface + key edges, mirroring the existing usage-quota-core-split / usage-scalars-split pattern. * docs(changelog): add fragment for this PR
62 lines
2.4 KiB
TypeScript
62 lines
2.4 KiB
TypeScript
// Characterization of the services/usage.ts qoder split (god-file decomposition): the Qoder
|
|
// /api/v3/user/status fetcher (getQoderUsage) + the pure status→quotas mapper
|
|
// (parseQoderUserStatusUsage) + the plan-label prettifier moved into services/usage/qoder.ts so
|
|
// usage.ts stays a thin dispatcher. Behavior-preserving move — these locks pin the export surface
|
|
// and the pure parser edges already covered via __testing in qoder-usage-quota.test.ts.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const Q = await import("../../open-sse/services/usage/qoder.ts");
|
|
|
|
test("module exposes getQoderUsage + parseQoderUserStatusUsage", () => {
|
|
assert.equal(typeof Q.getQoderUsage, "function");
|
|
assert.equal(typeof Q.parseQoderUserStatusUsage, "function");
|
|
});
|
|
|
|
test("getQoderUsage returns a Personal Access Token prompt when no token is present", async () => {
|
|
const r = (await Q.getQoderUsage(undefined, {})) as { message?: string };
|
|
assert.match(r.message ?? "", /Personal Access Token/i);
|
|
});
|
|
|
|
test("parseQoderUserStatusUsage maps a Teams/pooled seat to an unlimited plan entry", () => {
|
|
const { plan, quotas } = Q.parseQoderUserStatusUsage({
|
|
userType: "teams",
|
|
userTag: "Teams",
|
|
plan: "PLAN_TIER_TEAM",
|
|
quota: 0,
|
|
isQuotaExceeded: false,
|
|
nextResetAt: 1784736000000,
|
|
});
|
|
assert.equal(plan, "Teams");
|
|
assert.deepEqual(Object.keys(quotas), ["Plan"]);
|
|
assert.equal(quotas.Plan.unlimited, true);
|
|
assert.equal(quotas.Plan.remainingPercentage, 100);
|
|
});
|
|
|
|
test("parseQoderUserStatusUsage maps an individual plan with remaining quota to a Requests entry", () => {
|
|
const { plan, quotas } = Q.parseQoderUserStatusUsage({
|
|
userType: "individual",
|
|
plan: "PLAN_TIER_PRO",
|
|
quota: 42,
|
|
isQuotaExceeded: false,
|
|
nextResetAt: 1784736000000,
|
|
});
|
|
assert.equal(plan, "Pro");
|
|
assert.deepEqual(Object.keys(quotas), ["Requests"]);
|
|
assert.equal(quotas.Requests.remaining, 42);
|
|
assert.equal(quotas.Requests.unlimited, false);
|
|
});
|
|
|
|
test("parseQoderUserStatusUsage flags an exceeded quota", () => {
|
|
const { quotas } = Q.parseQoderUserStatusUsage({
|
|
userType: "individual",
|
|
plan: "PLAN_TIER_FREE",
|
|
quota: 100,
|
|
isQuotaExceeded: true,
|
|
nextResetAt: 1784736000000,
|
|
});
|
|
assert.deepEqual(Object.keys(quotas), ["Quota"]);
|
|
assert.equal(quotas.Quota.remaining, 0);
|
|
assert.match(quotas.Quota.displayName!, /exceeded/i);
|
|
});
|