From fd8db894d8763734111ccc01a1a11d32aedd4a87 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 10 Oct 2026 12:16:11 +0200 Subject: [PATCH] fix: test extras grouping through the real chain --- scripts/generate_pack.py | 1 - scripts/packextras.py | 15 ------------ tests/test_e2e.py | 49 +++++++++++++++++++++++++++------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index 05144f60..312e9ce2 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -3798,7 +3798,6 @@ from packextras import ( # noqa: E402,F401 _detect_extras_prefix, _detect_slug_structure, _map_emulator_to_slug, - _emulator_systems_index, _collect_emulator_extras, _extra_system_ids, platform_region_groups, diff --git a/scripts/packextras.py b/scripts/packextras.py index 63fd5ccc..bfecfd16 100644 --- a/scripts/packextras.py +++ b/scripts/packextras.py @@ -15,22 +15,7 @@ from common import runs_standalone from common import sanitize_pack_path from common import size_fits from validation import read_from_system_dir -def _emulator_systems_index(emu_profiles: dict | None) -> dict[str, list[str]]: - """Map both the profile key and its display name to the profile's systems. - find_undeclared_files reports the display name ("Beetle PSX (Mednafen - PSX)"), while the profile dictionary is keyed by slug. A key-only lookup - therefore missed almost every core, dropping its files into one shared - bucket and losing the per-system grouping the narrowing passes rely on. - """ - index: dict[str, list[str]] = {} - for key, profile in (emu_profiles or {}).items(): - systems = list(profile.get("systems", [])) - index[key] = systems - display = profile.get("emulator", "") - if display: - index.setdefault(display, systems) - return index def _detect_extras_prefix(config: dict, base_dest: str) -> str: """The prefix core-extra destinations take (may be empty). diff --git a/tests/test_e2e.py b/tests/test_e2e.py index 863c2b4f..f61c477e 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -6151,26 +6151,43 @@ struct BurnDriver BurnDrvneogeo = { self.assertIn("sony-playstation", readme) def test_extras_group_under_their_system_not_a_shared_bucket(self): - """find_undeclared_files reports the display name, the profiles are - keyed by slug; a key-only lookup put nearly every core extra in one - bucket and lost the per-system grouping both narrowing passes need.""" - from generate_pack import _emulator_systems_index + """A core extra competes in its system's group: the chain from the + gap report (system, systems) to platform_region_groups, not a + dictionary built by hand. Without it every extra stood alone and + --region compared nothing.""" + import hashlib # noqa: PLC0415 - index = _emulator_systems_index( - { - "beetle_psx": { - "emulator": "Beetle PSX (Mednafen PSX)", - "systems": ["sony-playstation"], - }, - "beebem": {"emulator": "beebem", "systems": ["bbc-micro-b"]}, - } + from packextras import platform_region_groups # noqa: PLC0415 + + files, by_name = {}, {} + for name in ("core_us.bin", "core_jp.bin"): + payload = name.encode() + path = os.path.join(self.bios_dir, name) + with open(path, "wb") as handle: + handle.write(payload) + sha1 = hashlib.sha1(payload).hexdigest() + files[sha1] = {"path": path, "name": name, "size": len(payload), + "md5": hashlib.md5(payload).hexdigest()} + by_name[name] = [sha1] + db = {"files": files, "indexes": {"by_name": by_name, "by_md5": {}, + "by_crc32": {}, "by_path_suffix": {}}} + profiles = {"psxcore": { + "emulator": "PSX Core (Display Name)", "type": "libretro", + "systems": ["sony-playstation"], + "files": [{"name": "core_us.bin", "region": ["north-america"]}, + {"name": "core_jp.bin", "region": ["japan"]}], + }} + config = {"platform": "P", "cores": ["psxcore"], "base_destination": "system", + "systems": {"sony-playstation": {"files": [ + {"name": "declared.bin", "destination": "declared.bin"}]}}} + groups, _ = platform_region_groups( + config, config["systems"], self.emulators_dir, db, "system", profiles, ) - self.assertEqual(index["beetle_psx"], ["sony-playstation"]) self.assertEqual( - index["Beetle PSX (Mednafen PSX)"], ["sony-playstation"] + sorted(groups["sony-playstation"]), + [("core_jp.bin", "core_jp.bin"), ("core_us.bin", "core_us.bin"), + ("declared.bin", "declared.bin")], ) - self.assertEqual(index["beebem"], ["bbc-micro-b"]) - self.assertNotIn("_extras", index) def test_slot_narrowed_pack_gets_its_own_name(self): names = {