mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 02:24:09 +01:00
* fix(scan): look a file named by several titles up by each of them No-Intro and Redump name a game released under several titles by all of them, joined by " ~ ". Each file-name lookup now tries the full name first and then each title, tags and extension kept, until one matches; SteamGridDB searches the titles too. Only the title is split, never a tag group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Eky1CPt1rz6BWLAqWVNmU9 * fix(scan): search each SteamGridDB name once From Greptile's review: a title can repeat a name a provider already gave, so SteamGridDB's candidate names are deduplicated, first position kept, with a test. The new test module's docstring is one sentence, as AGENTS.md asks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Eky1CPt1rz6BWLAqWVNmU9 * fix(scan): keep the full-name answer on a miss and cap title lookups pr-ready step 2 (code-review xhigh --fix): return the full name's result when every title misses, dedupe and cap titles at 4, and stop wrapping CSDb, whose lookup only reads a (csdb-N) tag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(scan): give SteamGridDB the bare titles and inline lookup args pr-ready step 3 (simplify): add compute_titles so SteamGridDB stops re-attaching and re-stripping tags, inline the Moby and SS platform ids, and merge the two all-miss tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scan): keep the narrowed Moby and SS platform ids for mypy pr-ready step 4 (review-polish): the locals inlined in step 3 narrow the optional platform ids, which a lambda body cannot do; restore them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(scan): reword the title cap comment pr-ready step 5 (humanizer). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
118 lines
3.8 KiB
Python
118 lines
3.8 KiB
Python
"""How a scan looks up a file named by all of a game's titles."""
|
|
|
|
from unittest.mock import AsyncMock, call, patch
|
|
|
|
from tests.factories import make_platform
|
|
from tests.handler.scan_stubs import add_rom, run_scan
|
|
|
|
from handler.metadata.hltb_handler import HLTBRom
|
|
from handler.metadata.igdb_handler import IGDBRom
|
|
from handler.metadata.sgdb_handler import SGDBRom
|
|
from handler.scan.lookups import lookup_by_file_name
|
|
from handler.scan.sources import MetadataSource, ScanType
|
|
|
|
FS_NAME = "Sonic Wings 2 ~ Aero Fighters 2 (World) (En,Ja).chd"
|
|
FIRST_TITLE = "Sonic Wings 2 (World) (En,Ja).chd"
|
|
SECOND_TITLE = "Aero Fighters 2 (World) (En,Ja).chd"
|
|
MATCH = HLTBRom(hltb_id=4821, name="Aero Fighters 2")
|
|
NO_MATCH = HLTBRom(hltb_id=None)
|
|
|
|
|
|
async def test_a_match_on_the_full_name_stands():
|
|
lookup = AsyncMock(return_value=MATCH)
|
|
|
|
result = await lookup_by_file_name(MetadataSource.HLTB, FS_NAME, lookup)
|
|
|
|
lookup.assert_awaited_once_with(FS_NAME)
|
|
assert result == MATCH
|
|
|
|
|
|
async def test_each_title_is_looked_up_until_one_matches():
|
|
lookup = AsyncMock(side_effect=[NO_MATCH, MATCH])
|
|
|
|
result = await lookup_by_file_name(MetadataSource.HLTB, FS_NAME, lookup)
|
|
|
|
assert lookup.await_args_list == [call(FS_NAME), call(FIRST_TITLE)]
|
|
assert result == MATCH
|
|
|
|
|
|
async def test_a_miss_on_every_title_keeps_the_full_name_answer():
|
|
full_name_miss = HLTBRom(hltb_id=None, name="Sonic Wings 2 ~ Aero Fighters 2")
|
|
lookup = AsyncMock(side_effect=[full_name_miss, NO_MATCH, NO_MATCH])
|
|
|
|
result = await lookup_by_file_name(MetadataSource.HLTB, FS_NAME, lookup)
|
|
|
|
assert lookup.await_args_list == [
|
|
call(FS_NAME),
|
|
call(FIRST_TITLE),
|
|
call(SECOND_TITLE),
|
|
]
|
|
assert result is full_name_miss
|
|
|
|
|
|
async def test_a_single_title_is_looked_up_once():
|
|
lookup = AsyncMock(return_value=NO_MATCH)
|
|
|
|
await lookup_by_file_name(MetadataSource.HLTB, SECOND_TITLE, lookup)
|
|
|
|
lookup.assert_awaited_once_with(SECOND_TITLE)
|
|
|
|
|
|
async def test_a_scan_matches_igdb_by_the_second_title():
|
|
platform = make_platform("neo-geo-cd", id=1, igdb_id=136)
|
|
rom = add_rom(platform, FS_NAME, "Sonic Wings 2 ~ Aero Fighters 2")
|
|
lookup = AsyncMock(
|
|
side_effect=[
|
|
IGDBRom(igdb_id=None),
|
|
IGDBRom(igdb_id=None),
|
|
IGDBRom(igdb_id=6773, name="Aero Fighters 2"),
|
|
]
|
|
)
|
|
|
|
with patch("handler.scan.lookups.meta_igdb_handler.get_rom", new=lookup):
|
|
result = await run_scan(
|
|
platform,
|
|
rom,
|
|
scan_type=ScanType.COMPLETE,
|
|
metadata_sources=[MetadataSource.IGDB],
|
|
)
|
|
|
|
assert [lookup_call.args[1:] for lookup_call in lookup.await_args_list] == [
|
|
(FS_NAME, 136),
|
|
(FIRST_TITLE, 136),
|
|
(SECOND_TITLE, 136),
|
|
]
|
|
assert result.igdb_id == 6773
|
|
assert result.name == "Aero Fighters 2"
|
|
|
|
|
|
async def test_steamgriddb_searches_each_title_once():
|
|
platform = make_platform("neo-geo-cd", id=1, igdb_id=136)
|
|
rom = add_rom(platform, FS_NAME, "Sonic Wings 2 ~ Aero Fighters 2")
|
|
igdb_lookup = AsyncMock(
|
|
side_effect=[
|
|
IGDBRom(igdb_id=None),
|
|
IGDBRom(igdb_id=None),
|
|
IGDBRom(igdb_id=6773, name="Aero Fighters 2"),
|
|
]
|
|
)
|
|
sgdb_lookup = AsyncMock(return_value=SGDBRom(sgdb_id=None))
|
|
|
|
with (
|
|
patch("handler.scan.lookups.meta_igdb_handler.get_rom", new=igdb_lookup),
|
|
patch(
|
|
"handler.scan.lookups.meta_sgdb_handler.get_details_by_names",
|
|
new=sgdb_lookup,
|
|
),
|
|
):
|
|
await run_scan(
|
|
platform,
|
|
rom,
|
|
scan_type=ScanType.COMPLETE,
|
|
metadata_sources=[MetadataSource.IGDB, MetadataSource.SGDB],
|
|
)
|
|
|
|
sgdb_lookup.assert_awaited_once_with(
|
|
["Aero Fighters 2", "Sonic Wings 2 ~ Aero Fighters 2", "Sonic Wings 2"]
|
|
)
|