Skip to content

Commit 569a2a6

Browse files
committed
acceptance: refactor SubsetExpanded to use key->index map instead of map->slice conversion
Replaces map[string][][]string (engine -> group) with a parallel pair of slices (result, groups) indexed by first-seen insertion order, using a keyToIdx map[string]int as the side structure for deduplication. This eliminates the non-deterministic map iteration that determined result order. Co-authored-by: Isaac
1 parent 22304e1 commit 569a2a6

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

acceptance/internal/config.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,11 @@ func SubsetExpanded(expanded [][]string, testDir string, scriptUsesEngine bool)
436436
return expanded
437437
}
438438
if scriptUsesEngine {
439-
// Group by engine value and pick one combo per group.
440-
groups := make(map[string][][]string)
439+
// Collect candidates per engine key, preserving first-seen order.
440+
// keyToIdx maps engine value -> index in result/groups slices.
441+
var result [][]string
442+
var groups [][][]string
443+
keyToIdx := make(map[string]int)
441444
for _, envset := range expanded {
442445
engine := ""
443446
for _, kv := range envset {
@@ -446,11 +449,17 @@ func SubsetExpanded(expanded [][]string, testDir string, scriptUsesEngine bool)
446449
break
447450
}
448451
}
449-
groups[engine] = append(groups[engine], envset)
452+
idx, ok := keyToIdx[engine]
453+
if !ok {
454+
idx = len(result)
455+
keyToIdx[engine] = idx
456+
result = append(result, nil)
457+
groups = append(groups, nil)
458+
}
459+
groups[idx] = append(groups[idx], envset)
450460
}
451-
var result [][]string
452-
for _, group := range groups {
453-
result = append(result, weightedSelect(group, testDir))
461+
for i, group := range groups {
462+
result[i] = weightedSelect(group, testDir)
454463
}
455464
return result
456465
}

0 commit comments

Comments
 (0)