From d86215235e91026994bc189caeb2fe4856c4979b Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:28:18 +0200 Subject: [PATCH] fix: keep scan copies out of region choices --- scripts/packextras.py | 7 +++- tests/test_region_agnostic_scan.py | 54 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/test_region_agnostic_scan.py diff --git a/scripts/packextras.py b/scripts/packextras.py index 476b0e6a..41d0e0bc 100644 --- a/scripts/packextras.py +++ b/scripts/packextras.py @@ -893,7 +893,12 @@ def platform_region_groups( extra.get("source_path", ""), ) ] = dest - for group_id in extra_region_groups(extra): + # A file a filename-agnostic scan accepts by shape competes only if + # its seed names a region: PCSX2 picks no PS2 BIOS by territory, and + # looked up by name its scph50006 took DuckStation's [japan], which + # describes DuckStation's own PS1-on-PS2 choice. + competes = not extra.get("agnostic_scan") or extra.get("region") + for group_id in extra_region_groups(extra) if competes else (): groups.setdefault(group_id, []).append((dest, name)) if extras_out is not None: extras_out.append(extra) diff --git a/tests/test_region_agnostic_scan.py b/tests/test_region_agnostic_scan.py new file mode 100644 index 00000000..35175f38 --- /dev/null +++ b/tests/test_region_agnostic_scan.py @@ -0,0 +1,54 @@ +"""A file an agnostic scan accepts by shape keeps out of region choices. + +PCSX2 picks no PS2 BIOS by territory, yet the copies its scan put under +pcsx2/bios/ were looked up by name and took DuckStation's region, which +describes DuckStation's own PS1-on-PS2 choice: `--region eu` withdrew +pcsx2/bios/ps2_scph50006.bin from RetroArch, Lakka, RetroPie, RetroDECK and +ROCKNIX. Reads the repository: skips when the database is absent. +""" + +from __future__ import annotations + +import os +import sys +import unittest +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(REPO_ROOT / "scripts")) + + +class ScanCopiesStay(unittest.TestCase): + def test_no_scan_copy_is_withdrawn(self): + if not (REPO_ROOT / "database.json").exists(): + self.skipTest("database.json is not built") + previous = os.getcwd() + os.chdir(REPO_ROOT) + self.addCleanup(os.chdir, previous) + import region as region_mod + from common import load_database, load_emulator_profiles, load_platform_config + from packextras import platform_region_groups + + db = load_database("database.json") + profiles = load_emulator_profiles("emulators") + config = load_platform_config("retroarch") + extras: list[dict] = [] + groups, _ = platform_region_groups( + config, config["systems"], "emulators", db, + config.get("base_destination", ""), profiles, extras_out=extras, + ) + scanned = { + e["destination"] for e in extras + if e.get("agnostic_scan") and not e.get("region") + } + if not scanned: + self.skipTest("no agnostic scan copy in the RetroArch pack") + index = region_mod.platform_region_index(config, profiles) + for regions in (["europe"], ["japan"], ["north-america"]): + with self.subTest(regions=regions): + drops = region_mod.resolve_region_drops(groups, index, regions) + self.assertEqual(sorted(drops & scanned), []) + + +if __name__ == "__main__": + unittest.main()