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:
@@ -7,152 +7,73 @@ import (
|
||||
|
||||
func approxEq(a, b float64) bool { return math.Abs(a-b) < 1e-9 }
|
||||
|
||||
func TestSimilarity_IdenticalVectors_Returns1(t *testing.T) {
|
||||
v := SessionVector{
|
||||
Artists: []string{"a1", "a2"},
|
||||
Tags: map[string]int{"rock": 2, "indie": 1},
|
||||
}
|
||||
got := Similarity(v, v, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 1.0) {
|
||||
t.Errorf("Similarity(v,v) = %v, want 1.0", got)
|
||||
// Similarity is the set overlap (Jaccard) of tags weighted 0.7 plus that of
|
||||
// artists weighted 0.3. Tag counts collapse to a set, an axis empty on either
|
||||
// side contributes nothing, empty vectors give 0 rather than NaN, and a seed
|
||||
// vector (too short a session to say anything) matches nothing.
|
||||
func TestSimilarity(t *testing.T) {
|
||||
v := SessionVector{Artists: []string{"a1", "a2"}, Tags: map[string]int{"rock": 2, "indie": 1}}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
a, b SessionVector
|
||||
want float64
|
||||
}{
|
||||
{"identical", v, v, 1.0},
|
||||
{"disjoint",
|
||||
SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}},
|
||||
SessionVector{Artists: []string{"a2"}, Tags: map[string]int{"jazz": 1}}, 0},
|
||||
{"tags only shared",
|
||||
SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}},
|
||||
SessionVector{Artists: []string{"a2"}, Tags: map[string]int{"rock": 5}}, 0.7},
|
||||
{"artists only shared",
|
||||
SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}},
|
||||
SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"jazz": 1}}, 0.3},
|
||||
{"partial tag overlap",
|
||||
SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1, "indie": 1}},
|
||||
SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1, "jazz": 1}}, 0.7*(1.0/3.0) + 0.3},
|
||||
{"counts collapse to a set",
|
||||
SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 2, "indie": 1}},
|
||||
SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 5, "indie": 3}}, 1.0},
|
||||
{"each side has a different axis",
|
||||
SessionVector{Tags: map[string]int{"rock": 1}}, SessionVector{Artists: []string{"a1"}}, 0},
|
||||
{"both empty", SessionVector{}, SessionVector{}, 0},
|
||||
{"a seed on the right", v, SessionVector{Seed: true, Artists: v.Artists, Tags: v.Tags}, 0},
|
||||
{"a seed on the left", SessionVector{Seed: true, Artists: v.Artists, Tags: v.Tags}, v, 0},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := Similarity(tc.a, tc.b, DefaultSimilarityWeights)
|
||||
if math.IsNaN(got) || !approxEq(got, tc.want) {
|
||||
t.Errorf("Similarity = %v, want %v", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimilarity_FullyDisjoint_Returns0(t *testing.T) {
|
||||
a := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
b := SessionVector{Artists: []string{"a2"}, Tags: map[string]int{"jazz": 1}}
|
||||
got := Similarity(a, b, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 0.0) {
|
||||
t.Errorf("disjoint = %v, want 0.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimilarity_TagsOnlyShared_AppliesTagsWeight(t *testing.T) {
|
||||
a := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
b := SessionVector{Artists: []string{"a2"}, Tags: map[string]int{"rock": 5}}
|
||||
got := Similarity(a, b, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 0.7) {
|
||||
t.Errorf("tags-only = %v, want 0.7", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimilarity_ArtistsOnlyShared_AppliesArtistsWeight(t *testing.T) {
|
||||
a := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
b := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"jazz": 1}}
|
||||
got := Similarity(a, b, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 0.3) {
|
||||
t.Errorf("artists-only = %v, want 0.3", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimilarity_EitherSeed_Returns0(t *testing.T) {
|
||||
v := SessionVector{Artists: []string{"a"}, Tags: map[string]int{"rock": 1}}
|
||||
seed := SessionVector{Seed: true, Artists: []string{"a"}, Tags: map[string]int{"rock": 1}}
|
||||
if got := Similarity(v, seed, DefaultSimilarityWeights); !approxEq(got, 0.0) {
|
||||
t.Errorf("v vs seed = %v, want 0.0", got)
|
||||
}
|
||||
if got := Similarity(seed, v, DefaultSimilarityWeights); !approxEq(got, 0.0) {
|
||||
t.Errorf("seed vs v = %v, want 0.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimilarity_BothEmpty_Returns0NotNaN(t *testing.T) {
|
||||
a := SessionVector{}
|
||||
b := SessionVector{}
|
||||
got := Similarity(a, b, DefaultSimilarityWeights)
|
||||
if math.IsNaN(got) || !approxEq(got, 0.0) {
|
||||
t.Errorf("empty = %v, want 0.0 (not NaN)", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimilarity_OneAxisEmptyOneSide_AxisContributesZero(t *testing.T) {
|
||||
a := SessionVector{Tags: map[string]int{"rock": 1}}
|
||||
b := SessionVector{Artists: []string{"a1"}}
|
||||
got := Similarity(a, b, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 0.0) {
|
||||
t.Errorf("one-axis-each = %v, want 0.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimilarity_PartialTagsOverlap(t *testing.T) {
|
||||
a := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1, "indie": 1}}
|
||||
b := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1, "jazz": 1}}
|
||||
got := Similarity(a, b, DefaultSimilarityWeights)
|
||||
want := 0.7*(1.0/3.0) + 0.3*1.0
|
||||
if !approxEq(got, want) {
|
||||
t.Errorf("partial = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimilarity_BagOfCountsCollapsesToSet(t *testing.T) {
|
||||
a := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 2, "indie": 1}}
|
||||
b := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 5, "indie": 3}}
|
||||
got := Similarity(a, b, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 1.0) {
|
||||
t.Errorf("set-collapse = %v, want 1.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextualMatchScore_NoLikes_Returns0(t *testing.T) {
|
||||
current := SessionVector{Artists: []string{"a"}, Tags: map[string]int{"rock": 1}}
|
||||
got := ContextualMatchScore(current, nil, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 0.0) {
|
||||
t.Errorf("no likes = %v, want 0.0", got)
|
||||
}
|
||||
got = ContextualMatchScore(current, []SessionVector{}, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 0.0) {
|
||||
t.Errorf("empty likes = %v, want 0.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextualMatchScore_CurrentSeed_Returns0(t *testing.T) {
|
||||
current := SessionVector{Seed: true}
|
||||
likes := []SessionVector{
|
||||
{Artists: []string{"a"}, Tags: map[string]int{"rock": 1}},
|
||||
}
|
||||
got := ContextualMatchScore(current, likes, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 0.0) {
|
||||
t.Errorf("current seed = %v, want 0.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextualMatchScore_AllLikesSeed_Returns0(t *testing.T) {
|
||||
current := SessionVector{Artists: []string{"a"}, Tags: map[string]int{"rock": 1}}
|
||||
likes := []SessionVector{
|
||||
{Seed: true, Artists: []string{"a"}, Tags: map[string]int{"rock": 1}},
|
||||
{Seed: true, Artists: []string{"a"}, Tags: map[string]int{"rock": 1}},
|
||||
}
|
||||
got := ContextualMatchScore(current, likes, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 0.0) {
|
||||
t.Errorf("all-seed likes = %v, want 0.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextualMatchScore_TakesMax(t *testing.T) {
|
||||
// Three likes: full match, partial match, mismatch. Expect full match (1.0).
|
||||
// A track's contextual match is its best similarity to the sessions in which
|
||||
// it was liked, ignoring likes made in a seed session; a current seed session
|
||||
// matches nothing.
|
||||
func TestContextualMatchScore(t *testing.T) {
|
||||
current := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
// Three likes covering 1.0 (full match), 0.7 (tags-only match), 0.0 (mismatch).
|
||||
likes := []SessionVector{
|
||||
{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}},
|
||||
{Artists: []string{"a2"}, Tags: map[string]int{"rock": 1}},
|
||||
{Artists: []string{"a99"}, Tags: map[string]int{"jazz": 1}},
|
||||
}
|
||||
got := ContextualMatchScore(current, likes, DefaultSimilarityWeights)
|
||||
if !approxEq(got, 1.0) {
|
||||
t.Errorf("takes-max = %v, want 1.0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextualMatchScore_FiltersSeedThenMaxes(t *testing.T) {
|
||||
// One Seed=true match (would be 1.0 if not filtered) + one partial match.
|
||||
current := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
likes := []SessionVector{
|
||||
{Seed: true, Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}},
|
||||
{Artists: []string{"a2"}, Tags: map[string]int{"rock": 1}},
|
||||
}
|
||||
got := ContextualMatchScore(current, likes, DefaultSimilarityWeights)
|
||||
// Seed=true filtered out → only partial match counts → 0.7
|
||||
if !approxEq(got, 0.7) {
|
||||
t.Errorf("filter-then-max = %v, want 0.7", got)
|
||||
full := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
tagsOnly := SessionVector{Artists: []string{"a2"}, Tags: map[string]int{"rock": 1}}
|
||||
none := SessionVector{Artists: []string{"a99"}, Tags: map[string]int{"jazz": 1}}
|
||||
seedFull := SessionVector{Seed: true, Artists: full.Artists, Tags: full.Tags}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
current SessionVector
|
||||
likes []SessionVector
|
||||
want float64
|
||||
}{
|
||||
{"no likes", current, nil, 0},
|
||||
{"the best like counts", current, []SessionVector{full, tagsOnly, none}, 1.0},
|
||||
{"likes in seed sessions are ignored", current, []SessionVector{seedFull, seedFull}, 0},
|
||||
{"seed likes are dropped before the max", current, []SessionVector{seedFull, tagsOnly}, 0.7},
|
||||
{"a seed session matches nothing", SessionVector{Seed: true}, []SessionVector{full}, 0},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := ContextualMatchScore(tc.current, tc.likes, DefaultSimilarityWeights); !approxEq(got, tc.want) {
|
||||
t.Errorf("ContextualMatchScore = %v, want %v", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user