From 315549a5b04624427155fc2146ec2889906e9498 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 10 Oct 2026 11:20:33 +0200 Subject: [PATCH] fix: decide destination winners without data dirs --- scripts/generate_pack.py | 9 +++++---- scripts/verify.py | 5 ++--- tests/test_archive_choice.py | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index eb608b36..05144f60 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -442,7 +442,6 @@ def _preferred_entries( base_dest: str, required_only: bool, zip_contents, - data_registry, offline, ) -> dict[str, int]: """Which declaration wins when several claim the same destination. @@ -451,6 +450,9 @@ def _preferred_entries( in one and hash-constrained in another. First-come dedup would let the bare entry pack whatever answers to the name, so a constrained sibling that resolves by content claims the destination instead. + The choice is about the baseline and reads no data directory, for the + pack, the manifest and verify alike: verify alone passed the registry + and could crown a declaration only a data/ cache satisfies. """ preferred_entries: dict[str, int] = {} dest_entries: dict[str, list[dict]] = {} @@ -481,7 +483,6 @@ def _preferred_entries( db, bios_dir, zip_contents, - data_dir_registry=data_registry, offline=offline, )) for fe in constrained @@ -734,7 +735,7 @@ def generate_pack( # atari-5200). No data directories: the choice is about the baseline. preferred_entries = _preferred_entries( pack_systems, db, bios_dir, base_dest, required_only, - zip_contents, None, offline, + zip_contents, offline, ) # Region selection is decided once, over both the platform baseline and the @@ -3362,7 +3363,7 @@ def generate_manifest( # does; a manifest carries no data directories. preferred_entries = _preferred_entries( pack_systems, db, bios_dir, base_dest, required_only, - zip_contents, None, offline, + zip_contents, offline, ) for sys_id, system in sorted(pack_systems.items()): for file_entry in system.get("files", []): diff --git a/scripts/verify.py b/scripts/verify.py index 5935b94c..cf513ee6 100644 --- a/scripts/verify.py +++ b/scripts/verify.py @@ -776,14 +776,13 @@ def _mark_unplaced(config: dict, undeclared: list[dict], profiles: dict) -> None def _twin_index( verify_systems: dict, db: dict, base_dest: str, zip_contents: dict, - data_dir_registry: dict | None, ) -> tuple[dict[str, int], dict[int, tuple[str, dict]]]: """Which declaration the pack ships at each destination, and every declaration by id.""" from generate_pack import _preferred_entries preferred_entries = _preferred_entries( verify_systems, db, DEFAULT_BIOS_DIR, base_dest, False, - zip_contents, data_dir_registry, True, + zip_contents, True, ) winners = { id(fe): (sid, fe) @@ -968,7 +967,7 @@ def verify_platform( # xroar component hashes bios/disk.rom and finds the PC-88 ROM. base_dest = config.get("base_destination", "") preferred_entries, winners = _twin_index( - verify_systems, db, base_dest, zip_contents, data_dir_registry + verify_systems, db, base_dest, zip_contents ) for sys_id, system in verify_systems.items(): diff --git a/tests/test_archive_choice.py b/tests/test_archive_choice.py index 718ba7ad..46421a1a 100644 --- a/tests/test_archive_choice.py +++ b/tests/test_archive_choice.py @@ -54,12 +54,26 @@ class PreferredArchive(unittest.TestCase): ] systems = {"s": {"files": declarations}} preferred = generate_pack._preferred_entries( - systems, db, "bios", "", False, {}, None, True) + systems, db, "bios", "", False, {}, True) chosen = next(fe for fe in declarations if id(fe) == preferred["set.zip"]) path, _status = generate_pack.resolve_file(chosen, db, "bios", {}, offline=True) self.assertEqual(path, "bios/b/set.zip") +class OneWinnerRuleForEveryReader(unittest.TestCase): + """verify passed the data-directory registry to the winner rule, the pack + and the manifest passed none: a declaration only a data/ cache satisfies + won in the report and lost in the pack. The rule takes no registry.""" + + def test_the_rule_reads_no_data_directory(self): + import inspect # noqa: PLC0415 + + import generate_pack # noqa: PLC0415 + + parameters = inspect.signature(generate_pack._preferred_entries).parameters + self.assertFalse([name for name in parameters if "registry" in name]) + + class IntegrityChecksEveryMember(unittest.TestCase): """A pack holding one ROM of an archive declared per ROM fails its check.