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

Function TestExecutorWithCallbacks

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

Source from the content-addressed store, hash-verified

85}
86
87func 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
142func TestExecuteSequential(t *testing.T) {
143 tool1 := newMockTool("tool1", "result1", nil)

Callers

nothing calls this directly

Calls 9

AddStepMethod · 0.95
ExecuteMethod · 0.95
newMockToolFunction · 0.85
WithOnStepStartFunction · 0.85
WithOnStepCompleteFunction · 0.85
WithOnPlanCompleteFunction · 0.85
NewExecutionPlanFunction · 0.85
NewExecutorFunction · 0.70
ErrorMethod · 0.65

Tested by

no test coverage detected