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

Function TestExecuteWithError

pkg/executionplan/executor_test.go:190–232  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

188}
189
190func TestExecuteWithError(t *testing.T) {
191 testErr := errors.New("test error")
192 tool1 := newMockTool("tool1", "result1", nil)
193 tool2 := newMockTool("tool2", nil, testErr)
194 tool3 := newMockTool("tool3", "result3", nil)
195
196 toolMap := map[string]tools.Tool{
197 "tool1": tool1,
198 "tool2": tool2,
199 "tool3": tool3,
200 }
201
202 executor := NewExecutor(toolMap)
203
204 plan := NewExecutionPlan("Error test")
205 plan.AddStep("tool1", "Step 1", nil)
206 plan.AddStep("tool2", "Step 2", nil)
207 plan.AddStep("tool3", "Step 3", nil)
208 plan.Options.RequireApproval = false
209 plan.Options.StopOnError = true
210
211 ctx := context.Background()
212 toolCtx := &tools.ToolContext{AgentID: "test-agent"}
213
214 err := executor.Execute(ctx, plan, toolCtx)
215 if err == nil {
216 t.Fatal("expected error, got nil")
217 }
218
219 if plan.Steps[0].Status != StepStatusCompleted {
220 t.Errorf("step 0: expected %v, got %v", StepStatusCompleted, plan.Steps[0].Status)
221 }
222 if plan.Steps[1].Status != StepStatusFailed {
223 t.Errorf("step 1: expected %v, got %v", StepStatusFailed, plan.Steps[1].Status)
224 }
225 if plan.Steps[2].Status != StepStatusSkipped {
226 t.Errorf("step 2: expected %v, got %v", StepStatusSkipped, plan.Steps[2].Status)
227 }
228
229 if tool3.ExecutionCount() != 0 {
230 t.Errorf("tool3 should not have been executed")
231 }
232}
233
234func TestExecuteContinueOnError(t *testing.T) {
235 testErr := errors.New("test error")

Callers

nothing calls this directly

Calls 6

AddStepMethod · 0.95
ExecuteMethod · 0.95
newMockToolFunction · 0.85
NewExecutionPlanFunction · 0.85
ExecutionCountMethod · 0.80
NewExecutorFunction · 0.70

Tested by

no test coverage detected