d3bec2ee10
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
from lyra_worker.ranker import rank_candidates
|
|
from lyra_worker.types import Candidate, MBTarget, Quality
|
|
|
|
HIRES = Quality(fmt="FLAC", lossless=True, bit_depth=24, sample_rate=96000)
|
|
CD = Quality(fmt="FLAC", lossless=True, bit_depth=16, sample_rate=44100)
|
|
MP3 = Quality(fmt="MP3", lossless=False, bitrate_kbps=320)
|
|
TARGET = MBTarget(artist="Radiohead", album="In Rainbows", track_count=10)
|
|
|
|
_TIERS = {"qobuz": 0, "soulseek": 1, "youtube": 2}
|
|
|
|
|
|
def _cand(source, quality, artist="Radiohead", album="In Rainbows", tracks=10):
|
|
return Candidate(source=source, source_ref=f"{source}:{quality.fmt}",
|
|
matched_artist=artist, matched_album=album,
|
|
quality=quality, track_count=tracks,
|
|
source_tier=_TIERS[source])
|
|
|
|
|
|
def test_returns_empty_for_no_candidates():
|
|
assert rank_candidates(TARGET, []) == []
|
|
|
|
|
|
def test_best_quality_wins_among_correct_matches():
|
|
ranked = rank_candidates(TARGET, [
|
|
_cand("youtube", MP3),
|
|
_cand("qobuz", HIRES),
|
|
_cand("soulseek", CD),
|
|
])
|
|
assert [c.source for c in ranked] == ["qobuz", "soulseek", "youtube"]
|
|
assert all(c.confidence > 0.9 for c in ranked)
|
|
|
|
|
|
def test_confidence_gate_drops_wrong_album_even_if_higher_quality():
|
|
ranked = rank_candidates(TARGET, [
|
|
_cand("qobuz", HIRES, album="OK Computer", tracks=12), # wrong release, hi-res
|
|
_cand("soulseek", CD), # correct, lossless
|
|
])
|
|
assert [c.source for c in ranked] == ["soulseek"]
|
|
|
|
|
|
def test_all_below_threshold_returns_empty():
|
|
ranked = rank_candidates(TARGET, [
|
|
_cand("qobuz", HIRES, artist="Nirvana", album="Nevermind"),
|
|
])
|
|
assert ranked == []
|