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:
@@ -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) == []
|
||||
@@ -0,0 +1,14 @@
|
||||
from lyra_worker.release_filter import is_core_release
|
||||
|
||||
|
||||
def test_core_studio_types_pass():
|
||||
assert is_core_release("Album", ()) is True
|
||||
assert is_core_release("Single", []) is True
|
||||
assert is_core_release("EP", ()) is True
|
||||
|
||||
|
||||
def test_secondary_types_and_non_core_fail():
|
||||
assert is_core_release("Album", ("Live",)) is False
|
||||
assert is_core_release("Album", ("Compilation",)) is False
|
||||
assert is_core_release("Broadcast", ()) is False
|
||||
assert is_core_release("", ()) is False
|
||||
Reference in New Issue
Block a user