Files
OmniRoute/tests/unit/proxy-noauth-provider-6272.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

94 lines
3.6 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-6272-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const ORIGINAL_INITIAL_PASSWORD = process.env.INITIAL_PASSWORD;
delete process.env.INITIAL_PASSWORD;
const core = await import("../../src/lib/db/core.ts");
const settingsDb = await import("../../src/lib/db/settings.ts");
const { safeResolveProxy } = await import("../../src/sse/handlers/chatHelpers.ts");
test.after(async () => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
if (ORIGINAL_INITIAL_PASSWORD === undefined) delete process.env.INITIAL_PASSWORD;
else process.env.INITIAL_PASSWORD = ORIGINAL_INITIAL_PASSWORD;
});
test("#6272: resolveProxyForConnection('noauth', ...) honors a provider-level proxy assigned to 'opencode'", async () => {
core.getDbInstance();
const proxy = { type: "http", host: "127.0.0.1", port: 8888 };
// Reporter's second symptom: "same thing happen when i set the proxy directly
// in the provider menu" -> assign a provider-scoped proxy to the opencode
// provider id, the way Settings -> Providers -> opencode would persist it.
await settingsDb.setProxyForLevel("provider", "opencode", proxy);
const resolved = await settingsDb.resolveProxyForConnection("noauth", undefined);
assert.equal(
resolved?.proxy?.host,
"127.0.0.1",
`expected the opencode provider-level proxy to be honored, got level=${resolved?.level} proxy=${JSON.stringify(resolved?.proxy)}`
);
assert.equal(resolved?.level, "provider");
assert.equal(resolved?.levelId, "opencode");
});
test("control: resolveProxyForConnection('noauth', ...) still honors the GLOBAL proxy when no no-auth provider proxy is set", async () => {
core.getDbInstance();
await settingsDb.deleteProxyForLevel("provider", "opencode");
const proxy = { type: "http", host: "10.0.0.1", port: 9999 };
await settingsDb.setProxyForLevel("global", null, proxy);
const resolved = await settingsDb.resolveProxyForConnection("noauth", undefined);
assert.equal(resolved?.proxy?.host, "10.0.0.1");
assert.equal(resolved?.level, "global");
});
test("resolveProxyForConnection keeps provider-level no-auth proxies isolated", async () => {
core.getDbInstance();
await settingsDb.deleteProxyForLevel("global", null);
await settingsDb.setProxyForLevel("provider", "opencode", {
type: "http",
host: "127.0.0.2",
port: 8889,
});
await settingsDb.setProxyForLevel("provider", "theoldllm", {
type: "http",
host: "127.0.0.3",
port: 8890,
});
const opencode = await settingsDb.resolveProxyForConnection("noauth", undefined, "opencode");
const theOldLlm = await settingsDb.resolveProxyForConnection("noauth", undefined, "theoldllm");
assert.equal(opencode?.proxy?.host, "127.0.0.2");
assert.equal(theOldLlm?.proxy?.host, "127.0.0.3");
});
test("safeResolveProxy keeps the synthetic no-auth connection provider-specific", async () => {
core.getDbInstance();
await settingsDb.setProxyForLevel("provider", "opencode", {
type: "http",
host: "127.0.0.4",
port: 8891,
});
await settingsDb.setProxyForLevel("provider", "theoldllm", {
type: "http",
host: "127.0.0.5",
port: 8892,
});
const opencode = await safeResolveProxy("noauth", undefined, "opencode");
const theOldLlm = await safeResolveProxy("noauth", undefined, "theoldllm");
assert.equal(opencode?.proxy?.host, "127.0.0.4");
assert.equal(theOldLlm?.proxy?.host, "127.0.0.5");
});