Files
minstrel/internal/playlists/song_copies_test.go
T
bvandeusenandClaude Opus 5.5 fcf5b7e5a8 docs: wanted, dbtest, recommendation and playlists comments say what the code does (#6277)
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>
2026-10-23 12:19:15 -04:00

51 lines
1.6 KiB
Go

package playlists_test
import (
"context"
"testing"
"github.com/jackc/pgx/v5/pgtype"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
"git.fabledsword.com/bvandeusen/minstrel/internal/playlists"
)
// A mix holds a song once and never a held-back video rip: of a single and its
// album cut, the better-ranked copy stays; a rip is left out and the next copy
// of its song takes the place.
func TestOneCopyPerSong_Integration(t *testing.T) {
pool := newPool(t)
ctx := context.Background()
q := dbq.New(pool)
single := seedTrack(t, pool, "copies-single", "copies-artist")
albumCut := seedTrack(t, pool, "copies-album-cut", "copies-artist")
rip := seedTrack(t, pool, "copies-rip", "copies-artist")
clean := seedTrack(t, pool, "copies-clean", "copies-artist")
other := seedTrack(t, pool, "copies-other", "copies-artist")
for _, pair := range [][]pgtype.UUID{{single.ID, albumCut.ID}, {rip.ID, clean.ID}} {
if _, err := q.LinkTracksAsSong(ctx, pair); err != nil {
t.Fatal(err)
}
}
if _, err := pool.Exec(ctx, `UPDATE tracks SET source_verdict = 'suspect' WHERE id = $1`, rip.ID); err != nil {
t.Fatal(err)
}
in := []playlists.RankedCandidate{
{TrackID: single.ID}, {TrackID: rip.ID}, {TrackID: albumCut.ID}, {TrackID: other.ID}, {TrackID: clean.ID},
}
out, err := playlists.OneCopyPerSong(ctx, q, in)
if err != nil {
t.Fatal(err)
}
want := []pgtype.UUID{single.ID, other.ID, clean.ID}
if len(out) != len(want) {
t.Fatalf("got %d tracks, want %d", len(out), len(want))
}
for i, w := range want {
if out[i].TrackID != w {
t.Errorf("position %d = %s, want %s", i, uuidString(out[i].TrackID), uuidString(w))
}
}
}