TestCache_TrimSpaces verifies that whitespace trimming is applied when TrimSpaces is enabled.
(t *testing.T)
| 119 | // TestCache_TrimSpaces verifies that whitespace trimming is applied when |
| 120 | // TrimSpaces is enabled. |
| 121 | func 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. |
nothing calls this directly
no test coverage detected