Skip to content

Commit 822618f

Browse files
committed
add tests
1 parent 8205fe0 commit 822618f

File tree

1 file changed

+356
-0
lines changed

1 file changed

+356
-0
lines changed
Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Test
3+
metadata:
4+
name: vmcp-composite-tool-definition
5+
spec:
6+
description: Test VirtualMCPCompositeToolDefinition CRD validation and lifecycle
7+
timeouts:
8+
apply: 30s
9+
assert: 60s
10+
cleanup: 30s
11+
steps:
12+
- name: verify-operator
13+
description: Ensure operator is ready before testing
14+
try:
15+
- assert:
16+
file: ../../setup/assert-operator-ready.yaml
17+
18+
- name: create-valid-composite-tool
19+
description: Create a valid composite tool definition
20+
try:
21+
- apply:
22+
resource:
23+
apiVersion: toolhive.stacklok.dev/v1alpha1
24+
kind: VirtualMCPCompositeToolDefinition
25+
metadata:
26+
name: deploy-workflow
27+
namespace: toolhive-system
28+
spec:
29+
name: deploy_and_verify
30+
description: Deploy application and verify deployment status
31+
timeout: 10m
32+
failureMode: abort
33+
steps:
34+
- id: deploy
35+
type: tool_call
36+
tool: kubectl.apply
37+
arguments:
38+
manifest: "{{.params.manifest}}"
39+
namespace: "{{.params.namespace}}"
40+
timeout: 5m
41+
- id: verify
42+
type: tool_call
43+
tool: kubectl.get
44+
arguments:
45+
resource: "deployment"
46+
namespace: "{{.params.namespace}}"
47+
dependsOn:
48+
- deploy
49+
timeout: 2m
50+
- assert:
51+
resource:
52+
apiVersion: toolhive.stacklok.dev/v1alpha1
53+
kind: VirtualMCPCompositeToolDefinition
54+
metadata:
55+
name: deploy-workflow
56+
namespace: toolhive-system
57+
58+
- name: test-validation-status-valid
59+
description: Verify validation status is set to Valid
60+
try:
61+
- script:
62+
content: |
63+
#!/bin/bash
64+
set -e
65+
echo "Checking validation status for valid composite tool..."
66+
67+
i=1
68+
while [ $i -le 10 ]; do
69+
STATUS=$(kubectl get vmcpctd deploy-workflow -n toolhive-system -o jsonpath='{.status.validationStatus}' 2>/dev/null || echo "")
70+
71+
if [ "$STATUS" = "Valid" ]; then
72+
echo "✓ Validation status is Valid"
73+
exit 0
74+
fi
75+
76+
echo "⚠ Attempt $i/10: Status is '$STATUS', waiting..."
77+
sleep 2
78+
i=$((i + 1))
79+
done
80+
81+
echo "✗ Validation status never became Valid"
82+
kubectl get vmcpctd deploy-workflow -n toolhive-system -o yaml
83+
exit 1
84+
85+
- name: create-invalid-duplicate-steps
86+
description: Test validation rejection for duplicate step IDs
87+
try:
88+
- apply:
89+
resource:
90+
apiVersion: toolhive.stacklok.dev/v1alpha1
91+
kind: VirtualMCPCompositeToolDefinition
92+
metadata:
93+
name: duplicate-steps
94+
namespace: toolhive-system
95+
spec:
96+
name: invalid_duplicate
97+
description: Workflow with duplicate step IDs
98+
steps:
99+
- id: step1
100+
type: tool_call
101+
tool: kubectl.apply
102+
- id: step1
103+
type: tool_call
104+
tool: kubectl.get
105+
- script:
106+
content: |
107+
#!/bin/bash
108+
set -e
109+
echo "Checking validation status for duplicate steps..."
110+
111+
i=1
112+
while [ $i -le 10 ]; do
113+
STATUS=$(kubectl get vmcpctd duplicate-steps -n toolhive-system -o jsonpath='{.status.validationStatus}' 2>/dev/null || echo "")
114+
115+
if [ "$STATUS" = "Invalid" ]; then
116+
echo "✓ Validation status is Invalid (as expected)"
117+
118+
ERRORS=$(kubectl get vmcpctd duplicate-steps -n toolhive-system -o jsonpath='{.status.validationErrors}' 2>/dev/null || echo "")
119+
if echo "$ERRORS" | grep -q "duplicated"; then
120+
echo "✓ Validation error mentions 'duplicated'"
121+
exit 0
122+
else
123+
echo "✗ Validation error doesn't mention duplicate: $ERRORS"
124+
exit 1
125+
fi
126+
fi
127+
128+
echo "⚠ Attempt $i/10: Status is '$STATUS', waiting..."
129+
sleep 2
130+
i=$((i + 1))
131+
done
132+
133+
echo "✗ Validation status never became Invalid"
134+
kubectl get vmcpctd duplicate-steps -n toolhive-system -o yaml
135+
exit 1
136+
137+
- name: create-invalid-tool-reference
138+
description: Test validation rejection for invalid tool reference format
139+
try:
140+
- apply:
141+
resource:
142+
apiVersion: toolhive.stacklok.dev/v1alpha1
143+
kind: VirtualMCPCompositeToolDefinition
144+
metadata:
145+
name: bad-tool-ref
146+
namespace: toolhive-system
147+
spec:
148+
name: invalid_tool_ref
149+
description: Workflow with invalid tool reference
150+
steps:
151+
- id: step1
152+
type: tool_call
153+
tool: invalid-no-dot
154+
- script:
155+
content: |
156+
#!/bin/bash
157+
set -e
158+
echo "Checking validation status for bad tool reference..."
159+
160+
i=1
161+
while [ $i -le 10 ]; do
162+
STATUS=$(kubectl get vmcpctd bad-tool-ref -n toolhive-system -o jsonpath='{.status.validationStatus}' 2>/dev/null || echo "")
163+
164+
if [ "$STATUS" = "Invalid" ]; then
165+
echo "✓ Validation status is Invalid (as expected)"
166+
167+
ERRORS=$(kubectl get vmcpctd bad-tool-ref -n toolhive-system -o jsonpath='{.status.validationErrors}' 2>/dev/null || echo "")
168+
if echo "$ERRORS" | grep -q "workload.tool_name"; then
169+
echo "✓ Validation error mentions correct format"
170+
exit 0
171+
else
172+
echo "✗ Validation error doesn't mention format: $ERRORS"
173+
exit 1
174+
fi
175+
fi
176+
177+
echo "⚠ Attempt $i/10: Status is '$STATUS', waiting..."
178+
sleep 2
179+
i=$((i + 1))
180+
done
181+
182+
echo "✗ Validation status never became Invalid"
183+
kubectl get vmcpctd bad-tool-ref -n toolhive-system -o yaml
184+
exit 1
185+
186+
- name: create-invalid-circular-dependency
187+
description: Test validation rejection for circular dependencies
188+
try:
189+
- apply:
190+
resource:
191+
apiVersion: toolhive.stacklok.dev/v1alpha1
192+
kind: VirtualMCPCompositeToolDefinition
193+
metadata:
194+
name: circular-deps
195+
namespace: toolhive-system
196+
spec:
197+
name: circular_workflow
198+
description: Workflow with circular dependencies
199+
steps:
200+
- id: step1
201+
type: tool_call
202+
tool: tool.a
203+
dependsOn:
204+
- step2
205+
- id: step2
206+
type: tool_call
207+
tool: tool.b
208+
dependsOn:
209+
- step1
210+
- script:
211+
content: |
212+
#!/bin/bash
213+
set -e
214+
echo "Checking validation status for circular dependencies..."
215+
216+
i=1
217+
while [ $i -le 10 ]; do
218+
STATUS=$(kubectl get vmcpctd circular-deps -n toolhive-system -o jsonpath='{.status.validationStatus}' 2>/dev/null || echo "")
219+
220+
if [ "$STATUS" = "Invalid" ]; then
221+
echo "✓ Validation status is Invalid (as expected)"
222+
223+
ERRORS=$(kubectl get vmcpctd circular-deps -n toolhive-system -o jsonpath='{.status.validationErrors}' 2>/dev/null || echo "")
224+
if echo "$ERRORS" | grep -q "cycle"; then
225+
echo "✓ Validation error mentions 'cycle'"
226+
exit 0
227+
else
228+
echo "✗ Validation error doesn't mention cycle: $ERRORS"
229+
exit 1
230+
fi
231+
fi
232+
233+
echo "⚠ Attempt $i/10: Status is '$STATUS', waiting..."
234+
sleep 2
235+
i=$((i + 1))
236+
done
237+
238+
echo "✗ Validation status never became Invalid"
239+
kubectl get vmcpctd circular-deps -n toolhive-system -o yaml
240+
exit 1
241+
242+
- name: create-composite-tool-with-parameters
243+
description: Create composite tool with parameter schema
244+
try:
245+
- apply:
246+
resource:
247+
apiVersion: toolhive.stacklok.dev/v1alpha1
248+
kind: VirtualMCPCompositeToolDefinition
249+
metadata:
250+
name: with-parameters
251+
namespace: toolhive-system
252+
spec:
253+
name: parameterized_deploy
254+
description: Deploy with parameters
255+
parameters:
256+
environment:
257+
type: string
258+
description: Target environment
259+
required: true
260+
replicas:
261+
type: integer
262+
description: Number of replicas
263+
default: "3"
264+
steps:
265+
- id: deploy
266+
type: tool_call
267+
tool: kubectl.apply
268+
arguments:
269+
env: "{{.params.environment}}"
270+
replicas: "{{.params.replicas}}"
271+
- script:
272+
content: |
273+
#!/bin/bash
274+
set -e
275+
echo "Checking validation status for composite tool with parameters..."
276+
277+
i=1
278+
while [ $i -le 10 ]; do
279+
STATUS=$(kubectl get vmcpctd with-parameters -n toolhive-system -o jsonpath='{.status.validationStatus}' 2>/dev/null || echo "")
280+
281+
if [ "$STATUS" = "Valid" ]; then
282+
echo "✓ Validation status is Valid"
283+
exit 0
284+
fi
285+
286+
echo "⚠ Attempt $i/10: Status is '$STATUS', waiting..."
287+
sleep 2
288+
i=$((i + 1))
289+
done
290+
291+
echo "✗ Validation status never became Valid"
292+
kubectl get vmcpctd with-parameters -n toolhive-system -o yaml
293+
exit 1
294+
295+
- name: create-composite-tool-with-error-handling
296+
description: Create composite tool with error handling
297+
try:
298+
- apply:
299+
resource:
300+
apiVersion: toolhive.stacklok.dev/v1alpha1
301+
kind: VirtualMCPCompositeToolDefinition
302+
metadata:
303+
name: with-error-handling
304+
namespace: toolhive-system
305+
spec:
306+
name: resilient_deploy
307+
description: Deploy with retry logic
308+
steps:
309+
- id: deploy
310+
type: tool_call
311+
tool: kubectl.apply
312+
onError:
313+
action: retry
314+
maxRetries: 3
315+
timeout: 5m
316+
- script:
317+
content: |
318+
#!/bin/bash
319+
set -e
320+
echo "Checking validation status for composite tool with error handling..."
321+
322+
i=1
323+
while [ $i -le 10 ]; do
324+
STATUS=$(kubectl get vmcpctd with-error-handling -n toolhive-system -o jsonpath='{.status.validationStatus}' 2>/dev/null || echo "")
325+
326+
if [ "$STATUS" = "Valid" ]; then
327+
echo "✓ Validation status is Valid"
328+
exit 0
329+
fi
330+
331+
echo "⚠ Attempt $i/10: Status is '$STATUS', waiting..."
332+
sleep 2
333+
i=$((i + 1))
334+
done
335+
336+
echo "✗ Validation status never became Valid"
337+
kubectl get vmcpctd with-error-handling -n toolhive-system -o yaml
338+
exit 1
339+
340+
- name: test-composite-tool-ready-condition
341+
description: Verify Ready condition is set correctly
342+
try:
343+
- script:
344+
content: |
345+
echo "Checking Ready condition for composite tool..."
346+
347+
READY=$(kubectl get vmcpctd deploy-workflow -n toolhive-system -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' 2>/dev/null || echo "")
348+
349+
if [ "$READY" = "True" ]; then
350+
echo "✓ Ready condition is True"
351+
exit 0
352+
fi
353+
354+
echo "⚠ Ready condition is '$READY', not 'True' (may not be implemented yet)"
355+
kubectl get vmcpctd deploy-workflow -n toolhive-system -o yaml
356+
exit 0

0 commit comments

Comments
 (0)