From eed2785e35191b16e887d967e2c26eeff56572d2 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 19 Jul 2026 19:07:26 -0400 Subject: [PATCH] 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) --- backend/config/config_manager.py | 36 +++++++++++++++++++-- backend/tests/config/test_config_loader.py | 9 ++++++ backend/tests/handler/test_scan_priority.py | 10 ++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/backend/config/config_manager.py b/backend/config/config_manager.py index a336ab6d1..b99b6c22f 100644 --- a/backend/config/config_manager.py +++ b/backend/config/config_manager.py @@ -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") diff --git a/backend/tests/config/test_config_loader.py b/backend/tests/config/test_config_loader.py index fd221bf78..0048f94d5 100644 --- a/backend/tests/config/test_config_loader.py +++ b/backend/tests/config/test_config_loader.py @@ -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( diff --git a/backend/tests/handler/test_scan_priority.py b/backend/tests/handler/test_scan_priority.py index 3472e5a2c..81e9d391a 100644 --- a/backend/tests/handler/test_scan_priority.py +++ b/backend/tests/handler/test_scan_priority.py @@ -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]