fix: persist all found candidates and guard duplicate adapter names

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-10 18:54:15 +02:00
parent 71c7945da2
commit 7c28eddd47
2 changed files with 41 additions and 5 deletions
+29
View File
@@ -99,3 +99,32 @@ def test_dedupe_skips_already_in_library(conn):
cur.execute('SELECT count(*) FROM "LibraryItem" WHERE artist = %s AND album = %s',
("Radiohead", "In Rainbows"))
assert cur.fetchone()[0] == 1 # not duplicated
def test_below_threshold_candidates_are_persisted_for_diagnosis(conn):
from lyra_worker.adapters.fakes import FakeQobuz
from lyra_worker.types import MBTarget
class WrongAlbumQobuz(FakeQobuz):
def search(self, target):
# returns a candidate for a different album -> scores below the gate
return super().search(MBTarget(artist=target.artist, album="Some Completely Unrelated Title"))
job_id = insert_request(conn, artist="Radiohead", album="In Rainbows")
claim_next(conn)
run_pipeline(conn, job_id, [WrongAlbumQobuz()], dest_root="/tmp/lib")
assert _job_state(conn, job_id)[0] == "needs_attention"
with conn.cursor() as cur:
cur.execute('SELECT count(*) FROM "Candidate" WHERE "jobId" = %s', (job_id,))
assert cur.fetchone()[0] >= 1 # found-but-rejected candidate retained for diagnosis
def test_duplicate_adapter_names_raise(conn):
import pytest
from lyra_worker.adapters.fakes import FakeQobuz
job_id = insert_request(conn, artist="Radiohead", album="In Rainbows")
claim_next(conn)
with pytest.raises(ValueError):
run_pipeline(conn, job_id, [FakeQobuz(), FakeQobuz()], dest_root="/tmp/lib")