Files
OmniRoute/open-sse/services/__tests__/volumeDetector.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

126 lines
4.5 KiB
TypeScript

import { describe, it, expect, vi } from "vitest";
// Mock the DB so recommendStrategyOverride sees adaptiveVolumeRouting = true.
// Without this the real getSettings() throws (no SQLite in test env), the
// catch block fires, and the function returns noOverride before any rule runs.
vi.mock("@/lib/localDb", () => ({
getSettings: vi.fn().mockResolvedValue({ adaptiveVolumeRouting: true }),
}));
import { detectVolumeSignals, recommendStrategyOverride } from "../volumeDetector";
describe("volumeDetector", async () => {
describe("detectVolumeSignals", async () => {
it("detects simple single-message request", async () => {
const body = {
messages: [{ role: "user", content: "Hello" }],
};
const signals = detectVolumeSignals(body);
expect(signals.batchSize).toBe(1);
expect(signals.estimatedTokens).toBeLessThan(100);
expect(signals.toolCount).toBe(0);
expect(signals.hasBrowser).toBe(false);
expect(signals.complexity).toBe("trivial");
});
it("detects tool-heavy request as high complexity", async () => {
const body = {
messages: [{ role: "user", content: "Deploy the app to production" }],
tools: [
{ type: "function", function: { name: "run_command" } },
{ type: "function", function: { name: "read_file" } },
{ type: "function", function: { name: "write_file" } },
{ type: "function", function: { name: "browser_action" } },
],
};
const signals = detectVolumeSignals(body);
expect(signals.toolCount).toBe(4);
expect(signals.complexity).toBe("critical");
});
it("detects browser keywords", async () => {
const body = {
messages: [{ role: "user", content: "Navigate to the page and take a screenshot" }],
};
const signals = detectVolumeSignals(body);
expect(signals.hasBrowser).toBe(true);
});
it("detects batch from multi-part content", async () => {
const parts = Array.from({ length: 20 }, (_, i) => ({
type: "text",
text: `Item ${i}`,
}));
const body = {
messages: [{ role: "user", content: parts }],
};
const signals = detectVolumeSignals(body);
expect(signals.batchSize).toBe(20);
});
it("detects security keywords as high complexity", async () => {
const body = {
messages: [{ role: "user", content: "Refactor the authentication module for production" }],
};
const signals = detectVolumeSignals(body);
expect(
signals.complexity === "critical" || signals.complexity === "high",
`expected critical or high, got ${signals.complexity}`
).toBe(true);
});
});
describe("recommendStrategyOverride", async () => {
it("recommends round-robin for large batches", async () => {
const signals = detectVolumeSignals({ input: Array(60).fill("item") });
const override = await recommendStrategyOverride(signals, "priority");
expect(override.shouldOverride).toBe(true);
expect(override.strategy).toBe("round-robin");
expect(override.preferEconomy).toBe(true);
});
it("recommends premium-first for browser tasks", async () => {
const signals = {
batchSize: 1,
estimatedTokens: 500,
toolCount: 2,
hasBrowser: true,
hasImages: false,
complexity: "high" as const,
};
const override = await recommendStrategyOverride(signals, "round-robin");
expect(override.shouldOverride).toBe(true);
expect(override.strategy).toBe("priority");
expect(override.forcePremium).toBe(true);
});
it("flags economy for tiny requests without changing strategy", async () => {
const signals = {
batchSize: 1,
estimatedTokens: 100,
toolCount: 0,
hasBrowser: false,
hasImages: false,
complexity: "trivial" as const,
};
const override = await recommendStrategyOverride(signals, "priority");
expect(override.shouldOverride).toBe(false);
expect(override.preferEconomy).toBe(true);
});
it("no override for normal medium requests", async () => {
const signals = {
batchSize: 1,
estimatedTokens: 1000,
toolCount: 0,
hasBrowser: false,
hasImages: false,
complexity: "low" as const,
};
const override = await recommendStrategyOverride(signals, "priority");
expect(override.shouldOverride).toBe(false);
expect(override.preferEconomy).toBe(false);
});
});
});