mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-19 05:12:16 +03:00
Merged. Both Token Plan providers had no `modelsUrl` and no discovery config, so Sync Models never even tried a live request. Fetching the public Personal Plan catalog through `safeOutboundFetch` with fixed hosts, no inference keys and no cookies, validating the gateway envelope and reusing the DashScope text-model classifier keeps this narrow and safe; a failed or media-only result falls back without touching the previous catalog. Validated as a combined board first (this PR merged with the 4 siblings of the JxnLexn wave on the release tip): eslint with the frozen suppressions, typecheck:core, check:open-sse-typecheck, complexity, cognitive-complexity, changelog-integrity, docs-sync, migration-numbering, provider-consistency and a duplicate-identifier audit all green, plus 77 passing / 0 failing focused node:test cases across the test files the wave touches. The wave's i18n fill (new keys carried to all 66 locales), free-tier doc counts and file-size rebaseline land in one follow-up PR right after the wave, as with #13904. Thank you.
77 lines
2.6 KiB
TypeScript
77 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
buildTokenPlanCatalogRequest,
|
|
isTokenPlanCatalogProvider,
|
|
parseTokenPlanCatalog,
|
|
} from "../../src/lib/providerModels/tokenPlanModelDiscovery.ts";
|
|
|
|
function envelope(ids: unknown[]) {
|
|
return {
|
|
code: "200",
|
|
data: { success: true, DataV2: { data: { code: "200", success: true, data: ids } } },
|
|
};
|
|
}
|
|
|
|
test("Token Plan discovery uses regional public gateways without forwarding credentials", () => {
|
|
for (const provider of ["qwen-cloud-token-plan", "bailian-coding-plan"]) {
|
|
for (const region of ["global-sg", "china-beijing"]) {
|
|
const request = buildTokenPlanCatalogRequest(provider, {
|
|
region,
|
|
apiKey: "secret-key",
|
|
cookie: "secret-cookie",
|
|
baseUrl: "http://127.0.0.1/private",
|
|
});
|
|
const expectedHost =
|
|
region === "china-beijing"
|
|
? "cs-data.qianwenai.com"
|
|
: provider === "bailian-coding-plan"
|
|
? "bailian-singapore-cs.alibabacloud.com"
|
|
: "cs-data.qwencloud.com";
|
|
assert.equal(new URL(request.url).hostname, expectedHost);
|
|
assert.equal(request.init.method, "POST");
|
|
assert.equal(JSON.stringify(request).includes("secret"), false);
|
|
const data = JSON.parse(new URLSearchParams(request.init.body).get("params")!).Data;
|
|
assert.equal(data.edition, "PERSONAL");
|
|
}
|
|
}
|
|
assert.equal(isTokenPlanCatalogProvider("qwen-cloud"), false);
|
|
assert.equal(isTokenPlanCatalogProvider("alibaba"), false);
|
|
assert.throws(() => buildTokenPlanCatalogRequest("alibaba"));
|
|
});
|
|
|
|
test("live IDs survive without a static allowlist while media and duplicates are excluded", () => {
|
|
const models = parseTokenPlanCatalog(
|
|
envelope([
|
|
"qwen3.8-flash",
|
|
"deepseek-v4-pro-0813",
|
|
"glm-5.2",
|
|
"qwen-future-model",
|
|
"qwen3.8-flash",
|
|
"qwen-image-3.0-pro",
|
|
"wan2.7-image",
|
|
"happyhorse-1.1-i2v",
|
|
"qwen-audio-3.0-asr-flash",
|
|
"qwen-audio-3.0-realtime-plus",
|
|
"qwen-audio-3.0-tts-plus",
|
|
])
|
|
);
|
|
assert.deepEqual(
|
|
models.map(({ id }) => id),
|
|
["qwen3.8-flash", "deepseek-v4-pro-0813", "glm-5.2", "qwen-future-model"]
|
|
);
|
|
});
|
|
|
|
test("HTTP-success gateway errors and unusable catalogs cannot replace the cached list", () => {
|
|
for (const payload of [
|
|
{ code: "200", data: { success: false, errorCode: "LoginRequired" } },
|
|
envelope([]),
|
|
envelope(["qwen-image-3.0-pro"]),
|
|
envelope([null]),
|
|
envelope(["qwen-valid", "../bad"]),
|
|
"<html>login</html>",
|
|
]) {
|
|
assert.throws(() => parseTokenPlanCatalog(payload));
|
|
}
|
|
});
|