MCPcopy
hub / github.com/docker/docker-agent / TestGetMessages_CacheControlWithSummary

Function TestGetMessages_CacheControlWithSummary

pkg/session/session_test.go:207–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

205}
206
207func TestGetMessages_CacheControlWithSummary(t *testing.T) {
208 t.Parallel()
209
210 // Caching contract pinned by this test:
211 //
212 // - The last invariant system message gets a cache-control marker.
213 // - The last caller-supplied extra (typically turn_start hook output)
214 // ALSO gets a cache-control marker so stable per-session/per-day
215 // extras (AddPromptFiles, AddEnvironmentInfo) participate in
216 // prompt caching. This matches the prior
217 // buildContextSpecificSystemMessages caching behavior.
218 // - Summary and conversation messages are not cache-controlled.
219 testAgent := agent.New("root", "instructions",
220 agent.WithToolSets(todoToolSet(t)),
221 )
222
223 s := New()
224 s.Messages = append(s.Messages, Item{Summary: "Test summary"})
225
226 extra := chat.Message{
227 Role: chat.MessageRoleSystem,
228 Content: "Today's date: 2026-04-25",
229 }
230 messages := s.GetMessages(testAgent, extra)
231
232 var checkpointIndices []int
233 for i, msg := range messages {
234 if msg.Role == chat.MessageRoleSystem && msg.CacheControl {
235 checkpointIndices = append(checkpointIndices, i)
236 }
237 }
238
239 require.Len(t, checkpointIndices, 2,
240 "invariant and last-extra messages should each be cache-controlled")
241
242 // Checkpoint #1: last invariant message (toolset instructions).
243 assert.Contains(t, messages[checkpointIndices[0]].Content, "Todo Tools",
244 "checkpoint #1 must land on the last invariant message")
245
246 // Checkpoint #2: last extra (the date system message).
247 assert.Equal(t, extra.Content, messages[checkpointIndices[1]].Content,
248 "checkpoint #2 must land on the last extra system message")
249
250 // The extra must come AFTER the invariant block.
251 assert.Greater(t, checkpointIndices[1], checkpointIndices[0],
252 "extras must come AFTER the invariant cache checkpoint")
253}
254
255func TestGetLastUserMessages(t *testing.T) {
256 t.Parallel()

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
WithToolSetsFunction · 0.92
todoToolSetFunction · 0.85
GetMessagesMethod · 0.80
NewFunction · 0.70
LenMethod · 0.65

Tested by

no test coverage detected