fix(scan): count every metadata source when deciding a ROM is identified

The not-identified check in scan_rom listed 13 provider ids by hand and
missed tgdb_id and libretro_id, so a ROM matched only by Libretro (or by a
TGDB id from Hasheous) took the early return: it skipped the SteamGridDB
lookup and missing_from_fs reset, while Rom.is_identified counted it as
matched. Derive the check from METADATA_SOURCE_COLUMNS instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XZW9ChvmiTKXYYWY6JvTKU
This commit is contained in:
Claude
2026-10-01 04:12:16 +00:00
parent acafe37287
commit ef57ee300d
2 changed files with 78 additions and 15 deletions

View File

@@ -77,7 +77,13 @@ from logger.logger import log
from models.assets import MemoryCardVersion, Save, Screenshot, State
from models.firmware import Firmware
from models.platform import Platform
from models.rom import Rom, RomFile, RomFileCategory, RomIdentity
from models.rom import (
METADATA_SOURCE_COLUMNS,
Rom,
RomFile,
RomFileCategory,
RomIdentity,
)
from models.user import User
from utils import emoji
from utils.audio_tags import persist_embedded_cover, remove_persisted_cover
@@ -1616,20 +1622,8 @@ async def scan_rom(
rom_attrs["url_cover"] = pico8_url
# If not found in any metadata source, we return the rom with the default values
if (
not rom_attrs.get("igdb_id")
and not rom_attrs.get("moby_id")
and not rom_attrs.get("ss_id")
and not rom_attrs.get("ra_id")
and not rom_attrs.get("launchbox_id")
and not rom_attrs.get("hasheous_id")
and not rom_attrs.get("flashpoint_id")
and not rom_attrs.get("hltb_id")
and not rom_attrs.get("demozoo_id")
and not rom_attrs.get("pouet_id")
and not rom_attrs.get("csdb_id")
and not rom_attrs.get("steam_id")
and not rom_attrs.get("gamelist_id")
if not any(
rom_attrs.get(column.key) for column in METADATA_SOURCE_COLUMNS.values()
):
if inconclusive_sources:
# Reporting a plain "not identified" here writes the ROM up as a

View File

@@ -0,0 +1,69 @@
"""Which provider matches count as an identified ROM during a scan.
A scan that finds no match returns early and skips the SteamGridDB lookup, so
every source `Rom.is_identified` counts must keep the scan going.
"""
from unittest.mock import AsyncMock, patch
import pytest
from tests.handler.scan_stubs import add_n64_platform, add_rom, run_scan
from handler.metadata.libretro_handler import LibretroRom
from handler.metadata.sgdb_handler import SGDBRom
from handler.scan_handler import MetadataSource, ScanType
FS_NAME = "Mario Kart 64 (USA).z64"
@pytest.fixture
def sgdb_lookup():
with patch(
"handler.scan_handler.meta_sgdb_handler.get_details_by_names",
new=AsyncMock(return_value=SGDBRom(sgdb_id=None)),
) as lookup:
yield lookup
async def test_libretro_only_match_counts_as_identified(sgdb_lookup):
platform = add_n64_platform()
rom = add_rom(platform, FS_NAME, "Mario Kart 64")
with patch(
"handler.scan_handler.meta_libretro_handler.get_rom",
new=AsyncMock(
return_value=LibretroRom(
libretro_id="Mario Kart 64 (USA)", name="Mario Kart 64"
)
),
):
result = await run_scan(
platform,
rom,
scan_type=ScanType.COMPLETE,
metadata_sources=[MetadataSource.LIBRETRO, MetadataSource.SGDB],
)
assert result.libretro_id == "Mario Kart 64 (USA)"
assert result.is_identified
assert result.missing_from_fs is False
sgdb_lookup.assert_awaited_once()
async def test_unmatched_rom_skips_the_sgdb_lookup(sgdb_lookup):
platform = add_n64_platform()
rom = add_rom(platform, FS_NAME, "Mario Kart 64")
with patch(
"handler.scan_handler.meta_libretro_handler.get_rom",
new=AsyncMock(return_value=LibretroRom(libretro_id=None)),
):
result = await run_scan(
platform,
rom,
scan_type=ScanType.COMPLETE,
metadata_sources=[MetadataSource.LIBRETRO, MetadataSource.SGDB],
)
assert not result.is_identified
sgdb_lookup.assert_not_awaited()