[test] Add tests for config.stripExtensionFieldsForValidation and assignLegacyIntAlias#5762
Conversation
…cyIntAlias These two private functions in internal/config/config_stdin.go had zero direct test coverage: - stripExtensionFieldsForValidation: removes gateway-specific extension fields (guards, guard, auth, tool_response_filters) from JSON config before upstream schema validation. Tests cover all branches: top-level guards removal, per-server field stripping for each extension field, multiple servers, guard-policies preservation, and invalid JSON error. - assignLegacyIntAlias: maps a legacy field name to a typed int pointer only when the target has not already been set. Tests cover all branches: target already set (skip), alias absent (no-op), valid int assignment, zero value, negative value, and invalid/malformed JSON (error path). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds direct unit coverage for private stdin configuration helpers in internal/config, focusing on extension-field stripping before schema validation and legacy integer alias assignment.
Changes:
- Adds table-driven tests for
stripExtensionFieldsForValidation. - Adds branch-focused tests for
assignLegacyIntAlias. - Covers success, no-op, and error cases for both helpers.
Show a summary per file
| File | Description |
|---|---|
internal/config/config_stdin_helpers_test.go |
New unit tests for stdin config helper functions. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 3
| "s1": { | ||
| "type": "http", | ||
| "url": "https://example.com", | ||
| "guard-policies": [{"allow-only": {"repos": "public", "min-integrity": "none"}}] |
| "timeout": json.RawMessage(`42`), | ||
| } | ||
| err := assignLegacyIntAlias(fields, "timeout", &target) | ||
| require.NoError(t, err) | ||
| // target should remain unchanged |
| name: "empty config is preserved", | ||
| input: `{}`, |
|
@copilot address review feedback |
Addressed all three review findings in the latest commit:
|
Test Coverage Improvement
Functions Analyzed
internal/configstripExtensionFieldsForValidation,assignLegacyIntAliasinternal/config/config_stdin.goWhy These Functions?
Static analysis of all source files identified these two private functions as having zero direct test coverage (confirmed via codebase-wide grep for function name references in
*_test.gofiles).Both functions are called on every
LoadFromStdin()invocation, making them part of a critical hot path. They contain multiple branches that previously relied entirely on integration-level tests to exercise.stripExtensionFieldsForValidation(11 branches):guardsfieldguard,auth, andtool_response_filtersfields from all serversguard-policies(already injected into the upstream schema)mcpServersgracefullyassignLegacyIntAlias(5 branches):Tests Added
guard-policieskept, non-extension fields keptassignLegacyIntAliasTest Structure
All tests follow the codebase's established table-driven pattern with
testify/assertandtestify/require.Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgSee Network Configuration for more information.