Skip to content

Commit 52ee1b7

Browse files
yroblataskbot
andauthored
add validation tests to detect invalid configs (#2896)
Co-authored-by: taskbot <taskbot@users.noreply.github.com>
1 parent bdfe68c commit 52ee1b7

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

cmd/thv-operator/api/v1alpha1/virtualmcpserver_webhook_test.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,33 @@ func TestVirtualMCPServerValidate(t *testing.T) {
3535
wantErr: true,
3636
errMsg: "spec.groupRef.name is required",
3737
},
38+
{
39+
name: "empty IncomingAuth type",
40+
vmcp: &VirtualMCPServer{
41+
Spec: VirtualMCPServerSpec{
42+
GroupRef: GroupRef{Name: "test-group"},
43+
IncomingAuth: &IncomingAuthConfig{
44+
Type: "",
45+
},
46+
},
47+
},
48+
wantErr: true,
49+
errMsg: "spec.incomingAuth.type is required",
50+
},
51+
{
52+
name: "OIDC auth without OIDCConfig",
53+
vmcp: &VirtualMCPServer{
54+
Spec: VirtualMCPServerSpec{
55+
GroupRef: GroupRef{Name: "test-group"},
56+
IncomingAuth: &IncomingAuthConfig{
57+
Type: "oidc",
58+
OIDCConfig: nil,
59+
},
60+
},
61+
},
62+
wantErr: true,
63+
errMsg: "spec.incomingAuth.oidcConfig is required when type is oidc",
64+
},
3865
{
3966
name: "valid outgoingAuth with discovered source",
4067
vmcp: &VirtualMCPServer{
@@ -60,6 +87,23 @@ func TestVirtualMCPServerValidate(t *testing.T) {
6087
wantErr: true,
6188
errMsg: "spec.outgoingAuth.source must be one of: discovered, inline",
6289
},
90+
{
91+
name: "invalid backend auth type",
92+
vmcp: &VirtualMCPServer{
93+
Spec: VirtualMCPServerSpec{
94+
GroupRef: GroupRef{Name: "test-group"},
95+
OutgoingAuth: &OutgoingAuthConfig{
96+
Backends: map[string]BackendAuthConfig{
97+
"test-backend": {
98+
Type: "invalid-type",
99+
},
100+
},
101+
},
102+
},
103+
},
104+
wantErr: true,
105+
errMsg: "spec.outgoingAuth.backends[test-backend].type must be one of: discovered, external_auth_config_ref",
106+
},
63107
{
64108
name: "valid backend external auth config ref",
65109
vmcp: &VirtualMCPServer{
@@ -369,6 +413,42 @@ func TestVirtualMCPServerValidate(t *testing.T) {
369413
wantErr: true,
370414
errMsg: "spec.compositeTools[0].steps[1].id \"step1\" is duplicated",
371415
},
416+
{
417+
name: "invalid composite tool - invalid step type",
418+
vmcp: &VirtualMCPServer{
419+
Spec: VirtualMCPServerSpec{
420+
GroupRef: GroupRef{Name: "test-group"},
421+
CompositeTools: []CompositeToolSpec{
422+
{
423+
Name: "test-tool",
424+
Description: "Test composite tool",
425+
Steps: []WorkflowStep{
426+
{
427+
ID: "step1",
428+
Type: "invalid-type",
429+
Tool: "backend.tool",
430+
},
431+
},
432+
},
433+
},
434+
},
435+
},
436+
wantErr: true,
437+
errMsg: "spec.compositeTools[0].steps[0].type must be tool or elicitation",
438+
},
439+
{
440+
name: "invalid aggregation - invalid conflict resolution strategy",
441+
vmcp: &VirtualMCPServer{
442+
Spec: VirtualMCPServerSpec{
443+
GroupRef: GroupRef{Name: "test-group"},
444+
Aggregation: &AggregationConfig{
445+
ConflictResolution: "invalid-strategy",
446+
},
447+
},
448+
},
449+
wantErr: true,
450+
errMsg: "spec.aggregation.conflictResolution must be one of: prefix, priority, manual",
451+
},
372452
}
373453

374454
for _, tt := range tests {
@@ -458,6 +538,31 @@ func TestValidateCompositeToolsWithDependencies(t *testing.T) {
458538
},
459539
wantErr: false,
460540
},
541+
{
542+
name: "invalid error handling action",
543+
vmcp: &VirtualMCPServer{
544+
Spec: VirtualMCPServerSpec{
545+
GroupRef: GroupRef{Name: "test-group"},
546+
CompositeTools: []CompositeToolSpec{
547+
{
548+
Name: "test-tool",
549+
Description: "Test composite tool",
550+
Steps: []WorkflowStep{
551+
{
552+
ID: "step1",
553+
Tool: "backend.tool1",
554+
OnError: &ErrorHandling{
555+
Action: "invalid-action",
556+
},
557+
},
558+
},
559+
},
560+
},
561+
},
562+
},
563+
wantErr: true,
564+
errMsg: "spec.compositeTools[0].steps[0].onError.action must be abort, continue, or retry",
565+
},
461566
{
462567
name: "invalid error handling - retry without maxRetries",
463568
vmcp: &VirtualMCPServer{
@@ -563,6 +668,29 @@ func TestValidateCompositeToolsWithDependencies(t *testing.T) {
563668
wantErr: true,
564669
errMsg: "spec.compositeTools[0].steps[0].onError.retryDelay: invalid duration format \"invalid\", expected format like '30s', '5m', '1h', '1h30m'",
565670
},
671+
{
672+
name: "invalid composite tool - unknown dependency reference",
673+
vmcp: &VirtualMCPServer{
674+
Spec: VirtualMCPServerSpec{
675+
GroupRef: GroupRef{Name: "test-group"},
676+
CompositeTools: []CompositeToolSpec{
677+
{
678+
Name: "test-tool",
679+
Description: "Test composite tool",
680+
Steps: []WorkflowStep{
681+
{
682+
ID: "step1",
683+
Tool: "backend.tool1",
684+
DependsOn: []string{"unknown-step"},
685+
},
686+
},
687+
},
688+
},
689+
},
690+
},
691+
wantErr: true,
692+
errMsg: "spec.compositeTools[0].steps[0].dependsOn references unknown step \"unknown-step\"",
693+
},
566694
}
567695

568696
for _, tt := range tests {

0 commit comments

Comments
 (0)