Files
OmniRoute/tests/unit/codex-synced-bare-model-routing.test.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
2026-08-23 11:45:01 -03:00

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 });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
});
test.after(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
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");
});