fix(worker): resolve MB to the original edition + loosen duration gate
Root cause of albums re-downloading forever despite completing (Linkin Park "Hybrid Theory"): the MB resolver read the tracklist from an arbitrary releases[0], often a later reissue/deluxe. HT resolved to a 2023 13-track reissue (~52 min); a complete 2000 12-track download (~38 min) then failed _download_problem's duration gate (2267s < 2877s×0.85) and fell through peer after peer, never importing. - _pick_release: choose the ORIGINAL standard edition (Official, earliest date) instead of releases[0], so completeness/duration are judged against the edition sources actually deliver. - _DURATION_MIN_RATIO 0.85 -> 0.65: a source legitimately delivering a shorter edition than MB's release shouldn't be rejected; only genuinely truncated/preview downloads (a fraction of expected runtime) should be. Together with the est-time peer ranking, this stops the download→reject→re-download loop. 334 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import musicbrainzngs
|
||||
import pytest
|
||||
|
||||
from lyra_worker._musicbrainz import _best_release_group, _with_retry
|
||||
from lyra_worker._musicbrainz import _best_release_group, _pick_release, _with_retry
|
||||
|
||||
# Offline unit tests for the pure release-group selection logic. The live resolve()
|
||||
# path (network) is covered by test_musicbrainz_live.py.
|
||||
@@ -68,6 +68,30 @@ def test_prefers_credited_artist_over_same_titled_other_artist_album():
|
||||
# --- _with_retry: transient MusicBrainz failures (SSL EOF, 503 rate-limit) ---
|
||||
|
||||
|
||||
def test_pick_release_prefers_original_official_over_later_reissue():
|
||||
# Real "Hybrid Theory" bug: MB's arbitrary releases[0] was a 2023 13-track reissue; the 2000
|
||||
# original is what sources deliver, so completeness checks must reference it.
|
||||
releases = [
|
||||
{"id": "reissue", "status": "Official", "date": "2023-06-01"},
|
||||
{"id": "original", "status": "Official", "date": "2000-10-24"},
|
||||
{"id": "deluxe", "status": "Official", "date": "2020-10-09"},
|
||||
]
|
||||
assert _pick_release(releases)["id"] == "original"
|
||||
|
||||
|
||||
def test_pick_release_skips_non_official_and_undated():
|
||||
releases = [
|
||||
{"id": "promo", "status": "Promotion", "date": "1999-01-01"}, # earliest but not official
|
||||
{"id": "undated", "status": "Official", "date": ""},
|
||||
{"id": "official", "status": "Official", "date": "2001-03-03"},
|
||||
]
|
||||
assert _pick_release(releases)["id"] == "official"
|
||||
|
||||
|
||||
def test_pick_release_empty_is_none():
|
||||
assert _pick_release([]) is None
|
||||
|
||||
|
||||
def test_retry_returns_value_without_backoff_when_first_call_succeeds():
|
||||
sleeps: list[float] = []
|
||||
calls = {"n": 0}
|
||||
|
||||
Reference in New Issue
Block a user