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
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:
@@ -21,66 +21,42 @@ func fixedRNG(v float64) func() float64 {
|
||||
return func() float64 { return v }
|
||||
}
|
||||
|
||||
func TestScore_BaseCase_NeverPlayed_NoJitter(t *testing.T) {
|
||||
in := ScoringInputs{}
|
||||
// Score is base + like boost + recency + context + similarity − skip
|
||||
// penalty, plus jitter, which a fixed RNG of 0.5 zeroes. With the default
|
||||
// weights a never-played, unliked track scores 2.0 (base 1.0, recency 1.0,
|
||||
// since never played counts as long ago), and each case moves one term.
|
||||
func TestScore(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
got := Score(in, defaultWeights(), now, fixedRNG(0.5))
|
||||
// rng=0.5 -> jitter contribution = (0.5*2 - 1) * 0.1 = 0
|
||||
// expected = 1.0 + 0 (not liked) + 1.0 (never played) - 0 + 0 = 2.0
|
||||
want := 2.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_LikeBoost(t *testing.T) {
|
||||
notLiked := Score(ScoringInputs{}, defaultWeights(), time.Now(), fixedRNG(0.5))
|
||||
liked := Score(ScoringInputs{IsGeneralLiked: true}, defaultWeights(), time.Now(), fixedRNG(0.5))
|
||||
if math.Abs(liked-notLiked-2.0) > 1e-9 {
|
||||
t.Errorf("delta = %v, want 2.0 (LikeBoost)", liked-notLiked)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_RecencyRamp_15Days(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
played := now.Add(-15 * 24 * time.Hour)
|
||||
got := Score(ScoringInputs{LastPlayedAt: &played}, defaultWeights(), now, fixedRNG(0.5))
|
||||
// recency = 0.5 -> contributes 0.5 * 1.0 = 0.5; expected = 1.0 + 0 + 0.5 - 0 + 0 = 1.5
|
||||
want := 1.5
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_RecencyRamp_60DaysCapsAt1(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
played := now.Add(-60 * 24 * time.Hour)
|
||||
got := Score(ScoringInputs{LastPlayedAt: &played}, defaultWeights(), now, fixedRNG(0.5))
|
||||
want := 2.0 // base + capped recency (1.0)
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_SkipRatio(t *testing.T) {
|
||||
// 4 plays, 2 skips -> ratio 0.5 -> -0.5 * SkipPenalty = -0.5
|
||||
in := ScoringInputs{PlayCount: 4, SkipCount: 2}
|
||||
got := Score(in, defaultWeights(), time.Now(), fixedRNG(0.5))
|
||||
// recency = 1.0 (never played by virtue of LastPlayedAt being nil even though PlayCount > 0;
|
||||
// for this test we rely on the recencyDecay treating nil as max). Adjust: the tests above
|
||||
// explicitly use nil for LastPlayedAt unless set. So: 1.0 + 1.0 - 0.5 = 1.5.
|
||||
want := 1.5
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_ColdStartSkip_ZeroPlaysZeroSkips(t *testing.T) {
|
||||
in := ScoringInputs{PlayCount: 0, SkipCount: 0}
|
||||
got := Score(in, defaultWeights(), time.Now(), fixedRNG(0.5))
|
||||
want := 2.0 // base + recency, no skip penalty
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
daysAgo := func(d int) *time.Time { p := now.Add(-time.Duration(d) * 24 * time.Hour); return &p }
|
||||
withContext := func(w ScoringWeights) ScoringWeights { w.ContextWeight = 2.0; return w }
|
||||
withSimilarity := func(w ScoringWeights) ScoringWeights { w.SimilarityWeight = 2.0; return w }
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
in ScoringInputs
|
||||
weights func(ScoringWeights) ScoringWeights
|
||||
want float64
|
||||
}{
|
||||
{"never played", ScoringInputs{}, nil, 2.0},
|
||||
{"liked", ScoringInputs{IsGeneralLiked: true}, nil, 4.0},
|
||||
{"played 15 days ago, recency halved", ScoringInputs{LastPlayedAt: daysAgo(15)}, nil, 1.5},
|
||||
{"played 60 days ago, recency capped at 1", ScoringInputs{LastPlayedAt: daysAgo(60)}, nil, 2.0},
|
||||
{"half the plays skipped", ScoringInputs{PlayCount: 4, SkipCount: 2}, nil, 1.5},
|
||||
{"full context match at weight 2", ScoringInputs{ContextualMatchScore: 1.0}, withContext, 4.0},
|
||||
{"half context match at weight 2", ScoringInputs{ContextualMatchScore: 0.5}, withContext, 3.0},
|
||||
{"no context match adds nothing", ScoringInputs{}, withContext, 2.0},
|
||||
{"full similarity at weight 2", ScoringInputs{SimilarityScore: 1.0}, withSimilarity, 4.0},
|
||||
{"half similarity at weight 2", ScoringInputs{SimilarityScore: 0.5}, withSimilarity, 3.0},
|
||||
{"no similarity adds nothing", ScoringInputs{}, withSimilarity, 2.0},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
if tc.weights != nil {
|
||||
w = tc.weights(w)
|
||||
}
|
||||
if got := Score(tc.in, w, now, fixedRNG(0.5)); math.Abs(got-tc.want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,23 +74,6 @@ func TestScore_JitterBounds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_Determinism(t *testing.T) {
|
||||
in := ScoringInputs{IsGeneralLiked: true, PlayCount: 10, SkipCount: 3}
|
||||
w := defaultWeights()
|
||||
now := time.Now().UTC()
|
||||
a := Score(in, w, now, fixedRNG(0.7))
|
||||
b := Score(in, w, now, fixedRNG(0.7))
|
||||
if a != b {
|
||||
t.Errorf("non-deterministic with fixed RNG: %v vs %v", a, b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecencyDecay_NilIsOne(t *testing.T) {
|
||||
if got := recencyDecay(nil, time.Now()); got != 1.0 {
|
||||
t.Errorf("recencyDecay(nil) = %v, want 1.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecencyDecay_Clamping(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
cases := []struct {
|
||||
@@ -136,83 +95,3 @@ func TestRecencyDecay_Clamping(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkipRatio_ZeroPlays_IsZero(t *testing.T) {
|
||||
if got := skipRatio(0, 0); got != 0.0 {
|
||||
t.Errorf("skipRatio(0,0) = %v, want 0.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkipRatio_Half(t *testing.T) {
|
||||
if got := skipRatio(4, 2); got != 0.5 {
|
||||
t.Errorf("skipRatio(4,2) = %v, want 0.5", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_ContextualMatch_PerfectMatchAtWeight2(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
w.ContextWeight = 2.0
|
||||
in := ScoringInputs{ContextualMatchScore: 1.0}
|
||||
got := Score(in, w, time.Now(), fixedRNG(0.5))
|
||||
// base 1.0 + recency 1.0 (never played) + contextual 2.0 = 4.0
|
||||
want := 4.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_ContextualMatch_HalfMatchAtWeight2(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
w.ContextWeight = 2.0
|
||||
in := ScoringInputs{ContextualMatchScore: 0.5}
|
||||
got := Score(in, w, time.Now(), fixedRNG(0.5))
|
||||
// base 1.0 + recency 1.0 + contextual 1.0 = 3.0
|
||||
want := 3.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_ContextualMatch_ZeroNoEffect(t *testing.T) {
|
||||
wWithCtx := defaultWeights()
|
||||
wWithCtx.ContextWeight = 2.0
|
||||
withCtx := Score(ScoringInputs{ContextualMatchScore: 0}, wWithCtx, time.Now(), fixedRNG(0.5))
|
||||
withoutCtx := Score(ScoringInputs{}, defaultWeights(), time.Now(), fixedRNG(0.5))
|
||||
if math.Abs(withCtx-withoutCtx) > 1e-9 {
|
||||
t.Errorf("score-with-zero-ctx = %v, score-without = %v; should be equal", withCtx, withoutCtx)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_SimilarityScore_PerfectMatchAtWeight2(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
w.SimilarityWeight = 2.0
|
||||
in := ScoringInputs{SimilarityScore: 1.0}
|
||||
got := Score(in, w, time.Now(), fixedRNG(0.5))
|
||||
// base 1.0 + recency 1.0 (never played) + similarity 2.0 = 4.0
|
||||
want := 4.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_SimilarityScore_HalfMatchAtWeight2(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
w.SimilarityWeight = 2.0
|
||||
in := ScoringInputs{SimilarityScore: 0.5}
|
||||
got := Score(in, w, time.Now(), fixedRNG(0.5))
|
||||
// base 1.0 + recency 1.0 + similarity 1.0 = 3.0
|
||||
want := 3.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_SimilarityScore_ZeroNoEffect(t *testing.T) {
|
||||
wWithSim := defaultWeights()
|
||||
wWithSim.SimilarityWeight = 2.0
|
||||
withSim := Score(ScoringInputs{SimilarityScore: 0}, wWithSim, time.Now(), fixedRNG(0.5))
|
||||
withoutSim := Score(ScoringInputs{}, defaultWeights(), time.Now(), fixedRNG(0.5))
|
||||
if math.Abs(withSim-withoutSim) > 1e-9 {
|
||||
t.Errorf("score-with-zero-sim = %v, score-without = %v; should be equal", withSim, withoutSim)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user