test(playlists, recommendation): system-mix builds stop drawing covers no test reads; merge repeated cases (#8297)
release / go (push) Successful in 1m44s
release / web (push) Successful in 1m16s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 2m45s
release / android (push) Successful in 4m29s
release / Build signed APK (push) Successful in 4m40s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped

Timings from one run of the integration lane with -v (39c5b1ed, reverted
here) put the system-mix builds at 1.4-3.8s each, most of the playlists
package's 35s. A build draws a JPEG collage per mix; under -race that is
most of its time, and no build test looked at a cover. The build tests now
pass no data folder, which skips drawing, except SufficientActivity, which
keeps drawing and now checks every mix got a cover: nothing tested that the
build wires covers before.

Merged:
- playlists service: 22 tests become 5 scenario tests (access, bad input,
  partial update, track-list edits, cover-file cleanup), one database
  reset each.
- ARebuildKeepsEachMixsID into DailyNonceDeterminism (both built twice in
  one day); the two You might like builds into one.
- capCandidatesByAlbumAndArtist, Score, Similarity, ContextualMatchScore
  and the session-vector seed rule: one table each.
- LoadCandidates' six contextual-like database tests: the max and seed
  rules are ContextualMatchScore's unit table; the database test keeps what
  only it can see, a like reaching its track and a withdrawn like ignored.

Dropped: Score determinism with a fixed RNG (a pure function), Score's
cold-start case (the same input as the base case), and recencyDecay(nil)
and skipRatio's two cases, which Score's table covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 13:35:36 -05:00
co-authored by Claude Opus 5.5
parent 39c5b1ed66
commit a2dae7ec8c
10 changed files with 471 additions and 1055 deletions
+59 -69
View File
@@ -126,6 +126,12 @@ func TestBuildSystemPlaylists_SufficientActivity(t *testing.T) {
if r.TrackCount == 0 {
t.Errorf("row %s: empty track_count", uuidString(r.ID))
}
// The one build test that draws covers: every mix gets one. The
// others pass no data folder, which skips drawing, since a JPEG per
// mix is most of a build's time under -race.
if r.CoverPath == nil {
t.Errorf("row %s: no collage cover", uuidString(r.ID))
}
// For-You / Discover / the discovery mixes are sized to ~100
// songs_like_artist stays at systemMixLength (25).
if r.TrackCount > 100 {
@@ -163,7 +169,7 @@ func TestBuildSystemPlaylists_StaleActivity_SongsLikeSurvives(t *testing.T) {
}
}
if err := playlists.BuildSystemPlaylists(context.Background(), pool, logger, u.ID, time.Now().UTC(), t.TempDir()); err != nil {
if err := playlists.BuildSystemPlaylists(context.Background(), pool, logger, u.ID, time.Now().UTC(), ""); err != nil {
t.Fatalf("build: %v", err)
}
@@ -201,7 +207,7 @@ func TestBuildSystemPlaylists_QuarantineExcluded(t *testing.T) {
quarantined := tracks[0]
seedQuarantine(t, pool, u.ID, quarantined.ID)
if err := playlists.BuildSystemPlaylists(context.Background(), pool, logger, u.ID, time.Now().UTC(), t.TempDir()); err != nil {
if err := playlists.BuildSystemPlaylists(context.Background(), pool, logger, u.ID, time.Now().UTC(), ""); err != nil {
t.Fatalf("build: %v", err)
}
@@ -228,65 +234,6 @@ func TestBuildSystemPlaylists_QuarantineExcluded(t *testing.T) {
}
}
// A rebuild refills each mix in place: a Subsonic app caches, pins and
// downloads a playlist by id, so the same mix keeps its id from one build to
// the next, and no mix is left behind twice.
func TestBuildSystemPlaylists_ARebuildKeepsEachMixsID(t *testing.T) {
pool := dbtest.Pool(t)
logger := discardLogger()
u, _ := seedActiveLibrary(t, pool, "atomic", 3, 3)
ctx := context.Background()
dir := t.TempDir()
// A mix is named by its name AND its seed artist: the fixtures make one
// artist row per track, all named alike, so two Songs like mixes can
// share a name (see snapshotSystemTracks).
list := func() map[string]pgtype.UUID {
t.Helper()
rows, err := pool.Query(ctx, `
SELECT p.name || ' [' || COALESCE(p.seed_artist_id::text, '-') || ']', p.id
FROM playlists p
WHERE p.user_id = $1 AND p.kind = 'system'`, u.ID)
if err != nil {
t.Fatalf("list: %v", err)
}
defer rows.Close()
out := map[string]pgtype.UUID{}
for rows.Next() {
var mix string
var id pgtype.UUID
if err := rows.Scan(&mix, &id); err != nil {
t.Fatalf("scan: %v", err)
}
if _, dup := out[mix]; dup {
t.Fatalf("mix %q is held twice", mix)
}
out[mix] = id
}
if err := rows.Err(); err != nil {
t.Fatalf("rows: %v", err)
}
return out
}
if err := playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, time.Now().UTC(), dir); err != nil {
t.Fatalf("first build: %v", err)
}
first := list()
if len(first) == 0 {
t.Fatal("no system playlists from the first build")
}
if err := playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, time.Now().UTC(), dir); err != nil {
t.Fatalf("second build: %v", err)
}
second := list()
for name, id := range first {
if again, ok := second[name]; ok && again != id {
t.Errorf("mix %q got a new id on rebuild: %s then %s", name, uuidString(id), uuidString(again))
}
}
}
func TestBuildSystemPlaylists_Concurrency(t *testing.T) {
pool := dbtest.Pool(t)
logger := discardLogger()
@@ -296,9 +243,8 @@ func TestBuildSystemPlaylists_Concurrency(t *testing.T) {
var wg sync.WaitGroup
wg.Add(2)
dataDir := t.TempDir()
go func() { defer wg.Done(); _ = playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, now, dataDir) }()
go func() { defer wg.Done(); _ = playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, now, dataDir) }()
go func() { defer wg.Done(); _ = playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, now, "") }()
go func() { defer wg.Done(); _ = playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, now, "") }()
wg.Wait()
// Exactly one run must have completed; in_flight must be false either way.
@@ -390,7 +336,7 @@ func TestBuildSystemPlaylists_SongsLikeIncludesItsSeedArtist(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 5, 4, 12, 0, 0, 0, time.UTC)
if err := playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, now, t.TempDir()); err != nil {
if err := playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, now, ""); err != nil {
t.Fatalf("build: %v", err)
}
@@ -445,6 +391,9 @@ func TestBuildSystemPlaylists_SongsLikeIncludesItsSeedArtist(t *testing.T) {
}
}
// A same-day rebuild picks the same tracks, and refills each mix in place: a
// Subsonic app caches, pins and downloads a playlist by id, so the same mix
// keeps its id from one build to the next, and no mix is held twice.
func TestBuildSystemPlaylists_DailyNonceDeterminism(t *testing.T) {
pool := dbtest.Pool(t)
logger := discardLogger()
@@ -452,22 +401,63 @@ func TestBuildSystemPlaylists_DailyNonceDeterminism(t *testing.T) {
ctx := context.Background()
day1 := time.Date(2026, 5, 4, 12, 0, 0, 0, time.UTC)
dataDir := t.TempDir()
if err := playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, day1, dataDir); err != nil {
if err := playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, day1, ""); err != nil {
t.Fatalf("build day1 first: %v", err)
}
snap1 := snapshotSystemTracks(t, pool, u.ID)
ids1 := systemMixIDs(t, pool, u.ID)
if len(ids1) == 0 {
t.Fatal("no system playlists from the first build")
}
if err := playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, day1, dataDir); err != nil {
if err := playlists.BuildSystemPlaylists(ctx, pool, logger, u.ID, day1, ""); err != nil {
t.Fatalf("build day1 second: %v", err)
}
snap2 := snapshotSystemTracks(t, pool, u.ID)
ids2 := systemMixIDs(t, pool, u.ID)
for mix, id := range ids1 {
if again, ok := ids2[mix]; ok && again != id {
t.Errorf("mix %q got a new id on rebuild: %s then %s", mix, uuidString(id), uuidString(again))
}
}
if !equalSnapshots(snap1, snap2) {
t.Errorf("same-day rebuild produced different track lists: %s", describeSnapshotDiff(snap1, snap2))
}
}
// systemMixIDs maps each of the user's system mixes to its playlist id. A mix
// is named by its name AND its seed artist: the fixtures make one artist row
// per track, all named alike, so two Songs like mixes can share a name (see
// snapshotSystemTracks). A mix held twice fails the test.
func systemMixIDs(t *testing.T, pool *pgxpool.Pool, userID pgtype.UUID) map[string]pgtype.UUID {
t.Helper()
rows, err := pool.Query(context.Background(), `
SELECT p.name || ' [' || COALESCE(p.seed_artist_id::text, '-') || ']', p.id
FROM playlists p
WHERE p.user_id = $1 AND p.kind = 'system'`, userID)
if err != nil {
t.Fatalf("list: %v", err)
}
defer rows.Close()
out := map[string]pgtype.UUID{}
for rows.Next() {
var mix string
var id pgtype.UUID
if err := rows.Scan(&mix, &id); err != nil {
t.Fatalf("scan: %v", err)
}
if _, dup := out[mix]; dup {
t.Fatalf("mix %q is held twice", mix)
}
out[mix] = id
}
if err := rows.Err(); err != nil {
t.Fatalf("rows: %v", err)
}
return out
}
// snapshotSystemTracks returns a per-mix → []track_id mapping for the
// user's system playlists, in playlist_tracks position order.
//
@@ -604,7 +594,7 @@ func TestBuildSystemPlaylists_DiscoverColdStart(t *testing.T) {
t.Fatalf("clear plays: %v", err)
}
if err := playlists.BuildSystemPlaylists(context.Background(), pool, logger, u.ID, time.Now().UTC(), t.TempDir()); err != nil {
if err := playlists.BuildSystemPlaylists(context.Background(), pool, logger, u.ID, time.Now().UTC(), ""); err != nil {
t.Fatalf("build: %v", err)
}