test(recommendation): check LoadCandidates errors in new contextual tests
Code review caught four tests using `got, _` to discard load errors. A DB failure would have surfaced as a misleading "wrong score" assertion rather than a clear "load failed" message. Match the t.Fatalf pattern used by the other LoadCandidates tests in this file. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -296,7 +296,10 @@ func TestLoadCandidates_MultipleMatchingLikes_TakesMax(t *testing.T) {
|
||||
})
|
||||
|
||||
current := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
got, _ := LoadCandidates(context.Background(), f.q, f.user, f.tracks[0].ID, 1, current)
|
||||
got, err := LoadCandidates(context.Background(), f.q, f.user, f.tracks[0].ID, 1, current)
|
||||
if err != nil {
|
||||
t.Fatalf("load: %v", err)
|
||||
}
|
||||
for _, c := range got {
|
||||
if c.Track.ID == target.ID && c.Inputs.ContextualMatchScore < 0.99 {
|
||||
t.Errorf("target = %v, want ~1.0 (max)", c.Inputs.ContextualMatchScore)
|
||||
@@ -315,7 +318,10 @@ func TestLoadCandidates_SoftDeletedLikes_Ignored(t *testing.T) {
|
||||
}
|
||||
|
||||
current := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
got, _ := LoadCandidates(context.Background(), f.q, f.user, f.tracks[0].ID, 1, current)
|
||||
got, err := LoadCandidates(context.Background(), f.q, f.user, f.tracks[0].ID, 1, current)
|
||||
if err != nil {
|
||||
t.Fatalf("load: %v", err)
|
||||
}
|
||||
for _, c := range got {
|
||||
if c.Inputs.ContextualMatchScore != 0 {
|
||||
t.Errorf("soft-deleted track %s ContextualMatchScore = %v", c.Track.Title, c.Inputs.ContextualMatchScore)
|
||||
@@ -331,7 +337,10 @@ func TestLoadCandidates_OnlySeedLikes_ScoresZero(t *testing.T) {
|
||||
})
|
||||
|
||||
current := SessionVector{Artists: []string{"a1"}, Tags: map[string]int{"rock": 1}}
|
||||
got, _ := LoadCandidates(context.Background(), f.q, f.user, f.tracks[0].ID, 1, current)
|
||||
got, err := LoadCandidates(context.Background(), f.q, f.user, f.tracks[0].ID, 1, current)
|
||||
if err != nil {
|
||||
t.Fatalf("load: %v", err)
|
||||
}
|
||||
for _, c := range got {
|
||||
if c.Inputs.ContextualMatchScore != 0 {
|
||||
t.Errorf("seed-only track %s ContextualMatchScore = %v", c.Track.Title, c.Inputs.ContextualMatchScore)
|
||||
@@ -346,7 +355,10 @@ func TestLoadCandidates_CurrentSeed_ScoresZero(t *testing.T) {
|
||||
helperInsertContextualLike(t, f, target.ID, likeVec)
|
||||
|
||||
currentSeed := SessionVector{Seed: true}
|
||||
got, _ := LoadCandidates(context.Background(), f.q, f.user, f.tracks[0].ID, 1, currentSeed)
|
||||
got, err := LoadCandidates(context.Background(), f.q, f.user, f.tracks[0].ID, 1, currentSeed)
|
||||
if err != nil {
|
||||
t.Fatalf("load: %v", err)
|
||||
}
|
||||
for _, c := range got {
|
||||
if c.Inputs.ContextualMatchScore != 0 {
|
||||
t.Errorf("seed-current track %s ContextualMatchScore = %v", c.Track.Title, c.Inputs.ContextualMatchScore)
|
||||
|
||||
Reference in New Issue
Block a user