Files
OmniRoute/tests/unit/compression/engine-registry.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

106 lines
3.9 KiB
TypeScript

import { describe, it, beforeEach } from "node:test";
import assert from "node:assert/strict";
import {
aggressiveEngine,
cavemanEngine,
liteEngine,
ultraEngine,
} from "../../../open-sse/services/compression/engines/cavemanAdapter.ts";
import { rtkEngine as realRtkEngine } from "../../../open-sse/services/compression/engines/rtk/index.ts";
import {
clearCompressionEngineRegistry,
getEngine,
getEngineEntry,
listEnabledEngines,
listEngines,
registerEngine,
setEngineEnabled,
updateEngineConfig,
} from "../../../open-sse/services/compression/index.ts";
describe("compression engine registry contract", () => {
beforeEach(() => {
clearCompressionEngineRegistry();
});
it("registers and retrieves an engine by id", () => {
registerEngine(cavemanEngine);
assert.equal(getEngine("caveman"), cavemanEngine);
assert.equal(getEngine("missing"), null);
});
it("lists engine entries and filters enabled entries", () => {
registerEngine(cavemanEngine);
registerEngine(realRtkEngine);
assert.equal(listEngines().length, 2);
assert.equal(listEnabledEngines().length, 2);
assert.equal(setEngineEnabled("rtk", false), true);
assert.equal(
listEnabledEngines()
.map((entry) => entry.engine.id)
.join(","),
"caveman"
);
});
it("updates config only after engine validation passes", () => {
registerEngine(realRtkEngine);
const invalid = updateEngineConfig("rtk", { intensity: "extreme" });
assert.equal(invalid.valid, false);
assert.match(invalid.errors.join(" "), /intensity/);
const valid = updateEngineConfig("rtk", {
intensity: "aggressive",
applyToCodeBlocks: true,
});
assert.equal(valid.valid, true);
assert.deepEqual(getEngineEntry("rtk")?.config, {
intensity: "aggressive",
applyToCodeBlocks: true,
});
});
it("exposes schema and validation for built-in adapters", () => {
const cavemanSchema = cavemanEngine.getConfigSchema();
const rtkSchema = realRtkEngine.getConfigSchema();
const aggressiveSchema = aggressiveEngine.getConfigSchema();
const ultraSchema = ultraEngine.getConfigSchema();
assert.ok(cavemanSchema.some((field) => field.key === "intensity"));
assert.ok(rtkSchema.some((field) => field.key === "applyToCodeBlocks"));
assert.ok(aggressiveSchema.some((field) => field.key === "maxTokensPerMessage"));
assert.ok(ultraSchema.some((field) => field.key === "compressionRate"));
// Lite exposes its OWN minimal schema (preserveSystemPrompt), NOT the aggressive
// summarizer/threshold fields it previously leaked.
const liteSchema = liteEngine.getConfigSchema();
assert.ok(liteSchema.some((field) => field.key === "preserveSystemPrompt"));
assert.ok(
liteSchema.some((field) => field.key === "compressToolResults" && field.defaultValue === true)
);
assert.ok(!liteSchema.some((field) => field.key === "maxTokensPerMessage"));
assert.ok(!liteSchema.some((field) => field.key === "summarizerEnabled"));
assert.equal(
liteEngine.validateConfig({
preserveSystemPrompt: true,
compressToolResults: false,
}).valid,
true
);
assert.equal(liteEngine.validateConfig({ preserveSystemPrompt: "yes" }).valid, false);
assert.equal(liteEngine.validateConfig({ compressToolResults: "no" }).valid, false);
assert.equal(cavemanEngine.validateConfig({ intensity: "full" }).valid, true);
assert.equal(cavemanEngine.validateConfig({ intensity: "bad" }).valid, false);
assert.equal(realRtkEngine.validateConfig({ maxLinesPerResult: 20 }).valid, true);
assert.equal(aggressiveEngine.validateConfig({ maxTokensPerMessage: 2048 }).valid, true);
assert.equal(aggressiveEngine.validateConfig({ maxTokensPerMessage: 10 }).valid, false);
assert.equal(ultraEngine.validateConfig({ compressionRate: 0.4 }).valid, true);
assert.equal(ultraEngine.validateConfig({ compressionRate: 4 }).valid, false);
});
});