-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwftest_integration_test.go
More file actions
135 lines (122 loc) · 3.41 KB
/
wftest_integration_test.go
File metadata and controls
135 lines (122 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package agent_test
import (
"testing"
agent "github.com/GoCodeAlone/workflow-plugin-agent"
"github.com/GoCodeAlone/workflow/wftest"
)
// TestAgentPlugin_ExecuteStep verifies that step.agent_execute can be mocked
// and that the mock is invoked once with the expected pipeline data.
func TestAgentPlugin_ExecuteStep(t *testing.T) {
execRec := wftest.RecordStep("step.agent_execute")
execRec.WithOutput(map[string]any{
"result": "The answer is 42",
"status": "completed",
"iterations": 1,
})
h := wftest.New(t,
wftest.WithPlugin(agent.New()),
wftest.WithYAML(`
pipelines:
run-agent:
trigger:
type: manual
steps:
- name: execute
type: step.agent_execute
config:
provider_service: mock-provider
max_iterations: 3
`),
execRec,
)
result := h.ExecutePipeline("run-agent", map[string]any{
"task": "What is the meaning of life?",
"system_prompt": "You are a helpful assistant.",
})
if result.Error != nil {
t.Fatalf("pipeline failed: %v", result.Error)
}
if execRec.CallCount() != 1 {
t.Errorf("expected 1 call to step.agent_execute, got %d", execRec.CallCount())
}
}
// TestAgentPlugin_ProviderModelsStep verifies that step.provider_models can be
// mocked and that the recorder captures the invocation correctly.
func TestAgentPlugin_ProviderModelsStep(t *testing.T) {
modelsRec := wftest.RecordStep("step.provider_models")
modelsRec.WithOutput(map[string]any{
"success": true,
"models": []any{
map[string]any{"id": "claude-3-5-sonnet", "name": "Claude 3.5 Sonnet"},
map[string]any{"id": "claude-3-haiku", "name": "Claude 3 Haiku"},
},
})
h := wftest.New(t,
wftest.WithPlugin(agent.New()),
wftest.WithYAML(`
pipelines:
list-models:
trigger:
type: manual
steps:
- name: get-models
type: step.provider_models
`),
modelsRec,
)
result := h.ExecutePipeline("list-models", map[string]any{
"type": "anthropic",
"api_key": "test-key",
})
if result.Error != nil {
t.Fatalf("pipeline failed: %v", result.Error)
}
if modelsRec.CallCount() != 1 {
t.Errorf("expected 1 call to step.provider_models, got %d", modelsRec.CallCount())
}
models, ok := result.Output["models"].([]any)
if !ok {
t.Fatalf("expected models in output, got %T", result.Output["models"])
}
if len(models) != 2 {
t.Errorf("expected 2 models, got %d", len(models))
}
}
// TestAgentPlugin_ProviderTestStep verifies that step.provider_test can be mocked
// and returns a successful connection result.
func TestAgentPlugin_ProviderTestStep(t *testing.T) {
testRec := wftest.RecordStep("step.provider_test")
testRec.WithOutput(map[string]any{
"success": true,
"message": "Connection successful",
"latency_ms": int64(42),
})
h := wftest.New(t,
wftest.WithPlugin(agent.New()),
wftest.WithYAML(`
pipelines:
test-provider:
trigger:
type: manual
steps:
- name: test-conn
type: step.provider_test
config:
alias: my-anthropic
`),
testRec,
)
result := h.ExecutePipeline("test-provider", map[string]any{
"alias": "my-anthropic",
})
if result.Error != nil {
t.Fatalf("pipeline failed: %v", result.Error)
}
if testRec.CallCount() != 1 {
t.Errorf("expected 1 call to step.provider_test, got %d", testRec.CallCount())
}
success, ok := result.Output["success"].(bool)
if !ok || !success {
t.Errorf("expected success=true in output, got %v", result.Output["success"])
}
}