Fix non-deterministic JSON key order causing Swift Testing args to be misidentified#286
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
anmarchenko
approved these changes
Jun 23, 2026
… misidentified Add .sortedKeys to apiEncoder outputFormatting so test argument dictionaries always serialize in a consistent order, preventing the same test from being treated as different tests across runs. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…Models.swift
The apiEncoder change fixed key ordering in API payloads, but the test
parameters tag is encoded via a separate plain JSONEncoder() in set(parameters:).
Add .sortedKeys there so the JSONGeneric dictionary keys ("name", "value", "type")
always appear in a stable order in test.parameters.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Replace the standalone JSONEncoder with the shared apiEncoder which already has .sortedKeys (and other settings) configured. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…raw JSON With apiEncoder's .sortedKeys the serialized test.parameters tag is fully deterministic, so there is no need to decode into a typed struct. Sort the raw JSON strings (lexicographic order matches the p1 int values) and compare directly against expected string literals. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
ypopovych
force-pushed
the
fix/sort-json-keys-for-stable-test-args
branch
from
June 23, 2026 11:57
09e94da to
35b98e5
Compare
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
Parameterized Swift Testing tests were being misidentified across runs because the `test.parameters` tag serialized argument dictionaries with non-deterministic key order.
Root cause: `set(parameters:)` in `Models.swift` encoded a `JSONGeneric.object(Dictionary<String, Self>)` using a plain `JSONEncoder()` with no key ordering configured. Swift dictionaries have no guaranteed iteration order, so the three argument keys (`name`, `value`, `type`) could appear in any order in the JSON string, producing a different fingerprint for the same test across runs.
Fix:
Test plan
🤖 Generated with Claude Code