feat: wire the mutagen tagger into the worker loop

This commit is contained in:
Jonathan
2026-07-10 23:59:28 +02:00
parent d1fcfd544f
commit 1596bab23e
3 changed files with 59 additions and 2 deletions
+49
View File
@@ -0,0 +1,49 @@
import os
from lyra_worker.adapters.youtube import YouTubeAdapter
from lyra_worker.claim import claim_next
from lyra_worker.pipeline import run_pipeline
from lyra_worker.registry import build_tagger
from lyra_worker.types import MBTarget
from tests.conftest import insert_request
from tests.test_youtube_adapter import FakeYtClient
def test_build_tagger_returns_a_tagger():
t = build_tagger()
assert hasattr(t, "tag_album")
def test_download_dir_receives_files_and_tagger_runs(conn, tmp_path):
# A fake YouTube client that actually writes a file into dest, so a real MutagenTagger-shaped
# tagger has something to operate on. Here we use a recording tagger to assert it's invoked
# on the album directory the download wrote to.
written = {}
def fake_download(source_ref, dest, on_progress):
os.makedirs(dest, exist_ok=True)
open(os.path.join(dest, "track.opus"), "wb").close()
written["dir"] = dest
on_progress(1.0)
return {"track_count": 1, "path": dest}
client = FakeYtClient(results=[{"source_ref": "yt1", "title": "Continuum", "artist": "John Mayer", "track_count": 1}])
client.download = fake_download
class RecordingTagger:
def __init__(self):
self.seen = None
def tag_album(self, album_dir, target):
self.seen = album_dir
tagger = RecordingTagger()
job_id = insert_request(conn, artist="John Mayer", album="Continuum")
claim_next(conn)
run_pipeline(conn, job_id, [YouTubeAdapter(client)], tagger=tagger, dest_root=str(tmp_path))
with conn.cursor() as cur:
cur.execute('SELECT state FROM "Job" WHERE id = %s', (job_id,))
assert cur.fetchone()[0] == "imported"
assert tagger.seen == written["dir"] # tagger ran on the exact directory the download wrote to
assert os.path.isdir(tagger.seen)