Files
OmniRoute/tests/unit/routing-finish-reason.test.ts
Ravi Tharuma 3e2a6d8f35 fix(credentialHealth): do not poison multi-upstream openai-compat conn on one model 402 (#12875)
Validado numa worktree combinada com a onda de dashboard/monitoring desta leva sobre `release/v3.8.51`: typecheck:core limpo, check-api-typecheck OK (289), check-file-size OK após rebaseline, 130/131 nos testes focados — a falha restante é asserção de tempo de parede sob carga, verde 6/6 isolada.

Envenenar a conexão inteira por um 402 de **um** modelo é o erro clássico de granularidade em provider openai-compatible com múltiplos upstreams — derruba modelos que estavam saudáveis. Restringir ao modelo afetado é o comportamento correto, e é a mesma distinção que o guia de resiliência faz entre cooldown de conexão e lockout de modelo.
2026-09-10 10:42:34 -03:00

37 lines
1.1 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { routingFinishReason } from "../../open-sse/handlers/chatCore/routingFinishReason.ts";
test("routing finish reasons preserve chat and Responses shapes", () => {
assert.equal(routingFinishReason({ choices: [{ finish_reason: "stop" }] }), "stop");
assert.equal(routingFinishReason({ output: [null, {}, { finish_reason: "length" }] }), "length");
assert.equal(
routingFinishReason({
choices: [{ finish_reason: "tool_calls" }],
output: [{ finish_reason: "stop" }],
}),
"tool_calls"
);
});
test("unknown routing response shapes remain null", () => {
for (const body of [
null,
undefined,
false,
"stop",
12,
{},
{ choices: [] },
{ choices: [null] },
{ choices: [{ finish_reason: 42 }] },
{ output: [null, 3, { finish_reason: false }] },
]) {
assert.equal(routingFinishReason(body), null);
}
});
test("missing chat finish reason falls back to Responses output", () => {
assert.equal(routingFinishReason({ choices: [{}], output: [{ finish_reason: "stop" }] }), "stop");
});