Files
OmniRoute/tests/unit/runtime-env.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

107 lines
3.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import path from "node:path";
import { EventEmitter } from "node:events";
import { createRequire, syncBuiltinESMExports } from "node:module";
import { pathToFileURL } from "node:url";
const require = createRequire(import.meta.url);
const childProcess = require("node:child_process");
const modulePath = path.join(process.cwd(), "scripts/build/runtime-env.mjs");
const originalSpawn = childProcess.spawn;
const originalProcessOn = process.on;
const originalProcessExit = process.exit;
const originalProcessKill = process.kill;
async function loadRuntimeEnv(label) {
return import(`${pathToFileURL(modulePath).href}?case=${label}-${Date.now()}`);
}
test.afterEach(() => {
childProcess.spawn = originalSpawn;
process.on = originalProcessOn;
process.exit = originalProcessExit;
process.kill = originalProcessKill;
syncBuiltinESMExports();
});
test("runtime env helpers normalize runtime ports and conflicting color flags", async () => {
const runtimeEnv = await loadRuntimeEnv("helpers");
assert.deepEqual(
runtimeEnv.withRuntimePortEnv(
{ NODE_ENV: "test" },
{ basePort: 20128, apiPort: 21128, dashboardPort: 22128 }
),
{
NODE_ENV: "test",
OMNIROUTE_PORT: "20128",
PORT: "22128",
DASHBOARD_PORT: "22128",
API_PORT: "21128",
// #8999 (docker entrypoint moved to /app) made withRuntimePortEnv also pin
// the bind address, defaulting to 0.0.0.0 when OMNIROUTE_HOSTNAME is unset.
HOSTNAME: "0.0.0.0",
}
);
assert.deepEqual(
runtimeEnv.sanitizeColorEnv({ FORCE_COLOR: "1", NO_COLOR: "1", TERM: "xterm-256color" }),
{ NO_COLOR: "1", TERM: "xterm-256color" }
);
assert.deepEqual(runtimeEnv.sanitizeColorEnv({ FORCE_COLOR: "1" }), { FORCE_COLOR: "1" });
});
test("spawnWithForwardedSignals forwards process signals and exit status", async () => {
const signalHandlers = new Map();
const childKillSignals = [];
const processKills = [];
const processExits = [];
const spawnCalls = [];
let child;
childProcess.spawn = (command, args, options) => {
spawnCalls.push({ command, args, options });
child = new EventEmitter();
child.kill = (signal) => childKillSignals.push(signal);
return child;
};
process.on = (signal, handler) => {
signalHandlers.set(signal, handler);
return process;
};
process.exit = (code) => {
processExits.push(code);
};
process.kill = (pid, signal) => {
processKills.push({ pid, signal });
return true;
};
syncBuiltinESMExports();
const runtimeEnv = await loadRuntimeEnv("spawn");
const returnedChild = runtimeEnv.spawnWithForwardedSignals("node", ["server.js"], {
stdio: "inherit",
});
assert.equal(returnedChild, child);
assert.deepEqual(spawnCalls, [
{
command: "node",
args: ["server.js"],
options: { stdio: "inherit" },
},
]);
signalHandlers.get("SIGINT")();
signalHandlers.get("SIGTERM")();
assert.deepEqual(childKillSignals, ["SIGINT", "SIGTERM"]);
child.emit("exit", 3, null);
child.emit("exit", null, "SIGTERM");
assert.deepEqual(processExits, [3]);
assert.deepEqual(processKills, [{ pid: process.pid, signal: "SIGTERM" }]);
});