Files
OmniRoute/tests/unit/command-code-user-array-5166.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

138 lines
4.8 KiB
TypeScript

/**
* #5166 (user-content-array 400 on Command Code / deepseek-v4-pro) context.
*
* The original regression was that a user message whose `content` was an array of
* content parts reached the CLI-only /alpha/generate endpoint, which required
* user content to be a plain string. Since #10265 the executor posts to the
* documented /provider/v1/chat/completions endpoint, which natively speaks the
* OpenAI chat.completions format — array content (text + image_url parts) is
* valid there and passes through unchanged. These tests pin that OpenAI-shaped
* passthrough.
*/
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-cmd-code-user-array-5166-")
);
process.env.DATA_DIR = TEST_DATA_DIR;
const { getExecutor } = await import("../../open-sse/executors/index.ts");
const core = await import("../../src/lib/db/core.ts");
const originalFetch = globalThis.fetch;
function okResponse() {
return new Response("{}", { status: 200, headers: { "Content-Type": "application/json" } });
}
test.after(() => {
globalThis.fetch = originalFetch;
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
test.afterEach(() => {
globalThis.fetch = originalFetch;
});
// ── helpers ────────────────────────────────────────────────────────────
type FetchCall = { url: string; init: Record<string, unknown>; body: Record<string, unknown> };
function captureFetch(response: Response) {
const calls: FetchCall[] = [];
globalThis.fetch = async (url, init: RequestInit = {}) => {
calls.push({
url: String(url),
init: init as Record<string, unknown>,
body: JSON.parse(String(init.body)),
});
return response;
};
return calls;
}
test("#5166 user message with multi-part array content passes through as an OpenAI array", async () => {
const calls = captureFetch(okResponse());
await getExecutor("command-code").execute({
model: "deepseek/deepseek-v4-pro",
stream: false,
credentials: { apiKey: "cc_test_key" },
body: {
messages: [
{
role: "user",
content: [
{ type: "text", text: "Hello" },
{ type: "text", text: "World" },
],
},
],
},
});
const userMsg = (calls[0].body.messages as Record<string, unknown>[])[0];
// OpenAI array content is valid on /provider/v1 — forwarded as-is.
assert.ok(Array.isArray(userMsg.content), "array content forwarded (no CLI flattening)");
const parts = userMsg.content as Record<string, unknown>[];
assert.equal(parts.length, 2);
assert.equal(parts[0].text, "Hello");
assert.equal(parts[1].text, "World");
});
test("#5166 user message with single text-part array passes through", async () => {
const calls = captureFetch(okResponse());
await getExecutor("command-code").execute({
model: "deepseek/deepseek-v4-pro",
stream: false,
credentials: { apiKey: "cc_test_key" },
body: {
messages: [{ role: "user", content: [{ type: "text", text: "Hi there" }] }],
},
});
const userMsg = (calls[0].body.messages as Record<string, unknown>[])[0];
const parts = userMsg.content as Record<string, unknown>[];
assert.equal(parts.length, 1);
assert.equal(parts[0].text, "Hi there");
});
test("#5166 user message with plain string content passes through unchanged", async () => {
const calls = captureFetch(okResponse());
await getExecutor("command-code").execute({
model: "deepseek/deepseek-v4-pro",
stream: false,
credentials: { apiKey: "cc_test_key" },
body: { messages: [{ role: "user", content: "Plain string message" }] },
});
const userMsg = (calls[0].body.messages as Record<string, unknown>[])[0];
assert.equal(userMsg.content, "Plain string message");
});
test("#5166 user message with mixed parts (text + image_url) keeps all parts", async () => {
const calls = captureFetch(okResponse());
await getExecutor("command-code").execute({
model: "deepseek/deepseek-v4-pro",
stream: false,
credentials: { apiKey: "cc_test_key" },
body: {
messages: [
{
role: "user",
content: [
{ type: "text", text: "Describe this:" },
{ type: "image_url", image_url: { url: "https://example.com/img.png" } },
],
},
],
},
});
const userMsg = (calls[0].body.messages as Record<string, unknown>[])[0];
const parts = userMsg.content as Record<string, unknown>[];
assert.equal(parts.length, 2, "text + image both preserved");
assert.equal(parts[0].text, "Describe this:");
assert.equal(parts[1].type, "image_url");
});