Files
romm/backend/tests/utils/test_platform_aliases.py
Spinnich 60703be09c chore(platforms): split arcade aliases into per-emulator-family slugs (#5273)
* feat(platforms): split arcade aliases into per-emulator-family slugs

Give MAME, AdvanceMAME, FBNeo, FBA, Daphne, Singe and the arcade boards
that need their own emulator (NAOMI/NAOMI 2/NAOMI GD-ROM, Model 2/3,
Hikaru, Triforce, Lindbergh, Namco System 246/3xx, Gaelco, ...) their own
slugs with verified provider IDs. Providers without a dedicated entry fall
back to their Arcade platform via arcade_fallbacks(). MAME-only boards
(CPS1-3, System 16/32, Model 1, Namco 22) stay aliases of arcade.

Refs #5272

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(platforms): code-review pass on arcade slugs

- Retry IGDB on unmatched scans for every platform IGDB resolves, not
  just slugs in IGDB_PLATFORM_LIST.
- Resolve config binding/version values through the alias table, so a
  binding to a retired slug (cps2, model1, ...) still lands on a platform.
- Alias the Batocera `typex` folder to type-x.
- Build provider id->slug reverse maps before merging Arcade fallbacks.
- Share one MAME title lookup between base_handler and libretro.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(platforms): simplify pass on arcade slugs

- Alias the three RomM-keyed IGDB versions inside IGDB_PLATFORM_VERSIONS,
  dropping IGDB_VERSION_SLUGS and _version_slug.
- Derive EmulatorJS arcade entries from ARCADE_SET_PLATFORMS.
- Remove the unused provider id->slug reverse maps, so the Arcade
  fallback merge no longer has an ordering constraint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(platforms): humanizer pass on arcade slug comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(platforms): settle arcade slug review decisions

- Migration 0154 moves platforms still on a retired MAME-only board slug
  (cps1-3, model1, system16, system32, system-32) to arcade, so no row
  carries a slug the enum no longer has.
- MAME shortname expansion keys off the RomM slug via
  MAME_SHORTNAME_PLATFORMS instead of per-provider arcade ids, so Daphne,
  Singe, Type X and Lindbergh sets are no longer read as MAME sets. Neo Geo
  now expands at ScreenScraper too, as it already did at IGDB and Moby.
- fba offers fbneo before the FinalBurn Alpha CPS cores.
- AdvanceMAME leaves the WebRcade feed; EmulatorJS and WebRcade share
  PLAYABLE_ARCADE_SET_PLATFORMS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(platforms): code-review pass (xhigh) on arcade slugs

Verify arcade-board BIOS files against the known list's arcade entries,
and make migration 0154 match retired slugs case-insensitively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(platforms): simplify pass on arcade slugs

Apply IGDB family overrides once in get_platform instead of on each
return path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(platforms): use a slug with no shipped icon

singe now ships an icon, so the no-icon prefetch test needs a slug that never will.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(platforms): add a teknoparrot arcade slug

TeknoParrot runs PC-based arcade boards outside the MAME/FinalBurn family,
so its folder gets its own platform (RetroBat and ES-DE both use
`teknoparrot`). Providers fall back to their Arcade entry, MAME shortname
expansion skips it, and it gets a placeholder icon copied from `arcade`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(platforms): give each arcade-family icon its own marquee title

Redraws the ARCADE marquee on the copied cabinet icons with each
platform's name, in the Bungee typeface with the original inline and
extrusion styling. Sega boards use Sega blue, Namco systems Namco red,
and Type X Taito blue; the rest keep the original amber.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(platforms): code-review pass (xhigh) on arcade slugs

Neo Geo BIOS lives under arcade in the known BIOS list, so map
neogeoaes and neogeomvs there too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(platforms): simplify pass on arcade slug tests

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>
2026-10-28 19:53:06 -04:00

162 lines
5.7 KiB
Python

from pathlib import Path
import pytest
import yaml
from config.config_manager import Config
from utils.platform_aliases import (
PLATFORM_FS_ALIASES,
PLATFORM_SLUG_FOLDERS,
resolve_fs_folder,
resolve_fs_slug,
resolve_platform_slug,
)
from utils.platform_slugs import UniversalPlatformSlug as UPS
EXAMPLE_CONFIGS = sorted((Path(__file__).parents[3] / "examples").glob("config.*.yml"))
def _config(
bindings: dict[str, str] | None = None,
versions: dict[str, str] | None = None,
) -> Config:
return Config(
PLATFORMS_BINDING=bindings or {},
PLATFORMS_VERSIONS=versions or {},
)
def test_alias_keys_are_not_slugs():
"""An alias for a folder name that already is a slug could never be reached."""
assert not [k for k in PLATFORM_FS_ALIASES if k in UPS]
def test_alias_keys_are_lowercase():
assert all(k == k.lower() for k in PLATFORM_FS_ALIASES)
def test_resolves_frontend_folder_names():
config = _config()
assert resolve_platform_slug("gamecube", config) == "ngc"
assert resolve_platform_slug("megadrive", config) == "genesis"
assert resolve_platform_slug("n3ds", config) == "3ds"
assert resolve_platform_slug("GameCube", config) == "ngc"
def test_folder_without_alias_passes_through():
config = _config()
# atari800 is a Batocera folder name that is also a RomM slug, so it can
# only be remapped through a config binding.
assert resolve_platform_slug("atari800", config) == "atari800"
assert resolve_platform_slug("my-custom-folder", config) == "my-custom-folder"
def test_resolves_zc_folders_to_zelda_classic():
"""zc210 (Batocera/libretro 2.10) and zc250 (2.50) both map to Zelda Classic."""
assert resolve_platform_slug("zc210", _config()) == UPS.ZELDA_CLASSIC.value
assert resolve_platform_slug("zc250", _config()) == UPS.ZELDA_CLASSIC.value
# Two folder names map here, so no single reverse folder is canonical.
assert resolve_fs_slug(UPS.ZELDA_CLASSIC.value, _config()) is None
def test_resolves_easyrpg_to_rpg_maker():
"""Batocera, RetroBat and ES-DE all name the RPG Maker folder after the engine."""
assert resolve_platform_slug("easyrpg", _config()) == UPS.RPG_MAKER.value
assert resolve_fs_slug(UPS.RPG_MAKER.value, _config()) == "easyrpg"
@pytest.mark.parametrize(
("folder", "slug"),
[
("mame", UPS.MAME),
("fbneo", UPS.FBNEO),
("naomi", UPS.NAOMI),
("lindbergh", UPS.LINDBERGH),
("laserdisc", UPS.DAPHNE),
("cps2", UPS.ARCADE),
("system16", UPS.ARCADE),
("model1", UPS.ARCADE),
("namco22", UPS.ARCADE),
("system-32", UPS.ARCADE),
("typex", UPS.TYPE_X),
("teknoparrot", UPS.TEKNOPARROT),
],
)
def test_arcade_folders_resolve_by_emulator(folder: str, slug: UPS):
"""Emulator families and boards with their own emulator keep a slug; MAME-only boards are Arcade."""
assert resolve_platform_slug(folder, _config()) == slug.value
def test_a_binding_to_an_alias_resolves_to_its_platform():
config = _config(bindings={"capcom": "cps2"}, versions={"sega": "Mastersystem"})
assert resolve_platform_slug("capcom", config) == UPS.ARCADE.value
assert resolve_platform_slug("sega", config) == UPS.SMS.value
assert resolve_fs_slug(UPS.SMS.value, config) == "sega"
def test_binding_and_version_win_over_alias():
bound = _config(bindings={"gamecube": "arcade"})
assert resolve_platform_slug("gamecube", bound) == "arcade"
versioned = _config(versions={"gamecube": "wii"})
assert resolve_platform_slug("gamecube", versioned) == "wii"
both = _config(bindings={"gamecube": "arcade"}, versions={"gamecube": "wii"})
assert resolve_platform_slug("gamecube", both) == "arcade"
def test_resolution_is_case_insensitive():
config = _config(bindings={"gamecube": "arcade"})
assert resolve_platform_slug("GameCube", config) == "arcade"
assert resolve_platform_slug("SNES", _config()) == "snes"
def test_resolves_slug_back_to_folder_name():
assert resolve_fs_slug("dc", _config()) == "dreamcast"
assert resolve_fs_slug("wii", _config(bindings={"wiiware": "wii"})) == "wiiware"
def test_slug_reached_by_several_folders_has_no_reverse():
"""amiga500, amiga600 and amiga1200 all resolve to amiga, so none is canonical."""
assert resolve_fs_slug("amiga", _config()) is None
assert resolve_fs_slug("ngc", _config()) is None
assert resolve_fs_slug("my-custom-slug", _config()) is None
def test_resolves_a_config_key_to_the_folder_on_disk():
"""Config keys are lowercased; paths need the folder's own casing."""
assert resolve_fs_folder("nintendo 64", ["Nintendo 64", "psx"]) == "Nintendo 64"
def test_resolves_a_folder_that_is_not_on_disk_to_nothing():
assert resolve_fs_folder("nintendo 64", ["psx"]) is None
def test_two_folders_differing_only_by_case_each_resolve_to_themselves():
"""A case-sensitive filesystem allows both; neither may claim the other."""
folders = ["PSX", "psx"]
assert resolve_fs_folder("psx", folders) == "psx"
assert resolve_fs_folder("PSX", folders) == "PSX"
def test_reverse_map_agrees_with_alias_table():
for slug, fs_slug in PLATFORM_SLUG_FOLDERS.items():
assert PLATFORM_FS_ALIASES[fs_slug].value == slug
@pytest.mark.parametrize("config_file", EXAMPLE_CONFIGS, ids=lambda p: p.name)
def test_example_configs_list_only_needed_overrides(config_file: Path):
"""Every example entry must be one the alias table cannot resolve on its own."""
raw = yaml.safe_load(config_file.read_text()) or {}
platforms = (raw.get("system") or {}).get("platforms") or {}
empty = _config()
redundant = {
fs_slug: slug
for fs_slug, slug in platforms.items()
if resolve_platform_slug(fs_slug, empty) == slug
}
assert not redundant