mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 02:42:24 +03:00
* test(infra): retry recursive temp-dir removal instead of failing a shard on ENOTEMPTY (#11966) Two shards on release/v3.8.51 went red in one day with the same signature — "ENOTEMPTY, Directory not empty: /tmp/omniroute-<test>-XXXXXX" — from combo-same-provider-cascade (Unit Tests fast-path 4/4, on a PR that touches only .github/) and auth-policy-embeddings-webfetch-7785 (the 20k-test TIA step). Both pass alone and on re-run: the cleanup races something still writing into the directory (SQLite WAL/-shm checkpoint, a worker, the backup) and under a loaded hosted runner the window opens. 1154 test files do their own cleanup with fs.rmSync(dir, { recursive: true, force: true }); 57 already asked for retries. One-shot codemod (scripts/ad-hoc/codemod-rm-maxretries.mjs, kept for the record): every rm / rmSync / rmdirSync option object with `recursive: true` and no `maxRetries` gains `maxRetries: 5, retryDelay: 100` — Node itself then retries ENOTEMPTY/EBUSY/EPERM for up to ~0.5 s before giving up. 2243 call sites in 1292 files under tests/, the shared tests/_setup/isolateDataDir.ts exit hook included. Only the option object changes: no call site, assertion or import is touched. Validation: prettier and ESLint (with the frozen suppressions) clean on all 1292 files; a random 20-file sample runs green (quota-redis-store hangs identically on the untouched tree — it needs a Redis on localhost, an environment matter). The four unit shards on this PR are the full run. * fix(quality): let check-forgotten-sibling-tests read a 1,000-file diff The gate shells out to `git diff` through execFileSync with Node's default 1 MB maxBuffer; the 1,292-file codemod in this PR is the first diff large enough to overflow it, and the gate died with `spawnSync git ENOBUFS` before comparing anything. 64 MB is far above any real PR and costs nothing when unused.
226 lines
7.2 KiB
TypeScript
226 lines
7.2 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-dashscope-models-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const providersDb = await import("../../src/lib/db/providers.ts");
|
|
const modelsDb = await import("../../src/lib/db/models.ts");
|
|
const modelsRoute = await import("../../src/app/api/providers/[id]/models/route.ts");
|
|
|
|
const ALIBABA_MODEL_STUDIO_MODEL_IDS = [
|
|
"qwen3.7-max",
|
|
"qwen3.7-plus",
|
|
"qwen3.6-plus",
|
|
"qwen3.6-27b",
|
|
"qwen3.6-35b-a3b",
|
|
"qwen3.5-plus",
|
|
"qwen3.5-122b-a10b",
|
|
"qwen3.5-397b-a17b",
|
|
"glm-5.2",
|
|
"glm-5.2-fast-preview",
|
|
"deepseek-v4-pro",
|
|
"deepseek-v4-flash",
|
|
"kimi-k2.7-code",
|
|
];
|
|
|
|
const QWEN_CLOUD_TEXT_MODEL_IDS = [
|
|
"qwen3.7-max-2026-06-08",
|
|
"qwen3.7-plus",
|
|
"qwen3.6-plus",
|
|
"qwen3.6-27b",
|
|
"qwen3.6-35b-a3b",
|
|
"qwen3.5-plus-2026-04-20",
|
|
"qwen3.5-122b-a10b",
|
|
"qwen3.5-397b-a17b",
|
|
"glm-5.2",
|
|
"glm-5.2-fast-preview",
|
|
"deepseek-v4-pro",
|
|
"deepseek-v4-flash",
|
|
"kimi-k2.7-code",
|
|
];
|
|
|
|
const ALL_DASHSCOPE_TEXT_MODEL_IDS = [
|
|
...QWEN_CLOUD_TEXT_MODEL_IDS,
|
|
...ALIBABA_MODEL_STUDIO_MODEL_IDS,
|
|
"qwen3-coder-next",
|
|
"qwen-mt-plus",
|
|
"MiniMax-M2.5",
|
|
];
|
|
const UPSTREAM_TEXT_MODEL_IDS = [...ALL_DASHSCOPE_TEXT_MODEL_IDS].reverse();
|
|
|
|
const MIXED_DASHSCOPE_MODELS = [
|
|
...UPSTREAM_TEXT_MODEL_IDS.map((id) => ({
|
|
id,
|
|
object: "model",
|
|
owned_by: "system",
|
|
})),
|
|
{ id: "qwen-image-2.0-pro", object: "model", owned_by: "system" },
|
|
{ id: "wan2.7-image-pro", object: "model", owned_by: "system" },
|
|
{ id: "qwen3-tts-flash", object: "model", owned_by: "system" },
|
|
{ id: "qwen3-asr-flash", object: "model", owned_by: "system" },
|
|
{ id: "qwen3.5-omni-plus", object: "model", owned_by: "system" },
|
|
{ id: "qwen3-vl-plus", object: "model", owned_by: "system" },
|
|
{ id: "qwen3-rerank", object: "model", owned_by: "system" },
|
|
{ id: "text-embedding-v4", object: "model", owned_by: "system" },
|
|
{ id: "qvq-max", object: "model", owned_by: "system" },
|
|
{ id: "ccai-pro", object: "model", owned_by: "system" },
|
|
];
|
|
|
|
async function resetStorage() {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
}
|
|
|
|
async function assertTextOnlyDiscovery({
|
|
provider,
|
|
region,
|
|
expectedUrl,
|
|
expectedModelIds,
|
|
}: {
|
|
provider: "alibaba" | "alibaba-cn" | "qwen-cloud";
|
|
region?: "global-sg" | "china-beijing";
|
|
expectedUrl: string;
|
|
expectedModelIds: string[];
|
|
}) {
|
|
await resetStorage();
|
|
const connection = await providersDb.createProviderConnection({
|
|
provider,
|
|
authType: "apikey",
|
|
name: `${provider}-live-text`,
|
|
apiKey: "test-dashscope-key",
|
|
...(region ? { providerSpecificData: { region } } : {}),
|
|
});
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection(provider, connection.id, [
|
|
{ id: "qwen-image-stale", name: "Stale image model", source: "imported" },
|
|
]);
|
|
|
|
let fetchCalls = 0;
|
|
let requestedUrl = "";
|
|
const originalFetch = globalThis.fetch;
|
|
globalThis.fetch = (async (input) => {
|
|
fetchCalls += 1;
|
|
requestedUrl = typeof input === "string" ? input : input.toString();
|
|
return new Response(JSON.stringify({ object: "list", data: MIXED_DASHSCOPE_MODELS }), {
|
|
status: 200,
|
|
headers: { "Content-Type": "application/json" },
|
|
});
|
|
}) as typeof globalThis.fetch;
|
|
|
|
try {
|
|
const response = await modelsRoute.GET(
|
|
new Request(`http://localhost/api/providers/${connection.id}/models?refresh=true`),
|
|
{ params: { id: connection.id } }
|
|
);
|
|
assert.equal(response.status, 200);
|
|
const body = await response.json();
|
|
assert.equal(body.source, "api");
|
|
assert.deepEqual(
|
|
body.models.map((model: { id: string }) => model.id),
|
|
expectedModelIds
|
|
);
|
|
assert.equal(requestedUrl, expectedUrl);
|
|
assert.equal(fetchCalls, 1);
|
|
|
|
const persisted = await modelsDb.getSyncedAvailableModelsForConnection(provider, connection.id);
|
|
assert.deepEqual(
|
|
persisted.map((model) => model.id),
|
|
expectedModelIds
|
|
);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
}
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
test("Qwen Cloud syncs only text models from the selected Beijing region", async () => {
|
|
await assertTextOnlyDiscovery({
|
|
provider: "qwen-cloud",
|
|
region: "china-beijing",
|
|
expectedUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1/models",
|
|
expectedModelIds: QWEN_CLOUD_TEXT_MODEL_IDS,
|
|
});
|
|
});
|
|
|
|
test("Alibaba syncs only text models from the selected Global region", async () => {
|
|
await assertTextOnlyDiscovery({
|
|
provider: "alibaba",
|
|
region: "global-sg",
|
|
expectedUrl: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",
|
|
expectedModelIds: ALIBABA_MODEL_STUDIO_MODEL_IDS,
|
|
});
|
|
});
|
|
|
|
test("Alibaba syncs only text models from the selected Beijing region", async () => {
|
|
await assertTextOnlyDiscovery({
|
|
provider: "alibaba",
|
|
region: "china-beijing",
|
|
expectedUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1/models",
|
|
expectedModelIds: ALIBABA_MODEL_STUDIO_MODEL_IDS,
|
|
});
|
|
});
|
|
|
|
test("legacy Alibaba China connections also sync only Beijing text models", async () => {
|
|
await assertTextOnlyDiscovery({
|
|
provider: "alibaba-cn",
|
|
expectedUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1/models",
|
|
expectedModelIds: ALIBABA_MODEL_STUDIO_MODEL_IDS,
|
|
});
|
|
});
|
|
|
|
test("Alibaba free billing mode syncs all live text models, not only the curated catalog", async () => {
|
|
await resetStorage();
|
|
const connection = await providersDb.createProviderConnection({
|
|
provider: "alibaba",
|
|
authType: "apikey",
|
|
name: "alibaba-free-live",
|
|
apiKey: "test-dashscope-key",
|
|
providerSpecificData: { region: "global-sg", alibabaBillingMode: "free" },
|
|
});
|
|
|
|
const originalFetch = globalThis.fetch;
|
|
globalThis.fetch = (async () =>
|
|
new Response(JSON.stringify({ object: "list", data: MIXED_DASHSCOPE_MODELS }), {
|
|
status: 200,
|
|
headers: { "Content-Type": "application/json" },
|
|
})) as typeof globalThis.fetch;
|
|
|
|
try {
|
|
const response = await modelsRoute.GET(
|
|
new Request(`http://localhost/api/providers/${connection.id}/models?refresh=true`),
|
|
{ params: { id: connection.id } }
|
|
);
|
|
assert.equal(response.status, 200);
|
|
const body = await response.json();
|
|
assert.ok(
|
|
body.models.length > ALIBABA_MODEL_STUDIO_MODEL_IDS.length,
|
|
"free billing mode should expose more than the curated catalog"
|
|
);
|
|
assert.ok(
|
|
body.models.some((model: { id: string }) => model.id === "qwen3-coder-next"),
|
|
"expected upstream-only free-tier model to be included"
|
|
);
|
|
assert.equal(
|
|
body.models.some((model: { id: string }) => model.id === "qwen-image-2.0-pro"),
|
|
false,
|
|
"non-text models must still be filtered out"
|
|
);
|
|
assert.equal(
|
|
body.models.some((model: { id: string }) => model.id === "kimi-k2.7-code"),
|
|
false,
|
|
"third-party paid-only models must be excluded from free billing discovery"
|
|
);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|