Files
OmniRoute/tests/unit/reasoning-input-policy-summary-11108.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

146 lines
4.5 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
const { applyReasoningInputPolicy } =
await import("../../open-sse/services/reasoningInputPolicy.ts");
test("#11108 applyReasoningInputPolicy defaults summary on a kept opaque reasoning item", () => {
const body: Record<string, unknown> = {
input: [
{
type: "reasoning",
id: "rs_example",
encrypted_content: "opaque-blob",
},
],
};
applyReasoningInputPolicy(body, "responses", {
provider: "opencode",
preserveEncryptedReasoning: true,
});
const input = body.input as Record<string, unknown>[];
assert.equal(input.length, 1);
assert.deepEqual(input[0].summary, []);
});
test("#11108 applyReasoningInputPolicy preserves an existing summary on a kept reasoning item", () => {
const body: Record<string, unknown> = {
input: [
{
type: "reasoning",
id: "rs_example",
encrypted_content: "opaque-blob",
summary: [{ type: "summary_text", text: "Planning." }],
},
],
};
applyReasoningInputPolicy(body, "responses", {
provider: "opencode",
preserveEncryptedReasoning: true,
});
const input = body.input as Record<string, unknown>[];
assert.deepEqual(input[0].summary, [{ type: "summary_text", text: "Planning." }]);
});
test("#11108 applyReasoningInputPolicy defaults summary on an opaque item surviving incompatible-drop", () => {
// Mixed item (plaintext + opaque) on an opaque-only transport is incompatible;
// dropIncompatibleResponsesReasoning() strips the plaintext content but keeps
// the opaque item alive — it must still get a default `summary`.
const body: Record<string, unknown> = {
input: [
{
type: "reasoning",
id: "rs_mixed",
content: [{ type: "reasoning_text", text: "inspect first" }],
encrypted_content: "opaque-blob",
},
],
};
const result = applyReasoningInputPolicy(body, "responses", {
provider: "codex",
onIncompatibleReasoning: "drop",
});
assert.equal(result.incompatibleReasoning, false);
const input = body.input as Record<string, unknown>[];
assert.equal(input.length, 1);
assert.equal(input[0].content, undefined);
assert.equal(input[0].encrypted_content, "opaque-blob");
assert.deepEqual(input[0].summary, []);
});
test("#11108 applyReasoningInputPolicy strips a non-string id on a kept opaque reasoning item", () => {
// Same gap class as the summary fix above: opencode/zen also omits `id`
// entirely (surfaced by the client as `id: null`) on opaque-only reasoning
// items instead of a `rs_...` string. Replaying that shape verbatim trips
// strict Responses-API validators with "Expected 'id' to be a string."
const body: Record<string, unknown> = {
input: [
{
type: "reasoning",
id: null,
encrypted_content: "opaque-blob",
},
],
};
applyReasoningInputPolicy(body, "responses", {
provider: "opencode",
preserveEncryptedReasoning: true,
});
const input = body.input as Record<string, unknown>[];
assert.equal(input.length, 1);
assert.equal("id" in input[0], false);
});
test("#11108 applyReasoningInputPolicy strips a non-string id on a non-reasoning item (function_call)", () => {
// Same gap class, generic branch: any non-"reasoning" input item (function_call,
// message, ...) only stripped `id` when it was already a valid string, so a
// malformed `id` (e.g. `null`, mirroring the opencode/zen omission pattern)
// on a function_call item survived replay untouched.
const body: Record<string, unknown> = {
input: [
{
type: "function_call",
id: null,
call_id: "call_abc",
name: "bash",
arguments: "{}",
},
],
};
applyReasoningInputPolicy(body, "responses", { provider: "opencode" });
const input = body.input as Record<string, unknown>[];
assert.equal(input.length, 1);
assert.equal("id" in input[0], false);
assert.equal(input[0].call_id, "call_abc");
});
test("#11108 applyReasoningInputPolicy preserves a valid string id on a kept opaque reasoning item", () => {
const body: Record<string, unknown> = {
input: [
{
type: "reasoning",
id: "rs_example",
encrypted_content: "opaque-blob",
},
],
};
applyReasoningInputPolicy(body, "responses", {
provider: "opencode",
preserveEncryptedReasoning: true,
});
const input = body.input as Record<string, unknown>[];
assert.equal(input[0].id, "rs_example");
});