mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +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.
122 lines
4.8 KiB
TypeScript
122 lines
4.8 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";
|
|
|
|
// #4264: When a provider key is imported and its models are synced, the synced
|
|
// model records dropped the vision capability — OpenRouter (and other catalogs)
|
|
// declare image input via `architecture.input_modalities` / `architecture.modality`,
|
|
// but `SyncedAvailableModel` never captured it, and the `/v1/models` catalog only
|
|
// derived vision from the OpenRouter live block, which is SKIPPED once a provider
|
|
// has synced models. So vision-capable models showed up as non-vision after import.
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-or-vision-4264-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET || "vision-4264-secret";
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const providersDb = await import("../../src/lib/db/providers.ts");
|
|
const apiKeysDb = await import("../../src/lib/db/apiKeys.ts");
|
|
const modelDiscovery = await import("../../src/lib/providerModels/modelDiscovery.ts");
|
|
const v1ModelsCatalog = await import("../../src/app/api/v1/models/catalog.ts");
|
|
|
|
async function resetStorage() {
|
|
core.resetDbInstance();
|
|
apiKeysDb.resetApiKeyState();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
}
|
|
|
|
test.beforeEach(async () => {
|
|
await resetStorage();
|
|
});
|
|
|
|
test.after(async () => {
|
|
core.resetDbInstance();
|
|
apiKeysDb.resetApiKeyState();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
test("#4264 normalizeDiscoveredModels captures vision from OpenRouter architecture", () => {
|
|
const out = modelDiscovery.normalizeDiscoveredModels([
|
|
{
|
|
id: "nex-agi/nex-n2-pro:free",
|
|
name: "Nex N2 Pro (free)",
|
|
architecture: { modality: "text+image->text", input_modalities: ["text", "image"] },
|
|
},
|
|
{
|
|
// string-form modality only (no input_modalities array)
|
|
id: "modality/string-only",
|
|
name: "Str modality",
|
|
architecture: { modality: "text+image->text" },
|
|
},
|
|
{
|
|
id: "some/text-only",
|
|
name: "Text Only",
|
|
architecture: { modality: "text->text", input_modalities: ["text"] },
|
|
},
|
|
{
|
|
// top-level input_modalities (no architecture wrapper)
|
|
id: "toplevel/vision",
|
|
name: "Top-level modalities",
|
|
input_modalities: ["text", "image"],
|
|
},
|
|
]);
|
|
const byId = Object.fromEntries(out.map((m: any) => [m.id, m]));
|
|
|
|
assert.equal(byId["nex-agi/nex-n2-pro:free"].supportsVision, true);
|
|
assert.equal(byId["modality/string-only"].supportsVision, true);
|
|
assert.equal(byId["toplevel/vision"].supportsVision, true);
|
|
assert.equal(byId["some/text-only"].supportsVision, undefined);
|
|
});
|
|
|
|
test("#4264 synced OpenRouter vision model surfaces capabilities.vision in /v1/models", async () => {
|
|
const connection = await providersDb.createProviderConnection({
|
|
provider: "openrouter",
|
|
authType: "apikey",
|
|
name: "openrouter-test",
|
|
apiKey: "sk-or-test",
|
|
isActive: true,
|
|
testStatus: "active",
|
|
providerSpecificData: {},
|
|
});
|
|
|
|
// Simulate "import models": persist the raw OpenRouter /models entries (with
|
|
// architecture) through the real discovery path. Having synced models makes the
|
|
// catalog use the synced path (the OpenRouter live-enrichment block is skipped),
|
|
// which is exactly the path that dropped vision before this fix.
|
|
await modelDiscovery.persistDiscoveredModels("openrouter", connection.id, [
|
|
{
|
|
id: "nex-agi/nex-n2-pro:free",
|
|
name: "Nex AGI: Nex-N2-Pro (free)",
|
|
architecture: { modality: "text+image->text", input_modalities: ["text", "image"] },
|
|
context_length: 262144,
|
|
},
|
|
{
|
|
id: "some/text-only-model",
|
|
name: "Text Only Model",
|
|
architecture: { modality: "text->text", input_modalities: ["text"] },
|
|
context_length: 32768,
|
|
},
|
|
]);
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
assert.equal(response.status, 200);
|
|
const body = (await response.json()) as any;
|
|
|
|
const visionModel = body.data.find((m: any) => String(m.id).endsWith("nex-agi/nex-n2-pro:free"));
|
|
assert.ok(visionModel, `expected the synced vision model in the catalog`);
|
|
// RED before the fix: synced models carried no capabilities at all.
|
|
assert.equal(visionModel.capabilities?.vision, true);
|
|
|
|
const textModel = body.data.find((m: any) => String(m.id).endsWith("some/text-only-model"));
|
|
assert.ok(textModel, `expected the synced text-only model in the catalog`);
|
|
assert.ok(
|
|
!textModel.capabilities || textModel.capabilities.vision !== true,
|
|
`text-only model must not be marked vision-capable`
|
|
);
|
|
});
|