Files
OmniRoute/tests/unit/request-defaults-store-session.test.ts
Diego Rodrigues de Sa e Souza 81a37b67ed Release v3.8.26 (#3875)
OmniRoute v3.8.26 — see CHANGELOG.md [3.8.26] for the full notes.

Highlights: Vertex AI media generation (#3929), GLM-5.2 effort-tier routing (#3885),
sticky round-robin combos (#3846), OpenRouter connection presets (#3878), compression
prompt-cache fix (#3936/#3890), and a security pass (form-data/vite + workflow hardening, #3949).

Co-authored-by: artickc <artickc@users.noreply.github.com>
Co-authored-by: rdself <rdself@users.noreply.github.com>
Co-authored-by: herjarsa <herjarsa@users.noreply.github.com>
Co-authored-by: Jack Smith <16862258+YunyunZhai@users.noreply.github.com>
Co-authored-by: dhaern <dhaern@users.noreply.github.com>
Co-authored-by: adivekar-utexas <adivekar-utexas@users.noreply.github.com>
Co-authored-by: megamen32 <megamen32@users.noreply.github.com>
Co-authored-by: zhiru <zhiru@users.noreply.github.com>
Co-authored-by: insoln <insoln@users.noreply.github.com>
Co-authored-by: diego-anselmo <diego-anselmo@users.noreply.github.com>
2026-06-16 01:00:40 -03:00

111 lines
3.4 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
const {
buildOpenAIStoreSessionId,
ensureOpenAIStoreSessionFallback,
getClaudeCodeCompatibleRequestDefaults,
normalizeProviderSpecificData,
} = await import("../../src/lib/providers/requestDefaults.ts");
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,
customFlag: "keep-me",
},
});
assert.deepEqual(getClaudeCodeCompatibleRequestDefaults(normalized), {
context1m: true,
redactThinking: true,
});
assert.deepEqual(normalized?.requestDefaults, {
context1m: true,
redactThinking: true,
customFlag: "keep-me",
});
const stripped = normalizeProviderSpecificData("anthropic-compatible-cc-demo", {
requestDefaults: {
context1m: "yes",
redactThinking: "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");
});