mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-15 19:32:20 +03:00
* test(infra): retry recursive temp-dir removal on main (main twin of #11968)
`main` has been red since b342c1a361 on the vitest and integration gates:
✖ tests/unit/autoCombo/provider-family-combos.test.ts > auto/<family>
✖ chat pipeline applies Codex OAuth fingerprint and priority tier inside combos
Both call resetStorage() from beforeEach, which does an fs.rmSync(TEST_DATA_DIR,
{recursive: true, force: true}) with no retry, and intermittently loses the race
with a not-yet-released SQLite handle (ENOTEMPTY).
release/v3.8.51 fixed this in #11968 with a mechanical codemod adding
maxRetries/retryDelay to every recursive rm/rmSync/rmdirSync under tests/, but
that PR landed only on the release branch. Because main only receives work at
the release squash, it stayed broken for the whole cycle — and repo-wide gates
then turn every open PR into main red on checks unrelated to their diff.
This is the --base main twin: re-runs the same codemod that already shipped on
the release branch (scripts/ad-hoc/codemod-rm-maxretries.mjs), so the two
branches converge on identical test-teardown semantics. Test-only; no product
logic is touched.
The remaining three failures reported on #12133 (unit full suite exceeding its
4800s ceiling, package-artifact exceeding 1200s, and the boot-smoke that is
skipped as a consequence) are runner-contention timeouts, not code defects —
validate-release-green.mjs runs those heavy gates concurrently on one shared
hosted runner. There is no fix to port for those.
* chore(scripts): carry the rm-maxretries codemod onto main alongside its output
The codemod that generated the previous commit lives in the repo on
release/v3.8.51 (added by #11968) but was never on main. Bringing it over keeps
the tool next to the change it produced, so the transformation stays
reproducible and auditable from either branch.
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;
|
|
}
|
|
});
|