From 2173db889ba47396880bd2534942920d4cb16610 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 18 Oct 2026 14:31:52 +0200 Subject: [PATCH] fix: count values the RomM export normalises --- scripts/export_native.py | 3 +++ scripts/exporter/romm_exporter.py | 24 ++++++++++++++++++++++-- tests/test_export_counts.py | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/scripts/export_native.py b/scripts/export_native.py index a6fa3692..d6c45ed0 100644 --- a/scripts/export_native.py +++ b/scripts/export_native.py @@ -342,6 +342,9 @@ def landed_changes(exporter: object, systems: dict) -> LandedChanges: and not entry.hashes(field_name) and exporter.states(entry, field_name) ) + # A value the render rewrote though the model reads it as the + # platform's own (RomM's sha1 with a leading space). + changes.applied.extend(getattr(exporter, "normalized", [])) return changes diff --git a/scripts/exporter/romm_exporter.py b/scripts/exporter/romm_exporter.py index f5df5077..33292bfa 100644 --- a/scripts/exporter/romm_exporter.py +++ b/scripts/exporter/romm_exporter.py @@ -112,6 +112,7 @@ class Exporter(BaseExporter): if fe.platform is not None } self._first_addition = {} + self.normalized: list[str] = [] for system in sorted(systems.values(), key=lambda s: s.native_id): for fe in sorted(system.files, key=lambda f: f.name): key = (fe.native_system, fe.name) @@ -137,16 +138,35 @@ class Exporter(BaseExporter): if size is None and fe.platform is not None: size = fe.platform.get("size") if size is not None: - entry["size"] = str(int(size)) + self._write(entry, "size", str(int(size)), fe, "size") for field, hash_name in (("crc", "crc32"), ("md5", "md5"), ("sha1", "sha1")): value = fe.record_hash(hash_name) if value: - entry[field] = value + self._write(entry, field, value, fe, hash_name) output[key] = entry text = json.dumps(output, indent=2, ensure_ascii=False) + "\n" return {self.native_filename(): text} + def _write( + self, entry: dict, field: str, value: str, fe: NativeFile, name: str + ) -> None: + """Set one field, noting a value the model reads as RomM's own. + + RomM compares strings as stored: PLUTONIA.WAD's sha1 starts with a + space and never matches. The model normalises it away, so no + correction names it, yet the written file changes it. + """ + theirs = entry.get(field) + if ( + theirs is not None + and str(theirs) != value + and str(theirs).strip().lower() == value + and name not in fe.corrections + ): + self.normalized.append(f"{fe.native_system}/{fe.name} {name}") + entry[field] = value + def validate( self, systems: dict[str, NativeSystem], diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index 6755e9ac..9c59d021 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -492,6 +492,24 @@ class RommKeepsItsOwnKeys(unittest.TestCase): self.assertEqual(written["dc:boot.bin"]["size"], "2097152") self.assertFalse(exporter.writable(ours)) + def test_a_normalised_value_is_counted(self): + """known_bios_files.json writes PLUTONIA.WAD's sha1 with a leading + space, which RomM compares as stored and never matches. The export + wrote it stripped and the summary named no change for it.""" + from export_native import landed_changes # noqa: PLC0415 + + sha1 = "8" * 40 + fe = NativeFile("PLUTONIA.WAD", "doom/PLUTONIA.WAD", "doom", + platform={"size": 1024, "sha1": sha1}) + exporter = Romm() + original = json.dumps({"doom:PLUTONIA.WAD": {"size": "1024", "sha1": " " + sha1}}) + produced = exporter.render({"doom": NativeSystem("doom", files=[fe])}, None, + {exporter.native_filename(): original}) + written = json.loads(produced[exporter.native_filename()]) + self.assertEqual(written["doom:PLUTONIA.WAD"]["sha1"], sha1) + changes = landed_changes(exporter, {"doom": NativeSystem("doom", files=[fe])}) + self.assertEqual(changes.applied, ["doom/PLUTONIA.WAD sha1"]) + def test_the_shared_helper_reads_every_exporter_the_same_way(self): """RomM's writable is per instance; the base helper bound fe as self.""" from exporter import discover_exporters # noqa: PLC0415