Files
romm/backend/tests/tasks/test_task_func_paths.py
T
Sam DornanandClaude Opus 5.5 d4f10ac018 feat(cd-audio): extract CD audio in the background after a scan
A new scan.cd_audio.extract setting (off by default, toggle in the v2 Scan
settings) queues one job on the low-priority queue when a scan completes.
It covers the ROMs of the scanned platforms (or the named ROMs of a
scoped scan) that have a .cue, .gdi or .chd game file. For each one the
job runs the same probe as the Soundtrack subtab and extracts only when
tracks are missing, so later scans cost a layout read per disc.

- The job depends on the scan job that queued it, so it only starts once
  the scan is done, and it stops early if another scan starts: moving a
  lone CHD into its folder mid-scan would get it marked missing. That
  scan queues a fresh job when it ends.
- A failing disc is logged and the rest carry on. A missing flac skips
  the whole job with one warning; a missing libchdr skips CHDs only.
- The setting's description and config.example.yml warn that a lone .chd
  is moved into a folder of its own.
- The manual Extract CD audio button is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HSvProqsBrUknEAs4nNKDs
2026-09-28 22:18:16 +00:00

41 lines
1.3 KiB
Python

import os
import subprocess
import sys
from pathlib import Path
import pytest
BACKEND_ROOT = Path(__file__).resolve().parents[2]
# The only callables a job payload names. Everything else runs through
# run_task_by_name, which resolves it from the registry.
JOB_FUNC_PATHS = (
"tasks.tasks.run_task_by_name",
"endpoints.sockets.scan.scan_platforms",
"tasks.registry.enqueue_scheduled_scan",
"tasks.extract_cd_audio.extract_cd_audio_after_scan",
)
@pytest.mark.parametrize("func", JOB_FUNC_PATHS)
def test_task_func_resolves_in_a_fresh_interpreter(func):
"""The RQ worker resolves a job by importing its func path into a process
where that module is the first application module imported. An import cycle
that stays hidden in the web process breaks the job there."""
result = subprocess.run(
[
sys.executable,
"-c",
"import sys\n"
"from rq.utils import import_attribute\n"
"assert callable(import_attribute(sys.argv[1]))\n",
func,
],
cwd=BACKEND_ROOT,
env={**os.environ, "PYTHONPATH": str(BACKEND_ROOT)},
capture_output=True,
text=True,
)
assert result.returncode == 0, f"{func} is not importable by RQ:\n{result.stderr}"