From 98f1d65a7c9eae4854ef5336fcfdfe17b042c21a Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 20 Apr 2026 21:36:59 -0400 Subject: [PATCH] fixes --- backend/endpoints/sockets/scan.py | 8 ++-- backend/tests/endpoints/sockets/test_scan.py | 37 +++++++++++++------ .../src/components/common/Game/AdminMenu.vue | 18 +++++---- .../common/Game/Dialog/RefreshMetadata.vue | 19 ++++------ 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index bc3374981..9dce115cf 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -159,6 +159,10 @@ def _should_scan_rom( metadata_sources (list[str]): List of metadata sources to be used. """ + # When roms_ids is provided, the scan is scoped to those roms only + if rom and roms_ids: + return bool(rom.id in roms_ids) + # This logic is tricky so only touch it if you know what you're doing""" should_scan = bool( # Any new roms should be scanned @@ -170,10 +174,8 @@ def _should_scan_rom( or ( rom and ( - # Selected ROMs are always scanned - (rom.id in roms_ids) # Update scan should scan ROMs identified by the selected metadata sources - or ( + ( scan_type == ScanType.UPDATE and rom.is_identified and any(getattr(rom, f"{source}_id") for source in metadata_sources) diff --git a/backend/tests/endpoints/sockets/test_scan.py b/backend/tests/endpoints/sockets/test_scan.py index 1408568bf..f58f8113f 100644 --- a/backend/tests/endpoints/sockets/test_scan.py +++ b/backend/tests/endpoints/sockets/test_scan.py @@ -98,17 +98,23 @@ class TestShouldScanRom: # Test COMPLETE scan type def test_complete_scan_always_scans(self, rom: Rom): - """COMPLETE should always scan regardless of rom state""" + """COMPLETE should scan everything when unscoped, but respect roms_ids when scoped""" assert _should_scan_rom(ScanType.COMPLETE, None, [], ["igdb"]) is True assert _should_scan_rom(ScanType.COMPLETE, rom, [], ["igdb"]) is True - assert _should_scan_rom(ScanType.COMPLETE, rom, [2, 3], ["igdb"]) is True + # Scoped scan: rom not in list → skip even for COMPLETE + assert ( + _should_scan_rom(ScanType.COMPLETE, rom, [rom.id + 99], ["igdb"]) is False + ) + assert _should_scan_rom(ScanType.COMPLETE, rom, [rom.id], ["igdb"]) is True # Test HASHES scan type def test_hashes_scan_always_scans(self, rom: Rom): - """HASHES should always scan regardless of rom state""" + """HASHES should scan everything when unscoped, but respect roms_ids when scoped""" assert _should_scan_rom(ScanType.HASHES, None, [], ["igdb"]) is True assert _should_scan_rom(ScanType.HASHES, rom, [], ["igdb"]) is True - assert _should_scan_rom(ScanType.HASHES, rom, [2, 3], ["igdb"]) is True + # Scoped scan: rom not in list → skip even for HASHES + assert _should_scan_rom(ScanType.HASHES, rom, [rom.id + 99], ["igdb"]) is False + assert _should_scan_rom(ScanType.HASHES, rom, [rom.id], ["igdb"]) is True # Test UNMATCHED scan type def test_unmatched_scan_with_no_rom(self): @@ -170,17 +176,24 @@ class TestShouldScanRom: assert result is True def test_no_scan_when_rom_id_not_in_list(self, rom: Rom): - """Should follow normal rules when rom.id is not in roms_ids list""" + """When roms_ids is non-empty, scan is scoped — roms outside the list are skipped for every scan type""" rom.id = 4 + rom.igdb_id = None + rom.moby_id = None + rom.ss_id = None + rom.ra_id = None + rom.launchbox_id = None roms_ids = [1, 2, 3] - # These should not scan because rom exists and id not in list - assert ( - _should_scan_rom(ScanType.NEW_PLATFORMS, rom, roms_ids, ["igdb"]) is False - ) - assert _should_scan_rom(ScanType.QUICK, rom, roms_ids, ["igdb"]) is False - assert _should_scan_rom(ScanType.UPDATE, rom, roms_ids, ["igdb"]) is False - assert _should_scan_rom(ScanType.UNMATCHED, rom, roms_ids, ["igdb"]) is True + for scan_type in [ + ScanType.NEW_PLATFORMS, + ScanType.QUICK, + ScanType.UPDATE, + ScanType.UNMATCHED, + ScanType.COMPLETE, + ScanType.HASHES, + ]: + assert _should_scan_rom(scan_type, rom, roms_ids, ["igdb"]) is False # Edge cases def test_empty_roms_ids_list(self, rom: Rom): diff --git a/frontend/src/components/common/Game/AdminMenu.vue b/frontend/src/components/common/Game/AdminMenu.vue index 2492dd3f0..8f10ad262 100644 --- a/frontend/src/components/common/Game/AdminMenu.vue +++ b/frontend/src/components/common/Game/AdminMenu.vue @@ -51,7 +51,6 @@ async function resetLastPlayed() { return; }); } -