Files
CLIProxyAPI/internal/runtime/executor/helps/claude_builtin_tools_test.go
sususu98 788e9b7928 fix(claude): restore tool_search_tool_result references and recognize advisor/agent server tools (#5044) (#5082)
- 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.
2026-08-19 22:29:51 +08:00

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)
}
}
}