MCPcopy Index your code
hub / github.com/docker/docker-agent / TestCache_EmptyResponseIsNotCached

Function TestCache_EmptyResponseIsNotCached

pkg/runtime/cache_test.go:215–242  ·  view source on GitHub ↗

TestCache_EmptyResponseIsNotCached documents that the cache_response stop-hook deliberately drops empty (whitespace-only) assistant responses on the floor: replaying nothing on a future turn would leave the user staring at a blank reply with no recourse but to ask again, so the model is called every

(t *testing.T)

Source from the content-addressed store, hash-verified

213// the user staring at a blank reply with no recourse but to ask again,
214// so the model is called every time.
215func TestCache_EmptyResponseIsNotCached(t *testing.T) {
216 t.Parallel()
217
218 c, err := cache.New(cache.Config{Enabled: true})
219 require.NoError(t, err)
220
221 // Two empty-response streams; we expect the model to be called both
222 // times because the empty answer must never reach the cache.
223 stream1 := newStreamBuilder().AddContent("").AddStopWithUsage(5, 0).Build()
224 stream2 := newStreamBuilder().AddContent("").AddStopWithUsage(5, 0).Build()
225 prov := &messageRecordingProvider{
226 id: "test/mock-model",
227 streams: []*mockStream{stream1, stream2},
228 }
229
230 sess1 := session.New(session.WithUserMessage("silent treatment"))
231 runWithCache(t, c, prov, sess1)
232 sess2 := session.New(session.WithUserMessage("silent treatment"))
233 runWithCache(t, c, prov, sess2)
234
235 prov.mu.Lock()
236 defer prov.mu.Unlock()
237 assert.Len(t, prov.recordedMessages, 2,
238 "empty responses must not be cached; the model must be called every time")
239
240 _, found := c.Lookup("silent treatment")
241 assert.False(t, found, "empty assistant response must not appear in the cache")
242}
243
244func hasAgentChoice(events []Event, content string) bool {
245 for _, ev := range events {

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
newStreamBuilderFunction · 0.85
runWithCacheFunction · 0.85
AddStopWithUsageMethod · 0.80
LenMethod · 0.65
BuildMethod · 0.45
AddContentMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45
LookupMethod · 0.45

Tested by

no test coverage detected