Files
OmniRoute/tests/unit/repro-8430.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

79 lines
3.1 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
const { VisionBridgeGuardrail } = await import("../../src/lib/guardrails/visionBridge.ts");
const { resetGuardrailsForTests } = await import("../../src/lib/guardrails/registry.ts");
const { getBestVisionModel } = await import("../../src/lib/guardrails/visionBridgeRouter.ts");
import type { GuardrailContext } from "../../src/lib/guardrails/base.ts";
import type { VisionModelConfig } from "../../src/lib/guardrails/visionBridgeHelpers.ts";
const mockSettings: Record<string, unknown> = {
visionBridgeEnabled: true,
visionBridgePrompt: "Describe this image concisely.",
visionBridgeTimeout: 30000,
visionBridgeMaxImages: 10,
};
function createGuardrail(options?: Parameters<typeof VisionBridgeGuardrail>[0]) {
return new VisionBridgeGuardrail({
...options,
deps: {
getSettings: async () => mockSettings,
callVisionModel: async (_i: string, _c: VisionModelConfig) => {
throw new Error("Vision API error 401: Missing API key");
},
hasUsableCredentials: async () => false,
...(options?.deps ?? {}),
},
});
}
function createContext(o: Partial<GuardrailContext> = {}): GuardrailContext {
return { model: "deepseek/deepseek-v4-pro", log: console, ...o };
}
function createPayload(o: Record<string, unknown> = {}): Record<string, unknown> {
return {
model: "deepseek/deepseek-v4-pro",
messages: [
{
role: "user",
content: [
{ type: "text", text: "What is in this image?" },
{ type: "image_url", image_url: { url: "https://example.com/image.png" } },
],
},
],
...o,
};
}
test.beforeEach(() => { resetGuardrailsForTests({ registerDefaults: false }); });
test("8430a: getBestVisionModel returns null when every vision-capable candidate is unusable", async () => {
const model = await getBestVisionModel({}, { hasUsableCredentials: async () => false });
assert.strictEqual(model, null, `no vision provider reachable, but returned unreachable '${model}'`);
});
test("8430b: fixedModel describe-path target must not be an unreachable model", async () => {
const model = await getBestVisionModel(
{ fixedModel: "openai/gpt-4o-mini" },
{ hasUsableCredentials: async () => false }
);
assert.strictEqual(model, null, `fixedModel short-circuit returned unreachable '${model}'`);
});
test("8430c: describe path does not forward raw image when no vision provider is reachable", async () => {
const guardrail = createGuardrail({
deps: { checkModelHasComboMapping: async (_m: string) => true },
});
const result = await guardrail.preCall(createPayload(), createContext());
assert.strictEqual(result.block, false);
assert.ok(result.modifiedPayload, "expected a modified payload");
const modified = result.modifiedPayload as {
messages: Array<{ content: Array<{ type: string; text?: string }> }>;
};
const content = modified.messages[0].content;
const imagePart = content.find((p) => p.type === "image_url" || p.type === "image");
assert.strictEqual(imagePart, undefined, "raw image forwarded with no clear error (ask #2 unimplemented)");
});