From 552ac3a393b0865fb3397305a9bfa56df891795f Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Mon, 26 Oct 2026 14:28:30 -0500 Subject: [PATCH] fix(platforms): share provider entries across duplicate platform slugs (#5359) * fix(platforms): share provider entries across duplicate slugs and rename system-32 Three consoles have two RomM slugs, each used by different providers, so a library folder only matched the providers that knew its spelling: vc-4000 / interton-vc-4000, apple-pippin / pippin and tandy-vis / vis. DUPLICATE_PLATFORM_SLUGS lists them once, and fill_duplicate_slugs gives each slug the other's entry in every provider table. pippin and interton-vc-4000 now get an IGDB platform id, and IGDB's family override also applies to a listed duplicate so both VC 4000 slugs stay in the Interton family. The system-32 slug mapped to Namco System 22 in ScreenScraper and LaunchBox, easy to confuse with Sega System 32 (system32). It is now namco-system-22. Folders and config bindings named system-32 still resolve to it, and migration 0154 renames existing platform rows. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh * fix(platforms): resolve bindings to a renamed slug back to their folder resolve_platform_slug already maps a binding to system-32 onto namco-system-22, but resolve_fs_slug compared the raw binding with the new slug, so a moved folder bound to the old slug was never found. Both now go through the same renamed-slug lookup. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh * fix(platforms): drop the system-32 slug backfill migration Every scan resolves a platform's slug from its folder again, so the next scan renames system-32 rows through the renamed-slug alias without a migration, as the backend guide asks for normalizations the parser now handles. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh * chore(platforms): reword two comments so the product isn't the actor Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh * revert(platforms): leave system-32 to the arcade slug split rommapp/romm#5273 retires system-32 as an alias of arcade and resolves aliases in config bindings in both directions, which covers what the namco-system-22 rename and the renamed-slug lookup did here. This PR now only shares provider entries across duplicate slugs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh --------- Co-authored-by: Claude Opus 5.5 --- backend/adapters/services/igdb.py | 9 +++- backend/adapters/services/rahasher.py | 3 ++ backend/handler/metadata/demozoo_handler.py | 3 ++ .../handler/metadata/flashpoint_handler.py | 3 ++ backend/handler/metadata/hasheous_handler.py | 3 ++ backend/handler/metadata/hltb_handler.py | 3 ++ backend/handler/metadata/igdb_handler.py | 6 ++- .../metadata/launchbox_handler/platforms.py | 3 ++ backend/handler/metadata/libretro_handler.py | 3 ++ backend/handler/metadata/moby_handler.py | 3 ++ backend/handler/metadata/ra_handler.py | 3 ++ backend/handler/metadata/ss_handler.py | 3 ++ backend/handler/metadata/tgdb_handler.py | 3 ++ .../handler/metadata/test_igdb_handler.py | 26 ++++++++-- backend/tests/utils/test_platform_slugs.py | 51 +++++++++++++++++++ backend/utils/platform_slugs.py | 20 ++++++++ 16 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 backend/tests/utils/test_platform_slugs.py diff --git a/backend/adapters/services/igdb.py b/backend/adapters/services/igdb.py index 0ad501142..db6a5c44b 100644 --- a/backend/adapters/services/igdb.py +++ b/backend/adapters/services/igdb.py @@ -18,6 +18,7 @@ from logger.logger import log from utils import get_version from utils.context import ctx_aiohttp_session from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from utils.rate_limiter import RateLimiter if TYPE_CHECKING: @@ -2862,6 +2863,8 @@ IGDB_PLATFORM_LIST: dict[UPS, SlugToIGDB] = { }, } +fill_duplicate_slugs(IGDB_PLATFORM_LIST) + class SlugToIGDBVersion(TypedDict): id: int @@ -4818,7 +4821,6 @@ IGDB_SIBLING_PLATFORMS: dict[UPS, UPS] = { UPS.WINDOWS_APPS: UPS.WIN, UPS.BEENA: UPS.ADVANCED_PICO_BEENA, UPS.VMU: UPS.VISUAL_MEMORY_UNIT_SLASH_VISUAL_MEMORY_SYSTEM, - UPS.PIPPIN: UPS.APPLE_PIPPIN, UPS.ATARI800: UPS.ATARI8BIT, UPS.ATARI_XEGS: UPS.ATARI8BIT, UPS.ATARI_VCS: UPS.ATARI2600, @@ -4881,7 +4883,8 @@ _MOS_TECHNOLOGY_FAMILY = PlatformFamily( family_name="MOS Technology", family_slug="mos-technology" ) -# Platforms IGDB doesn't list, mapped to their family. Overrides a sibling's. +# Platforms IGDB doesn't list or lists without a family, mapped to their family. +# Overrides a sibling's. IGDB_PLATFORM_FAMILIES: dict[UPS, PlatformFamily] = { UPS.MODEL1: _igdb_family(UPS.DC), UPS.MODEL2: _igdb_family(UPS.DC), @@ -4960,3 +4963,5 @@ IGDB_PLATFORM_FAMILIES: dict[UPS, PlatformFamily] = { UPS.KIM_1: _MOS_TECHNOLOGY_FAMILY, UPS.MOS_TECHNOLOGY_6502: _MOS_TECHNOLOGY_FAMILY, } + +fill_duplicate_slugs(IGDB_PLATFORM_FAMILIES) diff --git a/backend/adapters/services/rahasher.py b/backend/adapters/services/rahasher.py index 497ceef9d..fee4c1414 100644 --- a/backend/adapters/services/rahasher.py +++ b/backend/adapters/services/rahasher.py @@ -11,6 +11,7 @@ from utils.archives import extract_largest_archive_member from utils.filesystem import COMPRESSED_FILE_EXTENSIONS from utils.m3u import first_playlist_entry from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from utils.psp_hasher import calculate_psp_ra_hash, is_psp_native_hash_file from utils.rvz_hasher import ( calculate_gamecube_ra_hash, @@ -154,6 +155,8 @@ PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID: dict[UPS, int] = { UPS.WONDERSWAN_COLOR: 53, } +fill_duplicate_slugs(PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID) + RA_BUFFER_HASH_UNSUPPORTED_IDS: frozenset[int] = frozenset( PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID[ups] for ups in RA_BUFFER_HASH_UNSUPPORTED ) diff --git a/backend/handler/metadata/demozoo_handler.py b/backend/handler/metadata/demozoo_handler.py index 40bd67951..9e977838a 100644 --- a/backend/handler/metadata/demozoo_handler.py +++ b/backend/handler/metadata/demozoo_handler.py @@ -18,6 +18,7 @@ from logger.logger import log from utils import int_or_none, valid_youtube_id from utils.datetime import parse_utc_timestamp from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from utils.rate_limiter import RateLimiter from .base_handler import ( @@ -635,3 +636,5 @@ DEMOZOO_PLATFORM_LIST: dict[UPS, _DemozooPlatform] = { UPS.SNES: {"id": 34, "name": "Nintendo SNES/Super FamiCom"}, UPS.GENESIS: {"id": 22, "name": "Sega Megadrive/Genesis"}, } + +fill_duplicate_slugs(DEMOZOO_PLATFORM_LIST) diff --git a/backend/handler/metadata/flashpoint_handler.py b/backend/handler/metadata/flashpoint_handler.py index abf432751..7f99239f2 100644 --- a/backend/handler/metadata/flashpoint_handler.py +++ b/backend/handler/metadata/flashpoint_handler.py @@ -11,6 +11,7 @@ from utils import get_version, is_valid_uuid from utils.context import ctx_httpx_client from utils.datetime import parse_utc_timestamp from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from .base_handler import HTTPX_REQUEST_ERRORS, MetadataHandler @@ -408,3 +409,5 @@ class SlugToFlashpointId(TypedDict): FLASHPOINT_PLATFORM_LIST: dict[UPS, SlugToFlashpointId] = { UPS.BROWSER: {"id": 1, "name": "Browser (Flash/HTML5)"} } + +fill_duplicate_slugs(FLASHPOINT_PLATFORM_LIST) diff --git a/backend/handler/metadata/hasheous_handler.py b/backend/handler/metadata/hasheous_handler.py index d007fff94..7e2ea8e00 100644 --- a/backend/handler/metadata/hasheous_handler.py +++ b/backend/handler/metadata/hasheous_handler.py @@ -21,6 +21,7 @@ from utils import get_version from utils.context import ctx_httpx_client from utils.datetime import parse_utc_timestamp from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from .base_handler import BaseRom, MetadataHandler from .igdb_handler import ( @@ -1631,3 +1632,5 @@ HASHEOUS_PLATFORM_LIST: dict[UPS, SlugToHasheousId] = { "tgdb_id": None, }, } + +fill_duplicate_slugs(HASHEOUS_PLATFORM_LIST) diff --git a/backend/handler/metadata/hltb_handler.py b/backend/handler/metadata/hltb_handler.py index 1888fc0a3..d63587c59 100644 --- a/backend/handler/metadata/hltb_handler.py +++ b/backend/handler/metadata/hltb_handler.py @@ -26,6 +26,7 @@ from utils.hltb_search import ( search_headers, ) from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from utils.rate_limiter import RateLimiter from utils.update_hltb_api_url import discover_hltb_endpoint @@ -879,3 +880,5 @@ HLTB_PLATFORM_LIST: dict[UPS, SlugToHLTBPlatform] = { UPS.ZX81: {"name": "ZX81", "slug": "zx81", "count": 41}, UPS.ZEEBO: {"name": "Zeebo", "slug": "zeebo", "count": 9}, } + +fill_duplicate_slugs(HLTB_PLATFORM_LIST) diff --git a/backend/handler/metadata/igdb_handler.py b/backend/handler/metadata/igdb_handler.py index 9279b1385..607c2d2c7 100644 --- a/backend/handler/metadata/igdb_handler.py +++ b/backend/handler/metadata/igdb_handler.py @@ -779,6 +779,8 @@ class IGDBHandler(MetadataHandler): def get_platform(self, slug: str) -> IGDBPlatform: if slug in IGDB_PLATFORM_LIST: platform = IGDB_PLATFORM_LIST[UPS(slug)] + # A duplicate of a family-less IGDB platform takes its family from IGDB_PLATFORM_FAMILIES. + family = IGDB_PLATFORM_FAMILIES.get(UPS(slug), platform) return IGDBPlatform( igdb_id=platform["id"], @@ -787,8 +789,8 @@ class IGDBHandler(MetadataHandler): name=platform["name"], category=platform["category"], generation=platform["generation"], - family_name=platform["family_name"], - family_slug=platform["family_slug"], + family_name=family["family_name"], + family_slug=family["family_slug"], url=platform["url"], url_logo=self.normalize_cover_url(platform["url_logo"]), ) diff --git a/backend/handler/metadata/launchbox_handler/platforms.py b/backend/handler/metadata/launchbox_handler/platforms.py index 8d8e1ef45..a8bb06195 100644 --- a/backend/handler/metadata/launchbox_handler/platforms.py +++ b/backend/handler/metadata/launchbox_handler/platforms.py @@ -1,6 +1,7 @@ from typing import TypedDict from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from .types import LaunchboxPlatform @@ -220,6 +221,8 @@ LAUNCHBOX_PLATFORM_LIST: dict[UPS, SlugToLaunchboxId] = { UPS.ZXS: {"id": 46, "name": "Sinclair ZX Spectrum"}, } +fill_duplicate_slugs(LAUNCHBOX_PLATFORM_LIST) + # Reverse lookup: LaunchBox platform ID → UPS slug LAUNCHBOX_PLATFORM_NAME_TO_SLUG = { v["id"]: k for k, v in LAUNCHBOX_PLATFORM_LIST.items() diff --git a/backend/handler/metadata/libretro_handler.py b/backend/handler/metadata/libretro_handler.py index 41799984d..465181436 100644 --- a/backend/handler/metadata/libretro_handler.py +++ b/backend/handler/metadata/libretro_handler.py @@ -10,6 +10,7 @@ from config.config_manager import MetadataMediaType from config.config_manager import config_manager as cm from logger.logger import log from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from .base_handler import MetadataHandler @@ -264,3 +265,5 @@ LIBRETRO_PLATFORM_LIST: Final[dict[UPS, str]] = { UPS.TOMY_TUTOR: "Tomy - Tutor", UPS.SUPERVISION: "Watara - Supervision", } + +fill_duplicate_slugs(LIBRETRO_PLATFORM_LIST) diff --git a/backend/handler/metadata/moby_handler.py b/backend/handler/metadata/moby_handler.py index c23b15460..1369d922d 100644 --- a/backend/handler/metadata/moby_handler.py +++ b/backend/handler/metadata/moby_handler.py @@ -10,6 +10,7 @@ from config import MOBYGAMES_API_KEY from logger.logger import log from models.rom import Rom from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from .base_handler import ( BaseRom, @@ -1331,6 +1332,8 @@ MOBYGAMES_PLATFORM_LIST: dict[UPS, SlugToMobyId] = { UPS.ZX81: {"id": 119, "name": "ZX81", "slug": "zx81"}, } +fill_duplicate_slugs(MOBYGAMES_PLATFORM_LIST) + # Reverse lookup MOBY_ID_TO_SLUG = {v["id"]: k for k, v in MOBYGAMES_PLATFORM_LIST.items()} diff --git a/backend/handler/metadata/ra_handler.py b/backend/handler/metadata/ra_handler.py index 2006478c3..babf0b82f 100644 --- a/backend/handler/metadata/ra_handler.py +++ b/backend/handler/metadata/ra_handler.py @@ -20,6 +20,7 @@ from logger.logger import log from models.rom import Rom from utils.datetime import parse_utc_timestamp from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from .base_handler import ( BaseRom, @@ -517,5 +518,7 @@ RA_PLATFORM_LIST: dict[UPS, SlugToRAId] = { UPS.WONDERSWAN_COLOR: {"id": 53, "name": "WonderSwan Color"}, } +fill_duplicate_slugs(RA_PLATFORM_LIST) + # Reverse lookup RA_ID_TO_SLUG = {v["id"]: k for k, v in RA_PLATFORM_LIST.items()} diff --git a/backend/handler/metadata/ss_handler.py b/backend/handler/metadata/ss_handler.py index 6fe40e4db..1854e4e4e 100644 --- a/backend/handler/metadata/ss_handler.py +++ b/backend/handler/metadata/ss_handler.py @@ -43,6 +43,7 @@ from models.rom import LookupHashes, Rom, RomFile from utils.database import safe_int from utils.datetime import parse_utc_timestamp from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from .base_handler import ( BaseRom, @@ -2109,6 +2110,8 @@ SCREENSAVER_PLATFORM_LIST: dict[UPS, SlugToSSId] = { }, } +fill_duplicate_slugs(SCREENSAVER_PLATFORM_LIST) + SS_INDEXED_FORMAT_PLATFORMS: Final = IndexedFormatPlatforms( ps1=PS1_SS_ID, ps2=PS2_SS_ID, diff --git a/backend/handler/metadata/tgdb_handler.py b/backend/handler/metadata/tgdb_handler.py index 8f9892c7e..8d9aab15d 100644 --- a/backend/handler/metadata/tgdb_handler.py +++ b/backend/handler/metadata/tgdb_handler.py @@ -2,6 +2,7 @@ from typing import NotRequired, TypedDict from config import TGDB_API_ENABLED from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs from .base_handler import MetadataHandler @@ -2265,3 +2266,5 @@ TGDB_PLATFORM_LIST: dict[UPS, SlugToTGDBId] = { "url_logo": None, }, } + +fill_duplicate_slugs(TGDB_PLATFORM_LIST) diff --git a/backend/tests/handler/metadata/test_igdb_handler.py b/backend/tests/handler/metadata/test_igdb_handler.py index 9dc127ff9..d27c794c1 100644 --- a/backend/tests/handler/metadata/test_igdb_handler.py +++ b/backend/tests/handler/metadata/test_igdb_handler.py @@ -142,6 +142,22 @@ class TestGetPlatformAliases: assert IGDBHandler().get_platform_aliases(UPS.ATARI_ST) == ("", []) +class TestGetPlatformDuplicateSlugs: + def test_both_slugs_resolve_to_the_igdb_platform(self) -> None: + handler = IGDBHandler() + assert handler.get_platform(UPS.PIPPIN)["igdb_id"] == ( + handler.get_platform(UPS.APPLE_PIPPIN)["igdb_id"] + ) + assert handler.get_platform(UPS.INTERTON_VC_4000)["igdb_id"] == ( + handler.get_platform(UPS.VC_4000)["igdb_id"] + ) + + def test_both_slugs_keep_romms_family(self) -> None: + handler = IGDBHandler() + for slug in (UPS.VC_4000, UPS.INTERTON_VC_4000): + assert handler.get_platform(slug)["family_slug"] == "interton" + + class TestGetIGDBPreferredLocale: def test_multi_region_rom_respects_user_priority(self): """The configured priority wins over filename tag order.""" @@ -1289,17 +1305,19 @@ class TestGetPlatform: "family_slug": "texas-instruments", } + def test_siblings_are_only_for_unlisted_platforms(self): + assert not IGDB_SIBLING_PLATFORMS.keys() & IGDB_PLATFORM_LIST.keys() + @pytest.mark.parametrize( "slug", sorted(IGDB_SIBLING_PLATFORMS.keys() | IGDB_PLATFORM_FAMILIES.keys()) ) - def test_every_unlisted_platform_gets_a_family( + def test_every_platform_with_a_family_entry_gets_a_family( self, handler: IGDBHandler, slug: UPS ): - assert slug not in IGDB_PLATFORM_LIST - platform = handler.get_platform(slug) - assert (platform["igdb_id"], platform["slug"]) == (None, slug) + assert platform["slug"] == slug + assert (platform["igdb_id"] is None) == (slug not in IGDB_PLATFORM_LIST) assert platform.get("family_name") assert platform.get("family_slug") diff --git a/backend/tests/utils/test_platform_slugs.py b/backend/tests/utils/test_platform_slugs.py new file mode 100644 index 000000000..915bdca11 --- /dev/null +++ b/backend/tests/utils/test_platform_slugs.py @@ -0,0 +1,51 @@ +import pytest + +from adapters.services.igdb import IGDB_PLATFORM_LIST +from adapters.services.rahasher import PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID +from handler.metadata.hasheous_handler import HASHEOUS_PLATFORM_LIST +from handler.metadata.launchbox_handler.platforms import LAUNCHBOX_PLATFORM_LIST +from handler.metadata.moby_handler import MOBYGAMES_PLATFORM_LIST +from handler.metadata.ra_handler import RA_PLATFORM_LIST +from handler.metadata.ss_handler import SCREENSAVER_PLATFORM_LIST +from handler.metadata.tgdb_handler import TGDB_PLATFORM_LIST +from utils.platform_slugs import DUPLICATE_PLATFORM_SLUGS +from utils.platform_slugs import UniversalPlatformSlug as UPS +from utils.platform_slugs import fill_duplicate_slugs + + +def test_fills_either_slug_from_the_other(): + platforms = {UPS.VC_4000: 1, UPS.PIPPIN: 2} + + fill_duplicate_slugs(platforms) + + assert platforms[UPS.INTERTON_VC_4000] == 1 + assert platforms[UPS.APPLE_PIPPIN] == 2 + assert UPS.VIS not in platforms + assert UPS.TANDY_VIS not in platforms + + +def test_keeps_both_entries_when_both_are_listed(): + platforms = {UPS.VC_4000: 1, UPS.INTERTON_VC_4000: 2} + + fill_duplicate_slugs(platforms) + + assert platforms == {UPS.VC_4000: 1, UPS.INTERTON_VC_4000: 2} + + +@pytest.mark.parametrize( + "platforms", + [ + IGDB_PLATFORM_LIST, + SCREENSAVER_PLATFORM_LIST, + LAUNCHBOX_PLATFORM_LIST, + RA_PLATFORM_LIST, + PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID, + TGDB_PLATFORM_LIST, + MOBYGAMES_PLATFORM_LIST, + HASHEOUS_PLATFORM_LIST, + ], + ids=["igdb", "ss", "launchbox", "ra", "rahasher", "tgdb", "moby", "hasheous"], +) +def test_provider_lists_cover_both_slugs_or_neither(platforms: dict[UPS, object]): + for slug, duplicate in DUPLICATE_PLATFORM_SLUGS: + assert (slug in platforms) == (duplicate in platforms) diff --git a/backend/utils/platform_slugs.py b/backend/utils/platform_slugs.py index 1081c61af..c63ffaf0b 100644 --- a/backend/utils/platform_slugs.py +++ b/backend/utils/platform_slugs.py @@ -5,6 +5,7 @@ stack, which imports the filesystem handlers that in turn read title ids. """ import enum +from typing import Final class UniversalPlatformSlug(enum.StrEnum): @@ -476,3 +477,22 @@ class UniversalPlatformSlug(enum.StrEnum): ZX80 = "zx80" ZX81 = "zx81" ZXS = "zxs" + + +# Slugs for the same hardware, each used by different providers. +DUPLICATE_PLATFORM_SLUGS: Final[ + tuple[tuple[UniversalPlatformSlug, UniversalPlatformSlug], ...] +] = ( + (UniversalPlatformSlug.VC_4000, UniversalPlatformSlug.INTERTON_VC_4000), + (UniversalPlatformSlug.APPLE_PIPPIN, UniversalPlatformSlug.PIPPIN), + (UniversalPlatformSlug.TANDY_VIS, UniversalPlatformSlug.VIS), +) + + +def fill_duplicate_slugs[T](platforms: dict[UniversalPlatformSlug, T]) -> None: + """Give each duplicate slug the entry of the other when only one is listed.""" + for slug, duplicate in DUPLICATE_PLATFORM_SLUGS: + if slug in platforms: + platforms.setdefault(duplicate, platforms[slug]) + elif duplicate in platforms: + platforms[slug] = platforms[duplicate]