@@ -3,199 +3,41 @@ package task
33import (
44 "context"
55
6- . "github.com/onsi/ginkgo/v2 "
7- . "github.com/onsi/gomega"
6+ "github.com/humanlayer/agentcontrolplane/acp/test/utils "
7+
88 corev1 "k8s.io/api/core/v1"
99 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010 "k8s.io/apimachinery/pkg/types"
1111 "k8s.io/client-go/tools/record"
1212
1313 acp "github.com/humanlayer/agentcontrolplane/acp/api/v1alpha1"
14- "go.opentelemetry.io/otel/trace/noop" // Import the noop tracer
14+ "go.opentelemetry.io/otel/trace/noop"
1515
1616 "github.com/humanlayer/agentcontrolplane/acp/internal/mcpmanager"
17+ . "github.com/onsi/ginkgo/v2"
18+ . "github.com/onsi/gomega"
1719)
1820
19- // todo this file should probably live in a shared package, but for now...
20- type TestSecret struct {
21- name string
22- secret * corev1.Secret
23- }
24-
25- func (t * TestSecret ) Setup (ctx context.Context ) * corev1.Secret {
26- By ("creating the secret" )
27- secret := & corev1.Secret {
28- ObjectMeta : metav1.ObjectMeta {
29- Name : t .name ,
30- Namespace : "default" ,
31- },
32- Data : map [string ][]byte {
33- "api-key" : []byte ("test-api-key" ),
34- },
35- }
36- err := k8sClient .Create (ctx , secret )
37- Expect (err ).NotTo (HaveOccurred ())
38- t .secret = secret
39- return secret
40- }
41-
42- func (t * TestSecret ) Teardown (ctx context.Context ) {
43- By ("deleting the secret" )
44- Expect (k8sClient .Delete (ctx , t .secret )).To (Succeed ())
45- }
46-
47- var testSecret = & TestSecret {
48- name : "test-secret" ,
49- }
50-
51- type TestLLM struct {
52- name string
53- llm * acp.LLM
54- }
55-
56- func (t * TestLLM ) Setup (ctx context.Context ) * acp.LLM {
57- By ("creating the llm" )
58- llm := & acp.LLM {
59- ObjectMeta : metav1.ObjectMeta {
60- Name : t .name ,
61- Namespace : "default" ,
62- },
63- Spec : acp.LLMSpec {
64- Provider : "openai" ,
65- APIKeyFrom : & acp.APIKeySource {
66- SecretKeyRef : acp.SecretKeyRef {
67- Name : testSecret .name ,
68- Key : "api-key" ,
69- },
70- },
71- },
72- }
73- err := k8sClient .Create (ctx , llm )
74- Expect (err ).NotTo (HaveOccurred ())
75- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : t .name , Namespace : "default" }, llm )).To (Succeed ())
76- t .llm = llm
77- return llm
78- }
79-
80- func (t * TestLLM ) SetupWithStatus (ctx context.Context , status acp.LLMStatus ) * acp.LLM {
81- llm := t .Setup (ctx )
82- llm .Status = status
83- Expect (k8sClient .Status ().Update (ctx , llm )).To (Succeed ())
84- t .llm = llm
85- return llm
86- }
87-
88- func (t * TestLLM ) Teardown (ctx context.Context ) {
89- By ("deleting the llm" )
90- Expect (k8sClient .Delete (ctx , t .llm )).To (Succeed ())
91- }
92-
93- var testLLM = & TestLLM {
94- name : "test-llm" ,
95- }
96-
97- type TestAgent struct {
98- name string
99- llmName string
100- system string
101- mcpServers []acp.LocalObjectReference
102- agent * acp.Agent
103- }
104-
105- func (t * TestAgent ) Setup (ctx context.Context ) * acp.Agent {
106- By ("creating the agent" )
107- agent := & acp.Agent {
108- ObjectMeta : metav1.ObjectMeta {
109- Name : t .name ,
110-
111- Namespace : "default" ,
112- },
113- Spec : acp.AgentSpec {
114- LLMRef : acp.LocalObjectReference {
115- Name : t .llmName ,
116- },
117- System : t .system ,
118- MCPServers : t .mcpServers ,
119- },
120- }
121- err := k8sClient .Create (ctx , agent )
122- Expect (err ).NotTo (HaveOccurred ())
123- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : t .name , Namespace : "default" }, agent )).To (Succeed ())
124- t .agent = agent
125- return agent
126- }
127-
128- func (t * TestAgent ) SetupWithStatus (ctx context.Context , status acp.AgentStatus ) * acp.Agent {
129- agent := t .Setup (ctx )
130- agent .Status = status
131- Expect (k8sClient .Status ().Update (ctx , agent )).To (Succeed ())
132- t .agent = agent
133- return agent
134- }
135-
136- func (t * TestAgent ) Teardown (ctx context.Context ) {
137- By ("deleting the agent" )
138- Expect (k8sClient .Delete (ctx , t .agent )).To (Succeed ())
139- }
140-
141- var testAgent = & TestAgent {
142- name : "test-agent" ,
143- llmName : testLLM .name ,
144- system : "you are a testing assistant" ,
145- mcpServers : []acp.LocalObjectReference {},
146- }
147-
148- type TestTask struct {
149- name string
150- agentName string
151- userMessage string
152- task * acp.Task
153- }
154-
155- func (t * TestTask ) Setup (ctx context.Context ) * acp.Task {
156- By ("creating the task" )
157- task := & acp.Task {
158- ObjectMeta : metav1.ObjectMeta {
159- Name : t .name ,
160- Namespace : "default" ,
161- },
162- Spec : acp.TaskSpec {},
163- }
164- if t .agentName != "" {
165- task .Spec .AgentRef = acp.LocalObjectReference {
166- Name : t .agentName ,
167- }
168- }
169- if t .userMessage != "" {
170- task .Spec .UserMessage = t .userMessage
171- }
172-
173- err := k8sClient .Create (ctx , task )
174- Expect (err ).NotTo (HaveOccurred ())
175-
176- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : t .name , Namespace : "default" }, task )).To (Succeed ())
177- t .task = task
178- return task
21+ var testSecret = & utils.TestSecret {
22+ Name : "test-secret" ,
17923}
18024
181- func (t * TestTask ) SetupWithStatus (ctx context.Context , status acp.TaskStatus ) * acp.Task {
182- task := t .Setup (ctx )
183- task .Status = status
184- Expect (k8sClient .Status ().Update (ctx , task )).To (Succeed ())
185- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : t .name , Namespace : "default" }, task )).To (Succeed ())
186- t .task = task
187- return task
25+ var testLLM = & utils.TestLLM {
26+ Name : "test-llm" ,
27+ SecretName : testSecret .Name ,
18828}
18929
190- func (t * TestTask ) Teardown (ctx context.Context ) {
191- By ("deleting the task" )
192- Expect (k8sClient .Delete (ctx , t .task )).To (Succeed ())
30+ var testAgent = & utils.TestAgent {
31+ Name : "test-agent" ,
32+ LLMName : testLLM .Name ,
33+ SystemPrompt : "you are a testing assistant" ,
34+ MCPServers : []acp.LocalObjectReference {},
19335}
19436
195- var testTask = & TestTask {
196- name : "test-task" ,
197- agentName : "test-agent" ,
198- userMessage : "what is the capital of the moon?" ,
37+ var testTask = & utils. TestTask {
38+ Name : "test-task" ,
39+ AgentName : "test-agent" ,
40+ UserMessage : "what is the capital of the moon?" ,
19941}
20042
20143type TestToolCall struct {
@@ -210,13 +52,13 @@ func (t *TestToolCall) Setup(ctx context.Context) *acp.ToolCall {
21052 Name : t .name ,
21153 Namespace : "default" ,
21254 Labels : map [string ]string {
213- "acp.humanlayer.dev/task" : testTask .name ,
55+ "acp.humanlayer.dev/task" : testTask .Name ,
21456 "acp.humanlayer.dev/toolcallrequest" : "test123" ,
21557 },
21658 },
21759 Spec : acp.ToolCallSpec {
21860 TaskRef : acp.LocalObjectReference {
219- Name : testTask .name ,
61+ Name : testTask .Name ,
22062 },
22163 ToolRef : acp.LocalObjectReference {
22264 Name : "test-tool" ,
@@ -254,12 +96,12 @@ var testToolCallTwo = &TestToolCall{
25496
25597// nolint:golint,unparam
25698func setupSuiteObjects (ctx context.Context ) (secret * corev1.Secret , llm * acp.LLM , agent * acp.Agent , teardown func ()) {
257- secret = testSecret .Setup (ctx )
258- llm = testLLM .SetupWithStatus (ctx , acp.LLMStatus {
99+ secret = testSecret .Setup (ctx , k8sClient )
100+ llm = testLLM .SetupWithStatus (ctx , k8sClient , acp.LLMStatus {
259101 Status : "Ready" ,
260102 Ready : true ,
261103 })
262- agent = testAgent .SetupWithStatus (ctx , acp.AgentStatus {
104+ agent = testAgent .SetupWithStatus (ctx , k8sClient , acp.AgentStatus {
263105 Status : "Ready" ,
264106 Ready : true ,
265107 })
0 commit comments