From e4728e003a4b6007b058f9efef0d33f2d84ad9e3 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 24 Nov 2026 07:45:43 -0500 Subject: [PATCH] test(playlists): the same-day determinism test names the mix that changed Co-Authored-By: Claude Opus 5.5 --- internal/playlists/system_test.go | 44 ++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/internal/playlists/system_test.go b/internal/playlists/system_test.go index 8adb83a6..3d66be46 100644 --- a/internal/playlists/system_test.go +++ b/internal/playlists/system_test.go @@ -6,6 +6,8 @@ import ( "io" "log/slog" "path/filepath" + "sort" + "strings" "sync" "testing" "time" @@ -439,7 +441,7 @@ func TestBuildSystemPlaylists_DailyNonceDeterminism(t *testing.T) { snap2 := snapshotSystemTracks(t, pool, u.ID) if !equalSnapshots(snap1, snap2) { - t.Errorf("same-day rebuild produced different track lists") + t.Errorf("same-day rebuild produced different track lists: %s", describeSnapshotDiff(snap1, snap2)) } } @@ -470,6 +472,46 @@ func snapshotSystemTracks(t *testing.T, pool *pgxpool.Pool, userID pgtype.UUID) return out } +// describeSnapshotDiff names each playlist that differs between two +// snapshots: missing from one side, a different length, or the first +// position whose track differs. Says which mix broke determinism, not +// only that one did. +func describeSnapshotDiff(a, b map[string][]string) string { + names := map[string]bool{} + for k := range a { + names[k] = true + } + for k := range b { + names[k] = true + } + sorted := make([]string, 0, len(names)) + for k := range names { + sorted = append(sorted, k) + } + sort.Strings(sorted) + var parts []string + for _, k := range sorted { + va, okA := a[k] + vb, okB := b[k] + switch { + case !okA: + parts = append(parts, fmt.Sprintf("%q only in the second build (%d tracks)", k, len(vb))) + case !okB: + parts = append(parts, fmt.Sprintf("%q only in the first build (%d tracks)", k, len(va))) + case len(va) != len(vb): + parts = append(parts, fmt.Sprintf("%q has %d tracks then %d", k, len(va), len(vb))) + default: + for i := range va { + if va[i] != vb[i] { + parts = append(parts, fmt.Sprintf("%q first differs at position %d of %d", k, i, len(va))) + break + } + } + } + } + return strings.Join(parts, "; ") +} + func equalSnapshots(a, b map[string][]string) bool { if len(a) != len(b) { return false