mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-21 14:22:14 +03:00
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.
162 lines
5.9 KiB
TypeScript
162 lines
5.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-codex-synced-routing-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const modelsDb = await import("../../src/lib/db/models.ts");
|
|
const providersDb = await import("../../src/lib/db/providers.ts");
|
|
const { getModelInfoCore } = await import("../../open-sse/services/model.ts");
|
|
|
|
type TestProvider = "anthropic" | "codex" | "openai";
|
|
|
|
const GPT_56_CODEX_MODEL = "gpt-5.6-sol";
|
|
const FUTURE_CODEX_MODEL = "codex-next-preview";
|
|
const FUTURE_NON_GPT_MODEL = "orion-preview-2027";
|
|
|
|
async function seedConnection(provider: TestProvider, isActive = true) {
|
|
return providersDb.createProviderConnection({
|
|
provider,
|
|
authType: provider === "codex" ? "oauth" : "apikey",
|
|
name: `${provider}-routing-test`,
|
|
email: provider === "codex" ? `${provider}@example.com` : undefined,
|
|
apiKey: provider !== "codex" ? `sk-${provider}-routing-test` : undefined,
|
|
isActive,
|
|
providerSpecificData: provider === "codex" ? { workspaceId: "ws-routing-test" } : undefined,
|
|
});
|
|
}
|
|
|
|
async function seedSyncedModel(provider: TestProvider, modelId: string, isActive = true) {
|
|
const connection = await seedConnection(provider, isActive);
|
|
assert.ok(connection?.id, `${provider} connection must be created`);
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection(provider, String(connection.id), [
|
|
{
|
|
id: modelId,
|
|
name: modelId,
|
|
apiFormat: "openai-responses",
|
|
supportedEndpoints: ["chat"],
|
|
},
|
|
]);
|
|
return connection;
|
|
}
|
|
|
|
test.beforeEach(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
});
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
test("bare GPT-5.6 model routes through Codex when it is the only active provider", async () => {
|
|
await seedSyncedModel("codex", GPT_56_CODEX_MODEL);
|
|
|
|
const info = await getModelInfoCore(GPT_56_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "codex");
|
|
assert.equal(info.model, GPT_56_CODEX_MODEL);
|
|
});
|
|
|
|
// #9275 put the whole gpt-5.6-sol tier set into CODEX_NATIVE_UNPREFIXED_MODELS, so an
|
|
// active Codex connection now claims the bare id ahead of OpenAI. Before, OpenAI won the
|
|
// overlap; the escape hatch is the explicit prefix, covered by the last test in this file.
|
|
test("Codex claims the bare model when both providers advertise it", async () => {
|
|
await seedSyncedModel("codex", GPT_56_CODEX_MODEL);
|
|
await seedSyncedModel("openai", GPT_56_CODEX_MODEL);
|
|
|
|
const info = await getModelInfoCore(GPT_56_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "codex");
|
|
assert.equal(info.model, GPT_56_CODEX_MODEL);
|
|
});
|
|
|
|
test("Codex is inferred when only its active catalog advertises the model", async () => {
|
|
await seedSyncedModel("codex", FUTURE_CODEX_MODEL);
|
|
await seedConnection("openai");
|
|
|
|
const info = await getModelInfoCore(FUTURE_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "codex");
|
|
assert.equal(info.model, FUTURE_CODEX_MODEL);
|
|
});
|
|
|
|
test("non-GPT models use the same active synchronized-catalog inference", async () => {
|
|
await seedSyncedModel("anthropic", FUTURE_NON_GPT_MODEL);
|
|
|
|
const info = await getModelInfoCore(FUTURE_NON_GPT_MODEL, null);
|
|
|
|
assert.equal(info.provider, "anthropic");
|
|
assert.equal(info.model, FUTURE_NON_GPT_MODEL);
|
|
});
|
|
|
|
test("OpenAI remains selected when it is the only active provider advertising the model", async () => {
|
|
await seedSyncedModel("openai", GPT_56_CODEX_MODEL);
|
|
|
|
const info = await getModelInfoCore(GPT_56_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "openai");
|
|
assert.equal(info.model, GPT_56_CODEX_MODEL);
|
|
});
|
|
|
|
test("inactive Codex synchronized models do not influence bare-model routing", async () => {
|
|
await seedSyncedModel("codex", GPT_56_CODEX_MODEL, false);
|
|
await seedSyncedModel("openai", GPT_56_CODEX_MODEL);
|
|
|
|
const info = await getModelInfoCore(GPT_56_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "openai");
|
|
assert.equal(info.model, GPT_56_CODEX_MODEL);
|
|
});
|
|
|
|
test("Codex claims an overlapping static model when both connections are active", async () => {
|
|
await seedConnection("codex");
|
|
await seedConnection("openai");
|
|
|
|
const info = await getModelInfoCore("gpt-5.5", null);
|
|
|
|
assert.equal(info.provider, "codex");
|
|
assert.equal(info.model, "gpt-5.5");
|
|
});
|
|
|
|
// The regression #9275 introduced and this file now guards: the Codex-native set must
|
|
// never claim a bare id when no codex connection is active — an OpenAI-only install
|
|
// would get "no active credentials for provider: codex" for a model OpenAI serves.
|
|
test("a Codex-native bare id stays on OpenAI when no codex connection exists", async () => {
|
|
await seedConnection("openai");
|
|
|
|
const info = await getModelInfoCore("gpt-5.5", null);
|
|
|
|
assert.equal(info.provider, "openai");
|
|
assert.equal(info.model, "gpt-5.5");
|
|
});
|
|
|
|
test("OpenAI remains selected for an overlapping static model when Codex is inactive", async () => {
|
|
await seedConnection("codex", false);
|
|
await seedConnection("openai");
|
|
|
|
const info = await getModelInfoCore("gpt-5.5", null);
|
|
|
|
assert.equal(info.provider, "openai");
|
|
assert.equal(info.model, "gpt-5.5");
|
|
});
|
|
|
|
test("explicit Codex and OpenAI prefixes remain authoritative", async () => {
|
|
await seedSyncedModel("codex", GPT_56_CODEX_MODEL);
|
|
await seedSyncedModel("openai", GPT_56_CODEX_MODEL);
|
|
|
|
const codexAlias = await getModelInfoCore(`cx/${GPT_56_CODEX_MODEL}`, null);
|
|
const codexCanonical = await getModelInfoCore(`codex/${GPT_56_CODEX_MODEL}`, null);
|
|
const openai = await getModelInfoCore(`openai/${GPT_56_CODEX_MODEL}`, null);
|
|
|
|
assert.equal(codexAlias.provider, "codex");
|
|
assert.equal(codexCanonical.provider, "codex");
|
|
assert.equal(openai.provider, "openai");
|
|
});
|