From e71c132cc7c1d6404493dca778a3a4248b9c2b85 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 24 Nov 2026 09:17:17 -0500 Subject: [PATCH] test(playlists): key the same-day snapshot by mix, not by name The fixture makes one artist row per track, so artists share names, and with twelve Songs like mixes two can both be "Songs like X". Keyed by name, their tracks merged and interleaved in tie order, so the snapshot varied though the mixes did not. Name plus seed artist identifies a mix. Co-Authored-By: Claude Opus 5.5 --- internal/playlists/system_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/playlists/system_test.go b/internal/playlists/system_test.go index 3d66be46..913468ec 100644 --- a/internal/playlists/system_test.go +++ b/internal/playlists/system_test.go @@ -445,16 +445,23 @@ func TestBuildSystemPlaylists_DailyNonceDeterminism(t *testing.T) { } } -// snapshotSystemTracks returns a per-playlist-name → []track_id mapping -// for the user's system playlists, in playlist_tracks position order. +// snapshotSystemTracks returns a per-mix → []track_id mapping for the +// user's system playlists, in playlist_tracks position order. +// +// A mix is keyed by its name AND its seed artist, because names are not +// unique: two artists can share a name (the test fixtures make one artist +// row per track, all named alike), and their Songs like mixes are then +// both called "Songs like X". Keyed by name alone, two such mixes merge +// into one list whose interleaving is whatever order Postgres returns the +// tied rows in, and the snapshot varies even when the mixes do not. func snapshotSystemTracks(t *testing.T, pool *pgxpool.Pool, userID pgtype.UUID) map[string][]string { t.Helper() rows, err := pool.Query(context.Background(), ` - SELECT p.name, pt.track_id + SELECT p.name || ' [' || COALESCE(p.seed_artist_id::text, '-') || ']', pt.track_id FROM playlists p JOIN playlist_tracks pt ON pt.playlist_id = p.id WHERE p.user_id = $1 AND p.kind = 'system' - ORDER BY p.name, pt.position + ORDER BY p.name, p.seed_artist_id, pt.position `, userID) if err != nil { t.Fatalf("snapshot query: %v", err)