fix: count bizhawk corrections only where it writes

This commit is contained in:
Abdessamad Derraz committed 2026-10-06 09:41:28 +02:00
1 parent d085fd895b
commit aac09aa6ad
2 files changed
+24

No files matched your search

+9
View File
@@ -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.
+15
View File
@@ -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",