feat(scan): warn on unknown sources in artwork priority overrides

Unknown provider slugs in scan.priority.cover/screenshot/manual are
already dropped by the downstream availability filter, so they never
crash a scan, but they silently did nothing. Surface likely typos with
a load-time warning, consistent with scan.media handling. A drift-guard
test keeps VALID_SCAN_PRIORITY_SOURCES in sync with MetadataSource.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-07-19 19:07:26 -04:00
parent 096346a981
commit eed2785e35
3 changed files with 52 additions and 3 deletions

View File

@@ -96,6 +96,27 @@ ARTWORK_PRIORITY_KEYS = {
"manual": "url_manual",
}
# Valid provider slugs for scan.priority.* lists. Mirrors
# handler.scan_handler.MetadataSource, which can't be imported here without a
# circular import; test_config_loader guards against drift.
VALID_SCAN_PRIORITY_SOURCES = frozenset(
{
"igdb",
"moby",
"ss",
"ra",
"launchbox",
"hasheous",
"tgdb",
"sgdb",
"flashpoint",
"hltb",
"gamelist",
"libretro",
"playmatch",
}
)
class EjsControls(TypedDict):
_0: dict[int, EjsControlsButton] # button_number -> EjsControlsButton
@@ -690,11 +711,20 @@ class ConfigManager:
sys.exit(3)
for key, field in ARTWORK_PRIORITY_KEYS.items():
if field in self.config.SCAN_ARTWORK_PRIORITY_OVERRIDES and not isinstance(
self.config.SCAN_ARTWORK_PRIORITY_OVERRIDES[field], list
):
override = self.config.SCAN_ARTWORK_PRIORITY_OVERRIDES.get(field)
if override is None:
continue
if not isinstance(override, list):
log.critical(f"Invalid config.yml: scan.priority.{key} must be a list")
sys.exit(3)
# Unknown sources are dropped downstream; surface likely typos here
# rather than letting the override silently do nothing.
unknown = [s for s in override if s not in VALID_SCAN_PRIORITY_SOURCES]
if unknown:
log.warning(
f"Ignoring unknown values in scan.priority.{key}: {unknown}. "
"Check for typos, or update RomM if these are newer sources."
)
if not isinstance(self.config.SCAN_REGION_PRIORITY, list):
log.critical("Invalid config.yml: scan.priority.region must be a list")

View File

@@ -85,6 +85,15 @@ def test_config_loader():
assert loader.config.GAMELIST_MEDIA_IMAGE == "title_screen"
def test_scan_priority_sources_match_metadata_source_enum():
"""VALID_SCAN_PRIORITY_SOURCES duplicates MetadataSource to avoid a circular
import; guard against the two drifting apart."""
from config.config_manager import VALID_SCAN_PRIORITY_SOURCES
from handler.scan_handler import MetadataSource
assert VALID_SCAN_PRIORITY_SOURCES == {source.value for source in MetadataSource}
def test_empty_config_loader():
loader = ConfigManager(
os.path.join(

View File

@@ -51,6 +51,16 @@ def test_sources_absent_from_priority_are_appended():
assert set(ordered) == set(available)
def test_unknown_override_source_is_ignored_not_fatal():
"""A typo in an override list is dropped, never raising ValueError."""
available = [MetadataSource.IGDB, MetadataSource.SS]
config = _fake_config(url_cover=["sss", "igdb"]) # "sss" is a typo
with patch("handler.scan_handler.cm.get_config", return_value=config):
ordered = get_priority_ordered_metadata_sources(available, "url_cover")
assert ordered == [MetadataSource.IGDB, MetadataSource.SS]
def test_metadata_priority_is_unaffected_by_artwork_overrides():
"""Artwork overrides must never leak into the metadata priority pass."""
available = [MetadataSource.SS, MetadataSource.IGDB]