Files
OmniRoute/tests/unit/json-cookie-input.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

109 lines
4.1 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
const {
parseJsonCookiesToHeader,
normalizeSessionCookieHeader,
} = await import("../../src/lib/providers/webCookieAuth.ts");
// parseJsonCookiesToHeader — unit tests
test("parseJsonCookiesToHeader: valid JSON array returns Cookie header string", () => {
const json = `[{"name":"sso","value":"eyJ0eXAi.abc.def"}]`;
assert.equal(parseJsonCookiesToHeader(json), "sso=eyJ0eXAi.abc.def");
});
test("parseJsonCookiesToHeader: multiple entries joined with ; ", () => {
const json = `[
{"name":"sso","value":"AAA.bbb"},
{"name":"sso-rw","value":"CCC.ddd"},
{"name":"cf_clearance","value":"zzz"}
]`;
assert.equal(parseJsonCookiesToHeader(json), "sso=AAA.bbb; sso-rw=CCC.ddd; cf_clearance=zzz");
});
test("parseJsonCookiesToHeader: extra optional fields are ignored gracefully", () => {
const json = `[{"name":"session","value":"abc","domain":".example.com","path":"/","httpOnly":true,"secure":true,"sameSite":"Lax"}]`;
assert.equal(parseJsonCookiesToHeader(json), "session=abc");
});
test("parseJsonCookiesToHeader: missing name throws descriptive error at correct index", () => {
const json = `[{"name":"a","value":"1"},{"value":"no-name"}]`;
assert.throws(
() => parseJsonCookiesToHeader(json),
{ message: "Invalid cookie JSON at index 1: missing required field 'name'" }
);
});
test("parseJsonCookiesToHeader: missing value throws descriptive error at correct index", () => {
const json = `[{"name":"a","value":"1"},{"name":"no-value"}]`;
assert.throws(
() => parseJsonCookiesToHeader(json),
{ message: "Invalid cookie JSON at index 1: missing required field 'value'" }
);
});
test("parseJsonCookiesToHeader: empty array returns empty string", () => {
assert.equal(parseJsonCookiesToHeader("[]"), "");
});
test("parseJsonCookiesToHeader: raw string (non-JSON) returns null (pass-through)", () => {
assert.equal(parseJsonCookiesToHeader("sso=eyJ0eXAi.abc.def"), null);
assert.equal(parseJsonCookiesToHeader("__Secure-authjs.session-token=abc"), null);
assert.equal(parseJsonCookiesToHeader("bearer xyz"), null);
});
test("parseJsonCookiesToHeader: malformed JSON returns null (pass-through, no crash)", () => {
assert.equal(parseJsonCookiesToHeader("[not valid json"), null);
assert.equal(parseJsonCookiesToHeader("{invalid}"), null);
});
test("parseJsonCookiesToHeader: empty/whitespace input returns null", () => {
assert.equal(parseJsonCookiesToHeader(""), null);
assert.equal(parseJsonCookiesToHeader(" "), null);
});
test("parseJsonCookiesToHeader: parsed non-array JSON returns null", () => {
assert.equal(parseJsonCookiesToHeader(`{"name":"test"}`), null);
});
test("parseJsonCookiesToHeader: entry with empty name throws error", () => {
const json = `[{"name":"","value":"abc"}]`;
assert.throws(
() => parseJsonCookiesToHeader(json),
{ message: "Invalid cookie JSON at index 0: missing required field 'name'" }
);
});
test("parseJsonCookiesToHeader: entry with empty value returns empty value in header", () => {
const json = `[{"name":"session","value":""}]`;
assert.equal(parseJsonCookiesToHeader(json), "session=");
});
// Integration tests via normalizeSessionCookieHeader
test("normalizeSessionCookieHeader: JSON input returns correct header", () => {
const json = `[{"name":"__Secure-authjs.session-token","value":"abc"}]`;
assert.equal(
normalizeSessionCookieHeader(json, "__Secure-authjs.session-token"),
"__Secure-authjs.session-token=abc"
);
});
test("normalizeSessionCookieHeader: JSON input with prefix stripped works", () => {
const json = `[{"name":"sso","value":"eyJ0eXAi.abc"}]`;
assert.equal(
normalizeSessionCookieHeader(`Cookie: ${json}`, "sso"),
"sso=eyJ0eXAi.abc"
);
});
test("normalizeSessionCookieHeader: raw string unchanged after JSON support added", () => {
assert.equal(
normalizeSessionCookieHeader("__Secure-authjs.session-token=abc", "__Secure-authjs.session-token"),
"__Secure-authjs.session-token=abc"
);
assert.equal(
normalizeSessionCookieHeader("bare-value", "__Secure-authjs.session-token"),
"__Secure-authjs.session-token=bare-value"
);
});