opencode-cursor-agent/internal/sanitize/sanitize_test.go

61 lines
1.6 KiB
Go

package sanitize
import (
"strings"
"testing"
)
func TestSanitizeTextAnthropicBilling(t *testing.T) {
input := "x-anthropic-billing-header: abc123\nHello"
got := SanitizeText(input)
if strings.Contains(got, "x-anthropic-billing-header") {
t.Errorf("billing header not removed: %q", got)
}
}
func TestSanitizeTextClaudeCode(t *testing.T) {
input := "I am Claude Code assistant"
got := SanitizeText(input)
if strings.Contains(got, "Claude Code") {
t.Errorf("'Claude Code' not replaced: %q", got)
}
if !strings.Contains(got, "Cursor") {
t.Errorf("'Cursor' not present in output: %q", got)
}
}
func TestSanitizeTextAnthropic(t *testing.T) {
input := "Powered by Anthropic's technology and anthropic.com"
got := SanitizeText(input)
if strings.Contains(got, "Anthropic") {
t.Errorf("'Anthropic' not replaced: %q", got)
}
if strings.Contains(got, "anthropic.com") {
t.Errorf("'anthropic.com' not replaced: %q", got)
}
}
func TestSanitizeTextNoChange(t *testing.T) {
input := "Hello, this is a normal message about cursor."
got := SanitizeText(input)
if got != input {
t.Errorf("unexpected change: %q -> %q", input, got)
}
}
func TestSanitizeMessages(t *testing.T) {
messages := []interface{}{
map[string]interface{}{"role": "user", "content": "Ask Claude Code something"},
map[string]interface{}{"role": "system", "content": "Use Anthropic's tools"},
}
result := SanitizeMessages(messages)
for _, raw := range result {
m := raw.(map[string]interface{})
c := m["content"].(string)
if strings.Contains(c, "Claude Code") || strings.Contains(c, "Anthropic") {
t.Errorf("found unsanitized content: %q", c)
}
}
}