Skip to content

Commit 4df9270

Browse files
committed
Improve stdio transport validation and function naming
- Add validation that URL must be empty for stdio transport types - Rename validateTransport to validateRemoteTransport for clarity - Update test case to expect error when stdio transport has URL This addresses feedback from PR #345 requesting stricter validation for stdio transports and better function naming. :house: Remote-Dev: homespace
1 parent e0e51ea commit 4df9270

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

internal/validators/validators.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ValidateServerJSON(serverJSON *apiv0.ServerJSON) error {
3434

3535
// Validate all remotes
3636
for _, remote := range serverJSON.Remotes {
37-
if err := validateTransport(&remote); err != nil {
37+
if err := validateRemoteTransport(&remote); err != nil {
3838
return err
3939
}
4040
}
@@ -173,7 +173,10 @@ func validatePackageTransport(transport *model.Transport, availableVariables []s
173173
// Validate transport type is supported
174174
switch transport.Type {
175175
case model.TransportTypeStdio:
176-
// No additional validation needed for stdio - URL should be empty
176+
// Validate that URL is empty for stdio transport
177+
if transport.URL != "" {
178+
return fmt.Errorf("url must be empty for %s transport type, got: %s", transport.Type, transport.URL)
179+
}
177180
return nil
178181
case model.TransportTypeStreamableHTTP, model.TransportTypeSSE:
179182
// URL is required for streamable-http and sse
@@ -196,8 +199,8 @@ func validatePackageTransport(transport *model.Transport, availableVariables []s
196199
}
197200
}
198201

199-
// validateTransport validates a remote transport (no templating allowed)
200-
func validateTransport(obj *model.Transport) error {
202+
// validateRemoteTransport validates a remote transport (no templating allowed)
203+
func validateRemoteTransport(obj *model.Transport) error {
201204
// Validate transport type is supported - remotes only support streamable-http and sse
202205
switch obj.Type {
203206
case model.TransportTypeStreamableHTTP, model.TransportTypeSSE:

internal/validators/validators_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ func TestValidate_TransportValidation(t *testing.T) {
736736
}{
737737
// Package transport tests - stdio (no URL required)
738738
{
739-
name: "package transport stdio without URL",
739+
name: "package transport stdio without URL should pass",
740740
serverDetail: apiv0.ServerJSON{
741741
Name: "com.example/test-server",
742742
Description: "A test server",
@@ -756,7 +756,7 @@ func TestValidate_TransportValidation(t *testing.T) {
756756
expectedError: "",
757757
},
758758
{
759-
name: "package transport stdio with URL (should still work)",
759+
name: "package transport stdio with URL (should fail)",
760760
serverDetail: apiv0.ServerJSON{
761761
Name: "com.example/test-server",
762762
Description: "A test server",
@@ -774,7 +774,7 @@ func TestValidate_TransportValidation(t *testing.T) {
774774
},
775775
},
776776
},
777-
expectedError: "",
777+
expectedError: "url must be empty for stdio transport type",
778778
},
779779
// Package transport tests - streamable-http (URL required)
780780
{
@@ -1174,9 +1174,9 @@ func createValidServerWithArgument(arg model.Argument) apiv0.ServerJSON {
11741174
},
11751175
Packages: []model.Package{
11761176
{
1177-
Identifier: "test-package",
1178-
RegistryType: "npm",
1179-
RegistryBaseURL: "https://registry.npmjs.org",
1177+
Identifier: "test-package",
1178+
RegistryType: "npm",
1179+
RegistryBaseURL: "https://registry.npmjs.org",
11801180
Transport: model.Transport{
11811181
Type: "stdio",
11821182
},

0 commit comments

Comments
 (0)