The same rewrite as d191a282, for four packages whose comments carried the
most history: tuning stories, quotes from the operator, single-install
measurements in library_scale.go, and 'used to' accounts of bugs. The
constraint each story protected stays as a present-tense reason (why tier 3
is reduced not removed, why the randomised arms take an order seed, why the
seed artist is eligible in Songs-like). Comments naming system_cron.go and
config.RecommendationConfig, neither of which holds what they claimed, now
name the scheduler and internal/recsettings.
Checked: non-comment tokens identical to HEAD; gofmt clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
3.0 KiB
Go
86 lines
3.0 KiB
Go
package playlists_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
|
)
|
|
|
|
func likeTrack(t *testing.T, pool *pgxpool.Pool, userID, trackID pgtype.UUID) {
|
|
t.Helper()
|
|
if _, err := pool.Exec(context.Background(),
|
|
`INSERT INTO general_likes (user_id, track_id) VALUES ($1, $2)`,
|
|
userID, trackID); err != nil {
|
|
t.Fatalf("like track: %v", err)
|
|
}
|
|
}
|
|
|
|
func markMissing(t *testing.T, pool *pgxpool.Pool, trackID pgtype.UUID) {
|
|
t.Helper()
|
|
if _, err := pool.Exec(context.Background(),
|
|
`UPDATE tracks SET missing_since = now() WHERE id = $1`, trackID); err != nil {
|
|
t.Fatalf("mark missing: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestPickTopPlayedTracksForUser_LikedTierSkipsMissing: with no plays, For
|
|
// You seeds from likes. A liked track whose file is gone is not a seed.
|
|
func TestPickTopPlayedTracksForUser_LikedTierSkipsMissing(t *testing.T) {
|
|
pool := newPool(t)
|
|
u := seedUser(t, pool, "seedmissing")
|
|
present := seedTrack(t, pool, "Present", "Seed Artist A")
|
|
gone := seedTrack(t, pool, "Gone", "Seed Artist B")
|
|
likeTrack(t, pool, u.ID, present.ID)
|
|
likeTrack(t, pool, u.ID, gone.ID)
|
|
markMissing(t, pool, gone.ID)
|
|
|
|
seeds, err := dbq.New(pool).PickTopPlayedTracksForUser(context.Background(), u.ID)
|
|
if err != nil {
|
|
t.Fatalf("pick seeds: %v", err)
|
|
}
|
|
if len(seeds) != 1 || seeds[0] != present.ID {
|
|
t.Fatalf("seeds = %v, want only the present liked track %v", seeds, present.ID)
|
|
}
|
|
}
|
|
|
|
// TestPickTopPlayedTrackForArtistByUser_FallbackSkipsMissing: with no plays,
|
|
// Songs-like seeds from the artist's newest album. When that album's track is
|
|
// missing, the seed comes from the next album rather than the missing file.
|
|
func TestPickTopPlayedTrackForArtistByUser_FallbackSkipsMissing(t *testing.T) {
|
|
pool := newPool(t)
|
|
ctx := context.Background()
|
|
u := seedUser(t, pool, "songslikemissing")
|
|
older := seedTrack(t, pool, "Older", "Songs Like Artist")
|
|
newerAlbum := seedAlbumForArtist(t, pool, "Newer Album", older.ArtistID)
|
|
newer := seedTrackForArtist(t, pool, "Newer", newerAlbum, older.ArtistID)
|
|
if _, err := pool.Exec(ctx, `UPDATE albums SET release_date = '2010-01-01' WHERE id = $1`, older.AlbumID); err != nil {
|
|
t.Fatalf("date older album: %v", err)
|
|
}
|
|
if _, err := pool.Exec(ctx, `UPDATE albums SET release_date = '2020-01-01' WHERE id = $1`, newerAlbum); err != nil {
|
|
t.Fatalf("date newer album: %v", err)
|
|
}
|
|
|
|
q := dbq.New(pool)
|
|
args := dbq.PickTopPlayedTrackForArtistByUserParams{UserID: u.ID, ArtistID: older.ArtistID}
|
|
got, err := q.PickTopPlayedTrackForArtistByUser(ctx, args)
|
|
if err != nil {
|
|
t.Fatalf("pick seed: %v", err)
|
|
}
|
|
if got != newer.ID {
|
|
t.Fatalf("before marking: seed = %v, want the newest album's track %v", got, newer.ID)
|
|
}
|
|
|
|
markMissing(t, pool, newer.ID)
|
|
got, err = q.PickTopPlayedTrackForArtistByUser(ctx, args)
|
|
if err != nil {
|
|
t.Fatalf("pick seed: %v", err)
|
|
}
|
|
if got != older.ID {
|
|
t.Fatalf("after marking: seed = %v, want the present older track %v", got, older.ID)
|
|
}
|
|
}
|