|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +const { openaiToOpenAIResponsesRequest, openaiResponsesToOpenAIRequest } = |
| 4 | + await import("../../open-sse/translator/request/openai-responses.js"); |
| 5 | + |
| 6 | +const CHAT_BODY = (extra = {}) => ({ |
| 7 | + model: "example-model", |
| 8 | + messages: [{ role: "user", content: "hello" }], |
| 9 | + ...extra, |
| 10 | +}); |
| 11 | + |
| 12 | +describe("#3216 prompt_cache_key across the chat/responses translation", () => { |
| 13 | + it("preserves an explicit key when converting chat → responses", () => { |
| 14 | + const out = openaiToOpenAIResponsesRequest( |
| 15 | + "example-model", |
| 16 | + CHAT_BODY({ prompt_cache_key: "stable-cache-key" }), |
| 17 | + true, |
| 18 | + {}, |
| 19 | + ); |
| 20 | + |
| 21 | + expect(out.prompt_cache_key).toBe("stable-cache-key"); |
| 22 | + }); |
| 23 | + |
| 24 | + it("does not invent a key when the client sent none", () => { |
| 25 | + const out = openaiToOpenAIResponsesRequest("example-model", CHAT_BODY(), true, {}); |
| 26 | + |
| 27 | + expect(out.prompt_cache_key).toBeUndefined(); |
| 28 | + }); |
| 29 | + |
| 30 | + it("still drops the key on the responses → chat direction", () => { |
| 31 | + const out = openaiResponsesToOpenAIRequest( |
| 32 | + "example-model", |
| 33 | + { |
| 34 | + model: "example-model", |
| 35 | + input: [{ role: "user", content: [{ type: "input_text", text: "hello" }] }], |
| 36 | + prompt_cache_key: "stable-cache-key", |
| 37 | + }, |
| 38 | + true, |
| 39 | + {}, |
| 40 | + ); |
| 41 | + |
| 42 | + expect(out.prompt_cache_key).toBeUndefined(); |
| 43 | + }); |
| 44 | +}); |
0 commit comments