diff --git a/scripts/exporter/baseline.py b/scripts/exporter/baseline.py index 90984691..5fde02a5 100644 --- a/scripts/exporter/baseline.py +++ b/scripts/exporter/baseline.py @@ -265,6 +265,16 @@ def build_native_model( norm_to_scraped: dict[str, str] = { _norm_system_id(key): key for key in scraped_systems } + # Every system the platform names, files or none: an addition elsewhere + # is filed under our own slug. + platform_ids = { + native_id + for key, sys_data in scraped_systems.items() + for native_id in ( + sys_data.get("native_id") or key, + *(_native_id_of(key, sys_data, fe) for fe in sys_data.get("files", [])), + ) + } native_by_norm: dict[str, str] = {} for system in systems.values(): native_by_norm.setdefault(_norm_system_id(system.native_id), system.native_id) @@ -431,7 +441,7 @@ def build_native_model( destination=destination, native_system=native_id, truth=truth_entry, - foreign_system=not system.from_platform, + foreign_system=native_id not in platform_ids, ) ) report.files_added += 1 diff --git a/tests/test_exporters.py b/tests/test_exporters.py index cacd306d..10280f1b 100644 --- a/tests/test_exporters.py +++ b/tests/test_exporters.py @@ -917,6 +917,18 @@ class BatoceraExport(unittest.TestCase): ) self.assertNotIn('"nintendo-snes"', produced["batocera-systems"]) + def test_a_system_the_platform_names_without_files_is_its_own(self): + """A system the platform declares empty still has the platform's id.""" + scraped = {"systems": {"nintendo-snes": {"native_id": "snes", "files": []}}} + truth = {"systems": {"nintendo-snes": {"files": [{ + "name": "st010.zip", "path": "st010.zip", "md5": "2" * 32, + "required": False, "_cores": ["snes9x"], + }]}}} + systems, _ = build_native_model(truth, scraped) + (entry,) = systems["snes"].files + self.assertFalse(entry.foreign_system) + self.assertTrue(discover_exporters()["batocera"]().writable(entry)) + def test_writing_without_the_platform_file_is_refused(self): """A systems dict alone is not the script Batocera runs.""" systems, report = model()