Files
OmniRoute/tests/unit/combo-10597-error-body-logging.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

92 lines
3.1 KiB
TypeScript

/**
* #10597 — When a combo target fails with a non-2xx status, the per-target
* "Model X failed, trying next" COMBO log line only carries `{ status }` —
* the upstream error BODY (e.g. Anthropic's "prompt is too long" or a
* tool_use/tool_result pairing 400) is captured in `errorText` but never
* logged, so operators cannot distinguish failure causes from server logs
* without reproducing the request.
*/
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-combo-10597-"));
process.env.DATA_DIR = TEST_DATA_DIR;
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET || "combo-10597-test-secret";
const { handleComboChat } = await import("../../open-sse/services/combo.ts");
const DISTINCTIVE_ERROR_TEXT =
"messages.450: `tool_use` ids were found without `tool_result` blocks immediately after";
type WarnCall = { tag: string; msg: string; meta: unknown };
const warnCalls: WarnCall[] = [];
const log = {
info: () => {},
debug: () => {},
error: () => {},
warn: (tag: string, msg: string, meta?: unknown) => {
warnCalls.push({ tag, msg, meta });
},
};
function failing400() {
return new Response(
JSON.stringify({
type: "error",
error: { type: "invalid_request_error", message: DISTINCTIVE_ERROR_TEXT },
}),
{ status: 400, headers: { "Content-Type": "application/json" } }
);
}
function healthy200(model: string) {
return new Response(
JSON.stringify({
id: "ok",
object: "chat.completion",
model,
choices: [{ index: 0, message: { role: "assistant", content: "hello from " + model }, finish_reason: "stop" }],
}),
{ status: 200, headers: { "Content-Type": "application/json" } }
);
}
function makeCombo(models: string[]) {
return { name: "test-combo-10597", strategy: "priority", models: models.map((m) => ({ model: m })) };
}
test("#10597 COMBO failure log must surface the upstream error body, not just the status code", async () => {
const modelsCalled: string[] = [];
const handleSingleModel = async (_body: unknown, modelStr: string) => {
modelsCalled.push(modelStr);
if (modelsCalled.length === 1) return failing400();
return healthy200(modelStr);
};
const result = await handleComboChat({
body: { model: "test", messages: [{ role: "user", content: "hi" }] },
combo: makeCombo(["claude/claude-opus-4-8", "openai/gpt-4o-mini"]),
handleSingleModel,
log,
settings: {},
allCombos: [],
});
assert.equal(result.status, 200);
assert.equal(modelsCalled.length, 2);
const failureLog = warnCalls.find(
(c) => typeof c.msg === "string" && c.msg.includes("claude/claude-opus-4-8") && c.msg.includes("failed")
);
assert.ok(failureLog, "expected a COMBO warn log for the failing leg");
const serialized = JSON.stringify(failureLog);
assert.ok(
serialized.includes("tool_use") || serialized.includes(DISTINCTIVE_ERROR_TEXT),
`expected the upstream error body to appear in the COMBO failure log, but got: ${serialized}`
);
});