Files
OmniRoute/tests/unit/cli/launch-codex.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

68 lines
2.7 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import {
buildCodexEnv,
buildCodexProviderArgs,
resolveCodexTarget,
} from "../../../bin/cli/commands/launch-codex.mjs";
test("buildCodexEnv strips stale OpenAI/Codex creds from the child env (defense-in-depth)", () => {
const env = buildCodexEnv(
{
OPENAI_API_KEY: "leak",
OPENAI_BASE_URL: "https://api.openai.com/v1",
OPENAI_ORG_ID: "org",
CODEX_API_KEY: "leak2",
PATH: "/bin",
},
"oma_live_x"
);
assert.equal(env.OPENAI_API_KEY, undefined);
assert.equal(env.OPENAI_BASE_URL, undefined);
assert.equal(env.OPENAI_ORG_ID, undefined);
assert.equal(env.CODEX_API_KEY, undefined);
assert.equal(env.OMNIROUTE_API_KEY, "oma_live_x");
assert.equal(env.PATH, "/bin", "unrelated vars preserved");
});
test("buildCodexEnv uses a no-auth sentinel when no token is given", () => {
const env = buildCodexEnv({ PATH: "/bin" }, undefined);
assert.equal(env.OMNIROUTE_API_KEY, "omniroute-no-auth");
});
test("buildCodexEnv does not mutate the input env", () => {
const input = { OPENAI_API_KEY: "leak", PATH: "/bin" };
buildCodexEnv(input, "x");
assert.equal(input.OPENAI_API_KEY, "leak");
});
test("buildCodexProviderArgs defines the omniroute provider inline (works without config.toml)", () => {
const args = buildCodexProviderArgs("http://vps:20128");
const joined = args.join(" ");
assert.ok(joined.includes('model_provider="omniroute"'));
assert.ok(joined.includes('model_providers.omniroute.base_url="http://vps:20128/v1"'));
assert.ok(joined.includes('model_providers.omniroute.env_key="OMNIROUTE_API_KEY"'));
assert.ok(joined.includes('model_providers.omniroute.wire_api="responses"'));
assert.ok(joined.includes("model_providers.omniroute.requires_openai_auth=false"));
// each assignment is preceded by a -c flag
assert.equal(args.filter((a) => a === "-c").length, 6);
});
test("buildCodexProviderArgs accepts a model id and serializes it into provider args", () => {
const args = buildCodexProviderArgs("http://vps:20128", "glm/glm-4.5");
assert.equal(args.includes("-c"), true);
assert.ok(args.some((arg) => arg === 'model_providers.omniroute.model="glm/glm-4.5"'));
// model is optional => previous 6 assignments + one extra
assert.equal(args.filter((a) => a === "-c").length, 7);
});
test("resolveCodexTarget: --remote wins and /v1 is stripped from the root", () => {
const { baseUrl } = resolveCodexTarget({ remote: "http://vps:20128/v1" });
assert.equal(baseUrl, "http://vps:20128");
});
test("resolveCodexTarget: explicit --api-key wins", () => {
const { authToken } = resolveCodexTarget({ remote: "http://x:20128", apiKey: "tok-explicit" });
assert.equal(authToken, "tok-explicit");
});