Files
OmniRoute/tests/unit/compression/llmlingua-worker.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

92 lines
3.2 KiB
TypeScript

/**
* Tests for the real LLMLingua worker-thread backend (`worker.ts` + `onnxWorker.ts`).
*
* The three optional deps (`@atjsh/llmlingua-2`, `@huggingface/transformers`,
* `js-tiktoken`) are NOT installed in this worktree, so the
* default path MUST fail-open WITHOUT spawning a worker:
*
* 1. Deps absent → fail-open, no spawn (ALWAYS runs here): the backend returns the
* ORIGINAL text unchanged, fast (no model load / worker spawn).
* 2. Type smoke: `workerBackend` is a function.
* 3. GATED real compression (RUN_LLMLINGUA_INT=1): real shrink with deps present;
* no-op skip here (deps absent).
*/
import { test, after } from "node:test";
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import {
workerBackend,
__resetLlmlinguaWorkerForTests,
} from "../../../open-sse/services/compression/engines/llmlingua/worker.ts";
const require = createRequire(import.meta.url);
/** Whether all three optional deps resolve in this environment. */
function depsResolve(): boolean {
try {
require.resolve("@atjsh/llmlingua-2");
require.resolve("@huggingface/transformers");
require.resolve("js-tiktoken");
return true;
} catch {
return false;
}
}
// Let the process exit cleanly: terminate any spawned worker + reset singletons.
after(() => {
__resetLlmlinguaWorkerForTests();
});
test("deps absent → fail-open, no spawn, returns original text fast", async () => {
if (depsResolve()) {
// Premise of this test is that the optional deps are NOT installed (the CI
// default). When they ARE present (e.g. a local integration setup), the backend
// legitimately spawns the worker and compresses, so this assertion no longer
// applies — the real path is covered by the gated test below.
console.log("skip: optional deps present — fail-open-when-absent test N/A");
return;
}
const input = "hello world this is some prose";
const start = Date.now();
const out1 = await workerBackend(input, {});
const elapsed = Date.now() - start;
// EXACT original text (fail-open), unchanged.
assert.equal(out1, input);
// Fast: no model load / worker spawn (proves the optional-deps gate short-circuits).
assert.ok(elapsed < 1000, `expected <1000ms, got ${elapsed}ms`);
// Second call exercises the memoized gate — still fail-open, still fast.
const out2 = await workerBackend(input, {});
assert.equal(out2, input);
});
test("type smoke: workerBackend is a function", () => {
assert.equal(typeof workerBackend, "function");
});
test("GATED real compression (RUN_LLMLINGUA_INT=1)", async () => {
if (process.env.RUN_LLMLINGUA_INT !== "1") {
console.log("skip: RUN_LLMLINGUA_INT!=1");
return;
}
if (!depsResolve()) {
console.log("skip: deps absent");
return;
}
// Long prose well above any practical floor so compression has room to shrink.
const LONG_PROSE =
"The quick brown fox jumps over the lazy dog while the sun sets slowly behind the distant hills. ".repeat(
120
);
const out = await workerBackend(LONG_PROSE, { model: "tinybert", compressionRate: 0.5 });
assert.equal(typeof out, "string");
assert.ok(out.length < LONG_PROSE.length, "expected a real shrink");
});