fix(taste): a play still open, or closed unheard, no longer grades as a skip (#8127)

The taste build graded every play in its window, and a play with no
completion ratio and no played duration came out as completion 0: a song
playing during the rebuild, or a row the sweeper closed without hearing
how it ended, counted as abandoned and pushed its artist and tags
negative. Only plays whose completion is known are graded now; an open
play is graded once it ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 11:59:34 -05:00
co-authored by Claude Opus 5.5
parent 698ff23105
commit e2172e925e
3 changed files with 40 additions and 2 deletions
+32
View File
@@ -149,6 +149,38 @@ func TestBuildTasteProfile_PositiveVsNegative(t *testing.T) {
}
}
// A song playing now, and a play the sweeper closed without hearing how it
// ended, have no completion. Neither reads as a skip: the artist gets no
// negative weight from them.
func TestBuildTasteProfile_APlayWithNoKnownCompletionIsNotASkip(t *testing.T) {
pool := dbtest.Pool(t)
now := time.Now().UTC()
u := seedUser(t, pool, "tp-open")
playing := seedArtist(t, pool, "Playing Now")
track := seedTrack(t, pool, playing.ID, "Folk")
for i, ended := range []bool{false, true} {
started := now.Add(-time.Duration(i+1) * time.Hour)
_, err := pool.Exec(context.Background(), `
WITH s AS (
INSERT INTO play_sessions (user_id, started_at, last_event_at)
VALUES ($1, $3, $3) RETURNING id
)
INSERT INTO play_events (user_id, track_id, session_id, started_at, ended_at)
SELECT $1, $2, s.id, $3, CASE WHEN $4 THEN now() END FROM s
`, u.ID, track.ID, started, ended)
if err != nil {
t.Fatalf("seed play (ended=%v): %v", ended, err)
}
}
if err := BuildTasteProfile(context.Background(), pool, discardLogger(), u.ID, DefaultConfig()); err != nil {
t.Fatalf("build: %v", err)
}
if w, ok := artistWeight(t, pool, u.ID, playing.ID); ok && w < 0 {
t.Errorf("artist weight = %.3f, want no negative weight from plays of unknown completion", w)
}
}
// TestBuildTasteProfile_AggregationProtectsArtist: one early-skip among many
// completed plays must NOT make a loved artist net-negative (the user's
// concern that a track-dislike shouldn't tank the artist).