fix: strip Claude Code attribution from non-Anthropic translations
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
const claudeCodeAttributionSystemPrefix = "x-anthropic-billing-header:"
|
||||
|
||||
// IsClaudeCodeAttributionSystemText reports whether text is the Claude Code
|
||||
// attribution block that carries per-request billing and prompt fingerprint data.
|
||||
func IsClaudeCodeAttributionSystemText(text string) bool {
|
||||
text = strings.TrimLeftFunc(text, unicode.IsSpace)
|
||||
return strings.HasPrefix(text, claudeCodeAttributionSystemPrefix)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package util
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestIsClaudeCodeAttributionSystemText(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
text string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "Claude Code attribution block",
|
||||
text: "x-anthropic-billing-header: cc_version=2.1.63.abc; cc_entrypoint=cli; cch=12345;",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "leading whitespace",
|
||||
text: "\n\t x-anthropic-billing-header: cc_version=2.1.63.abc; cch=12345;",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "regular system prompt",
|
||||
text: "You are helpful.",
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "empty text",
|
||||
text: "",
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := IsClaudeCodeAttributionSystemText(tt.text); got != tt.want {
|
||||
t.Fatalf("IsClaudeCodeAttributionSystemText(%q) = %v, want %v", tt.text, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user