All checks were successful
Beta Release / beta (push) Successful in 2m23s
- Add ChatEngine for deduplicated chat logic (handlers_chat/shell_chat) - Add SendWithToolsStream for real-time streaming responses - Add /help, /plan, /export, /model commands in Studio - Fix XSS: sanitize HTML after markdown rendering - Add ConversationStoreMulti for multi-conversation support - Add Anthropic headers (x-api-key, anthropic-version) - Add fallback logging when provider switch occurs - Add API handler tests (handlers_test.go) - Polish Studio: max-height 200px, word-break on tool args - Update CLI version to show full info (version, go, platform) 🤖 Generated with Crush Assisted-by: MiniMax-M2.5 via Crush <crush@charm.land>
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/muyue/muyue/internal/agent"
|
|
)
|
|
|
|
func TestHandleToolCall(t *testing.T) {
|
|
// Test unknown tool returns error
|
|
registry := agent.NewRegistry()
|
|
|
|
// Register a test tool
|
|
testTool, _ := agent.NewTool[struct{ Command string }]("test_tool", "Test tool", func(ctx context.Context, params struct{ Command string }) (agent.ToolResponse, error) {
|
|
return agent.TextResponse("executed: " + params.Command), nil
|
|
})
|
|
registry.Register(testTool)
|
|
|
|
// Test executing known tool
|
|
resp, err := registry.Execute(context.Background(), agent.ToolCall{
|
|
ID: "test-id",
|
|
Name: "test_tool",
|
|
Arguments: json.RawMessage(`{"Command": "hello"}`),
|
|
})
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
if resp.IsError {
|
|
t.Errorf("expected no error, got error response")
|
|
}
|
|
|
|
// Test executing unknown tool
|
|
resp, err = registry.Execute(context.Background(), agent.ToolCall{
|
|
ID: "test-id",
|
|
Name: "unknown_tool",
|
|
Arguments: json.RawMessage(`{}`),
|
|
})
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
if !resp.IsError {
|
|
t.Errorf("expected error for unknown tool")
|
|
}
|
|
}
|
|
|
|
func TestCleanThinkingTags(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
expected string
|
|
}{
|
|
{"hello world", "hello world"},
|
|
{"<think>thinking</think>hello", "hello"},
|
|
{"<Think>THINKING</Think>hello", "hello"},
|
|
{"hello <think>thinking</think> world", "hello world"},
|
|
{"no tags here", "no tags here"},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
result := cleanThinkingTags(tc.input)
|
|
if result != tc.expected {
|
|
t.Errorf("cleanThinkingTags(%q) = %q, want %q", tc.input, result, tc.expected)
|
|
}
|
|
}
|
|
} |