From c37d7fc95ad5d2b8c7c68050ff011355d7b1de03 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 6 Oct 2026 04:46:03 +0200 Subject: [PATCH] fix: apply required-only to emulator pack archives --- scripts/generate_pack.py | 9 +++++++ tests/test_required_only_archives.py | 38 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/test_required_only_archives.py diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index d207150b..b476ae27 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -1345,6 +1345,15 @@ def generate_emulator_pack( ), {"name": archive_name}, ) + if required_only and archive_entry.get("required") is False and all( + member.get("required") is False + for member in files + if member.get("archive") == archive_name + ): + # Optional as a whole: its own entry and every member it + # carries. geolith's _Required pack held neocd.zip and + # irrmaze.zip all the same. + continue local_path, status = resolve_file( archive_entry, db, diff --git a/tests/test_required_only_archives.py b/tests/test_required_only_archives.py new file mode 100644 index 00000000..c2d4b306 --- /dev/null +++ b/tests/test_required_only_archives.py @@ -0,0 +1,38 @@ +"""--required-only reaches archives in emulator packs. + +geolith declares neocd.zip and irrmaze.zip optional, members included, and +its _Required pack held them anyway: the archive loop never read `required`. +""" + +from __future__ import annotations + +import subprocess +import sys +import tempfile +import unittest +import zipfile +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parents[1] + + +class RequiredOnlyArchives(unittest.TestCase): + def test_optional_archives_stay_out(self): + if not (REPO_ROOT / "database.json").is_file(): + self.skipTest("database.json not built") + with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + result = subprocess.run( + [sys.executable, "scripts/generate_pack.py", "--emulator", "geolith", + "--required-only", "--offline", "--output-dir", tmp], + capture_output=True, text=True, cwd=REPO_ROOT, timeout=600, + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + pack = next(Path(tmp).glob("*.zip")) + names = set(zipfile.ZipFile(pack).namelist()) + self.assertNotIn("neocd.zip", names) + self.assertNotIn("irrmaze.zip", names) + self.assertIn("neogeo.zip", names) + + +if __name__ == "__main__": + unittest.main()