06e7f91897
MusicBrainz search returns release-groups tied on title similarity in an arbitrary order; `max(groups, key=_ratio)` kept the first, so Michael Jackson's "Off the Wall" resolved to the 2-track *single* release-group (Off the Wall / Get on the Floor) instead of the 10-track album. Because plan_track_names labels files purely by position, that short tracklist got mapped onto the full album — track 2 became "Get on the Floor" instead of "Rock with You", and the real "Off the Wall"/"Get on the Floor" files kept their streamrip names, yielding duplicate titles. Extract selection into a pure `_best_release_group()` that breaks title- similarity ties toward primary-type == "Album". Similarity still dominates; album preference only settles ties. Live-verified: Off the Wall now resolves to the 10-track album with track 2 = "Rock With You". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
37 lines
1.5 KiB
Python
37 lines
1.5 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):
|
|
return {"id": title.lower(), "title": title, "primary-type": primary_type}
|
|
|
|
|
|
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"), _rg("Off the Wall", "Album")]
|
|
assert _best_release_group("Off the Wall", groups)["primary-type"] == "Album"
|
|
|
|
|
|
def test_album_preference_is_order_independent():
|
|
groups = [_rg("Off the Wall", "Album"), _rg("Off the Wall", "Single")]
|
|
assert _best_release_group("Off the Wall", groups)["primary-type"] == "Album"
|
|
|
|
|
|
def test_closer_title_still_wins_over_album_type():
|
|
# Title similarity dominates; the album-type preference only breaks ties.
|
|
groups = [_rg("Continuum", "Single"), _rg("Continuum Deluxe Reissue", "Album")]
|
|
assert _best_release_group("Continuum", groups)["title"] == "Continuum"
|
|
|
|
|
|
def test_below_threshold_returns_none():
|
|
groups = [_rg("Something Totally Different", "Album")]
|
|
assert _best_release_group("Off the Wall", groups) is None
|
|
|
|
|
|
def test_empty_groups_returns_none():
|
|
assert _best_release_group("Off the Wall", []) is None
|