Files
OmniRoute/tests/unit/repro-8841-context-overflow-opencode.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

90 lines
2.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-repro-8841-"));
const ORIGINAL_DATA_DIR = process.env.DATA_DIR;
process.env.DATA_DIR = TEST_DATA_DIR;
const { getResolvedModelCapabilities } = await import("../../src/lib/modelCapabilities.ts");
const { handleComboChat } = await import("../../open-sse/services/combo.ts");
const { getTokenLimit } = await import("../../open-sse/services/contextManager.ts");
const core = await import("../../src/lib/db/core.ts");
test.after(() => {
core.resetDbInstance();
if (ORIGINAL_DATA_DIR === undefined) delete process.env.DATA_DIR;
else process.env.DATA_DIR = ORIGINAL_DATA_DIR;
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
const noopLog = {
info() {},
warn() {},
error() {},
debug() {},
};
function largeBody() {
return {
messages: [{ role: "user", content: "x".repeat(840_000) }],
max_tokens: 8192,
};
}
function upstreamContextOverflowResponse() {
return new Response(
JSON.stringify({
error: {
code: "context_length_exceeded",
message:
"Input exceeds the context window for opencode/mimo-v2.5-free: estimated 210724 input tokens, limit 200000. Reduce the prompt or route to a model with a larger context window.",
},
}),
{
status: 400,
headers: { "Content-Type": "application/json" },
}
);
}
test("#8841 advertised vs compat-filter limit agree", () => {
const advertised = getTokenLimit("opencode-zen", "mimo-v2.5-free");
const caps = getResolvedModelCapabilities("opencode/mimo-v2.5-free");
assert.ok(advertised > 0);
assert.ok(
caps.contextWindow != null && caps.contextWindow > 0,
`contextWindow known (got ${caps.contextWindow})`
);
});
test("#8841 real upstream context overflow remains a fatal 400 after dispatch", async () => {
const body = largeBody();
let dispatches = 0;
const result = await handleComboChat({
body,
combo: {
name: "pro-coding-repro-8841",
strategy: "priority",
models: [
{ model: "opencode/north-mini-code-free" },
{ model: "opencode/north-mini-code-free" },
],
},
handleSingleModel: async () => {
dispatches += 1;
return upstreamContextOverflowResponse();
},
log: noopLog,
settings: {},
allCombos: [],
});
assert.equal(dispatches, 1, "real upstream overflow must short-circuit fallback");
assert.equal(result.status, 400);
const json = await result.json();
assert.equal(json.error?.code, "context_length_exceeded");
});