MCPcopy Create free account
hub / github.com/astercloud/aster / ExecuteToolWithWorkDir

Function ExecuteToolWithWorkDir

pkg/tools/builtin/testutils.go:154–173  ·  view source on GitHub ↗

ExecuteToolWithWorkDir 使用指定工作目录执行工具

(t *testing.T, tool tools.Tool, input map[string]any, workDir string)

Source from the content-addressed store, hash-verified

152
153// ExecuteToolWithWorkDir 使用指定工作目录执行工具
154func 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 的工具)
176func ExecuteToolWithoutContext(t *testing.T, tool tools.Tool, input map[string]any) map[string]any {

Calls 1

ExecuteMethod · 0.65