mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-11 14:47:58 +08:00
- Add bidirectional remapping for nested tool_references inside tool_search_tool_result across non-stream, SSE stream, and multi-turn message history. - Add advisor_ and agent_toolset_ to IsClaudeServerToolType to prevent schema stripping and MCP aliasing on native Anthropic server tools. - Wrap MCP alias restoration errors in claudeMCPAliasRestoreError with IsRequestScoped() bool to avoid cooling down healthy OAuth credentials. - Add unit tests for tool_search_tool_result remapping, error variants, server tool recognition, and error scoping.
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package helps
|
|
|
|
import "testing"
|
|
|
|
func TestClaudeBuiltinToolRegistry_DefaultSeedFallback(t *testing.T) {
|
|
registry := AugmentClaudeBuiltinToolRegistry(nil, nil)
|
|
for _, name := range defaultClaudeBuiltinToolNames {
|
|
if !registry[name] {
|
|
t.Fatalf("default builtin %q missing from fallback registry", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestClaudeBuiltinToolRegistry_AugmentsKnownTypedBuiltinsFromBody(t *testing.T) {
|
|
registry := AugmentClaudeBuiltinToolRegistry([]byte(`{
|
|
"tools": [
|
|
{"type": "web_search_20250305", "name": "web_search"},
|
|
{"type": "custom", "name": "client_custom"},
|
|
{"type": "custom_builtin_20250401", "name": "unknown_typed"},
|
|
{"name": "Read"}
|
|
]
|
|
}`), nil)
|
|
|
|
if !registry["web_search"] {
|
|
t.Fatal("expected known typed builtin web_search in registry")
|
|
}
|
|
for _, name := range []string{"client_custom", "unknown_typed", "Read"} {
|
|
if registry[name] {
|
|
t.Fatalf("expected client tool %q to stay out of builtin registry", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsClaudeServerToolType(t *testing.T) {
|
|
for _, toolType := range []string{
|
|
"web_search_20250305",
|
|
"code_execution_20250522",
|
|
"tool_search_tool_regex_20251119",
|
|
"advisor_20260301",
|
|
"agent_toolset_20260401",
|
|
"bash_20250124",
|
|
"text_editor_20250728",
|
|
"memory_20250818",
|
|
"computer_20241022",
|
|
"web_fetch_20260209",
|
|
} {
|
|
if !IsClaudeServerToolType(toolType) {
|
|
t.Fatalf("IsClaudeServerToolType(%q) = false, want true", toolType)
|
|
}
|
|
}
|
|
for _, toolType := range []string{"", "custom", "custom_builtin_20250401"} {
|
|
if IsClaudeServerToolType(toolType) {
|
|
t.Fatalf("IsClaudeServerToolType(%q) = true, want false", toolType)
|
|
}
|
|
}
|
|
}
|