Files
OmniRoute/tests/unit/chatcore-request-format.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

133 lines
5.3 KiB
TypeScript

// tests/unit/chatcore-request-format.test.ts
// Characterization of resolveChatCoreRequestFormat — the endpoint/format resolution slice extracted
// from the top of handleChatCore (chatCore god-file decomposition, #3501). Locks the endpointPath
// construction, the /responses detection, the nativeCodexPassthrough + isDroidCLI + copilot wiring,
// and the clientResponseFormat downgrade (OpenAI Responses shape off a non-/responses, non-Droid
// endpoint collapses to plain OpenAI).
import { test } from "node:test";
import assert from "node:assert/strict";
import { resolveChatCoreRequestFormat } from "../../open-sse/handlers/chatCore/requestFormat.ts";
import { shouldUseNativeCodexPassthrough } from "../../open-sse/handlers/chatCore/passthroughHelpers.ts";
import { FORMATS } from "../../open-sse/translator/formats.ts";
const base = {
body: { messages: [{ role: "user", content: "hi" }] },
provider: "openai",
userAgent: "unit-test",
};
test("chat/completions endpoint → openai source, not a responses endpoint, no downgrade", () => {
const r = resolveChatCoreRequestFormat({
...base,
clientRawRequest: { endpoint: "/v1/chat/completions", headers: new Headers() },
});
assert.equal(r.endpointPath, "/v1/chat/completions");
assert.equal(r.sourceFormat, FORMATS.OPENAI);
assert.equal(r.isResponsesEndpoint, false);
assert.equal(r.clientResponseFormat, FORMATS.OPENAI);
assert.equal(r.nativeCodexPassthrough, false); // provider !== codex
assert.equal(r.isDroidCLI, false);
assert.equal(r.copilotCompatibleReasoning, false);
});
test("/responses endpoint → openai-responses source + isResponsesEndpoint, kept (no downgrade)", () => {
const r = resolveChatCoreRequestFormat({
body: { input: "x" },
provider: "openai",
userAgent: "unit-test",
clientRawRequest: { endpoint: "/v1/responses", headers: new Headers() },
});
assert.equal(r.sourceFormat, FORMATS.OPENAI_RESPONSES);
assert.equal(r.isResponsesEndpoint, true);
assert.equal(r.clientResponseFormat, FORMATS.OPENAI_RESPONSES);
});
test("xAI oauth on /responses enables nativeXaiResponsesPassthrough (#8964)", () => {
const r = resolveChatCoreRequestFormat({
body: { input: "x", tools: [{ type: "web_search" }, { type: "x_search" }] },
provider: "xai-oauth",
userAgent: "unit-test",
clientRawRequest: { endpoint: "/v1/responses", headers: new Headers() },
});
assert.equal(r.sourceFormat, FORMATS.OPENAI_RESPONSES);
assert.equal(r.isResponsesEndpoint, true);
assert.equal(r.nativeXaiResponsesPassthrough, true);
assert.equal(r.nativeCodexPassthrough, false);
});
test("xao alias on /responses enables nativeXaiResponsesPassthrough (#8964)", () => {
const r = resolveChatCoreRequestFormat({
body: { input: "x" },
provider: "xao",
userAgent: "unit-test",
clientRawRequest: { endpoint: "/v1/responses", headers: new Headers() },
});
assert.equal(r.nativeXaiResponsesPassthrough, true);
});
test("Responses-shaped body on a /chat/completions endpoint downgrades clientResponseFormat to openai", () => {
const r = resolveChatCoreRequestFormat({
body: { input: "describe" }, // input + no messages → openai-responses via body
provider: "openai",
userAgent: "unit-test",
clientRawRequest: { endpoint: "/v1/chat/completions", headers: new Headers() },
});
assert.equal(r.sourceFormat, FORMATS.OPENAI_RESPONSES);
assert.equal(r.isResponsesEndpoint, false);
assert.equal(r.clientResponseFormat, FORMATS.OPENAI); // downgraded
});
test("Droid CLI suppresses the downgrade (clientResponseFormat stays openai-responses)", () => {
const r = resolveChatCoreRequestFormat({
body: { input: "describe" },
provider: "openai",
userAgent: "Droid/1.2 codex-cli",
clientRawRequest: { endpoint: "/v1/chat/completions", headers: new Headers() },
});
assert.equal(r.isDroidCLI, true);
assert.equal(r.sourceFormat, FORMATS.OPENAI_RESPONSES);
assert.equal(r.clientResponseFormat, FORMATS.OPENAI_RESPONSES); // !isDroidCLI is false → no downgrade
});
test("copilotCompatibleReasoning detects copilot via header or user-agent", () => {
const viaUa = resolveChatCoreRequestFormat({
...base,
userAgent: "GitHubCopilotChat/0.1",
clientRawRequest: { endpoint: "/v1/chat/completions", headers: new Headers() },
});
assert.equal(viaUa.copilotCompatibleReasoning, true);
const viaHeader = resolveChatCoreRequestFormat({
...base,
clientRawRequest: {
endpoint: "/v1/chat/completions",
headers: new Headers({ "x-client": "copilot-vscode" }),
},
});
assert.equal(viaHeader.copilotCompatibleReasoning, true);
});
test("nativeCodexPassthrough delegates to shouldUseNativeCodexPassthrough (codex + responses)", () => {
const r = resolveChatCoreRequestFormat({
body: { input: "x" },
provider: "codex",
userAgent: "unit-test",
clientRawRequest: { endpoint: "/v1/responses", headers: new Headers() },
});
assert.equal(
r.nativeCodexPassthrough,
shouldUseNativeCodexPassthrough({
provider: "codex",
sourceFormat: r.sourceFormat,
endpointPath: r.endpointPath,
body: { input: "x" },
headers: new Headers(),
})
);
});
test("missing clientRawRequest → empty endpointPath", () => {
const r = resolveChatCoreRequestFormat({ ...base, clientRawRequest: null });
assert.equal(r.endpointPath, "");
});