From aac09aa6ad1babdd6c2bfd0cb101866ed70231a1 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:41:28 +0200 Subject: [PATCH] fix: count bizhawk corrections only where it writes --- scripts/exporter/bizhawk_exporter.py | 9 +++++++++ tests/test_export_counts.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/scripts/exporter/bizhawk_exporter.py b/scripts/exporter/bizhawk_exporter.py index a7fc9981..2d56dfd4 100644 --- a/scripts/exporter/bizhawk_exporter.py +++ b/scripts/exporter/bizhawk_exporter.py @@ -60,6 +60,14 @@ class Exporter(BaseExporter): # hang off exist nowhere else. return True + def states(self, fe: NativeFile, field_name: str) -> bool: + """A name that resolves to several SHA1s is left alone, so its + correction is not a change the database receives.""" + touchable = getattr(self, "_touchable", None) + if field_name == "sha1" and touchable is not None and fe.name.casefold() not in touchable: + return False + return super().states(fe, field_name) + @staticmethod def _unambiguous(systems: dict[str, NativeSystem]) -> dict[str, NativeFile]: """Files whose name identifies exactly one entry with a SHA1. @@ -96,6 +104,7 @@ class Exporter(BaseExporter): ) index = self._unambiguous(systems) + self._touchable = set(index) def commented_out(text: str, position: int) -> bool: """Whether the call sits on a line the compiler never sees. diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index fce1c7e0..41b53924 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -166,6 +166,21 @@ class EmuDeckWritesItsCorrections(unittest.TestCase): ) +class BizHawkCountsWhatItWrites(unittest.TestCase): + def test_an_ambiguous_name_is_not_counted(self): + from exporter.bizhawk_exporter import Exporter as BizHawk + + sha_a, sha_b, sha_c = "a" * 40, "b" * 40, "c" * 40 + first = NativeFile("bios.bin", "bios.bin", "S1", platform={"sha1": sha_a}, + truth={"sha1": sha_b}, corrections=["sha1"]) + second = NativeFile("bios.bin", "bios.bin", "S2", platform={"sha1": sha_c}) + systems = {"S1": NativeSystem("S1", files=[first]), "S2": NativeSystem("S2", files=[second])} + exporter = BizHawk() + source = f'File("{sha_a.upper()}", 16, "bios.bin")\n' + exporter.render(systems, None, {exporter.native_filename(): source}) + self.assertFalse(exporter.states(first, "sha1")) + + class ModelKeepsOneFileOneEntry(unittest.TestCase): def test_size_describes_the_hash_written(self): fe = NativeFile("boot.bin", "dc/boot.bin", "dc",