mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
* fix(scan): delete screenshots and media a rescan leaves unreferenced A complete rescan keeps the stored artwork, so two kinds of file stayed on disk with nothing pointing at them: - screenshots indexed past a shorter new list, since files are named by position and only the indexes in range were rewritten - media of a type removed from the preferences, since providers record no path for it and stale media was compared over the preferred types only get_rom_screenshots now deletes the indexes past the new list, and remove_stale_media compares every media type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(scan): split scan_rom's merge into named steps scan_rom held seeding the row, following Demozoo links, splicing scene summaries, resetting rematched sources, the scene lock, rehash cleanup, priority merges for fields, tags and artwork, and the SteamGridDB pass in one body. Each step is now its own helper, the SteamGridDB lookup a _RomLookups method, and the providers' answers a dict keyed by source instead of fourteen locals. The Pouet and CSDb link follows share one helper. Behaviour is unchanged. McCabe complexity of scan_rom goes from 68 to 13, and the function from 664 to 215 lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scan): trim remove_stale_media's docstring per Greptile review Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(scan): move the scan vocabulary, lookups and merge into handler/scan scan_handler.py held the scan types and metadata sources, the per-source lookups, the merge of their answers and the orchestration in one 2,000-line module. It now builds on a handler/scan package: - sources.py: ScanType, MetadataSource, the tag constants, RESCAN_RULES, should_consult, stored_match_id and the priority ordering - lookups.py: RomLookups, the LaunchBox and Steam resolvers and get_main_platform_igdb_id - merge.py: the pure steps that merge the sources' answers into a rom's columns scan_handler.py keeps scan_platform, scan_rom, the asset scans and the media downloads. Importers point at the module that now defines each name, and the helpers that crossed a module boundary lost their leading underscore. clear_rehash_misses takes the attempted sources instead of the lookups, so merge does not depend on lookups. Behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ci): import ScanType from handler.scan.sources in the e2e seed script Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scan): harden leftover screenshot cleanup (pr-ready: code-review) List the screenshots folder once, use isdecimal() for the index test, and log rather than raise when a leftover can't be removed. Point three comments at handler/scan instead of scan_handler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(scan): tidy the merge helpers and patch paths (pr-ready: simplify) - fetch_sgdb_rom refetches by stored_id and builds the SGDB name list itself, so the name sources stay private to lookups. - follow_demozoo_link checks the source is enabled; scan_rom loops over Pouët and CSDb. - order_merge_sources holds the one ordering pass, and build_metadata_handlers adds the empty SGDB entry. - Leftover screenshots go through the quiet-delete helper, renamed _discard_file. - Tests patch rom lookups through handler.scan.lookups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scan): never leave a recorded media or screenshot path without its file - remove_stale_media only deletes a file whose owner or source changed when that new owner stores the type again in this pass. A file nothing records is still deleted. - Screenshots past a shorter list are pruned by remove_screenshots_past once the new paths are saved, in both download_rom_resources and update_rom, so a failed cover or manual leaves them in place. - The release-notes schema diff watches scan_handler.py beside scan/sources.py, for ranges that span the move. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
5.5 KiB
Python
140 lines
5.5 KiB
Python
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
from handler import metadata
|
|
from handler.scan.merge import scene_apply_sources
|
|
from handler.scan.sources import (
|
|
MetadataSource,
|
|
get_enabled_metadata_sources,
|
|
get_priority_ordered_metadata_sources,
|
|
)
|
|
|
|
|
|
def _fake_config(**overrides):
|
|
return SimpleNamespace(
|
|
SCAN_METADATA_PRIORITY=["igdb", "moby", "ss"],
|
|
SCAN_ARTWORK_PRIORITY=["igdb", "moby", "ss"],
|
|
SCAN_ARTWORK_PRIORITY_OVERRIDES=overrides,
|
|
)
|
|
|
|
|
|
def test_artwork_field_falls_back_to_shared_priority():
|
|
"""A field with no override uses SCAN_ARTWORK_PRIORITY."""
|
|
available = [MetadataSource.SS, MetadataSource.IGDB]
|
|
with patch("handler.scan_handler.cm.get_config", return_value=_fake_config()):
|
|
ordered = get_priority_ordered_metadata_sources(available, "url_cover")
|
|
|
|
assert ordered == [MetadataSource.IGDB, MetadataSource.SS]
|
|
|
|
|
|
def test_per_field_override_reorders_only_that_field():
|
|
"""A cover override wins for url_cover but not for url_screenshots."""
|
|
available = [MetadataSource.IGDB, MetadataSource.SS]
|
|
config = _fake_config(url_cover=["ss", "igdb"])
|
|
with patch("handler.scan_handler.cm.get_config", return_value=config):
|
|
cover = get_priority_ordered_metadata_sources(available, "url_cover")
|
|
screenshots = get_priority_ordered_metadata_sources(
|
|
available, "url_screenshots"
|
|
)
|
|
|
|
# Cover honors the override (ss first)...
|
|
assert cover == [MetadataSource.SS, MetadataSource.IGDB]
|
|
# ...while screenshots keep the shared artwork order (igdb first).
|
|
assert screenshots == [MetadataSource.IGDB, MetadataSource.SS]
|
|
|
|
|
|
def test_a_source_listed_twice_keeps_its_first_position():
|
|
"""A repeated config entry must not hand a provider two slots."""
|
|
config = _fake_config(url_cover=["sgdb", "steam", "sgdb"])
|
|
available = [MetadataSource.STEAM, MetadataSource.SGDB]
|
|
with patch("handler.scan_handler.cm.get_config", return_value=config):
|
|
ordered = get_priority_ordered_metadata_sources(available, "url_cover")
|
|
|
|
assert ordered == [MetadataSource.SGDB, MetadataSource.STEAM]
|
|
|
|
|
|
def test_sources_absent_from_priority_are_appended():
|
|
"""Available sources not named in the priority list still appear, last."""
|
|
available = [MetadataSource.SS, MetadataSource.MOBY, MetadataSource.LAUNCHBOX]
|
|
config = _fake_config(url_cover=["ss"])
|
|
with patch("handler.scan_handler.cm.get_config", return_value=config):
|
|
ordered = get_priority_ordered_metadata_sources(available, "url_cover")
|
|
|
|
assert ordered[0] == MetadataSource.SS
|
|
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]
|
|
config = _fake_config(url_cover=["ss", "igdb"])
|
|
with patch("handler.scan_handler.cm.get_config", return_value=config):
|
|
ordered = get_priority_ordered_metadata_sources(available, "metadata")
|
|
|
|
assert ordered == [MetadataSource.IGDB, MetadataSource.SS]
|
|
|
|
|
|
def test_scene_match_drops_similar_game_sources():
|
|
"""Demozoo/Pouët must not inherit a similarly titled game's box art."""
|
|
available = [
|
|
MetadataSource.IGDB,
|
|
MetadataSource.MOBY,
|
|
MetadataSource.DEMOZOO,
|
|
MetadataSource.POUET,
|
|
MetadataSource.SS,
|
|
]
|
|
assert scene_apply_sources(available) == [
|
|
MetadataSource.DEMOZOO,
|
|
MetadataSource.POUET,
|
|
]
|
|
|
|
|
|
def test_csdb_only_still_locks():
|
|
available = [MetadataSource.IGDB, MetadataSource.CSDB]
|
|
assert scene_apply_sources(available) == [MetadataSource.CSDB]
|
|
|
|
|
|
def test_scene_lock_is_a_no_op_for_regular_games():
|
|
"""Games without a Demozoo/Pouët id keep fuzzy catalog matching."""
|
|
available = [MetadataSource.IGDB, MetadataSource.MOBY, MetadataSource.SS]
|
|
assert scene_apply_sources(available) == available
|
|
|
|
|
|
def test_pouet_only_still_locks():
|
|
available = [MetadataSource.IGDB, MetadataSource.POUET]
|
|
assert scene_apply_sources(available) == [MetadataSource.POUET]
|
|
|
|
|
|
def test_persisted_scene_lock_survives_an_empty_scene_lookup():
|
|
"""An unreachable provider must not hand a known production to the catalogs."""
|
|
available = [MetadataSource.IGDB, MetadataSource.MOBY]
|
|
assert scene_apply_sources(available, scene_locked=True) == []
|
|
|
|
|
|
def test_scene_lock_keeps_this_scans_match():
|
|
available = [MetadataSource.IGDB, MetadataSource.DEMOZOO]
|
|
assert scene_apply_sources(available, scene_locked=True) == [MetadataSource.DEMOZOO]
|
|
|
|
|
|
def test_enabled_metadata_sources_follow_provider_config(mocker):
|
|
for name, handler in vars(metadata).items():
|
|
if name.startswith("meta_") and hasattr(handler, "is_enabled"):
|
|
mocker.patch.object(handler, "is_enabled", return_value=False)
|
|
for handler in (metadata.meta_ss_handler, metadata.meta_libretro_handler):
|
|
mocker.patch.object(handler, "is_enabled", return_value=True)
|
|
|
|
assert get_enabled_metadata_sources() == [
|
|
MetadataSource.SS,
|
|
MetadataSource.LIBRETRO,
|
|
]
|