diff --git a/pkg/workflow/mcp_http_url_validation_test.go b/pkg/workflow/mcp_http_url_validation_test.go new file mode 100644 index 0000000000..fda0e45112 --- /dev/null +++ b/pkg/workflow/mcp_http_url_validation_test.go @@ -0,0 +1,96 @@ +package workflow + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +// TestHTTPMCPServerRequiresURL tests that HTTP MCP servers require a url field +func TestHTTPMCPServerRequiresURL(t *testing.T) { + tests := []struct { + name string + workflow string + expectError bool + errorText string + }{ + { + name: "HTTP MCP server without url should fail", + workflow: `--- +on: issues +permissions: + contents: read +engine: copilot +mcp-servers: + test-http: + type: http +--- + +# Test workflow +`, + expectError: true, + errorText: "missing property 'url'", + }, + { + name: "HTTP MCP server with url should pass", + workflow: `--- +on: issues +permissions: + contents: read +engine: copilot +mcp-servers: + test-http: + type: http + url: "https://example.com" +--- + +# Test workflow +`, + expectError: false, + }, + { + name: "HTTP MCP server with url only (inferred type) should pass", + workflow: `--- +on: issues +permissions: + contents: read +engine: copilot +mcp-servers: + test-http: + url: "https://example.com" +--- + +# Test workflow +`, + expectError: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Create temporary workflow file + tmpDir := t.TempDir() + workflowPath := filepath.Join(tmpDir, "test.md") + if err := os.WriteFile(workflowPath, []byte(tt.workflow), 0644); err != nil { + t.Fatalf("Failed to write workflow file: %v", err) + } + + // Create compiler and try to compile the workflow + compiler := NewCompiler(false, "", "test") + err := compiler.CompileWorkflow(workflowPath) + + if tt.expectError { + if err == nil { + t.Errorf("Expected error but got none") + } else if tt.errorText != "" && !strings.Contains(err.Error(), tt.errorText) { + t.Errorf("Expected error to contain %q, got: %v", tt.errorText, err) + } + } else { + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + } + }) + } +}