mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +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
83 lines
2.7 KiB
TypeScript
83 lines
2.7 KiB
TypeScript
// Characterization of the services/usage.ts deepseek split (god-file decomposition): the DeepSeek
|
|
// balance fetcher (getDeepseekUsage) moved into services/usage/deepseek.ts so usage.ts stays a
|
|
// thin dispatcher. Behavior-preserving move — this locks the export surface and the
|
|
// credits-style shaping; the full balance matrix is covered via getUsageForProvider in
|
|
// usage-service-deepseek.test.ts.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const D = await import("../../open-sse/services/usage/deepseek.ts");
|
|
|
|
test("module exposes getDeepseekUsage", () => {
|
|
assert.equal(typeof D.getDeepseekUsage, "function");
|
|
});
|
|
|
|
test("getDeepseekUsage surfaces USD + CNY balances as unlimited credits entries", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
globalThis.fetch = async () =>
|
|
new Response(
|
|
JSON.stringify({
|
|
is_available: true,
|
|
balance_infos: [
|
|
{
|
|
currency: "CNY",
|
|
total_balance: "1000.00",
|
|
granted_balance: "0.00",
|
|
topped_up_balance: "1000.00",
|
|
},
|
|
{
|
|
currency: "USD",
|
|
total_balance: "50.00",
|
|
granted_balance: "5.00",
|
|
topped_up_balance: "45.00",
|
|
},
|
|
],
|
|
}),
|
|
{ status: 200, headers: { "content-type": "application/json" } }
|
|
);
|
|
try {
|
|
const r = (await D.getDeepseekUsage("conn-multi", "k")) as {
|
|
plan?: string;
|
|
quotas?: Record<string, { remaining: number; currency: string; unlimited: boolean }>;
|
|
};
|
|
assert.equal(r.plan, "DeepSeek");
|
|
assert.equal(r.quotas?.credits_usd.remaining, 50);
|
|
assert.equal(r.quotas?.credits_usd.currency, "USD");
|
|
assert.equal(r.quotas?.credits_cny.remaining, 1000);
|
|
assert.equal(r.quotas?.credits_usd.unlimited, true);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|
|
|
|
test("getDeepseekUsage labels the plan '(Insufficient Balance)' when is_available is false", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
globalThis.fetch = async () =>
|
|
new Response(
|
|
JSON.stringify({
|
|
is_available: false,
|
|
balance_infos: [
|
|
{
|
|
currency: "USD",
|
|
total_balance: "0.00",
|
|
granted_balance: "0.00",
|
|
topped_up_balance: "0.00",
|
|
},
|
|
],
|
|
}),
|
|
{ status: 200, headers: { "content-type": "application/json" } }
|
|
);
|
|
try {
|
|
const r = (await D.getDeepseekUsage("conn-empty", "k")) as {
|
|
plan?: string;
|
|
isAvailable?: boolean;
|
|
limitReached?: boolean;
|
|
};
|
|
assert.equal(r.plan, "DeepSeek (Insufficient Balance)");
|
|
assert.equal(r.isAvailable, false);
|
|
assert.equal(r.limitReached, true);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|