fix(go): ensure deterministic ordering in generated requests.go and requests_test.go#13339
Merged
patrickthornton merged 6 commits intomainfrom Mar 13, 2026
Merged
Conversation
Contributor
🌱 Seed Test SelectorSelect languages to run seed tests for:
How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR. |
There was a problem hiding this comment.
Pull request overview
Fixes non-deterministic ordering in the Go SDK generator output by sorting map keys prior to iteration, reducing noisy diffs in generated Go files.
Changes:
- Adds sorted key iteration helpers and applies them across map
rangeloops in the Go generator to make generation deterministic. - Introduces a new Go-only fixture (
go-deterministic-ordering) to reproduce and prevent regressions for ordering issues. - Bumps the Go generator version to
1.29.2and adds/updates related snapshots.
Reviewed changes
Copilot reviewed 182 out of 229 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| generators/go/sdk/versions.yml | Version bump to 1.29.2 documenting the deterministic-ordering fix. |
| seed/go-sdk/go-deterministic-ordering/go.mod | Adds a Go module for the new deterministic-ordering fixture. |
| seed/go-sdk/go-deterministic-ordering/.github/workflows/ci.yml | Adds fixture-local CI workflow for build/lint/test. |
| seed/go-sdk/go-deterministic-ordering/internal/error_decoder.go | Adds an error decoder utility used by generated clients. |
| seed/go-sdk/go-deterministic-ordering/internal/error_decoder_test.go | Adds unit tests for the error decoder behavior. |
| seed/go-sdk/go-deterministic-ordering/internal/extra_properties.go | Adds helper for extracting/marshaling extra JSON properties. |
| seed/go-sdk/go-deterministic-ordering/** | Adds generated Go SDK + wiremock tests + dynamic snippets for the new fixture. |
| packages/cli/fern-definition/ir-to-jsonschema/src/test/snapshots/go-deterministic-ordering/** | Adds JSON schema snapshots for the new fixture/types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
seed/go-sdk/go-deterministic-ordering/noreqbody/no_req_body_test/no_req_body_test.go
Show resolved
Hide resolved
…equests_test.go Go maps randomize iteration order, causing non-deterministic type ordering in requests.go when exportAllRequestsAtRoot is enabled. This sorts map keys before iteration using slices.SortFunc/cmp.Compare, and adds exhaustive test fixtures with duplicate endpoint names to reproduce and prevent regression.
…dering fixture Move duplicate-names services out of the shared exhaustive fixture into a new go-deterministic-ordering fixture with the full exhaustive IR definition. Remove export-all-requests-at-root from exhaustive since the ordering test now lives in the dedicated fixture. This avoids breaking C# and other generators that share the exhaustive test definitions.
b0cbf45 to
f616487
Compare
patrickthornton
approved these changes
Mar 13, 2026
4 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.
Description
Fix non-deterministic ordering in Go SDK generator output. Go maps randomize iteration order by design, so when the IR JSON is deserialized into Go maps, the insertion order is lost. This causes
requests.go,requests_test.go, and other generated files to have different type orderings across runs — producing noisy PR diffs.Changes Made
sortedMapKeysandsortedFileInfoKeysgeneric helpers usingslices.SortFunc/cmp.Compareto extract and sort map keys before iterationgenerators/go/internal/generator/generator.gothat were iterating Go maps non-deterministicallygo-deterministic-orderingGo-only test fixture with duplicate endpoint names (create,get,list) across 3 services to reproduce and prevent regression1.29.2ingenerators/go/sdk/versions.ymlTesting
go test ./...)