(t *testing.T)
| 85 | } |
| 86 | |
| 87 | func TestExecutorWithCallbacks(t *testing.T) { |
| 88 | toolMap := map[string]tools.Tool{ |
| 89 | "tool1": newMockTool("tool1", "result1", nil), |
| 90 | } |
| 91 | |
| 92 | var stepStartCalled, stepCompleteCalled, planCompleteCalled bool |
| 93 | var startedPlan, completedPlan *ExecutionPlan |
| 94 | var startedStep, completedStep *Step |
| 95 | |
| 96 | executor := NewExecutor( |
| 97 | toolMap, |
| 98 | WithOnStepStart(func(p *ExecutionPlan, s *Step) { |
| 99 | stepStartCalled = true |
| 100 | startedPlan = p |
| 101 | startedStep = s |
| 102 | }), |
| 103 | WithOnStepComplete(func(p *ExecutionPlan, s *Step) { |
| 104 | stepCompleteCalled = true |
| 105 | completedPlan = p |
| 106 | completedStep = s |
| 107 | }), |
| 108 | WithOnPlanComplete(func(p *ExecutionPlan) { |
| 109 | planCompleteCalled = true |
| 110 | }), |
| 111 | ) |
| 112 | |
| 113 | plan := NewExecutionPlan("Test plan") |
| 114 | plan.AddStep("tool1", "Test step", nil) |
| 115 | plan.Options.RequireApproval = false |
| 116 | |
| 117 | ctx := context.Background() |
| 118 | toolCtx := &tools.ToolContext{AgentID: "test-agent"} |
| 119 | |
| 120 | err := executor.Execute(ctx, plan, toolCtx) |
| 121 | if err != nil { |
| 122 | t.Fatalf("unexpected error: %v", err) |
| 123 | } |
| 124 | |
| 125 | if !stepStartCalled { |
| 126 | t.Error("OnStepStart callback not called") |
| 127 | } |
| 128 | if !stepCompleteCalled { |
| 129 | t.Error("OnStepComplete callback not called") |
| 130 | } |
| 131 | if !planCompleteCalled { |
| 132 | t.Error("OnPlanComplete callback not called") |
| 133 | } |
| 134 | if startedPlan == nil || startedStep == nil { |
| 135 | t.Error("start callback received nil plan or step") |
| 136 | } |
| 137 | if completedPlan == nil || completedStep == nil { |
| 138 | t.Error("complete callback received nil plan or step") |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | func TestExecuteSequential(t *testing.T) { |
| 143 | tool1 := newMockTool("tool1", "result1", nil) |
nothing calls this directly
no test coverage detected