fix: count values the RomM export normalises

This commit is contained in:
Abdessamad Derraz committed 2026-10-18 14:31:52 +02:00
1 parent 070e90eb64
commit 2173db889b
3 files changed
+43 -2

No files matched your search

+3
View File
@@ -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
+22 -2
View File
@@ -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],
+18
View File
@@ -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