| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| import test from "node:test";
|
| import assert from "node:assert/strict";
|
| import type { Config } from "@opencode-ai/plugin";
|
|
|
| import {
|
| buildStaticProviderEntry,
|
| createOmniRouteConfigHook,
|
| createOmniRouteProviderHook,
|
| OmniRoutePlugin,
|
| resolveOmniRoutePluginOptions,
|
| type OmniRouteCombosFetcher,
|
| type OmniRouteEnrichmentEntry,
|
| type OmniRouteEnrichmentFetcher,
|
| type OmniRouteEnrichmentMap,
|
| type OmniRouteFetchCache,
|
| type OmniRouteModelsFetcher,
|
| type OmniRouteProviderConnection,
|
| type OmniRouteProvidersFetcher,
|
| type OmniRouteRawCombo,
|
| type OmniRouteRawModelEntry,
|
| type OmniRouteReadAuthJson,
|
| type OmniRouteStaticProviderEntry,
|
| } from "../src/index.js";
|
|
|
|
|
|
|
|
|
|
|
| const MODEL_CLAUDE: OmniRouteRawModelEntry = {
|
| id: "claude-sonnet-4-6",
|
| capabilities: {
|
| tool_calling: true,
|
| reasoning: true,
|
| vision: true,
|
| thinking: false,
|
| temperature: true,
|
| },
|
| context_length: 200_000,
|
| max_output_tokens: 64_000,
|
| max_input_tokens: 180_000,
|
| input_modalities: ["text", "image"],
|
| output_modalities: ["text"],
|
| };
|
|
|
| const MODEL_GEMINI: OmniRouteRawModelEntry = {
|
| id: "gemini-3-flash",
|
| capabilities: { tool_calling: true, reasoning: false, vision: true, thinking: false },
|
| context_length: 1_000_000,
|
| max_output_tokens: 8_192,
|
| input_modalities: ["text", "image"],
|
| output_modalities: ["text"],
|
| };
|
|
|
| const COMBO_CLAUDE_TIER: OmniRouteRawCombo = {
|
| id: "combo-claude-tier",
|
| name: "Claude Tier",
|
| models: [
|
| { id: "s1", kind: "model", model: "claude-sonnet-4-6", weight: 100 },
|
| { id: "s2", kind: "model", model: "gemini-3-flash", weight: 50 },
|
| ],
|
| };
|
|
|
|
|
|
|
|
|
|
|
| function stubReadAuthJson(
|
| value: Record<string, unknown> | undefined | null
|
| ): OmniRouteReadAuthJson & { callCount: () => number } {
|
| let n = 0;
|
| const f: OmniRouteReadAuthJson = async () => {
|
| n++;
|
| return value as never;
|
| };
|
| return Object.assign(f, { callCount: () => n });
|
| }
|
|
|
| function throwingReadAuthJson(): OmniRouteReadAuthJson & { callCount: () => number } {
|
| let n = 0;
|
| const f: OmniRouteReadAuthJson = async () => {
|
| n++;
|
| throw new Error("EACCES");
|
| };
|
| return Object.assign(f, { callCount: () => n });
|
| }
|
|
|
| function stubModelsFetcher(
|
| payload: OmniRouteRawModelEntry[]
|
| ): OmniRouteModelsFetcher & { callCount: () => number; callsBy: () => Array<[string, string]> } {
|
| let n = 0;
|
| const calls: Array<[string, string]> = [];
|
| const f: OmniRouteModelsFetcher = async (baseURL, apiKey) => {
|
| n++;
|
| calls.push([baseURL, apiKey]);
|
| return payload;
|
| };
|
| return Object.assign(f, { callCount: () => n, callsBy: () => calls });
|
| }
|
|
|
| function stubCombosFetcher(
|
| payload: OmniRouteRawCombo[]
|
| ): OmniRouteCombosFetcher & { callCount: () => number; callsBy: () => Array<[string, string]> } {
|
| let n = 0;
|
| const calls: Array<[string, string]> = [];
|
| const f: OmniRouteCombosFetcher = async (baseURL, apiKey) => {
|
| n++;
|
| calls.push([baseURL, apiKey]);
|
| return payload;
|
| };
|
| return Object.assign(f, { callCount: () => n, callsBy: () => calls });
|
| }
|
|
|
| function throwingModelsFetcher(): OmniRouteModelsFetcher & { callCount: () => number } {
|
| let n = 0;
|
| const f: OmniRouteModelsFetcher = async () => {
|
| n++;
|
| throw new Error("ECONNREFUSED");
|
| };
|
| return Object.assign(f, { callCount: () => n });
|
| }
|
|
|
| function throwingCombosFetcher(): OmniRouteCombosFetcher & { callCount: () => number } {
|
| let n = 0;
|
| const f: OmniRouteCombosFetcher = async () => {
|
| n++;
|
| throw new Error("403 Forbidden");
|
| };
|
| return Object.assign(f, { callCount: () => n });
|
| }
|
|
|
| function stubEnrichmentFetcher(payload: OmniRouteEnrichmentMap): OmniRouteEnrichmentFetcher & {
|
| callCount: () => number;
|
| callsBy: () => Array<[string, string]>;
|
| } {
|
| let n = 0;
|
| const calls: Array<[string, string]> = [];
|
| const f: OmniRouteEnrichmentFetcher = async (baseURL, apiKey) => {
|
| n++;
|
| calls.push([baseURL, apiKey]);
|
| return payload;
|
| };
|
| return Object.assign(f, { callCount: () => n, callsBy: () => calls });
|
| }
|
|
|
| function throwingEnrichmentFetcher(): OmniRouteEnrichmentFetcher & { callCount: () => number } {
|
| let n = 0;
|
| const f: OmniRouteEnrichmentFetcher = async () => {
|
| n++;
|
| throw new Error("ETIMEDOUT");
|
| };
|
| return Object.assign(f, { callCount: () => n });
|
| }
|
|
|
| interface WarnCapture {
|
| warn: (...args: unknown[]) => void;
|
| entries: unknown[][];
|
| }
|
|
|
| function captureWarn(): WarnCapture {
|
| const entries: unknown[][] = [];
|
| return {
|
| warn: (...args: unknown[]) => {
|
| entries.push(args);
|
| },
|
| entries,
|
| };
|
| }
|
|
|
| function makeInput(initialProvider: Record<string, unknown> = {}): Config {
|
|
|
|
|
| return { provider: initialProvider } as unknown as Config;
|
| }
|
|
|
|
|
|
|
|
|
|
|
| test("config: with valid auth.json + apiKey + baseURL β mutates input.provider[id] with stripped models block", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test-1", baseURL: "https://or.example.com/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE, MODEL_GEMINI]);
|
| const combosFetcher = stubCombosFetcher([COMBO_CLAUDE_TIER]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const provider = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider;
|
| const entry = provider.omniroute;
|
| assert.ok(entry, "input.provider.omniroute set");
|
| assert.equal(entry.npm, "@ai-sdk/openai-compatible");
|
| assert.equal(entry.name, "OmniRoute");
|
| assert.equal(entry.options.baseURL, "https://or.example.com/v1");
|
| assert.equal(entry.options.apiKey, "sk-test-1");
|
|
|
|
|
|
|
|
|
| const claude = entry.models["claude-sonnet-4-6"];
|
| assert.ok(claude, "claude model surfaced");
|
| assert.equal(claude.name, "claude-sonnet-4-6");
|
| assert.equal(claude.attachment, true);
|
| assert.equal(claude.reasoning, true);
|
| assert.equal(claude.temperature, true);
|
| assert.equal(claude.tool_call, true);
|
| assert.equal(claude.limit?.context, 200_000);
|
| assert.equal(claude.limit?.output, 64_000);
|
| assert.equal(
|
| (claude.limit as Record<string, unknown>).input,
|
| undefined,
|
| "limit.input is NOT in OC's SDK schema β must not emit"
|
| );
|
|
|
|
|
| assert.deepEqual(claude.modalities?.input, ["text", "image"]);
|
| assert.deepEqual(claude.modalities?.output, ["text"]);
|
|
|
|
|
|
|
| const combo = entry.models["combo/claude-tier"];
|
| assert.ok(combo, "combo surfaced under combo/ namespace");
|
| assert.equal(combo.name, "Combo: Claude Tier");
|
| assert.equal(combo.reasoning, false, "LCD: any member reasoning=false β combo reasoning=false");
|
| assert.equal(combo.tool_call, true);
|
| assert.equal(combo.limit?.context, 200_000, "LCD: min(200_000, 1_000_000)");
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("config: missing auth.json file β no-op, no throw, no input mutation", async () => {
|
| const readAuthJson = stubReadAuthJson(undefined);
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| assert.deepEqual((input as { provider: Record<string, unknown> }).provider, {});
|
| assert.equal(fetcher.callCount(), 0, "no fetch on missing auth.json");
|
| assert.equal(combosFetcher.callCount(), 0, "no combos fetch on missing auth.json");
|
|
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("no apiKey")),
|
| "breadcrumb emitted"
|
| );
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("config: malformed auth.json β no-op + warn once", async () => {
|
|
|
|
|
| const readAuthJson = stubReadAuthJson(null);
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| assert.deepEqual((input as { provider: Record<string, unknown> }).provider, {});
|
| assert.equal(fetcher.callCount(), 0);
|
|
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("failed to parse")),
|
| "parse-failure breadcrumb emitted"
|
| );
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("config: existing input.provider[id] β no overwrite (respect manual override)", async () => {
|
| const manual = {
|
| npm: "@ai-sdk/openai-compatible",
|
| name: "Manual OmniRoute",
|
| options: { baseURL: "http://manual/v1", apiKey: "manual-key" },
|
| models: { "manual-model": { name: "manual-model" } },
|
| };
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput({ omniroute: manual });
|
| await hook(input);
|
|
|
| const provider = (input as { provider: Record<string, unknown> }).provider;
|
| assert.equal(provider.omniroute, manual, "manual override preserved by reference");
|
| assert.equal(fetcher.callCount(), 0, "no fetch β short-circuited before I/O");
|
| assert.equal(readAuthJson.callCount(), 0, "no auth.json read either");
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("already set")),
|
| "override breadcrumb emitted"
|
| );
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("config: fetchers throw β warn + emit stub entry with models: {}", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = throwingModelsFetcher();
|
| const combosFetcher = throwingCombosFetcher();
|
| const logger = captureWarn();
|
|
|
|
|
|
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", features: { diskCache: false } },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry, "stub provider entry published even when fetchers fail");
|
| assert.equal(entry.npm, "@ai-sdk/openai-compatible");
|
| assert.deepEqual(entry.models, {}, "models stub is empty object");
|
| assert.equal(entry.options.baseURL, "https://or.example/v1");
|
| assert.equal(entry.options.apiKey, "sk-test");
|
|
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("/v1/models fetch failed")),
|
| "models-fetch breadcrumb emitted"
|
| );
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("/api/combos fetch failed")),
|
| "combos-fetch breadcrumb emitted"
|
| );
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("config: combos fetcher throws β emit models-only catalog (no combos in models block)", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE, MODEL_GEMINI]);
|
| const combosFetcher = throwingCombosFetcher();
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry);
|
| const ids = Object.keys(entry.models).sort();
|
| assert.deepEqual(ids, ["claude-sonnet-4-6", "gemini-3-flash"]);
|
| assert.equal(entry.models["combo-claude-tier"], undefined, "no combo entry");
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("/api/combos fetch failed")),
|
| "combos-fetch breadcrumb emitted"
|
| );
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("config: baseURL from auth.json takes precedence when opts.baseURL absent", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://creds.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| assert.equal(fetcher.callsBy()[0][0], "https://creds.example/v1");
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.equal(entry.options.baseURL, "https://creds.example/v1");
|
| });
|
|
|
| test("config: opts.baseURL wins over auth.json's stored baseURL", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://creds.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://opts.example/v1" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| assert.equal(fetcher.callsBy()[0][0], "https://opts.example/v1");
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.equal(entry.options.baseURL, "https://opts.example/v1");
|
| });
|
|
|
| test("config: no baseURL resolvable (no opts, no auth.json baseURL) β no-op", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| assert.deepEqual((input as { provider: Record<string, unknown> }).provider, {});
|
| assert.equal(fetcher.callCount(), 0);
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("no baseURL")),
|
| "no-baseURL breadcrumb emitted"
|
| );
|
| });
|
|
|
|
|
|
|
|
|
|
|
|
|
| test("config: multi-instance β two plugins with different providerIds publish to their own keys without collision", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| "omniroute-prod": {
|
| type: "api",
|
| key: "sk-prod",
|
| baseURL: "https://prod.example/v1",
|
| },
|
| "omniroute-preprod": {
|
| type: "api",
|
| key: "sk-preprod",
|
| baseURL: "https://preprod.example/v1",
|
| },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hookA = createOmniRouteConfigHook(
|
| { providerId: "omniroute-prod" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const hookB = createOmniRouteConfigHook(
|
| { providerId: "omniroute-preprod" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
|
|
| const input = makeInput();
|
| await hookA(input);
|
| await hookB(input);
|
|
|
| const provider = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider;
|
| assert.ok(provider["omniroute-prod"], "prod block present");
|
| assert.ok(provider["omniroute-preprod"], "preprod block present");
|
| assert.equal(provider["omniroute-prod"].options.apiKey, "sk-prod");
|
| assert.equal(provider["omniroute-preprod"].options.apiKey, "sk-preprod");
|
| assert.equal(provider["omniroute-prod"].options.baseURL, "https://prod.example/v1");
|
| assert.equal(provider["omniroute-preprod"].options.baseURL, "https://preprod.example/v1");
|
| assert.notEqual(
|
| provider["omniroute-prod"],
|
| provider["omniroute-preprod"],
|
| "blocks are distinct references"
|
| );
|
| });
|
|
|
|
|
|
|
|
|
|
|
|
|
| test("config + provider share cache: second call uses cached fetch result (single fetch per TTL)", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-shared", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([COMBO_CLAUDE_TIER]);
|
| const sharedCache: OmniRouteFetchCache = new Map();
|
| const logger = captureWarn();
|
|
|
| const configHook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1", modelCacheTtl: 60_000 },
|
| { readAuthJson, fetcher, combosFetcher, cache: sharedCache, logger }
|
| );
|
| const providerHook = createOmniRouteProviderHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1", modelCacheTtl: 60_000 },
|
| { fetcher, combosFetcher, cache: sharedCache }
|
| );
|
|
|
|
|
|
|
| const input = makeInput();
|
| await configHook(input);
|
| assert.equal(fetcher.callCount(), 1, "config fired the only models fetch");
|
| assert.equal(combosFetcher.callCount(), 1, "config fired the only combos fetch");
|
|
|
|
|
| const apiAuth = { type: "api", key: "sk-shared" };
|
| await providerHook.models!({} as never, { auth: apiAuth as never });
|
| assert.equal(fetcher.callCount(), 1, "provider reused cached models");
|
| assert.equal(combosFetcher.callCount(), 1, "provider reused cached combos");
|
| });
|
|
|
| test("provider β config order also dedupes (cache populated by provider, consumed by config)", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-reverse", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const sharedCache: OmniRouteFetchCache = new Map();
|
| const logger = captureWarn();
|
|
|
| const configHook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1", modelCacheTtl: 60_000 },
|
| { readAuthJson, fetcher, combosFetcher, cache: sharedCache, logger }
|
| );
|
| const providerHook = createOmniRouteProviderHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1", modelCacheTtl: 60_000 },
|
| { fetcher, combosFetcher, cache: sharedCache }
|
| );
|
|
|
| await providerHook.models!({} as never, {
|
| auth: { type: "api", key: "sk-reverse" } as never,
|
| });
|
| assert.equal(fetcher.callCount(), 1);
|
|
|
| const input = makeInput();
|
| await configHook(input);
|
| assert.equal(fetcher.callCount(), 1, "config reused cached models");
|
| });
|
|
|
|
|
|
|
|
|
|
|
|
|
| test("buildStaticProviderEntry: stripped per-model shape matches sibling @omniroute/opencode-provider", () => {
|
| const resolved = resolveOmniRoutePluginOptions({
|
| providerId: "omniroute",
|
| displayName: "OmniRoute",
|
| });
|
| const block = buildStaticProviderEntry(
|
| [MODEL_CLAUDE, MODEL_GEMINI],
|
| [],
|
| resolved,
|
| "https://or.example/v1",
|
| "sk-test"
|
| );
|
|
|
|
|
| assert.deepEqual(Object.keys(block).sort(), ["models", "name", "npm", "options"]);
|
| assert.equal(block.npm, "@ai-sdk/openai-compatible");
|
| assert.equal(block.name, "OmniRoute");
|
| assert.deepEqual(Object.keys(block.options).sort(), ["apiKey", "baseURL"]);
|
|
|
|
|
|
|
|
|
|
|
| const allowedKeys = new Set([
|
| "name",
|
| "release_date",
|
| "attachment",
|
| "reasoning",
|
| "temperature",
|
| "tool_call",
|
| "cost",
|
| "limit",
|
| "modalities",
|
| ]);
|
| for (const [id, entry] of Object.entries(block.models)) {
|
| for (const key of Object.keys(entry)) {
|
| assert.ok(allowedKeys.has(key), `${id}.${key} is not in the SDK static shape`);
|
| }
|
|
|
|
|
| assert.equal(
|
| (entry as Record<string, unknown>).capabilities,
|
| undefined,
|
| `${id} must not carry nested capabilities tree`
|
| );
|
| }
|
|
|
|
|
| const claude = block.models["claude-sonnet-4-6"];
|
| assert.equal(typeof claude.name, "string");
|
| assert.equal(typeof claude.attachment, "boolean");
|
| assert.equal(typeof claude.reasoning, "boolean");
|
| assert.equal(typeof claude.temperature, "boolean");
|
| assert.equal(typeof claude.tool_call, "boolean");
|
| assert.equal(typeof claude.limit?.context, "number");
|
| });
|
|
|
| test("buildStaticProviderEntry: empty fetch results β stub block with models: {}", () => {
|
| const resolved = resolveOmniRoutePluginOptions({ providerId: "omniroute" });
|
| const block = buildStaticProviderEntry([], [], resolved, "https://or.example/v1", "sk-test");
|
| assert.deepEqual(block.models, {});
|
| assert.equal(block.options.apiKey, "sk-test");
|
| });
|
|
|
| test("buildStaticProviderEntry: hidden combos are excluded", () => {
|
| const resolved = resolveOmniRoutePluginOptions({ providerId: "omniroute" });
|
| const block = buildStaticProviderEntry(
|
| [MODEL_CLAUDE],
|
| [{ ...COMBO_CLAUDE_TIER, isHidden: true }],
|
| resolved,
|
| "https://or.example/v1",
|
| "sk-test"
|
| );
|
| assert.equal(block.models["combo-claude-tier"], undefined);
|
| assert.ok(block.models["claude-sonnet-4-6"]);
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("buildStaticProviderEntry: emits modalities.input from raw.input_modalities", () => {
|
| const resolved = resolveOmniRoutePluginOptions({ providerId: "omniroute" });
|
| const block = buildStaticProviderEntry(
|
| [MODEL_CLAUDE, MODEL_GEMINI],
|
| [],
|
| resolved,
|
| "https://or.example/v1",
|
| "sk-test"
|
| );
|
| const claude = block.models["claude-sonnet-4-6"];
|
| assert.deepEqual(claude.modalities?.input, ["text", "image"]);
|
| assert.deepEqual(claude.modalities?.output, ["text"]);
|
| });
|
|
|
| test("buildStaticProviderEntry: never emits limit.input (OC SDK rejects it)", () => {
|
| const resolved = resolveOmniRoutePluginOptions({ providerId: "omniroute" });
|
| const block = buildStaticProviderEntry(
|
| [MODEL_CLAUDE],
|
| [],
|
| resolved,
|
| "https://or.example/v1",
|
| "sk-test"
|
| );
|
| const claude = block.models["claude-sonnet-4-6"];
|
| assert.equal((claude.limit as Record<string, unknown>).input, undefined);
|
| assert.equal(typeof claude.limit?.context, "number");
|
| assert.equal(typeof claude.limit?.output, "number");
|
| });
|
|
|
| test("buildStaticProviderEntry: emits cost when enrichment carries pricing", () => {
|
| const resolved = resolveOmniRoutePluginOptions({ providerId: "omniroute" });
|
| const enrichment = new Map([
|
| [
|
| "claude-sonnet-4-6",
|
| {
|
| name: "Claude Sonnet 4.6",
|
| providerAlias: "cc",
|
| providerCanonical: "claude",
|
| providerDisplayName: "Claude",
|
| pricing: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
| },
|
| ],
|
| ]);
|
| const block = buildStaticProviderEntry(
|
| [MODEL_CLAUDE],
|
| [],
|
| resolved,
|
| "https://or.example/v1",
|
| "sk-test",
|
| enrichment
|
| );
|
| const claude = block.models["claude-sonnet-4-6"];
|
| assert.equal(claude.cost?.input, 3);
|
| assert.equal(claude.cost?.output, 15);
|
| assert.equal(claude.cost?.cache_read, 0.3);
|
| assert.equal(claude.cost?.cache_write, 3.75);
|
| });
|
|
|
| test("buildStaticProviderEntry: emits release_date when raw carries it; omits when null", () => {
|
| const resolved = resolveOmniRoutePluginOptions({ providerId: "omniroute" });
|
| const withDate: OmniRouteRawModelEntry = {
|
| ...MODEL_CLAUDE,
|
| id: "claude-with-date",
|
| release_date: "2026-02-19",
|
| };
|
| const block = buildStaticProviderEntry(
|
| [withDate, MODEL_GEMINI],
|
| [],
|
| resolved,
|
| "https://or.example/v1",
|
| "sk-test"
|
| );
|
| assert.equal(block.models["claude-with-date"].release_date, "2026-02-19");
|
| assert.equal(block.models["gemini-3-flash"].release_date, undefined);
|
| });
|
|
|
| test("buildStaticProviderEntry: combo modalities = intersection of members (LCD)", () => {
|
| const resolved = resolveOmniRoutePluginOptions({ providerId: "omniroute" });
|
| const TEXT_ONLY: OmniRouteRawModelEntry = {
|
| id: "text-only",
|
| capabilities: { tool_calling: true, reasoning: false, vision: false, thinking: false },
|
| context_length: 100_000,
|
| max_output_tokens: 4_096,
|
| input_modalities: ["text"],
|
| output_modalities: ["text"],
|
| };
|
| const block = buildStaticProviderEntry(
|
| [MODEL_CLAUDE, TEXT_ONLY],
|
| [
|
| {
|
| id: "combo-mixed",
|
| name: "Mixed Tier",
|
| models: [
|
| { id: "s1", kind: "model", model: "claude-sonnet-4-6", weight: 100 },
|
| { id: "s2", kind: "model", model: "text-only", weight: 50 },
|
| ],
|
| },
|
| ],
|
| resolved,
|
| "https://or.example/v1",
|
| "sk-test"
|
| );
|
| const combo = block.models["combo/mixed-tier"];
|
| assert.ok(combo, "combo emitted under slug key");
|
|
|
| assert.deepEqual(combo.modalities?.input, ["text"]);
|
| assert.deepEqual(combo.modalities?.output, ["text"]);
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("OmniRoutePlugin factory exposes config hook alongside auth + provider", async () => {
|
| const hooks = await OmniRoutePlugin({} as never, { providerId: "omniroute" });
|
| assert.equal(typeof hooks.config, "function", "config hook present");
|
| assert.ok(hooks.auth, "auth hook present");
|
| assert.ok(hooks.provider, "provider hook present");
|
| });
|
|
|
|
|
|
|
|
|
|
|
| test("config: auth.json entry of wrong type (oauth) β no-op", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "oauth", refresh: "r", access: "a", expires: 0 },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| assert.deepEqual((input as { provider: Record<string, unknown> }).provider, {});
|
| assert.equal(fetcher.callCount(), 0);
|
| });
|
|
|
| test("config: readAuthJson throws β treat as missing file (silent fallback)", async () => {
|
| const readAuthJson = throwingReadAuthJson();
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| assert.deepEqual((input as { provider: Record<string, unknown> }).provider, {});
|
| assert.equal(readAuthJson.callCount(), 1);
|
| assert.equal(fetcher.callCount(), 0);
|
| });
|
|
|
| test("config: initialises input.provider when undefined", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, logger }
|
| );
|
|
|
| const input = {} as Config;
|
| await hook(input);
|
| const provider = (input as { provider?: Record<string, unknown> }).provider;
|
| assert.ok(provider, "provider bag initialised");
|
| assert.ok(provider!.omniroute);
|
| });
|
|
|
|
|
|
|
|
|
|
|
|
|
| test("config: enrichment fetched + name overlaid on raw-model entries", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE, MODEL_GEMINI]);
|
| const combosFetcher = stubCombosFetcher([COMBO_CLAUDE_TIER]);
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["claude-sonnet-4-6", { name: "Claude Sonnet 4.6" }],
|
| ["gemini-3-flash", { name: "Gemini 3 Flash" }],
|
| ])
|
| );
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry);
|
| assert.equal(entry.models["claude-sonnet-4-6"].name, "Claude Sonnet 4.6");
|
| assert.equal(entry.models["gemini-3-flash"].name, "Gemini 3 Flash");
|
|
|
| assert.equal(entry.models["combo/claude-tier"].name, "Combo: Claude Tier");
|
| assert.equal(enrichmentFetcher.callCount(), 1);
|
| });
|
|
|
| test("config: features.enrichment=false skips enrichment fetch + keeps raw-id names", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["claude-sonnet-4-6", { name: "Claude Sonnet 4.6" }],
|
| ])
|
| );
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", features: { enrichment: false } },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry);
|
| assert.equal(enrichmentFetcher.callCount(), 0, "enrichment fetch suppressed by feature flag");
|
| assert.equal(entry.models["claude-sonnet-4-6"].name, "claude-sonnet-4-6", "raw id retained");
|
| });
|
|
|
| test("config: enrichment fetcher throws β soft-fail (warn + raw-id static catalog)", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const enrichmentFetcher = throwingEnrichmentFetcher();
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry, "static block still published on enrichment failure");
|
| assert.equal(entry.models["claude-sonnet-4-6"].name, "claude-sonnet-4-6", "raw id retained");
|
| assert.equal(enrichmentFetcher.callCount(), 1);
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("/api/pricing/models fetch failed")),
|
| "enrichment-fetch breadcrumb emitted"
|
| );
|
| });
|
|
|
| function stubProvidersFetcher(payload: OmniRouteProviderConnection[]): OmniRouteProvidersFetcher & {
|
| callCount: () => number;
|
| } {
|
| let n = 0;
|
| const f: OmniRouteProvidersFetcher = async () => {
|
| n++;
|
| return payload;
|
| };
|
| return Object.assign(f, { callCount: () => n });
|
| }
|
|
|
| function throwingProvidersFetcher(): OmniRouteProvidersFetcher & { callCount: () => number } {
|
| let n = 0;
|
| const f: OmniRouteProvidersFetcher = async () => {
|
| n++;
|
| throw new Error("ETIMEDOUT");
|
| };
|
| return Object.assign(f, { callCount: () => n });
|
| }
|
|
|
| const MODEL_CC_OPUS: OmniRouteRawModelEntry = {
|
| id: "cc/claude-opus-4-7",
|
| capabilities: { tool_calling: true, reasoning: true, temperature: true },
|
| context_length: 200_000,
|
| };
|
| const MODEL_NV_LLAMA: OmniRouteRawModelEntry = {
|
| id: "nvidia/llama-3-70b",
|
| capabilities: { tool_calling: true, temperature: true },
|
| context_length: 128_000,
|
| };
|
|
|
| test("config: usableOnly=false β no filter (existing behavior)", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CC_OPUS, MODEL_NV_LLAMA]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const providersFetcher = stubProvidersFetcher([
|
| { id: "c1", provider: "claude", isActive: true, testStatus: "active" },
|
| ]);
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["cc/claude-opus-4-7", { name: "Claude Opus 4.7" }],
|
| ["nvidia/llama-3-70b", { name: "Llama 3 70B" }],
|
| ])
|
| );
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1" },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, providersFetcher }
|
| );
|
|
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry.models["cc/claude-opus-4-7"], "claude kept");
|
| assert.ok(entry.models["nvidia/llama-3-70b"], "nvidia kept (filter off)");
|
| assert.equal(providersFetcher.callCount(), 0, "providers fetch not called when feature off");
|
| });
|
|
|
| test("config: usableOnly=true β drops models for non-usable providers, keeps usable + unknown", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([
|
| MODEL_CC_OPUS,
|
| MODEL_NV_LLAMA,
|
|
|
| {
|
| id: "agentrouter/synthetic-1",
|
| capabilities: { temperature: true },
|
| context_length: 100_000,
|
| },
|
| ]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const providersFetcher = stubProvidersFetcher([
|
|
|
| { id: "c1", provider: "claude", isActive: true, testStatus: "active" },
|
|
|
| { id: "c2", provider: "nvidia", isActive: true, testStatus: "error" },
|
| ]);
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| [
|
| "cc/claude-opus-4-7",
|
| { name: "Claude Opus 4.7", providerAlias: "cc", providerCanonical: "claude" },
|
| ],
|
| [
|
| "nvidia/llama-3-70b",
|
| { name: "Llama 3 70B", providerAlias: "nvidia", providerCanonical: "nvidia" },
|
| ],
|
| ])
|
| );
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1", features: { usableOnly: true } },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, providersFetcher }
|
| );
|
|
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry.models["cc/claude-opus-4-7"], "claude kept (active)");
|
| assert.equal(entry.models["nvidia/llama-3-70b"], undefined, "nvidia dropped (error status)");
|
| assert.ok(entry.models["agentrouter/synthetic-1"], "unknown prefix kept (subtract-filter)");
|
| assert.equal(providersFetcher.callCount(), 1);
|
| });
|
|
|
| test("config: usableOnly=true + providers fetch fails β soft-fail keeps everything", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CC_OPUS, MODEL_NV_LLAMA]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const providersFetcher = throwingProvidersFetcher();
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["cc/claude-opus-4-7", { name: "Claude Opus 4.7" }],
|
| ["nvidia/llama-3-70b", { name: "Llama 3 70B" }],
|
| ])
|
| );
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1", features: { usableOnly: true } },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, providersFetcher, logger }
|
| );
|
|
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry.models["cc/claude-opus-4-7"]);
|
| assert.ok(entry.models["nvidia/llama-3-70b"], "soft-fail keeps both");
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("/api/providers fetch failed")),
|
| "providers-fetch breadcrumb emitted"
|
| );
|
| });
|
|
|
| test("config: diskCache hydrates stale snapshot when /v1/models throws", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = throwingModelsFetcher();
|
| const combosFetcher = stubCombosFetcher([]);
|
| const logger = captureWarn();
|
|
|
|
|
|
|
| const diskSnapshotReader: typeof import("../src/index.js").defaultDiskSnapshotReader =
|
| async () => ({
|
| rawModels: [MODEL_CLAUDE],
|
| rawCombos: [],
|
| rawEnrichment: new Map([["claude-sonnet-4-6", { name: "Claude Sonnet 4.6 (cached)" }]]),
|
| rawCompressionCombos: [],
|
| rawConnections: [],
|
| });
|
| let writes = 0;
|
| const diskSnapshotWriter: typeof import("../src/index.js").defaultDiskSnapshotWriter =
|
| async () => {
|
| writes++;
|
| };
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", features: { diskCache: true } },
|
| {
|
| readAuthJson,
|
| fetcher,
|
| combosFetcher,
|
| diskSnapshotReader,
|
| diskSnapshotWriter,
|
| logger,
|
| }
|
| );
|
|
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry.models["claude-sonnet-4-6"], "stale snapshot hydrated into static block");
|
| assert.equal(
|
| entry.models["claude-sonnet-4-6"].name,
|
| "Claude Sonnet 4.6 (cached)",
|
| "stale enrichment also reused"
|
| );
|
| assert.equal(writes, 0, "disk write skipped when live fetch failed");
|
| assert.ok(
|
| logger.entries.some((e) => String(e[0]).includes("using stale disk cache")),
|
| "disk-cache hydration breadcrumb emitted"
|
| );
|
| });
|
|
|
| test("config: cached rawEnrichment from earlier provider hook is reused (no refetch)", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-shared", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["claude-sonnet-4-6", { name: "Claude Sonnet 4.6" }],
|
| ])
|
| );
|
| const sharedCache: OmniRouteFetchCache = new Map();
|
| const logger = captureWarn();
|
|
|
| const providerHook = createOmniRouteProviderHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1", modelCacheTtl: 60_000 },
|
| { fetcher, combosFetcher, enrichmentFetcher, cache: sharedCache }
|
| );
|
| const configHook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", baseURL: "https://or.example/v1", modelCacheTtl: 60_000 },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, cache: sharedCache, logger }
|
| );
|
|
|
|
|
| await providerHook.models!({} as never, {
|
| auth: { type: "api", key: "sk-shared" } as never,
|
| });
|
| assert.equal(enrichmentFetcher.callCount(), 1);
|
|
|
|
|
| const input = makeInput();
|
| await configHook(input);
|
| assert.equal(enrichmentFetcher.callCount(), 1, "config reused cached enrichment");
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.equal(entry.models["claude-sonnet-4-6"].name, "Claude Sonnet 4.6");
|
| });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| test("config: providerTag (default-on) prepends '<provider> - ' to enriched raw-model names", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE, MODEL_GEMINI]);
|
| const combosFetcher = stubCombosFetcher([COMBO_CLAUDE_TIER]);
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| [
|
| "claude-sonnet-4-6",
|
| {
|
| name: "Claude Sonnet 4.6",
|
| providerAlias: "cc",
|
| providerCanonical: "claude",
|
| providerDisplayName: "Claude",
|
| },
|
| ],
|
| [
|
| "gemini-3-flash",
|
| {
|
| name: "Gemini 3 Flash",
|
| providerAlias: "gemini-cli",
|
| providerCanonical: "gemini-cli",
|
| providerDisplayName: "Gemini-cli",
|
| },
|
| ],
|
| ])
|
| );
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.ok(entry);
|
| assert.equal(entry.models["claude-sonnet-4-6"].name, "Claude - Claude Sonnet 4.6");
|
| assert.equal(entry.models["gemini-3-flash"].name, "Gemini-cli - Gemini 3 Flash");
|
|
|
| assert.equal(entry.models["combo/claude-tier"].name, "Combo: Claude Tier");
|
| });
|
|
|
| test("config: providerTag=false suppresses the suffix", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["claude-sonnet-4-6", { name: "Claude Sonnet 4.6", providerDisplayName: "Claude" }],
|
| ])
|
| );
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", features: { providerTag: false } },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.equal(
|
| entry.models["claude-sonnet-4-6"].name,
|
| "Claude Sonnet 4.6",
|
| "enriched name kept, provider tag suppressed"
|
| );
|
| });
|
|
|
| test("config: providerTag falls back to UPPER(alias) when providerDisplayName missing", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
|
|
|
|
|
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["claude-sonnet-4-6", { name: "Claude Sonnet 4.6", providerAlias: "cc" }],
|
| ])
|
| );
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.equal(entry.models["claude-sonnet-4-6"].name, "CC - Claude Sonnet 4.6");
|
| });
|
|
|
| test("config: providerTag skipped entirely when neither providerDisplayName nor providerAlias set", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
|
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["claude-sonnet-4-6", { name: "Claude Sonnet 4.6" }],
|
| ])
|
| );
|
| const logger = captureWarn();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute" },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, logger }
|
| );
|
| const input = makeInput();
|
| await hook(input);
|
|
|
| const entry = (input as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.equal(entry.models["claude-sonnet-4-6"].name, "Claude Sonnet 4.6");
|
| });
|
|
|
| test("config: providerTag is idempotent β second hook call doesn't double-suffix", async () => {
|
| const readAuthJson = stubReadAuthJson({
|
| omniroute: { type: "api", key: "sk-test", baseURL: "https://or.example/v1" },
|
| });
|
| const fetcher = stubModelsFetcher([MODEL_CLAUDE]);
|
| const combosFetcher = stubCombosFetcher([]);
|
| const enrichmentFetcher = stubEnrichmentFetcher(
|
| new Map<string, OmniRouteEnrichmentEntry>([
|
| ["claude-sonnet-4-6", { name: "Claude Sonnet 4.6", providerDisplayName: "Claude" }],
|
| ])
|
| );
|
| const logger = captureWarn();
|
| const sharedCache = new Map();
|
|
|
| const hook = createOmniRouteConfigHook(
|
| { providerId: "omniroute", modelCacheTtl: 60_000 },
|
| { readAuthJson, fetcher, combosFetcher, enrichmentFetcher, cache: sharedCache, logger }
|
| );
|
|
|
| const inputA = makeInput();
|
| await hook(inputA);
|
| const entryA = (inputA as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.equal(entryA.models["claude-sonnet-4-6"].name, "Claude - Claude Sonnet 4.6");
|
|
|
|
|
| const inputB = makeInput();
|
| await hook(inputB);
|
| const entryB = (inputB as { provider: Record<string, OmniRouteStaticProviderEntry> }).provider
|
| .omniroute;
|
| assert.equal(entryB.models["claude-sonnet-4-6"].name, "Claude - Claude Sonnet 4.6");
|
| });
|
|
|