Files
OmniRoute/tests/unit/attempt-logging-extract-responses-id.test.ts
Markus Hartung 04dba0460e fix(responses-continuation): recover a real id/output for passthrough and translate-mode replies (#11434)
Retargetado para release/v3.8.51 (release/v3.8.50 está congelada — freeze issue #11439). Validado em lote combinado (batch-0824h2, junto de #11435/#11436/#11437) contra o tip de release/v3.8.51: typecheck:core limpo, gates estáticos OK, 127/127 testes focados passando.

Investigação sólida com repro real via container isolado, três causas independentes identificadas e corrigidas com testes de regressão dedicados para cada uma. Obrigado pela contribuição!
2026-08-24 19:57:12 -03:00

53 lines
2.3 KiB
TypeScript

/**
* extractResponsesId is the write-side half of previous_response_id
* continuation (src/lib/db/responsesContinuationStore.ts is the read-side
* half): it decides what gets indexed in call_logs.response_id. See
* responses-continuation-passthrough-client-payload.test.ts and
* responses-continuation-store.test.ts for the fuller bug writeup this
* fixes -- this file covers the id-extraction half in isolation.
*/
import test from "node:test";
import assert from "node:assert/strict";
import { extractResponsesId } from "../../open-sse/handlers/chatCore/attemptLogging.ts";
const RESPONSES = "openai-responses";
test("extractResponsesId reads a direct id (non-streaming clientResponse)", () => {
assert.equal(extractResponsesId(RESPONSES, { id: "resp_123" }), "resp_123");
});
test("extractResponsesId reads a wrapped id (streaming clientResponse via clientPayloadCollector.build())", () => {
assert.equal(
extractResponsesId(RESPONSES, { _streamed: true, summary: { id: "resp_456" } }),
"resp_456"
);
});
test("extractResponsesId prefers a direct id over a wrapped one when both are present", () => {
assert.equal(
extractResponsesId(RESPONSES, { id: "resp_direct", summary: { id: "resp_wrapped" } }),
"resp_direct"
);
});
test("extractResponsesId returns null when sourceFormat is not openai-responses (never mistake a chatcmpl-* id)", () => {
assert.equal(extractResponsesId("openai", { id: "chatcmpl-abc" }), null);
assert.equal(extractResponsesId(undefined, { id: "resp_123" }), null);
});
test("extractResponsesId returns null for a missing/empty/non-string id in either shape", () => {
assert.equal(extractResponsesId(RESPONSES, {}), null);
assert.equal(extractResponsesId(RESPONSES, { id: "" }), null);
assert.equal(extractResponsesId(RESPONSES, { id: 123 }), null);
assert.equal(extractResponsesId(RESPONSES, { summary: {} }), null);
assert.equal(extractResponsesId(RESPONSES, { summary: { id: "" } }), null);
assert.equal(extractResponsesId(RESPONSES, { summary: null }), null);
});
test("extractResponsesId returns null for a non-object or nullish clientResponse", () => {
assert.equal(extractResponsesId(RESPONSES, null), null);
assert.equal(extractResponsesId(RESPONSES, undefined), null);
assert.equal(extractResponsesId(RESPONSES, "resp_123"), null);
});