ExecuteToolWithInput 使用指定输入执行工具
(t *testing.T, tool tools.Tool, input map[string]any)
| 107 | |
| 108 | // ExecuteToolWithInput 使用指定输入执行工具 |
| 109 | func ExecuteToolWithInput(t *testing.T, tool tools.Tool, input map[string]any) map[string]any { |
| 110 | ctx := context.Background() |
| 111 | tc := &tools.ToolContext{ |
| 112 | Signal: ctx, |
| 113 | Sandbox: NewMockToolContext(), |
| 114 | } |
| 115 | |
| 116 | result, err := tool.Execute(ctx, input, tc) |
| 117 | if err != nil { |
| 118 | t.Fatalf("Tool execution failed: %v", err) |
| 119 | } |
| 120 | |
| 121 | // 将result转换为map[string]any |
| 122 | if resultMap, ok := result.(map[string]any); ok { |
| 123 | return resultMap |
| 124 | } |
| 125 | |
| 126 | t.Fatalf("Expected map[string]any result, got %T", result) |
| 127 | return nil |
| 128 | } |
| 129 | |
| 130 | // ExecuteToolWithRealFS 使用真实文件系统执行工具 |
| 131 | func ExecuteToolWithRealFS(t *testing.T, tool tools.Tool, input map[string]any) map[string]any { |