From 19b88ca055e586aa92896b8dbe7c426f69c53afb Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 20 Oct 2026 14:54:16 +0200 Subject: [PATCH] fix: refuse an export without its truth dist/ is not committed and exports/ is. On a fresh clone, or with a mistyped --truth-dir, the export copied each platform's file back uncorrected, said OK and replaced the corrected export in exports/. check_freshness then reported a stale export instead of the missing model. The platform now fails, writes nothing, and names the generate_truth command. --- scripts/export_native.py | 8 ++++++-- tests/test_exporters.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/scripts/export_native.py b/scripts/export_native.py index dea289a2..0f9ad98a 100644 --- a/scripts/export_native.py +++ b/scripts/export_native.py @@ -457,8 +457,12 @@ def export_platform( except StaleTruth as exc: return False, [str(exc)] if truth is None: - truth = {} - messages.append(f"no truth for {platform}, only the platform's own data") + # Without a truth the export is the platform's file copied back, and + # it replaced the corrected one in exports/ on a fresh clone. + return False, [ + f"{truth_dir / f'{platform}.yml'} is absent: run " + f"python scripts/generate_truth.py --platform {platform}" + ] systems, report = build_native_model(truth, scraped) if not systems: diff --git a/tests/test_exporters.py b/tests/test_exporters.py index c616ad62..1eb64f10 100644 --- a/tests/test_exporters.py +++ b/tests/test_exporters.py @@ -953,6 +953,31 @@ class AnExportLeavesNoStaleFile(unittest.TestCase): self.assertLess(body.index("_remove_stale("), body.index(".write_text(")) +class AnExportWithoutTruthIsRefused(unittest.TestCase): + """dist/ is not committed and exports/ is. On a fresh clone, or with a + mistyped --truth-dir, the export copied each platform's file back + uncorrected, said OK, and replaced the corrected export in exports/.""" + + def test_nothing_is_written_and_the_run_fails(self): + import export_native # noqa: PLC0415 + + exporter = discover_exporters()["batocera"] + with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + output = Path(tmp) / "out" + published = output / "batocera" / "batocera-systems" + published.parent.mkdir(parents=True) + published.write_text("corrected", encoding="utf-8") + ok, messages = export_native.export_platform( + "batocera", exporter, Path(tmp) / "no-truth", output, + str(REPO_ROOT / "platforms"), Path(tmp) / "no-cache", False, + ) + self.assertFalse(ok) + self.assertIn("generate_truth.py", messages[0]) + self.assertEqual(published.read_text(encoding="utf-8"), "corrected") + self.assertEqual(sorted(p.name for p in output.rglob("*")), + ["batocera", "batocera-systems"]) + + class RommKeepsItsFixture(unittest.TestCase): """The export rebuilt known_bios_files.json from our model in our order: 3 hash corrections came out as a 3116-line diff, and a key RomM had that