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