mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-15 11:22:15 +03:00
Validado em lote numa worktree combinada com os 9 PRs desta leva sobre o tip de `release/v3.8.51`: `typecheck:core` limpo, `check:provider-consistency` OK (273 entradas REGISTRY, **356** providers canônicos), `check-docs-counts-sync` exit 0 e **300/300** nos testes que a leva toca. O crescimento de arquivo que os PRs empilham uns sobre os outros foi rebaselinado num único registro datado (`_rebaseline_2026_09_03_houminxi_batch`), com a decomposição por arquivo: `providers/page.tsx` +18 (import CSV do #12504 + busca do #12495 no mesmo painel), `accountFallback.ts` +6 (o #12566 sobre o rebaseline que o #12590 já registrou — os dois tocam `checkFallbackError`) e `chatCore.ts` +3 (invalidez de cache de quota no 429 do #12325). As violações restantes (`codex.ts`, `stream.ts`) foram medidas também no tip puro e são drift da base, não desta leva.
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
parseMoonshotOrigin,
|
|
moonshotBalanceUrl,
|
|
resolveMoonshotOrigin,
|
|
isMoonshotOpenPlatformConnection,
|
|
} from "../../open-sse/services/usage/moonshotOpenPlatform.ts";
|
|
|
|
const CN = "https://api.moonshot.cn/v1";
|
|
const AI = "https://api.moonshot.ai/v1";
|
|
const COMPAT = "openai-compatible-chat-e2971611-bc02-4c37-8fc5-39b8e3906fdf";
|
|
|
|
test("parseMoonshotOrigin accepts cn and ai hosts only", () => {
|
|
assert.equal(parseMoonshotOrigin(CN), "https://api.moonshot.cn");
|
|
assert.equal(
|
|
parseMoonshotOrigin("https://api.moonshot.cn/v1/chat/completions"),
|
|
"https://api.moonshot.cn",
|
|
);
|
|
assert.equal(parseMoonshotOrigin(AI), "https://api.moonshot.ai");
|
|
assert.equal(parseMoonshotOrigin("https://api.openai.com/v1"), null);
|
|
assert.equal(parseMoonshotOrigin("https://api.kimi.com/coding/v1"), null);
|
|
assert.equal(parseMoonshotOrigin(""), null);
|
|
assert.equal(parseMoonshotOrigin(null), null);
|
|
});
|
|
|
|
test("moonshotBalanceUrl stays on the connection origin", () => {
|
|
assert.equal(
|
|
moonshotBalanceUrl("https://api.moonshot.cn"),
|
|
"https://api.moonshot.cn/v1/users/me/balance",
|
|
);
|
|
assert.equal(
|
|
moonshotBalanceUrl("https://api.moonshot.ai"),
|
|
"https://api.moonshot.ai/v1/users/me/balance",
|
|
);
|
|
});
|
|
|
|
test("resolveMoonshotOrigin prefers psd.baseUrl over node", () => {
|
|
const origin = resolveMoonshotOrigin(
|
|
{
|
|
provider: COMPAT,
|
|
providerSpecificData: { baseUrl: CN },
|
|
},
|
|
"https://api.moonshot.ai/v1",
|
|
);
|
|
assert.equal(origin, "https://api.moonshot.cn");
|
|
});
|
|
|
|
test("resolveMoonshotOrigin uses node baseUrl when psd has none", () => {
|
|
const origin = resolveMoonshotOrigin({ provider: COMPAT, providerSpecificData: {} }, CN);
|
|
assert.equal(origin, "https://api.moonshot.cn");
|
|
});
|
|
|
|
test("resolveMoonshotOrigin uses built-in moonshot/kimi registry host", () => {
|
|
assert.equal(resolveMoonshotOrigin({ provider: "moonshot" }), "https://api.moonshot.ai");
|
|
assert.equal(resolveMoonshotOrigin({ provider: "kimi" }), "https://api.moonshot.ai");
|
|
});
|
|
|
|
test("isMoonshotOpenPlatformConnection is true for mnative-shaped rows", () => {
|
|
assert.equal(
|
|
isMoonshotOpenPlatformConnection({
|
|
provider: COMPAT,
|
|
providerSpecificData: { baseUrl: CN, prefix: "mnative" },
|
|
}),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
isMoonshotOpenPlatformConnection({ provider: "deepseek", providerSpecificData: {} }),
|
|
false,
|
|
);
|
|
assert.equal(isMoonshotOpenPlatformConnection({ provider: "moonshot" }), true);
|
|
});
|