Skip to content

Commit eadb40a

Browse files
committed
test(api): vary the conversation in the same-task cache-key stability test
The same-task stability test reused one messages array for both sdk-task-one calls, so a prompt_cache_key derived from conversation content would have passed: identical input cannot distinguish a task-scoped key from a conversation-derived one. The second turn now carries a follow-up exchange and the test asserts its input differs while the key holds. Mutation proof: a key that appends the input length once the conversation exceeds one item is killed by this test (1 failed | 83 passed), while the pre-change body passes that same mutant 84/84.
1 parent 8d1d1e4 commit eadb40a

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎src/api/providers/__tests__/openai-native.spec.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,12 +1512,27 @@ describe("OpenAiNativeHandler", () => {
15121512

15131513
const cacheHandler = new OpenAiNativeHandler({ ...mockOptions, apiModelId: "gpt-5.1" })
15141514

1515-
for (const taskId of ["sdk-task-one", "sdk-task-one", "sdk-task-two"]) {
1516-
await collectStream(cacheHandler.createMessage(systemPrompt, messages, { taskId }))
1515+
// The second turn of the same task carries a longer conversation. Reusing one
1516+
// messages array would let a key derived from the conversation pass, so the two
1517+
// calls must differ in input while the key holds.
1518+
const followUp: Anthropic.Messages.MessageParam[] = [
1519+
...messages,
1520+
{ role: "assistant", content: "Hello! How can I help?" },
1521+
{ role: "user", content: "Tell me about prompt caching." },
1522+
]
1523+
const turns: Array<{ taskId: string; messages: Anthropic.Messages.MessageParam[] }> = [
1524+
{ taskId: "sdk-task-one", messages },
1525+
{ taskId: "sdk-task-one", messages: followUp },
1526+
{ taskId: "sdk-task-two", messages },
1527+
]
1528+
1529+
for (const turn of turns) {
1530+
await collectStream(cacheHandler.createMessage(systemPrompt, turn.messages, { taskId: turn.taskId }))
15171531
}
15181532

15191533
const bodies = mockResponsesCreate.mock.calls.map(([body]) => body)
15201534
expect(bodies[0].prompt_cache_key).toBe("sdk-task-one")
1535+
expect(bodies[1].input).not.toEqual(bodies[0].input)
15211536
expect(bodies[1].prompt_cache_key).toBe(bodies[0].prompt_cache_key)
15221537
expect(bodies[2].prompt_cache_key).toBe("sdk-task-two")
15231538
expect(bodies[0].prompt_cache_retention).toBe("24h")

0 commit comments

Comments
 (0)