From ced7588d17015a9272df65aedeb32fe0f2fb8b35 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:41:53 +0200 Subject: [PATCH] fix: count mister corrections only where it writes --- scripts/exporter/misterfpga_exporter.py | 11 ++++++++++- tests/test_export_counts.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/exporter/misterfpga_exporter.py b/scripts/exporter/misterfpga_exporter.py index 208ad091..0c2ad443 100644 --- a/scripts/exporter/misterfpga_exporter.py +++ b/scripts/exporter/misterfpga_exporter.py @@ -13,7 +13,7 @@ import zipfile from collections import OrderedDict from .base_exporter import BaseExporter -from .baseline import NativeSystem, Report +from .baseline import NativeFile, NativeSystem, Report SOURCE_URL = ( "https://raw.githubusercontent.com/ajgowans/BiosDB_MiSTer/db/bios_db.json.zip" @@ -57,6 +57,13 @@ class Exporter(BaseExporter): with zipfile.ZipFile(io.BytesIO(raw)) as archive: return {_DB_NAME: archive.read(_DB_NAME).decode("utf-8")} + def states(self, fe: NativeFile, field_name: str) -> bool: + """A correction whose path the database does not hold is not written.""" + written = getattr(self, "_written", None) + if written is not None and id(fe) not in written: + return False + return super().states(fe, field_name) + def _by_path(self, systems: dict[str, NativeSystem]) -> dict[str, object]: indexed: dict[str, object] = {} for system in systems.values(): @@ -80,11 +87,13 @@ class Exporter(BaseExporter): ) database = json.loads(original, object_pairs_hook=OrderedDict) indexed = self._by_path(systems) + self._written = set() for path, entry in database.get("files", {}).items(): fe = indexed.get(path) if fe is None: continue + self._written.add(id(fe)) md5 = fe.hash("md5") if md5: entry["hash"] = md5 diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index 41b53924..75f16bbd 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -181,6 +181,22 @@ class BizHawkCountsWhatItWrites(unittest.TestCase): self.assertFalse(exporter.states(first, "sha1")) +class MisterCountsWhatItWrites(unittest.TestCase): + def test_a_path_the_database_lacks_is_not_counted(self): + from exporter.misterfpga_exporter import Exporter as Mister + + held = NativeFile("boot.rom", "NES/boot.rom", "nes", platform={"md5": A}, + truth={"md5": B}, corrections=["md5"]) + absent = NativeFile("boot.rom", "SNES/boot.rom", "snes", platform={"md5": A}, + truth={"md5": C}, corrections=["md5"]) + systems = {"nes": NativeSystem("nes", files=[held]), "snes": NativeSystem("snes", files=[absent])} + database = {"db_id": "x", "files": {"games/NES/boot.rom": {"hash": A, "url": "u"}}} + exporter = Mister() + exporter.render(systems, None, {"bios_db.json": json.dumps(database)}) + self.assertTrue(exporter.states(held, "md5")) + self.assertFalse(exporter.states(absent, "md5")) + + class ModelKeepsOneFileOneEntry(unittest.TestCase): def test_size_describes_the_hash_written(self): fe = NativeFile("boot.bin", "dc/boot.bin", "dc",