mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-09 09:29:17 +08:00
- Add shared `GenerateClaudeToolCallID` in `common` and replace duplicated local `toolu_` generators across Claude request translators for consistent, uniform ID generation. - Replace `bufio.Scanner`-based SSE line handling with manual newline parsing and use `JoinRawArray` for array assembly to avoid scanner buffer limits and extra wrapping allocations. - Improve carrier/thought signature scrubbing to safely strip internal metadata only when present and detect spoofed/duplicate `thoughtSignature` keys (including raw/unicode-escaped forms) during sanitized JSON traversal.
36 lines
1022 B
Go
36 lines
1022 B
Go
package common
|
|
|
|
import "testing"
|
|
|
|
func TestRequestModelNamePrefersOriginalRequest(t *testing.T) {
|
|
original := []byte(`{"model":"original-model"}`)
|
|
translated := []byte(`{"model":"translated-model"}`)
|
|
|
|
if got := RequestModelName(original, translated); got != "original-model" {
|
|
t.Fatalf("model = %q, want original-model", got)
|
|
}
|
|
}
|
|
|
|
func TestRequestModelNameSupportsWrappedRequest(t *testing.T) {
|
|
request := []byte(`{"request":{"model":"wrapped-model"}}`)
|
|
|
|
if got := RequestModelName(nil, request); got != "wrapped-model" {
|
|
t.Fatalf("model = %q, want wrapped-model", got)
|
|
}
|
|
}
|
|
|
|
func TestGenerateClaudeToolCallID(t *testing.T) {
|
|
id := GenerateClaudeToolCallID()
|
|
if len(id) != 30 {
|
|
t.Fatalf("expected len 30 (toolu_ + 24), got %d: %q", len(id), id)
|
|
}
|
|
if id[:6] != "toolu_" {
|
|
t.Fatalf("expected prefix toolu_, got %q", id)
|
|
}
|
|
for _, ch := range id[6:] {
|
|
if !((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')) {
|
|
t.Fatalf("invalid character in ID %q: %c", id, ch)
|
|
}
|
|
}
|
|
}
|