fix: move validateTrustedBots to validation.go and enforce on stdin path#2217
Conversation
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/e8fa10a8-4831-4dee-b2dc-0dd2cd845d55
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
This PR aligns config validation behavior across TOML and JSON-stdin sources by centralizing trustedBots validation and ensuring trustedBots: [] is rejected consistently per spec §4.1.3.4.
Changes:
- Moved
validateTrustedBotsintointernal/config/validation.goand invoked it fromvalidateGatewayConfig. - Enforced
trustedBotsvalidation on the stdin JSON conversion path (convertStdinConfig) when the field is present. - Updated/added tests so the stdin path now expects an error for
trustedBots: [](including a fullLoadFromStdinintegration-style test).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/config/validation.go | Adds trustedBots validation to gateway validation and relocates the helper. |
| internal/config/config_core.go | Removes the old helper and drops an unused import after the move. |
| internal/config/config_stdin.go | Validates trustedBots when present during stdin config conversion. |
| internal/config/config_stdin_test.go | Updates conversion tests to expect an error for empty trustedBots. |
| internal/config/config_test.go | Adds an end-to-end stdin test expecting rejection of trustedBots: []. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return fmt.Errorf("trusted_bots must be a non-empty array when present (spec §4.1.3.4)") | ||
| } | ||
| for i, bot := range bots { | ||
| if strings.TrimSpace(bot) == "" { | ||
| return fmt.Errorf("trusted_bots[%d] must be a non-empty string", i) |
There was a problem hiding this comment.
validateTrustedBots returns plain fmt.Errorf messages, while the rest of validateGatewayConfig primarily returns *rules.ValidationError (with consistent Field/JSONPath/Suggestion formatting). This leads to inconsistent error formatting for trustedBots compared to port/timeouts/payloadDir. Consider returning rules.InvalidValue (and include an appropriate JSONPath like "gateway.trustedBots" / "gateway.trustedBots[i]") so error output is consistent across gateway validations (and still usable from the TOML path).
| return fmt.Errorf("trusted_bots must be a non-empty array when present (spec §4.1.3.4)") | |
| } | |
| for i, bot := range bots { | |
| if strings.TrimSpace(bot) == "" { | |
| return fmt.Errorf("trusted_bots[%d] must be a non-empty string", i) | |
| return rules.InvalidValue( | |
| "trusted_bots", | |
| "gateway.trustedBots", | |
| "trusted_bots must be a non-empty array when present (spec §4.1.3.4)", | |
| "Remove the trusted_bots setting or provide at least one non-empty trusted bot identifier.", | |
| ) | |
| } | |
| for i, bot := range bots { | |
| if strings.TrimSpace(bot) == "" { | |
| return rules.InvalidValue( | |
| "trusted_bots", | |
| fmt.Sprintf("gateway.trustedBots[%d]", i), | |
| "trusted_bots entries must be non-empty strings", | |
| "Remove empty entries from trusted_bots or replace them with valid trusted bot identifiers.", | |
| ) |
| // Validate trustedBots per spec §4.1.3.4: must be non-empty array when present | ||
| if err := validateTrustedBots(gateway.TrustedBots); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
validateGatewayConfig now enforces the trustedBots constraint, but TestValidateGatewayConfig in validation_test.go doesn’t cover the new cases (empty slice, whitespace-only entries). Adding focused unit cases there would prevent regressions even if JSON schema behavior changes and would directly exercise the new validation branch.
validateTrustedBotslived inconfig_core.gowhile all other validation helpers live invalidation.go. The stdin JSON path also silently droppedtrustedBots: []instead of rejecting it per spec §4.1.3.4.Changes
validation.go: MovevalidateTrustedBotshere; call it fromvalidateGatewayConfigso the stdin path enforces the same constraint as TOMLconfig_core.go: RemovevalidateTrustedBotsand unusedstringsimportconfig_stdin.go: CallvalidateTrustedBotsinconvertStdinConfigwhenTrustedBots != nil(defense-in-depth); restructured to eliminate redundant length checkconfig_stdin_test.go: Update"empty trustedBots not propagated"sub-test to expect an errorconfig_test.go: AddTestLoadFromStdin_WithEmptyTrustedBotscovering the fullLoadFromStdinpathBoth config sources now consistently reject
trustedBots: []:⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.