diff --git a/scripts/truth.py b/scripts/truth.py index 4cced3f7..b2ce7a75 100644 --- a/scripts/truth.py +++ b/scripts/truth.py @@ -8,7 +8,7 @@ from __future__ import annotations import sys -from common import _norm_system_id, resolve_platform_cores +from common import _norm_system_id, resolve_platform_cores, runs_standalone from validation import filter_files_by_mode @@ -22,28 +22,6 @@ def _serialize_source_ref(sr: object) -> str: return str(sr) -def _determine_core_mode( - emu_name: str, - profile: dict, - cores_config: str | list | None, - standalone_set: set[str] | None, -) -> str: - """Determine effective mode (libretro/standalone) for a resolved core.""" - if cores_config == "all_libretro": - return "libretro" - if standalone_set is not None: - profile_names = {emu_name} | {str(c) for c in profile.get("cores", [])} - if profile_names & standalone_set: - return "standalone" - return "libretro" - ptype = profile.get("type", "libretro") - if "standalone" in ptype and "libretro" in ptype: - return "both" - if "standalone" in ptype: - return "standalone" - return "libretro" - - def _enrich_hashes(entry: dict, db: dict) -> None: """Fill missing sibling hashes from the database, ground-truth preserving. @@ -288,13 +266,10 @@ def generate_platform_truth( Returns a dict with platform metadata, systems, and per-file details including which cores reference each file. """ - cores_config = config.get("cores") - - # Resolve standalone set for mode determination - standalone_set: set[str] | None = None - standalone_cores = config.get("standalone_cores") - if isinstance(standalone_cores, list): - standalone_set = {str(c) for c in standalone_cores} + # The layout rule verify and the pack builder apply: truth guessed its + # own from the profile type where the platform names no standalone + # emulator, and kept files the pack never carries. + standalone_set = {str(c) for c in config.get("standalone_cores") or []} resolved = resolve_platform_cores(config, profiles, target_cores) @@ -347,14 +322,10 @@ def generate_platform_truth( continue cores_profiled.add(emu_name) - mode = _determine_core_mode(emu_name, profile, cores_config, standalone_set) - raw_files = profile.get("files", []) - if mode == "both": - filtered = raw_files - else: - filtered = filter_files_by_mode( - raw_files, standalone=(mode == "standalone") - ) + filtered = filter_files_by_mode( + profile.get("files", []), + standalone=runs_standalone(emu_name, profile, standalone_set), + ) for fe in filtered: profile_sid = fe.get("system", "") diff --git a/tests/test_truth_layout.py b/tests/test_truth_layout.py new file mode 100644 index 00000000..b87d3e89 --- /dev/null +++ b/tests/test_truth_layout.py @@ -0,0 +1,55 @@ +"""Truth lays a core out the way verify and the pack builder do. + +truth.py kept its own rule: with no standalone_cores it read the profile +type, called a dual profile "both" and a standalone one "standalone", and +kept `mode: standalone` files that runs_standalone, and so the pack, leave +out on RetroBat, EmuDeck and RetroDECK. +""" + +from __future__ import annotations + +import sys +import unittest +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(REPO_ROOT / "scripts")) + +from truth import generate_platform_truth # noqa: E402 + + +def _names(truth: dict) -> set[str]: + return { + f["name"] + for system in truth.get("systems", {}).values() + for f in system.get("files", []) + } + + +class TruthFollowsRunsStandalone(unittest.TestCase): + PROFILE = { + "emulator": "Dual", + "type": "standalone + libretro", + "systems": ["sony-playstation"], + "files": [ + {"name": "both.bin", "system": "sony-playstation", "md5": "a" * 32}, + {"name": "only_sa.bin", "system": "sony-playstation", "md5": "b" * 32, + "mode": "standalone"}, + {"name": "only_lr.bin", "system": "sony-playstation", "md5": "c" * 32, + "mode": "libretro"}, + ], + } + + def test_no_standalone_cores_means_libretro_layout(self): + config = {"cores": ["dual"], "systems": {}} + truth = generate_platform_truth("p", config, {}, {"dual": self.PROFILE}) + self.assertEqual(_names(truth), {"both.bin", "only_lr.bin"}) + + def test_named_standalone_core_gets_its_files(self): + config = {"cores": ["dual"], "standalone_cores": ["dual"], "systems": {}} + truth = generate_platform_truth("p", config, {}, {"dual": self.PROFILE}) + self.assertEqual(_names(truth), {"both.bin", "only_sa.bin"}) + + +if __name__ == "__main__": + unittest.main()