927266d042
The worker MB resolver picked release groups on (title_ratio, is_album)
and never scored the artist — even though resolve() knows the followed
artist. For a generic title, same-titled release groups by *different*
artists tie on title, and the is_album tiebreak (added in 06e7f91 for
Off the Wall) then actively preferred a foreign Album over the correct
release. Concretely, following Lake Street Dive's "Fun Machine" EP
resolved to an unrelated band "Bastards of Melody"'s same-titled Album,
which then propagated as the downloaded/imported artist.
Make credited-artist similarity the primary sort key, above title and
above is_album. It's a soft signal, never a hard filter, so credited-
name variations (feat., punctuation) still resolve; is_album now only
breaks ties within the same artist+title, preserving the Off the Wall
fix. Verified live: resolve("Lake Street Dive", "Fun Machine") now
returns the 6-track LSD EP.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
63 lines
2.6 KiB
Python
63 lines
2.6 KiB
Python
from lyra_worker._musicbrainz import _best_release_group
|
|
|
|
# Offline unit tests for the pure release-group selection logic. The live resolve()
|
|
# path (network) is covered by test_musicbrainz_live.py.
|
|
|
|
|
|
def _rg(title, primary_type, artist=""):
|
|
g = {"id": title.lower(), "title": title, "primary-type": primary_type}
|
|
if artist:
|
|
g["artist-credit"] = [{"artist": {"name": artist, "id": artist.lower()}}]
|
|
return g
|
|
|
|
|
|
def test_prefers_album_over_same_titled_single():
|
|
# Real-world "Off the Wall" bug: MusicBrainz returns the Single release-group
|
|
# first, tied on title with the Album. We must pick the Album so a 10-track
|
|
# download isn't tagged from the 2-track single's tracklist.
|
|
groups = [
|
|
_rg("Off the Wall", "Single", "Michael Jackson"),
|
|
_rg("Off the Wall", "Album", "Michael Jackson"),
|
|
]
|
|
assert _best_release_group("Michael Jackson", "Off the Wall", groups)["primary-type"] == "Album"
|
|
|
|
|
|
def test_album_preference_is_order_independent():
|
|
groups = [
|
|
_rg("Off the Wall", "Album", "Michael Jackson"),
|
|
_rg("Off the Wall", "Single", "Michael Jackson"),
|
|
]
|
|
assert _best_release_group("Michael Jackson", "Off the Wall", groups)["primary-type"] == "Album"
|
|
|
|
|
|
def test_closer_title_still_wins_over_album_type():
|
|
# Title similarity dominates the album-type preference (for a single artist).
|
|
groups = [
|
|
_rg("Continuum", "Single", "John Mayer"),
|
|
_rg("Continuum Deluxe Reissue", "Album", "John Mayer"),
|
|
]
|
|
assert _best_release_group("John Mayer", "Continuum", groups)["title"] == "Continuum"
|
|
|
|
|
|
def test_below_threshold_returns_none():
|
|
groups = [_rg("Something Totally Different", "Album", "Michael Jackson")]
|
|
assert _best_release_group("Michael Jackson", "Off the Wall", groups) is None
|
|
|
|
|
|
def test_empty_groups_returns_none():
|
|
assert _best_release_group("Michael Jackson", "Off the Wall", []) is None
|
|
|
|
|
|
def test_prefers_credited_artist_over_same_titled_other_artist_album():
|
|
# Real-world "Fun Machine" bug: Lake Street Dive's EP is what we followed, but two
|
|
# unrelated bands also have a release group literally titled "Fun Machine" as an Album.
|
|
# All three tie on title (1.0), so the old is_album tiebreak wrongly grabbed a foreign
|
|
# Album. The followed artist must win over title-tied albums by other artists.
|
|
groups = [
|
|
_rg("Fun Machine", "EP", "Lake Street Dive"),
|
|
_rg("Fun Machine", "Album", "Bastards of Melody"),
|
|
_rg("Fun Machine", "Album", "Teledildonics 5000"),
|
|
]
|
|
best = _best_release_group("Lake Street Dive", "Fun Machine", groups)
|
|
assert best["artist-credit"][0]["artist"]["name"] == "Lake Street Dive"
|