Files
OmniRoute/tests/unit/compression/body-adapter.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

322 lines
9.9 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { applyCompression } from "../../../open-sse/services/compression/strategySelector.ts";
import { adaptBodyForCompression } from "../../../open-sse/services/compression/bodyAdapter.ts";
import { applyRtkCompression } from "../../../open-sse/services/compression/engines/rtk/index.ts";
describe("compression body adapter", () => {
it("drops a custom tool call when compaction removes its mapped output (#8932)", () => {
const body = {
input: [
{
type: "custom_tool_call",
call_id: "call_patch_1",
name: "apply_patch",
input: "*** Begin Patch",
},
{
type: "custom_tool_call_output",
call_id: "call_patch_1",
output: "Done!",
},
{
type: "message",
role: "user",
content: [{ type: "input_text", text: "Continue." }],
},
],
};
const adapter = adaptBodyForCompression(body);
const compressedMessages = (adapter.body.messages as Array<Record<string, unknown>>).filter(
(message) => message.role !== "tool"
);
const restored = adapter.restore(
{ ...adapter.body, messages: compressedMessages },
{ dropMissingMappedItems: true }
);
const input = restored.input as Array<Record<string, unknown>>;
assert.equal(
input.some((item) => item.type === "custom_tool_call"),
false
);
assert.equal(
input.some((item) => item.type === "custom_tool_call_output"),
false
);
assert.equal(
input.some((item) => item.type === "message"),
true
);
});
it("applies Caveman compression to OpenAI Responses input messages", () => {
const body = {
model: "gpt-5.5-codex",
input: [
{
type: "message",
role: "user",
content: [
{
type: "input_text",
text: "Please could you provide a detailed explanation of this implementation? Thank you so much for your help!",
},
],
},
{
type: "function_call",
call_id: "call_1",
name: "read_file",
arguments: "{}",
},
],
};
const result = applyCompression(body, "standard", {
config: {
enabled: true,
defaultMode: "standard",
autoTriggerTokens: 0,
cacheMinutes: 5,
preserveSystemPrompt: true,
comboOverrides: {},
cavemanConfig: {
enabled: true,
compressRoles: ["user"],
skipRules: [],
minMessageLength: 10,
preservePatterns: [],
intensity: "full",
},
},
});
assert.equal(result.compressed, true);
assert.ok(!("messages" in result.body), "Responses body must not leak synthetic messages");
const input = result.body.input as typeof body.input;
assert.equal(input[1], body.input[1], "non-message Responses items should be preserved");
const text = input[0].content[0].text;
assert.ok(!text.includes("Please could you"));
assert.ok(!text.includes("Thank you so much"));
assert.ok(text.includes("explain"));
});
it("applies RTK compression to Responses function_call_output items", () => {
const repeatedOutput = Array.from({ length: 20 }, () => "same noisy line").join("\n");
const body = {
input: [
{
type: "function_call_output",
call_id: "call_1",
output: repeatedOutput,
},
],
};
const result = applyRtkCompression(body);
assert.equal(result.compressed, true);
assert.ok(!("messages" in result.body), "Responses body must not leak synthetic messages");
const input = result.body.input as typeof body.input;
assert.match(input[0].output, /\[rtk:dropped/);
assert.equal(input[0].call_id, "call_1");
});
it("applies RTK compression to Codex custom_tool_call_output items", () => {
const repeatedOutput = Array.from({ length: 20 }, () => "same noisy line").join("\n");
const body = {
input: [
{
type: "custom_tool_call_output",
call_id: "call_patch_1",
output: repeatedOutput,
},
],
};
const result = applyRtkCompression(body);
assert.equal(result.compressed, true);
assert.ok(!("messages" in result.body), "Responses body must not leak synthetic messages");
const input = result.body.input as typeof body.input;
assert.equal(input[0].type, "custom_tool_call_output");
assert.equal(input[0].call_id, "call_patch_1");
assert.match(input[0].output, /\[rtk:dropped/);
});
it("preserves wrapped custom tool output metadata while compressing its output", () => {
const repeatedOutput = Array.from({ length: 20 }, () => "same noisy line").join("\n");
const body = {
input: [
{
type: "custom_tool_call_output",
call_id: "call_exec_1",
output: JSON.stringify({ output: repeatedOutput, metadata: { exitCode: 0 } }),
},
],
};
const result = applyRtkCompression(body);
const input = result.body.input as typeof body.input;
const restoredOutput = JSON.parse(input[0].output) as {
output: string;
metadata: { exitCode: number };
};
assert.equal(result.compressed, true);
assert.match(restoredOutput.output, /\[rtk:dropped/);
assert.deepEqual(restoredOutput.metadata, { exitCode: 0 });
});
it("restores custom tool output to content when that was the source field", () => {
const repeatedOutput = Array.from({ length: 20 }, () => "same noisy line").join("\n");
const body = {
input: [
{
type: "custom_tool_call_output",
call_id: "call_exec_2",
content: repeatedOutput,
},
],
};
const result = applyRtkCompression(body);
const input = result.body.input as Array<Record<string, unknown>>;
assert.equal(result.compressed, true);
assert.match(input[0].content as string, /\[rtk:dropped/);
assert.ok(!("output" in input[0]), "restore must not add a conflicting output field");
});
it("restores function call output to content when that was the source field", () => {
const repeatedOutput = Array.from({ length: 20 }, () => "same noisy line").join("\n");
const body = {
input: [
{
type: "function_call_output",
call_id: "call_2",
content: repeatedOutput,
},
],
};
const result = applyRtkCompression(body);
const input = result.body.input as Array<Record<string, unknown>>;
assert.equal(result.compressed, true);
assert.match(input[0].content as string, /\[rtk:dropped/);
assert.ok(!("output" in input[0]), "restore must not add a conflicting output field");
});
it("restores compressed array output on Responses function_call_output items", () => {
const repeatedOutput = Array.from({ length: 20 }, () => "same noisy line").join("\n");
const body = {
input: [
{
type: "function_call_output",
call_id: "call_1",
output: [{ type: "input_text", text: repeatedOutput }],
},
],
};
const result = applyRtkCompression(body);
const input = result.body.input as typeof body.input;
assert.equal(result.compressed, true);
assert.match(input[0].output[0].text, /\[rtk:dropped/);
assert.ok(!("content" in input[0]), "function_call_output should keep canonical output field");
});
it("restores adapted Responses bodies even when no compression is applied", () => {
const body = {
input: [
{
type: "message",
role: "user",
content: [{ type: "input_text", text: "short" }],
},
],
};
const result = applyCompression(body, "standard", {
config: {
enabled: true,
defaultMode: "standard",
autoTriggerTokens: 0,
cacheMinutes: 5,
preserveSystemPrompt: true,
comboOverrides: {},
cavemanConfig: {
enabled: true,
compressRoles: ["user"],
skipRules: [],
minMessageLength: 50,
preservePatterns: [],
intensity: "full",
},
},
});
assert.equal(result.compressed, false);
assert.ok(!("messages" in result.body));
assert.deepEqual(result.body.input, body.input);
});
it("does not misalign Responses input items if an engine removes a synthetic message", () => {
const body = {
input: [
{ type: "message", role: "user", content: "duplicate" },
{ type: "message", role: "user", content: "duplicate" },
{ type: "message", role: "user", content: "unique" },
],
};
const result = applyCompression(body, "lite", {
config: {
enabled: true,
defaultMode: "lite",
autoTriggerTokens: 0,
cacheMinutes: 5,
preserveSystemPrompt: true,
comboOverrides: {},
},
});
assert.equal(result.compressed, true);
assert.deepEqual(result.body.input, body.input);
});
it("compresses string Responses input without converting the request shape", () => {
const body = {
input:
"Please could you provide a detailed explanation of this implementation? Thank you so much for your help!",
};
const result = applyCompression(body, "standard", {
config: {
enabled: true,
defaultMode: "standard",
autoTriggerTokens: 0,
cacheMinutes: 5,
preserveSystemPrompt: true,
comboOverrides: {},
cavemanConfig: {
enabled: true,
compressRoles: ["user"],
skipRules: [],
minMessageLength: 10,
preservePatterns: [],
intensity: "full",
},
},
});
assert.equal(result.compressed, true);
assert.equal(typeof result.body.input, "string");
assert.ok(!(result.body.input as string).includes("Please could you"));
});
});