Sort toolsnaps JSON keys recursively to eliminate noop churn#1816
Merged
SamMorrowDrums merged 2 commits intomainfrom Jan 15, 2026
Merged
Sort toolsnaps JSON keys recursively to eliminate noop churn#1816SamMorrowDrums merged 2 commits intomainfrom
SamMorrowDrums merged 2 commits intomainfrom
Conversation
Sort all JSON object keys alphabetically at every level in toolsnaps by unmarshaling and remarshaling. This leverages Go's built-in behavior where json.Marshal automatically sorts map keys alphabetically, ensuring consistent field ordering and eliminating noop churn in diffs. Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Sort toolsnaps fields to avoid noop churn
Sort toolsnaps JSON keys recursively to eliminate noop churn
Jan 15, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses JSON key ordering instability in toolsnap files caused by Go's randomized map iteration. The solution adds a sortJSONKeys() function that recursively sorts all JSON object keys alphabetically by unmarshaling and remarshaling JSON data, leveraging Go's built-in alphabetical key sorting for maps.
Changes:
- Added
sortJSONKeys()function to recursively sort JSON keys at all nesting levels - Modified
writeSnap()to sort JSON before writing - Regenerated all 94 toolsnap files with consistent alphabetical key ordering
- Added comprehensive tests for sorting behavior and idempotency
Reviewed changes
Copilot reviewed 96 out of 96 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/toolsnaps/toolsnaps.go | Added sortJSONKeys() function and integrated it into writeSnap() |
| internal/toolsnaps/toolsnaps_test.go | Added comprehensive test coverage for JSON key sorting and idempotency |
| pkg/github/toolsnaps/*.snap | Regenerated all 94 toolsnap files with alphabetically sorted keys |
tommaso-moro
approved these changes
Jan 15, 2026
6 tasks
Copilot AI
added a commit
that referenced
this pull request
Jan 15, 2026
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
7 tasks
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.
Summary
Toolsnaps now write JSON with consistent alphabetical key ordering at all nesting levels, eliminating diff churn from Go's randomized map iteration.
Why
Toolsnap diffs showed field reordering noise even when schemas hadn't changed. Example from a typical regeneration:
"order": { - "type": "string", - "description": "Sort order", + "description": "Sort order", "enum": ["asc", "desc"] + "type": "string" }What changed
sortJSONKeys()ininternal/toolsnaps/toolsnaps.go: unmarshals and remarshals JSON to leverage Go's built-in alphabetical map key sortingwriteSnap()to sort before writingMCP impact
Prompts tested (tool changes only)
N/A
Security / limits
Tool renaming
Lint & tests
./script/lint./script/testDocs
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.