ollie/cmd/olliesrv/internal/agent/summary_cache_test.go

54 lines
1.7 KiB
Go

package agent
import (
"strings"
"testing"
"ollie/cmd/olliesrv/internal/backend"
)
func messageWithContent(callID, content string) backend.Message {
return backend.Message{Role: "tool", ToolCallID: callID, Content: content}
}
func TestToolSummaryHashSeparatesToolNames(t *testing.T) {
first := toolSummaryHash(backend.Message{Role: "tool", ToolName: "shell", Content: "same result"})
second := toolSummaryHash(backend.Message{Role: "tool", ToolName: "file_read", Content: "same result"})
if first == second {
t.Fatal("different tool names produced the same hash")
}
}
func TestNormalizeSummaryCacheContentPlainText(t *testing.T) {
got := normalizeSummaryCacheContent(" first line \r\n\r\n\nsecond line \t\n\n")
if got != "first line\n\nsecond line" {
t.Fatalf("normalized content = %q", got)
}
}
func TestNormalizeSummaryCacheContentPreservesStructuredContent(t *testing.T) {
content := "{\r\n \"key\": \"value\"\r\n}\r\n"
if got := normalizeSummaryCacheContent(content); got != content {
t.Fatalf("structured content changed: %q", got)
}
}
func TestToolSummaryHashIgnoresToolCallID(t *testing.T) {
first := toolSummaryHash(messageWithContent("first-call", "same result\n"))
second := toolSummaryHash(messageWithContent("second-call", "same result"))
if first != second {
t.Fatalf("hashes differ for identical content: %q != %q", first, second)
}
if !strings.HasPrefix(first, "cold-summary:v2:") {
t.Fatalf("hash missing version prefix: %q", first)
}
}
func TestToolSummaryHashSeparatesContent(t *testing.T) {
first := toolSummaryHash(messageWithContent("call", "first result"))
second := toolSummaryHash(messageWithContent("call", "second result"))
if first == second {
t.Fatal("different content produced the same hash")
}
}