@@ -615,8 +615,16 @@ func (tfg TestFlavorGroup) ToFlavorGroupsKnowledge() FlavorGroupsKnowledge {
615615 groupMap [groupName ] = append (groupMap [groupName ], flavor )
616616 }
617617
618+ // Sort group names for deterministic iteration
619+ sortedGroupNames := make ([]string , 0 , len (groupMap ))
620+ for groupName := range groupMap {
621+ sortedGroupNames = append (sortedGroupNames , groupName )
622+ }
623+ sort .Strings (sortedGroupNames )
624+
618625 var groups []compute.FlavorGroupFeature
619- for groupName , groupFlavors := range groupMap {
626+ for _ , groupName := range sortedGroupNames {
627+ groupFlavors := groupMap [groupName ]
620628 if len (groupFlavors ) == 0 {
621629 continue
622630 }
@@ -1765,6 +1773,7 @@ func newAPIResponse(rejectReasonSubstrings ...string) APIResponseExpectation {
17651773
17661774// buildRequestJSON converts a test CommitmentChangeRequest to JSON string.
17671775// Builds the nested JSON structure directly for simplicity.
1776+ // Uses sorted iteration to ensure deterministic JSON output.
17681777func buildRequestJSON (req CommitmentChangeRequest ) string {
17691778 // Group commitments by project and resource for nested structure
17701779 type projectResources map [liquid.ResourceName ][]TestCommitment
@@ -1780,11 +1789,30 @@ func buildRequestJSON(req CommitmentChangeRequest) string {
17801789 )
17811790 }
17821791
1783- // Build nested JSON structure
1792+ // Sort projects for deterministic iteration
1793+ sortedProjects := make ([]string , 0 , len (byProject ))
1794+ for projectID := range byProject {
1795+ sortedProjects = append (sortedProjects , projectID )
1796+ }
1797+ sort .Strings (sortedProjects )
1798+
1799+ // Build nested JSON structure with sorted iteration
17841800 var projectParts []string
1785- for projectID , resources := range byProject {
1801+ for _ , projectID := range sortedProjects {
1802+ resources := byProject [projectID ]
1803+
1804+ // Sort resource names for deterministic iteration
1805+ sortedResources := make ([]liquid.ResourceName , 0 , len (resources ))
1806+ for resourceName := range resources {
1807+ sortedResources = append (sortedResources , resourceName )
1808+ }
1809+ sort .Slice (sortedResources , func (i , j int ) bool {
1810+ return string (sortedResources [i ]) < string (sortedResources [j ])
1811+ })
1812+
17861813 var resourceParts []string
1787- for resourceName , commits := range resources {
1814+ for _ , resourceName := range sortedResources {
1815+ commits := resources [resourceName ]
17881816 var commitParts []string
17891817 for _ , c := range commits {
17901818 expiryTime := time .Now ().Add (time .Duration (defaultCommitmentExpiryYears ) * 365 * 24 * time .Hour )
0 commit comments