Conversation
…ve, formatSchemaError These three functions in internal/config/validation_schema.go handle user-friendly formatting of JSON Schema validation errors. They were only exercised indirectly through TestEnhancedErrorMessages which requires a network-fetched schema, leaving branches untested. New test file adds comprehensive coverage: - TestFormatErrorContext: 20 table-driven cases covering all 7 branch conditions (additionalProperties, type mismatch, enum, missing required, pattern, min/max, oneOf), keyword location display logic, prefix prepending, and unrecognized messages - TestFormatValidationErrorRecursive: 7 sub-tests covering root-level errors, empty location fallback (<root>), depth-based indentation, recursive cause traversal, and context detail inclusion - TestFormatSchemaError: 6 sub-tests covering nil input, jsonschema ValidationError formatting with version/location/footer, non-schema errors, fmt.Errorf wrapped errors, and recursive cause inclusion Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Feb 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds focused, offline unit tests for JSON Schema validation error formatting helpers in internal/config, improving coverage without relying on network-fetched schemas.
Changes:
- Introduces table-driven tests for
formatErrorContextmessage-to-context formatting. - Adds recursion/indentation tests for
formatValidationErrorRecursive(including nestedCauses). - Adds entry-point tests for
formatSchemaError, including footer/version presence and non-schema error behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+362
to
+366
| t.Run("jsonschema.ValidationError includes version and location info", func(t *testing.T) { | ||
| version.Set("v1.0.0-test") | ||
|
|
||
| ve := &jsonschema.ValidationError{ | ||
| InstanceLocation: "mcpServers.github", |
There was a problem hiding this comment.
TestFormatSchemaError repeatedly calls version.Set(...) but never restores the prior value. Since internal/version uses a package-level mutable variable, this can leak state to other tests in the config package and make the suite order-dependent. Consider capturing prev := version.Get() and restoring it with t.Cleanup(...) (or avoid setting entirely and assert against version.Get()).
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.
Test Coverage Improvement: Schema Error Formatting Functions
Functions Analyzed
internal/configformatErrorContext— provides human-friendly diagnostic context for JSON schema validation errors based on message content (7 if-branches)formatValidationErrorRecursive— recursively formats schema errors with depth-based indentationformatSchemaError— entry point that dispatches to the above and appends version + documentation footerTestEnhancedErrorMessageswhich requires network-fetched schemas)formatErrorContexthas 7 independent if-branches plus a keyword-location check;formatValidationErrorRecursiveis recursive with depth trackingWhy These Functions?
formatErrorContexthas the highest branch density invalidation_schema.gowith 7 independent conditional blocks, none directly tested. The existingTestEnhancedErrorMessagescallsvalidateJSONSchemawhich fetches a schema from GitHub over the network, making those tests environment-dependent and leaving the formatting functions without reliable direct coverage.Tests Added
✅
TestFormatErrorContext(20 table-driven cases):additionalProperties, type mismatch (expected+but got/type), enum (value must be one of/must be), missing required (missing properties/required), pattern (does not match pattern/pattern), min/max (must be >=/must be <=/minimum/maximum), oneOf (doesn't validate with any of/oneOf)✅
TestFormatValidationErrorRecursive(7 sub-tests):InstanceLocationfalls back to(root)placeholderCausessliceformatErrorContextare included in output✅
TestFormatSchemaError(6 sub-tests):nilinput returnsnil*jsonschema.ValidationErrorgets full formatted message with version, location, and documentation footererrors.Newgets compact one-line format with versionfmt.Errorfwrapped errors get compact formatadditionalPropertieserrors include context details in full pathTest Execution
Tests are designed to pass in CI where Go module dependencies are available. They use
jsonschema.ValidationErrorstruct directly (no network required),version.Set()for deterministic version assertions, and follow the project's table-driven test conventions withtestify/assert.Generated by Test Coverage Improver
Warning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.org