|
7 | 7 | "os" |
8 | 8 | "os/exec" |
9 | 9 | "path/filepath" |
| 10 | + "sort" |
10 | 11 | "strconv" |
11 | 12 | "strings" |
12 | 13 | "testing" |
@@ -424,11 +425,11 @@ func TestDotnetRequestedByDeterminism(t *testing.T) { |
424 | 425 | bi := publishedBuildInfo.BuildInfo |
425 | 426 | require.NotEmpty(t, bi.Modules, "No modules in build info for run %d", i) |
426 | 427 |
|
427 | | - // Extract RequestedBy for each dependency |
| 428 | + // Extract RequestedBy for each dependency, normalizing order for comparison |
428 | 429 | requestedByMap := make(map[string][][]string) |
429 | 430 | for _, module := range bi.Modules { |
430 | 431 | for _, dep := range module.Dependencies { |
431 | | - requestedByMap[dep.Id] = dep.RequestedBy |
| 432 | + requestedByMap[dep.Id] = sortRequestedByPaths(dep.RequestedBy) |
432 | 433 | } |
433 | 434 | } |
434 | 435 | allRunsRequestedBy = append(allRunsRequestedBy, requestedByMap) |
@@ -475,3 +476,24 @@ func TestDotnetRequestedByDeterminism(t *testing.T) { |
475 | 476 | t.Logf("Successfully verified RequestedBy determinism across %d runs", numRuns) |
476 | 477 | cleanTestsHomeEnv() |
477 | 478 | } |
| 479 | + |
| 480 | +// sortRequestedByPaths sorts RequestedBy paths for consistent comparison. |
| 481 | +// Paths are sorted by length first (shorter paths first), then lexicographically |
| 482 | +// for paths of the same length. |
| 483 | +func sortRequestedByPaths(paths [][]string) [][]string { |
| 484 | + if len(paths) <= 1 { |
| 485 | + return paths |
| 486 | + } |
| 487 | + // Make a copy to avoid modifying the original |
| 488 | + sorted := make([][]string, len(paths)) |
| 489 | + copy(sorted, paths) |
| 490 | + sort.Slice(sorted, func(i, j int) bool { |
| 491 | + // Sort by length first (shorter paths come first) |
| 492 | + if len(sorted[i]) != len(sorted[j]) { |
| 493 | + return len(sorted[i]) < len(sorted[j]) |
| 494 | + } |
| 495 | + // For same length, sort lexicographically by joining elements |
| 496 | + return strings.Join(sorted[i], "/") < strings.Join(sorted[j], "/") |
| 497 | + }) |
| 498 | + return sorted |
| 499 | +} |
0 commit comments