Skip to content

refactor(config): centralize stdio server type helpers#8098

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-is-stdio-predicate
Jun 25, 2026
Merged

refactor(config): centralize stdio server type helpers#8098
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-is-stdio-predicate

Conversation

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

The "is stdio" predicate (t == "" || t == "stdio" || t == "local") and the normalization pattern were duplicated across 7 sites in 3 files, with one site (validateStandardServerConfig) missing the "" case — a silent validation gap.

Changes

  • internal/config/server_type.go — new file with two helpers:

    • IsStdioServerType(t string) bool — canonical check covering "", "stdio", "local"
    • NormalizeServerType(t string) string — maps "" / "local""stdio", passes rest through
  • validation.go — 3 sites updated:

    • Normalization block collapsed from two if checks to one NormalizeServerType call
    • validateStandardServerConfig (line 62): "stdio" || "local"IsStdioServerType (also fixes the missing "" case)
    • validateTOMLStdioContainerization (line 489): triple OR → IsStdioServerType
  • config_stdin.go — 4-line normalization block replaced with single NormalizeServerType call

  • validation_schema.go — triple OR in validateStringPatterns replaced with IsStdioServerType

  • internal/config/server_type_test.go — table-driven tests for both helpers covering all type values including wrong-case strings

// Before (repeated 5× across 3 files):
if cfg.Type == "" || cfg.Type == "stdio" || cfg.Type == "local" { ... }

// After:
if IsStdioServerType(cfg.Type) { ... }

GitHub Advanced Security started work on behalf of lpcox June 25, 2026 16:09 View session
GitHub Advanced Security finished work on behalf of lpcox June 25, 2026 16:10
Copilot AI changed the title [WIP] Refactor duplicate 'is stdio server' logic into helper function refactor(config): centralize stdio server type helpers Jun 25, 2026
Copilot AI requested a review from lpcox June 25, 2026 16:14
Copilot finished work on behalf of lpcox June 25, 2026 16:14
GitHub Advanced Security started work on behalf of lpcox June 25, 2026 16:17 View session
GitHub Advanced Security finished work on behalf of lpcox June 25, 2026 16:18
@lpcox lpcox marked this pull request as ready for review June 25, 2026 16:55
Copilot AI review requested due to automatic review settings June 25, 2026 16:55
@lpcox

lpcox commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes the “stdio-family” server type predicate and normalization logic in internal/config, removing duplicated checks and fixing a validation gap where an empty type wasn’t treated as stdio in one validation path.

Changes:

  • Added IsStdioServerType and NormalizeServerType helpers to canonicalize stdio-type handling.
  • Replaced repeated "" || "stdio" || "local" checks with IsStdioServerType in validation and schema validation.
  • Added table-driven unit tests for the new helpers.
Show a summary per file
File Description
internal/config/server_type.go Introduces centralized stdio-type predicate + normalization helpers.
internal/config/server_type_test.go Adds unit coverage for helper behavior across expected/edge inputs.
internal/config/validation.go Uses helpers to normalize types and consistently enforce stdio container requirements.
internal/config/validation_schema.go Uses helper for stdio container-pattern validation.
internal/config/config_stdin.go Uses normalization helper when converting stdin server configs.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

internal/config/validation.go:60

  • This change fixes a validation gap: an empty server type now correctly behaves like stdio and requires container. There doesn't appear to be a regression test covering the failing case (Type == "" with missing container) in internal/config/validation_test.go; adding one would prevent reintroducing this silent acceptance.
	if IsStdioServerType(server.Type) {
		if server.Container == "" {
			logValidation.Printf("Validation failed: %s, name=%s, type=%s", "stdio server missing container field", name, server.Type)
			return MissingRequired("container", "stdio", jsonPath, "Add a 'container' field (e.g., \"ghcr.io/owner/image:tag\")")
		}
  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread internal/config/config_stdin.go Outdated
@@ -490,13 +490,7 @@ func convertStdinServerConfig(name string, server *StdinServerConfig, customSche
}

// Normalize type: "local" is an alias for "stdio" (backward compatibility)
Resolve conflict in config_stdin.go: drop redundant NormalizeServerType call
since server.Type is already normalized by validateServerConfigWithCustomSchemas.
Also picks up UnsupportedField -> InvalidValue consolidation from main.

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Resolved. The only conflict was in config_stdin.go — I kept the main branch's approach of using server.Type directly (with its accurate comment noting both "" and "local" are normalized to "stdio" by validateServerConfigWithCustomSchemas upstream). The merge also picks up the UnsupportedField → InvalidValue consolidation from main. All tests pass.

GitHub Advanced Security started work on behalf of lpcox June 25, 2026 17:04 View session
Copilot finished work on behalf of lpcox June 25, 2026 17:04
GitHub Advanced Security finished work on behalf of lpcox June 25, 2026 17:05
@lpcox lpcox merged commit 8d56995 into main Jun 25, 2026
27 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-is-stdio-predicate branch June 25, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants