Files
OmniRoute/tests/unit/combo-apply-strategy-ordering-split.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

100 lines
3.3 KiB
TypeScript

import { test, after } from "node:test";
import assert from "node:assert/strict";
import { applyStrategyOrdering } from "@omniroute/open-sse/services/combo/applyStrategyOrdering.ts";
import { resetDbInstance } from "@/lib/db/core.ts";
// Split guard for Block J Task 3: the non-`auto` strategy-ordering chain
// (lkgp / strict-random / random / fill-first / p2c / ... / quota-share) was
// extracted verbatim into applyStrategyOrdering. These tests pin the exits that
// need no DB/deck state (random / fill-first / unknown); the DB-backed branches
// (lkgp, reset-*, quota-share) are covered end-to-end by the 47 consumer tests
// (router-strategies / combo-strategy-fallbacks / rr-session-stickiness).
after(() => {
// some branches (lkgp/quota-share) may touch the DB singleton; release handles.
resetDbInstance();
});
const noopLog = { info() {}, warn() {}, error() {}, debug() {} } as never;
const target = (provider: string, modelStr: string): never =>
({
kind: "model",
stepId: "s1",
executionKey: `${provider}>${modelStr}`,
modelStr,
provider,
providerId: null,
connectionId: null,
weight: 1,
label: null,
}) as never;
const deps = () =>
({
combo: { id: "c1", name: "c1", config: {} },
config: {},
body: { messages: [] },
log: noopLog,
apiKeyAllowedConnections: null,
}) as never;
const keys = (arr: Array<{ executionKey: string }>) => arr.map((t) => t.executionKey).sort();
test("exports applyStrategyOrdering", () => {
assert.equal(typeof applyStrategyOrdering, "function");
});
test("unknown strategy -> input order unchanged (same reference contents)", async () => {
const input = [target("openai", "gpt-4o"), target("anthropic", "claude-3")];
const out = await applyStrategyOrdering("no-such-strategy", input, deps());
assert.deepEqual(
out.map((t: { executionKey: string }) => t.executionKey),
["openai>gpt-4o", "anthropic>claude-3"]
);
});
test("fill-first -> preserves priority order", async () => {
const input = [target("a", "m1"), target("b", "m2"), target("c", "m3")];
const out = await applyStrategyOrdering("fill-first", input, deps());
assert.deepEqual(
out.map((t: { executionKey: string }) => t.executionKey),
["a>m1", "b>m2", "c>m3"]
);
});
test("random -> same multiset of targets (a permutation)", async () => {
const input = [target("a", "m1"), target("b", "m2"), target("c", "m3")];
const out = await applyStrategyOrdering("random", input, deps());
assert.equal(out.length, 3);
assert.deepEqual(keys(out), keys(input));
});
test("cost-optimized manifest routing logs through the canonical strategy path", async () => {
const debugCalls: unknown[][] = [];
const log = {
info() {},
warn() {},
error() {},
debug(...args: unknown[]) {
debugCalls.push(args);
},
} as never;
const input = [target("openai", "gpt-4o"), target("anthropic", "claude-3")];
const out = await applyStrategyOrdering("cost-optimized", input, {
...deps(),
config: { manifestRouting: true },
body: { messages: [{ role: "user", content: "hello" }] },
log,
} as never);
assert.equal(out.length, 2);
assert.equal(
debugCalls.some((args) => args[1] === "manifest routing applied"),
true,
"manifest routing must log from applyStrategyOrdering"
);
});