chore: import Local-Cursor v1.1.8 source snapshot
Includes the current working directory changes. Historical commits and release binaries are excluded to limit Gitea storage. Source base: d7515973fbfd6dd2001fa156c483455b8081c7cb
This commit is contained in:
48
internal/backend/agent/model/anthropic_test.go
Normal file
48
internal/backend/agent/model/anthropic_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package modeladapter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAnthropicMessageCacheBreakpointsPreserveAppendOnlyHistory(t *testing.T) {
|
||||
for size := 1; size <= 32; size++ {
|
||||
t.Run(fmt.Sprintf("size_%02d", size), func(t *testing.T) {
|
||||
previous := anthropicMessagesForAppendOnlyTest(size)
|
||||
current := anthropicMessagesForAppendOnlyTest(size + 1)
|
||||
|
||||
applyAnthropicMessageCacheBreakpoints(previous)
|
||||
applyAnthropicMessageCacheBreakpoints(current)
|
||||
|
||||
want := mustMarshalAnthropicMessagesForTest(t, previous)
|
||||
got := mustMarshalAnthropicMessagesForTest(t, current[:len(previous)])
|
||||
if got != want {
|
||||
t.Fatalf("historical message prefix changed after append\nwant: %s\ngot: %s", want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func anthropicMessagesForAppendOnlyTest(count int) []anthropicMessage {
|
||||
messages := make([]anthropicMessage, 0, count)
|
||||
for index := 0; index < count; index++ {
|
||||
messages = append(messages, anthropicMessage{
|
||||
Role: "user",
|
||||
Content: []map[string]any{{
|
||||
"type": "text",
|
||||
"text": fmt.Sprintf("message-%02d", index),
|
||||
}},
|
||||
})
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
func mustMarshalAnthropicMessagesForTest(t *testing.T, messages []anthropicMessage) string {
|
||||
t.Helper()
|
||||
payload, err := json.Marshal(messages)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal anthropic messages: %v", err)
|
||||
}
|
||||
return string(payload)
|
||||
}
|
||||
Reference in New Issue
Block a user