From 3d2a521f8aa1aae231c114ff9c23b10e10ebc960 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 21 Oct 2026 09:52:13 +0200 Subject: [PATCH] fix: match profile_sync --system as verify does --system compared the raw id, so the normalized spelling printed by verify.py --list-systems selected 1 Saturn profile of 11. The hint now counts the spellings that listing prints. --- scripts/profile_sync.py | 18 +++++++++++++++--- tests/test_profile_sync.py | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index bec43bcc..dd5f65ef 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -30,7 +30,13 @@ import yaml sys.path.insert(0, os.path.dirname(__file__)) import upstream -from common import github_token, load_emulator_profiles, suggest_names +from common import ( + _norm_system_id, + github_token, + load_emulator_profiles, + suggest_names, + system_index, +) from hashing import parse_hash_list from sourceref import ( # noqa: F401 (re-exported for callers and tests) # noqa: F401 (the prose grammar, re-exported) _ANNOTATION_RE, @@ -3589,11 +3595,16 @@ def select_profiles(profiles: dict, args: argparse.Namespace) -> dict: ) return {args.emulator: profiles[args.emulator]} + # --system matches as verify.py --list-systems lists and --system selects: + # by normalized id, so `saturn` reaches the profiles declaring sega-saturn. + wanted_system = _norm_system_id(args.system) if args.system else None selected = {} for name, profile in sorted(profiles.items()): if profile.get("type") in ("alias", "test"): continue - if args.system and args.system not in (profile.get("systems") or []): + if wanted_system and wanted_system not in { + _norm_system_id(str(s)) for s in profile.get("systems") or [] + }: continue if args.type_ and profile.get("type") != args.type_: continue @@ -3615,7 +3626,8 @@ def select_profiles(profiles: dict, args: argparse.Namespace) -> dict: ) hint = "" if args.system: - systems = sorted({s for p in profiles.values() for s in p.get("systems") or []}) + # Suggested from the spellings the named listing prints. + systems = sorted(spelling for spelling, _ in system_index(profiles).values()) hint = " " + suggest_names([args.system], systems, "verify.py --list-systems") elif args.type_: kinds = sorted({str(p.get("type")) for p in profiles.values() if p.get("type")}) diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index 11dd3bd9..124197d5 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -4399,6 +4399,27 @@ class TestSelectionNamesWhatMatchedNothing(unittest.TestCase): selected = profile_sync.select_profiles(self.PROFILES, self._args(system="atari-lynx")) self.assertEqual(sorted(selected), ["handy", "mednafen_lynx"]) + def test_system_matches_as_the_listing_does(self): + """verify.py --list-systems printed `saturn`, which selected 1 profile + of 11 because 10 declare sega-saturn.""" + profiles = { + "a": {"type": "libretro", "systems": ["sega-saturn"]}, + "b": {"type": "libretro", "systems": ["saturn"]}, + } + for spelling in ("saturn", "sega-saturn"): + selected = profile_sync.select_profiles(profiles, self._args(system=spelling)) + self.assertEqual(sorted(selected), ["a", "b"]) + + def test_the_hint_counts_what_the_listing_prints(self): + profiles = { + "a": {"type": "libretro", "systems": ["sega-saturn"]}, + "b": {"type": "libretro", "systems": ["saturn"]}, + "c": {"type": "libretro", "systems": ["atari-lynx"]}, + } + with self.assertRaises(SystemExit) as caught: + profile_sync.select_profiles(profiles, self._args(system="nothing")) + self.assertIn("Known: atari-lynx, sega-saturn.", str(caught.exception.code)) + class TestTreeUrlIntoADirectory(unittest.TestCase):