mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 23:32:12 +03:00
Validated in local merge-train (devbox-vm-06-dev002) @ combined-tip (FAST gates green: static + changed tests + vitest — only pre-existing audit.test.ts flake). Evidence: /home/diegosouzapw/dev/proxys/OmniRoute/.claude/worktrees/merge-train-20260805-213228-suite.log
131 lines
5.2 KiB
TypeScript
131 lines
5.2 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,
|
|
})
|
|
);
|
|
});
|
|
|
|
test("missing clientRawRequest → empty endpointPath", () => {
|
|
const r = resolveChatCoreRequestFormat({ ...base, clientRawRequest: null });
|
|
assert.equal(r.endpointPath, "");
|
|
});
|