Files
OmniRoute/tests/unit/request-defaults-store-session.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

157 lines
4.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
const {
buildOpenAIStoreSessionId,
ensureOpenAIStoreSessionFallback,
getClaudeCodeCompatibleRequestDefaults,
normalizeCodexReasoningEffort,
normalizeProviderSpecificData,
sanitizeProviderSpecificDataForResponse,
} = await import("../../src/lib/providers/requestDefaults.ts");
test("Codex request defaults accept max but leave ultra to the Codex client", () => {
assert.equal(normalizeCodexReasoningEffort("max"), "max");
assert.equal(normalizeCodexReasoningEffort("ultra"), undefined);
});
test("normalizeProviderSpecificData keeps only boolean preserveEncryptedReasoning", () => {
assert.equal(
normalizeProviderSpecificData("codex", { preserveEncryptedReasoning: true })
?.preserveEncryptedReasoning,
true
);
assert.equal(
normalizeProviderSpecificData("codex", {
preserveEncryptedReasoning: "yes",
tag: "primary",
})?.preserveEncryptedReasoning,
undefined
);
});
test("buildOpenAIStoreSessionId normalizes external and generated session ids", () => {
assert.equal(
buildOpenAIStoreSessionId("ext:client session/abc"),
"omniroute-session-client-session-abc"
);
assert.equal(
buildOpenAIStoreSessionId(" internal:session "),
"omniroute-session-internal:session"
);
assert.equal(buildOpenAIStoreSessionId(""), undefined);
});
test("ensureOpenAIStoreSessionFallback injects session_id only when no stable cache key exists", () => {
const injected = ensureOpenAIStoreSessionFallback({ model: "gpt-5.3-codex" }, "ext:session-1");
assert.equal(injected.session_id, "omniroute-session-session-1");
const withPromptCacheKey = ensureOpenAIStoreSessionFallback(
{ model: "gpt-5.3-codex", prompt_cache_key: "cache-123" },
"ext:session-2"
);
assert.equal(withPromptCacheKey.session_id, undefined);
const withConversation = ensureOpenAIStoreSessionFallback(
{ model: "gpt-5.3-codex", conversation_id: "conv-1" },
"ext:session-3"
);
assert.equal(withConversation.session_id, undefined);
const withExplicitSession = ensureOpenAIStoreSessionFallback(
{ model: "gpt-5.3-codex", session_id: "existing-session" },
"ext:session-4"
);
assert.equal(withExplicitSession.session_id, "existing-session");
});
test("normalizeProviderSpecificData keeps only boolean CC-compatible request defaults", () => {
const normalized = normalizeProviderSpecificData("anthropic-compatible-cc-demo", {
baseUrl: "https://proxy.example.com/v1/messages?beta=true",
requestDefaults: {
context1m: true,
redactThinking: true,
summarizeThinking: true,
customFlag: "keep-me",
},
});
assert.deepEqual(getClaudeCodeCompatibleRequestDefaults(normalized), {
context1m: true,
redactThinking: true,
summarizeThinking: true,
});
assert.deepEqual(normalized?.requestDefaults, {
context1m: true,
redactThinking: true,
summarizeThinking: true,
customFlag: "keep-me",
});
const stripped = normalizeProviderSpecificData("anthropic-compatible-cc-demo", {
requestDefaults: {
context1m: "yes",
redactThinking: "yes",
summarizeThinking: "yes",
customFlag: "keep-me",
},
});
assert.deepEqual(stripped?.requestDefaults, {
customFlag: "keep-me",
});
});
test("normalizeProviderSpecificData trims OpenRouter preset and clears empty values", () => {
const normalized = normalizeProviderSpecificData("openrouter", {
preset: " email-copywriter ",
tag: "primary",
});
assert.equal(normalized?.preset, "email-copywriter");
assert.equal(normalized?.tag, "primary");
const stripped = normalizeProviderSpecificData("openrouter", {
preset: " ",
tag: "primary",
});
assert.equal(stripped?.preset, undefined);
assert.equal(stripped?.tag, "primary");
const oversized = normalizeProviderSpecificData("openrouter", {
preset: "x".repeat(201),
tag: "primary",
});
assert.equal(oversized?.preset, undefined);
assert.equal(oversized?.tag, "primary");
const ignored = normalizeProviderSpecificData("openai", {
preset: "email-copywriter",
tag: "primary",
});
assert.equal(ignored?.preset, undefined);
assert.equal(ignored?.tag, "primary");
});
test("sanitizeProviderSpecificDataForResponse removes credentials and quota scraping cookies", () => {
const sanitized = sanitizeProviderSpecificDataForResponse({
opencodeGoWorkspaceId: "workspace-123",
accessToken: "access-token",
refreshToken: "refresh-token",
idToken: "id-token",
apiKey: "api-key",
opencodeGoAuthCookie: "auth-cookie",
ollamaCloudUsageCookie: "ollama-cookie",
usageCookie: "fallback-cookie",
consoleApiKey: "console-key",
tag: "primary",
});
assert.deepEqual(sanitized, {
opencodeGoWorkspaceId: "workspace-123",
tag: "primary",
});
});