From e3f773dd829ebc9d488cda5e877bd36166dd2b81 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 6 Oct 2026 04:48:32 +0200 Subject: [PATCH] fix: finalize only the packs this run names --- scripts/generate_pack.py | 11 ++++++---- tests/test_finalize_pack_names.py | 36 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 tests/test_finalize_pack_names.py diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index b476ae27..7e0a2b06 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -3480,12 +3480,15 @@ def verify_and_finalize_packs( all_ok = True # Map ZIP names to platform names + # By the exact name this run's reduction gives a platform's pack, never by + # substring: a _Custom or regional pack left by another run was judged + # against this run's expectation and failed it. + registered = list_registered_platforms(platforms_dir, include_archived=True) + expected = _expected_pack_names(registered, platforms_dir, regions, target_name) pack_to_platform: dict[str, list[str]] = {} for name in _pack_archives(output_dir): - for pname in list_registered_platforms(platforms_dir, include_archived=True): - cfg = load_platform_config(pname, platforms_dir) - display = cfg.get("platform", pname).replace(" ", "_") - if display in name or display.replace("_", "") in name.replace("_", ""): + for pname in registered: + if name in expected[pname]: pack_to_platform.setdefault(name, []).append(pname) for name in _pack_archives(output_dir): diff --git a/tests/test_finalize_pack_names.py b/tests/test_finalize_pack_names.py new file mode 100644 index 00000000..333d1556 --- /dev/null +++ b/tests/test_finalize_pack_names.py @@ -0,0 +1,36 @@ +"""The post-build check judges only the packs this run would name. + +A MiSTer _Custom pack left in the directory by a --from-md5 run was +attached to misterfpga by substring and checked against the full list: +0/81, FAILED, exit code 1, for a run whose own pack was 81/81. +""" + +from __future__ import annotations + +import os +import sys +import tempfile +import unittest +import zipfile +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(REPO_ROOT / "scripts")) + + +class FinalizeByExactName(unittest.TestCase): + def test_a_custom_pack_is_not_judged_as_the_platform_pack(self): + from generate_pack import verify_and_finalize_packs + + previous = os.getcwd() + os.chdir(REPO_ROOT) + self.addCleanup(os.chdir, previous) + with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with zipfile.ZipFile(Path(tmp) / "MiSTer_FPGA_Custom_BIOS_Pack.zip", "w") as zf: + zf.writestr("README.txt", "custom") + ok = verify_and_finalize_packs(tmp, {"files": {}, "indexes": {}}) + self.assertTrue(ok) + + +if __name__ == "__main__": + unittest.main()