refactor: move DoAction to MCP tools call

This commit is contained in:
lilong.129
2025-05-25 08:10:57 +08:00
parent 4ff2692f02
commit 7986c4899f
8 changed files with 2220 additions and 359 deletions
+72
View File
@@ -0,0 +1,72 @@
package uixt
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewMCPServer(t *testing.T) {
server := NewMCPServer()
assert.NotNil(t, server)
// Check that tools are registered
tools := server.ListTools()
assert.Greater(t, len(tools), 0, "Should have at least one tool registered")
// Check specific tools exist
expectedTools := []string{
"list_available_devices",
"select_device",
"list_packages",
"launch_app",
"terminate_app",
"get_screen_size",
"press_button",
"tap_xy",
"swipe",
"drag",
"screenshot",
"home",
"back",
"input",
"sleep",
}
registeredToolNames := make(map[string]bool)
for _, tool := range tools {
registeredToolNames[tool.Name] = true
}
for _, expectedTool := range expectedTools {
assert.True(t, registeredToolNames[expectedTool], "Tool %s should be registered", expectedTool)
}
}
func TestToolInterfaces(t *testing.T) {
// Test that all tools implement the ActionTool interface correctly
tools := []ActionTool{
&ToolListAvailableDevices{},
&ToolSelectDevice{},
&ToolListPackages{},
&ToolLaunchApp{},
&ToolTerminateApp{},
&ToolGetScreenSize{},
&ToolPressButton{},
&ToolTapXY{},
&ToolSwipe{},
&ToolDrag{},
&ToolScreenShot{},
&ToolHome{},
&ToolBack{},
&ToolInput{},
&ToolSleep{},
}
for _, tool := range tools {
assert.NotEmpty(t, tool.Name(), "Tool name should not be empty")
assert.NotEmpty(t, tool.Description(), "Tool description should not be empty")
assert.NotNil(t, tool.Options(), "Tool options should not be nil")
assert.NotNil(t, tool.Implement(), "Tool implementation should not be nil")
}
}