Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions internal/config/config_stdin_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package config

import (
"errors"
"os"
"testing"

"github.com/github/gh-aw-mcpg/internal/config/rules"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -276,6 +278,17 @@ func TestConvertStdinServerConfig_ValidationError(t *testing.T) {
},
errorContains: "url",
},
{
name: "stdio with auth block",
server: &StdinServerConfig{
Type: "stdio",
Container: "ghcr.io/owner/image:latest",
Auth: &AuthConfig{
Type: "github-oidc",
},
},
errorContains: "auth is only supported for HTTP servers",
},
}

for _, tc := range testCases {
Expand All @@ -288,6 +301,30 @@ func TestConvertStdinServerConfig_ValidationError(t *testing.T) {
}
}

// TestConvertStdinServerConfig_StdioWithAuth verifies that a stdio server with an auth block
// returns a structured rules.ValidationError with the correct JSONPath and suggestion,
// guarding against regressions in error type or message.
func TestConvertStdinServerConfig_StdioWithAuth(t *testing.T) {
server := &StdinServerConfig{
Type: "stdio",
Container: "ghcr.io/owner/image:latest",
Auth: &AuthConfig{
Type: "github-oidc",
},
}

result, err := convertStdinServerConfig("my-server", server, nil)
require.Error(t, err)
assert.Nil(t, result)

var valErr *rules.ValidationError
require.True(t, errors.As(err, &valErr), "expected a *rules.ValidationError, got %T: %v", err, err)
assert.Equal(t, "auth", valErr.Field)
assert.Contains(t, valErr.Message, "auth is only supported for HTTP servers")
assert.Contains(t, valErr.JSONPath, "mcpServers.my-server")
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestConvertStdinServerConfig_StdioWithAuth says it verifies the “correct JSONPath”, but the assertion uses assert.Contains on valErr.JSONPath. Since the expected path is deterministic (mcpServers.my-server), asserting equality would make this test stricter and better at catching regressions (e.g., a different prefix/suffix that still contains the substring).

Suggested change
assert.Contains(t, valErr.JSONPath, "mcpServers.my-server")
assert.Equal(t, "mcpServers.my-server", valErr.JSONPath)

Copilot uses AI. Check for mistakes.
assert.NotEmpty(t, valErr.Suggestion)
}

// TestConvertStdinServerConfig_EmptyEnvAndHeaders tests handling of empty env and headers.
func TestConvertStdinServerConfig_EmptyEnvAndHeaders(t *testing.T) {
server := &StdinServerConfig{
Expand Down
Loading