ExecuteToolWithWorkDir 使用指定工作目录执行工具
(t *testing.T, tool tools.Tool, input map[string]any, workDir string)
| 152 | |
| 153 | // ExecuteToolWithWorkDir 使用指定工作目录执行工具 |
| 154 | func ExecuteToolWithWorkDir(t *testing.T, tool tools.Tool, input map[string]any, workDir string) map[string]any { |
| 155 | ctx := context.Background() |
| 156 | tc := &tools.ToolContext{ |
| 157 | Signal: ctx, |
| 158 | Sandbox: &CustomWorkDirSandbox{workDir: workDir}, |
| 159 | } |
| 160 | |
| 161 | result, err := tool.Execute(ctx, input, tc) |
| 162 | if err != nil { |
| 163 | t.Fatalf("Tool execution failed: %v", err) |
| 164 | } |
| 165 | |
| 166 | // 将result转换为map[string]any |
| 167 | if resultMap, ok := result.(map[string]any); ok { |
| 168 | return resultMap |
| 169 | } |
| 170 | |
| 171 | t.Fatalf("Expected map[string]any result, got %T", result) |
| 172 | return nil |
| 173 | } |
| 174 | |
| 175 | // ExecuteToolWithoutContext 不使用 ToolContext 执行工具(用于测试不依赖 sandbox 的工具) |
| 176 | func ExecuteToolWithoutContext(t *testing.T, tool tools.Tool, input map[string]any) map[string]any { |