Conversation
… files Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor config validation to remove duplicated logic
Consolidate duplicate config validation logic into centralized rules package
Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Config validation had three files (
env_validation.go,schema_validation.go,validation.go) with duplicate implementations of port range, timeout, and mount format validation. Each change to validation constraints required updates in 3 places.Changes
Created
internal/config/rules/package with centralized validation functions:PortRange(port, jsonPath)- validates 1-65535 rangeTimeoutPositive(timeout, fieldName, jsonPath)- validates ≥1MountFormat(mount, jsonPath, index)- validatessource:dest:modeformatValidationErrortype with consistent error messagingRefactored validation files to use centralized rules:
env_validation.go- port validation now callsrules.PortRange()schema_validation.go- port and timeout validation use rules packagevalidation.go- mount validation simplified from 46 lines to 5 linesImpact
Eliminates ~120 lines of duplicated validation:
Example of the consolidation:
Backward compatibility maintained via type alias in
validation.go.Original prompt
This section details on the original issue you should resolve
<issue_title>[duplicate-code] Config Validation Logic Duplication (Medium Severity)</issue_title>
<issue_description>## Summary
Config validation has three separate validation files with overlapping responsibilities and duplicated validation patterns for ports, timeouts, and field constraints.
Duplication Details
Pattern 1: Port Range Validation (3 instances)
Files:
internal/config/env_validation.go:275-276internal/config/schema_validation.go:240-248internal/config/validation.go:201-210Duplicated Code:
Pattern 2: Timeout Validation (4 instances)
Files:
internal/config/schema_validation.go:265-281internal/config/validation.go:213-229Duplicated Code:
Both files repeat this for
StartupTimeoutandToolTimeout.Pattern 3: ValidationError Creation (15+ instances)
Pattern across both schema_validation.go and validation.go:
Instances:
Pattern 4: Mount Validation
Files:
internal/config/schema_validation.go:201-210internal/config/validation.go:78-124Both validate mount format
source:dest:modewith nearly identical logic.schema_validation.go:201-210
validation.go:78-124 (46 lines)
File Responsibilities (Overlap)
env_validation.go
schema_validation.go
validation.go
Issues
1. Unclear Validation Flow
2. Inconsistent Error Messages
Port validation produces different error types:
fmt.Errorf&ValidationError&ValidationError3. Maintenance Burden
Severity Assessment: **ME...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.