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.
This commit is contained in:
Abdessamad Derraz committed 2026-10-20 14:54:16 +02:00
1 parent 63556b4873
commit 19b88ca055
2 files changed
+31 -2

No files matched your search

+6 -2
View File
@@ -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:
+25
View File
@@ -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