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

Function TestCache_TrimSpaces

pkg/runtime/cache_test.go:121–152  ·  view source on GitHub ↗

TestCache_TrimSpaces verifies that whitespace trimming is applied when TrimSpaces is enabled.

(t *testing.T)

Source from the content-addressed store, hash-verified

119// TestCache_TrimSpaces verifies that whitespace trimming is applied when
120// TrimSpaces is enabled.
121func TestCache_TrimSpaces(t *testing.T) {
122 t.Parallel()
123
124 c, err := cache.New(cache.Config{Enabled: true, TrimSpaces: true})
125 require.NoError(t, err)
126
127 stream := newStreamBuilder().
128 AddContent("Trimmed!").
129 AddStopWithUsage(5, 3).
130 Build()
131 prov := &messageRecordingProvider{
132 id: "test/mock-model",
133 streams: []*mockStream{stream},
134 }
135
136 // First turn: question with surrounding whitespace.
137 sess1 := session.New(session.WithUserMessage(" Hello "))
138 runWithCache(t, c, prov, sess1)
139
140 prov.mu.Lock()
141 require.Len(t, prov.recordedMessages, 1)
142 prov.mu.Unlock()
143
144 // Second turn: same question without whitespace must hit the cache.
145 sess2 := session.New(session.WithUserMessage("Hello"))
146 runWithCache(t, c, prov, sess2)
147
148 prov.mu.Lock()
149 defer prov.mu.Unlock()
150 assert.Len(t, prov.recordedMessages, 1, "trim-enabled cache must hit when whitespace differs")
151 assert.True(t, hasAssistantMessage(sess2, "Trimmed!"))
152}
153
154// TestCache_DisabledHasNoEffect verifies that when the agent has no cache
155// attached, every call goes through to the model.

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected