Files
OmniRoute/tests/unit/onnxruntime-single-copy.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

73 lines
3.3 KiB
TypeScript

/**
* Regression guard — the dependency tree must resolve exactly ONE
* `onnxruntime-node` (and one `onnxruntime-common`).
*
* `@huggingface/transformers` pins `onnxruntime-node` to an EXACT version
* (4.2.0 → "1.24.3"). Whenever the root range in package.json drifts off that
* pin, npm nests a second copy under
* `node_modules/@huggingface/transformers/node_modules/onnxruntime-node`.
*
* Two copies cannot coexist in one Node process: both ship a native
* `libonnxruntime.so.1` under the SAME SONAME, so glibc's loader binds
* whichever was dlopen()ed first and the other addon dies with
*
* Error: .../libonnxruntime.so.1: version `VERS_1.27.0' not found
* (required by .../onnxruntime_binding.node)
*
* That is exactly what a production-group dependabot bump did on 2026-08-16
* (root `onnxruntime-node` "~1.24.3" → "~1.27.0"): it broke the Docker image
* build at the Dockerfile's post-build standalone verification step, which
* imports `@huggingface/transformers` and `onnxruntime-node` in one process.
*
* Keep the root range compatible with whatever `@huggingface/transformers`
* pins — do not "fix" a future recurrence by copying the nested native
* binaries into the bundle; the SONAME clash makes that impossible.
*/
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
const repoRoot = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
const lockfile = JSON.parse(readFileSync(join(repoRoot, "package-lock.json"), "utf8")) as {
packages: Record<string, { version?: string; dependencies?: Record<string, string> }>;
};
function copiesOf(pkg: string): string[] {
return Object.keys(lockfile.packages).filter(
(key) => key === `node_modules/${pkg}` || key.endsWith(`/node_modules/${pkg}`)
);
}
// Scoped to `onnxruntime-node` on purpose. `onnxruntime-common` is types/interfaces
// only and `onnxruntime-web` is WASM — neither dlopen()s anything, so their nested
// duplicates (onnxruntime-web carries its own onnxruntime-common) are harmless.
// `onnxruntime-node` is the sole package shipping the native libonnxruntime.so.1.
test("package-lock.json resolves exactly one copy of onnxruntime-node", () => {
assert.deepEqual(
copiesOf("onnxruntime-node"),
["node_modules/onnxruntime-node"],
"onnxruntime-node must resolve to a single hoisted copy — a nested duplicate ships a " +
"second libonnxruntime.so.1 under the same SONAME and breaks the standalone/Docker build"
);
});
test("root onnxruntime-node matches the exact version @huggingface/transformers pins", () => {
const transformers = lockfile.packages["node_modules/@huggingface/transformers"];
assert.ok(transformers, "@huggingface/transformers must be present in the lockfile");
const pinned = transformers.dependencies?.["onnxruntime-node"];
assert.ok(pinned, "@huggingface/transformers must declare an onnxruntime-node dependency");
const resolved = lockfile.packages["node_modules/onnxruntime-node"]?.version;
assert.equal(
resolved,
pinned,
`the hoisted onnxruntime-node (${resolved}) must equal the version ` +
`@huggingface/transformers pins (${pinned}); otherwise npm nests a second, ` +
`ABI-incompatible native copy`
);
});