Files
new-api/setting/model_setting/claude_test.go
T
CaIon 91ed4e196a feat: implement tiered billing expression evaluation and related functionality
- Added support for tiered billing expressions in the billing system.
- Introduced new types and functions for handling billing expressions, including caching and execution.
- Updated existing billing logic to accommodate tiered billing scenarios.
- Enhanced request handling to support incoming billing expression requests.
- Added tests for tiered billing functionality to ensure correctness.
2026-03-17 16:59:25 +08:00

61 lines
1.7 KiB
Go

package model_setting
import (
"net/http"
"testing"
)
func TestClaudeSettingsWriteHeadersMergesConfiguredValuesIntoSingleHeader(t *testing.T) {
settings := &ClaudeSettings{
HeadersSettings: map[string]map[string][]string{
"claude-3-7-sonnet-20250219-thinking": {
"anthropic-beta": {
"token-efficient-tools-2025-02-19",
},
},
},
}
headers := http.Header{}
headers.Set("anthropic-beta", "output-128k-2025-02-19")
settings.WriteHeaders("claude-3-7-sonnet-20250219-thinking", &headers)
got := headers.Values("anthropic-beta")
if len(got) != 1 {
t.Fatalf("expected a single merged header value, got %v", got)
}
expected := "output-128k-2025-02-19,token-efficient-tools-2025-02-19"
if got[0] != expected {
t.Fatalf("expected merged header %q, got %q", expected, got[0])
}
}
func TestClaudeSettingsWriteHeadersDeduplicatesAcrossCommaSeparatedAndRepeatedValues(t *testing.T) {
settings := &ClaudeSettings{
HeadersSettings: map[string]map[string][]string{
"claude-3-7-sonnet-20250219-thinking": {
"anthropic-beta": {
"token-efficient-tools-2025-02-19",
"computer-use-2025-01-24",
},
},
},
}
headers := http.Header{}
headers.Add("anthropic-beta", "output-128k-2025-02-19, token-efficient-tools-2025-02-19")
headers.Add("anthropic-beta", "token-efficient-tools-2025-02-19")
settings.WriteHeaders("claude-3-7-sonnet-20250219-thinking", &headers)
got := headers.Values("anthropic-beta")
if len(got) != 1 {
t.Fatalf("expected duplicate values to collapse into one header, got %v", got)
}
expected := "output-128k-2025-02-19,token-efficient-tools-2025-02-19,computer-use-2025-01-24"
if got[0] != expected {
t.Fatalf("expected deduplicated merged header %q, got %q", expected, got[0])
}
}