fix: let search order guard regional files

This commit is contained in:
Abdessamad Derraz committed 2026-10-10 10:56:09 +02:00
1 parent c2bdef4db4
commit 1cedc9930b
19 files changed
+1635 -790

No files matched your search

+6 -1
View File
@@ -64,16 +64,21 @@ class TheRegionRuleIsTheBuilders(unittest.TestCase):
if rng.random() < 0.2
else set(rng.sample(self.POOL, rng.randint(1, 2)))
)
priority = rng.choice([None, None, 5, 10, 100, 200])
entries[dest] = {"dest": dest, "regions": sorted(regions),
"region_groups": []}
if priority is not None:
entries[dest]["priority"] = priority
index[dest] = {"regions": regions,
"has_untagged": not regions, "emulators": []}
"has_untagged": not regions, "emulators": [],
"priorities": {priority}}
groups.setdefault(f"g{g}", []).append((dest, dest))
if f"g{g}" not in entries[dest]["region_groups"]:
entries[dest]["region_groups"].append(f"g{g}")
for entry in entries.values():
if not entry["regions"]:
del entry["regions"], entry["region_groups"]
entry.pop("priority", None)
requested = rng.sample(["north-america", "europe", "japan", "uk", "canada"],
rng.randint(1, 3))
return groups, index, list(entries.values()), requested
+21
View File
@@ -265,6 +265,25 @@ class TestResolveRegionDrops(unittest.TestCase):
def _drops(self, groups, requested):
return region.resolve_region_drops(groups, self.index, requested)
def test_a_world_file_the_code_ranks_lower_keeps_the_regional_ones(self):
"""DuckStation looks for its PS1 images (5) before the world PS2 ones
(100): asked for Brazil, it kept only the PS2 fallbacks."""
index = region.build_region_index({"duckstation": {"files": [
{"name": "scph5501.bin", "region": ["north-america"], "priority": 5},
{"name": "ps2_scph30001.bin", "region": ["north-america"], "priority": 150},
{"name": "ps2_scph10000.bin", "region": ["world"], "priority": 100},
]}})
groups = {"psx": [(n, n) for n in ("scph5501.bin", "ps2_scph30001.bin",
"ps2_scph10000.bin")]}
self.assertEqual(
region.resolve_region_drops(groups, index, ["brazil"]), {"ps2_scph30001.bin"}
)
def test_without_ranks_the_world_file_still_wins(self):
groups = {"psx": [("scph5501.bin", "scph5501.bin"),
("psxonpsp660.bin", "psxonpsp660.bin")]}
self.assertEqual(self._drops(groups, ["brazil"]), {"scph5501.bin"})
def test_best_rank_wins_and_siblings_drop(self):
groups = {
"psx": [
@@ -677,6 +696,8 @@ class RegionalRequestsKeepWhatTheCodeLoads(unittest.TestCase):
("ace-dl", ["denmark"], "private/firmware/XMEM_FW_3_15_UK.rom"),
("ace-dl", ["spain"], "private/hacker/hacker481fr.rom"),
("ace-dl", ["france"], "private/firmware/Amstrad_s4.cpr"),
("duckstation", ["brazil"], "scph5501.bin"),
("duckstation", ["south-korea"], "scph5500.bin"),
)
def test_each_request_keeps_its_file(self):