From fa3654dd796aa9c5ea41df34f192a2b4f8ec60de Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi <3247106+gantoine@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:10:44 -0500 Subject: [PATCH] fix(platforms): stop filing sgb folders as Game Boy Color (#5530) * fix(platforms): stop filing sgb folders as Game Boy Color ES-DE and Batocera name their Super Game Boy system sgb (Game Boy games on the SNES adapter). Mapping sgb and sgb-msu1 to gbc gave those folders Game Boy Color provider ids and limited IGDB searches to the wrong platform. RomM has no Super Game Boy slug and IGDB, TheGamesDB, RetroAchievements and LaunchBox list none, so leave the folders unidentified; a config binding can still map them. Fixes #5506 Co-Authored-By: Claude Opus 5.5 * fix(scan): keep a missing platform folder unless its alias exists Addresses Greptile review on #5530: with the sgb aliases gone, gbc2players became the reverse folder for gbc, and a rescan with the gbc folder missing saved that nonexistent folder on the platform. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- backend/handler/scan_handler.py | 15 +++++++-------- backend/tests/handler/test_fastapi.py | 20 ++++++++++++++++++++ backend/tests/utils/test_platform_aliases.py | 7 +++++++ backend/utils/platform_aliases.py | 2 -- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/backend/handler/scan_handler.py b/backend/handler/scan_handler.py index 29e30ae0e..fa96b0b86 100644 --- a/backend/handler/scan_handler.py +++ b/backend/handler/scan_handler.py @@ -166,14 +166,13 @@ async def scan_platform( extra=LOGGER_MODULE_NAME, ) platform = db_platform_handler.get_platform_by_fs_slug(fs_slug) - if platform: - known_fs_slug = resolve_fs_slug(platform.slug, cnfg) - if known_fs_slug: - # `resolve_fs_slug` answers with a lowercased config key, but - # every path is built from the folder's own casing. - platform_attrs["fs_slug"] = ( - resolve_fs_folder(known_fs_slug, fs_platforms) or known_fs_slug - ) + known_fs_slug = platform and resolve_fs_slug(platform.slug, cnfg) + # `resolve_fs_slug` answers with a lowercased config key, but every + # path is built from the folder's own casing. A folder that isn't on + # disk either would only overwrite the stored one. + known_folder = known_fs_slug and resolve_fs_folder(known_fs_slug, fs_platforms) + if known_folder: + platform_attrs["fs_slug"] = known_folder platform_attrs["slug"] = resolve_platform_slug(fs_slug, cnfg) diff --git a/backend/tests/handler/test_fastapi.py b/backend/tests/handler/test_fastapi.py index cc9e386a9..38cd80618 100644 --- a/backend/tests/handler/test_fastapi.py +++ b/backend/tests/handler/test_fastapi.py @@ -79,6 +79,26 @@ async def test_scan_platform(): assert platform.tgdb_id is None +@pytest.mark.parametrize( + ("fs_platforms", "expected_fs_slug"), + [([], "gbc"), (["gbc2players"], "gbc2players")], +) +async def test_scan_platform_keeps_missing_folder_unless_alias_exists( + fs_platforms: list[str], expected_fs_slug: str +): + make_platform("gbc") + with patch.object( + meta_igdb_handler, + "get_platform_discovery", + new_callable=AsyncMock, + return_value={}, + ): + async with initialize_context(): + platform = await scan_platform("gbc", fs_platforms) + + assert platform.fs_slug == expected_fs_slug + + @pytest.mark.vcr async def test_scan_rom(): platform = make_platform("n64", id=1, name="Nintendo 64", igdb_id=4, hasheous_id=64) diff --git a/backend/tests/utils/test_platform_aliases.py b/backend/tests/utils/test_platform_aliases.py index ae8ee2207..a587122f5 100644 --- a/backend/tests/utils/test_platform_aliases.py +++ b/backend/tests/utils/test_platform_aliases.py @@ -66,6 +66,13 @@ def test_resolves_easyrpg_to_rpg_maker(): assert resolve_fs_slug(UPS.RPG_MAKER.value, _config()) == "easyrpg" +@pytest.mark.parametrize("folder", ["sgb", "sgb-msu1"]) +def test_super_game_boy_folders_stay_unidentified(folder: str): + """ES-DE and Batocera use sgb for the Super Game Boy, which has no RomM slug.""" + assert resolve_builtin_platform_slug(folder) is None + assert resolve_platform_slug(folder, _config()) == folder + + @pytest.mark.parametrize( ("folder", "slug"), [ diff --git a/backend/utils/platform_aliases.py b/backend/utils/platform_aliases.py index 7e19f825e..2ad490498 100644 --- a/backend/utils/platform_aliases.py +++ b/backend/utils/platform_aliases.py @@ -115,8 +115,6 @@ PLATFORM_FS_ALIASES: Final[dict[str, UPS]] = { "segastv": UPS.STV, "sfc": UPS.SFAM, "sg-1000": UPS.SG1000, - "sgb": UPS.GBC, - "sgb-msu1": UPS.GBC, "snes-msu1": UPS.SNES, "sufami": UPS.SUFAMI_TURBO, "supracan": UPS.SUPER_ACAN,