feat(discovery): derive core-album suggestions for surfaced artists

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-12 00:13:40 +02:00
parent ccf3fb59ab
commit 0338d8e119
4 changed files with 108 additions and 1 deletions
+45
View File
@@ -0,0 +1,45 @@
from lyra_worker.adapters.fakes import FakeMbBrowser, FakeSimilaritySource
from lyra_worker.browser import ReleaseGroupInfo
from lyra_worker.discovery import DiscoveryConfig, run_discovery
from lyra_worker.similarity.base import SimilarArtist
from tests.conftest import insert_monitored_release, insert_watched_artist
def _album_rows(conn):
with conn.cursor() as cur:
cur.execute('SELECT "artistMbid", "rgMbid", album, "primaryType" '
'FROM "DiscoverySuggestion" WHERE kind = \'album\' ORDER BY album')
return cur.fetchall()
def test_derives_most_recent_core_album_for_surfaced_artist(conn):
insert_watched_artist(conn, mbid="s1", name="Seed")
src = FakeSimilaritySource(similar={"s1": [SimilarArtist("c1", "Cand", 0.9)]})
browser = FakeMbBrowser(releases={"c1": [
ReleaseGroupInfo("rg-old", "Debut", "Album", (), "2001-01-01"),
ReleaseGroupInfo("rg-new", "Latest", "Album", (), "2020-01-01"),
ReleaseGroupInfo("rg-live", "At The Hall", "Album", ("Live",), "2021-01-01"),
]})
result = run_discovery(conn, [src], browser, DiscoveryConfig(albums_per_artist=1))
assert result.albums == 1
assert _album_rows(conn) == [("c1", "rg-new", "Latest", "Album")] # newest core, live excluded
def test_album_skips_release_groups_already_in_library(conn):
insert_watched_artist(conn, mbid="s1", name="Seed")
insert_monitored_release(conn, artist_mbid="c1", rg_mbid="rg-have", album="Owned")
src = FakeSimilaritySource(similar={"s1": [SimilarArtist("c1", "Cand", 0.9)]})
browser = FakeMbBrowser(releases={"c1": [
ReleaseGroupInfo("rg-have", "Owned", "Album", (), "2019-01-01"),
ReleaseGroupInfo("rg-fresh", "Fresh", "Album", (), "2018-01-01"),
]})
run_discovery(conn, [src], browser, DiscoveryConfig(albums_per_artist=1))
assert _album_rows(conn) == [("c1", "rg-fresh", "Fresh", "Album")] # owned rg excluded
def test_albums_per_artist_zero_derives_none(conn):
insert_watched_artist(conn, mbid="s1", name="Seed")
src = FakeSimilaritySource(similar={"s1": [SimilarArtist("c1", "Cand", 0.9)]})
browser = FakeMbBrowser(releases={"c1": [ReleaseGroupInfo("rg1", "A", "Album", (), "2020")]})
assert run_discovery(conn, [src], browser, DiscoveryConfig(albums_per_artist=0)).albums == 0
assert _album_rows(conn) == []