mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +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
117 lines
4.1 KiB
TypeScript
117 lines
4.1 KiB
TypeScript
/**
|
|
* Reasoning-effort mapping across the OpenAI Chat <-> Responses request translators.
|
|
*
|
|
* Chat Completions carries the reasoning hint as top-level `reasoning_effort`; the
|
|
* Responses API nests it as `reasoning.effort`. These tests pin both directions so
|
|
* the hint survives when a request crosses formats (e.g. a Responses client routed
|
|
* to an OpenAI-native Chat Completions upstream).
|
|
*
|
|
* Ported from upstream PR https://github.com/decolua/9router/pull/1817 (ryanngit).
|
|
* Adapted: OmniRoute previously promoted `reasoning.effort` only behind the
|
|
* Copilot-client gate (commit 75d9a83c25), which silently dropped the field for
|
|
* every other Responses client (OpenCode, Cursor, raw OpenAI Responses, ...).
|
|
* This test pins the unconditional promotion of effort while keeping the
|
|
* Copilot-only `summary` -> Claude thinking marker behind its existing gate.
|
|
*/
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
openaiToOpenAIResponsesRequest,
|
|
openaiResponsesToOpenAIRequest,
|
|
} from "../../open-sse/translator/request/openai-responses.ts";
|
|
import { convertResponsesApiFormat } from "../../open-sse/translator/helpers/responsesApiHelper.ts";
|
|
import { buildKiroPayload } from "../../open-sse/translator/request/openai-to-kiro.ts";
|
|
|
|
function asRecord(value: unknown): Record<string, unknown> {
|
|
return value as Record<string, unknown>;
|
|
}
|
|
|
|
test("Responses -> Chat promotes reasoning.effort for non-Copilot clients", () => {
|
|
const out = asRecord(
|
|
openaiResponsesToOpenAIRequest(
|
|
"gpt-test",
|
|
{ input: "hello", reasoning: { effort: "high" } },
|
|
true,
|
|
{} // no _copilotClient marker
|
|
)
|
|
);
|
|
assert.equal(out.reasoning_effort, "high");
|
|
assert.equal(out.reasoning, undefined);
|
|
});
|
|
|
|
test("Responses -> Ollama Cloud Chat preserves every advertised reasoning effort", () => {
|
|
for (const effort of ["low", "medium", "high"]) {
|
|
const out = asRecord(
|
|
openaiResponsesToOpenAIRequest(
|
|
"ollama-cloud/gpt-oss:20b",
|
|
{ input: "hello", reasoning: { effort } },
|
|
true,
|
|
{ _provider: "ollama-cloud" }
|
|
)
|
|
);
|
|
assert.equal(out.reasoning_effort, effort);
|
|
assert.equal(out.reasoning, undefined);
|
|
}
|
|
});
|
|
|
|
test("Responses -> Chat preserves reasoning.effort via the helper wrapper", () => {
|
|
const out = asRecord(
|
|
convertResponsesApiFormat({ input: "hello", reasoning: { effort: "medium" } })
|
|
);
|
|
assert.equal(out.reasoning_effort, "medium");
|
|
assert.equal(out.reasoning, undefined);
|
|
});
|
|
|
|
test("Responses -> Kiro preserves literal Max for GPT-5.6 models", () => {
|
|
for (const model of ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"]) {
|
|
const converted = asRecord(
|
|
convertResponsesApiFormat(
|
|
{
|
|
model: `kr/${model}`,
|
|
input: "hello",
|
|
reasoning: { effort: "max" },
|
|
},
|
|
null,
|
|
"kiro"
|
|
)
|
|
);
|
|
|
|
assert.equal(converted.reasoning_effort, "max");
|
|
|
|
const payload = buildKiroPayload(model, converted, false, null);
|
|
assert.equal(payload.additionalModelRequestFields?.reasoning?.effort, "max");
|
|
assert.equal(payload.additionalModelRequestFields?.output_config, undefined);
|
|
assert.equal(payload.additionalModelRequestFields?.thinking, undefined);
|
|
assert.equal(payload.additionalModelRequestFields?.max_tokens, undefined);
|
|
assert.doesNotMatch(
|
|
payload.conversationState.currentMessage.userInputMessage.content,
|
|
/<thinking_mode>/
|
|
);
|
|
}
|
|
});
|
|
|
|
test("Responses -> Chat does not overwrite an explicit reasoning_effort", () => {
|
|
const out = asRecord(
|
|
openaiResponsesToOpenAIRequest(
|
|
"gpt-test",
|
|
{ input: "hello", reasoning_effort: "low", reasoning: { effort: "high" } },
|
|
true,
|
|
{}
|
|
)
|
|
);
|
|
// Explicit Chat-level field wins over the Responses nesting.
|
|
assert.equal(out.reasoning_effort, "low");
|
|
});
|
|
|
|
test("Chat -> Responses already wraps reasoning_effort into reasoning.effort", () => {
|
|
const out = asRecord(
|
|
openaiToOpenAIResponsesRequest(
|
|
"gpt-test",
|
|
{ messages: [{ role: "user", content: "hi" }], reasoning_effort: "high" },
|
|
true,
|
|
{}
|
|
)
|
|
);
|
|
assert.deepEqual(out.reasoning, { effort: "high", summary: "auto" });
|
|
});
|