From d355649bc3e76663b85db521b04a766c075ab9a9 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:52:53 +0100 Subject: [PATCH] fix: narrowed manifests skip standalone layouts --- scripts/packs/manifest.py | 13 ++-- scripts/packs/manifestrun.py | 21 +++--- scripts/packs/naming.py | 25 +++++++ tests/test_manifest_narrowings.py | 107 ++++++++++++++++++++++++++++++ wiki/testing-guide.md | 2 +- 5 files changed, 151 insertions(+), 17 deletions(-) create mode 100644 tests/test_manifest_narrowings.py diff --git a/scripts/packs/manifest.py b/scripts/packs/manifest.py index 59f00e896..f5e5bad93 100644 --- a/scripts/packs/manifest.py +++ b/scripts/packs/manifest.py @@ -51,6 +51,7 @@ from packs.manifestentry import ( record_unplaceable, ) from packs.manifestselect import SelectionIndex +from packs.naming import manifest_suffix from packs.paths import platform_destination, save_layout from packs.scope import pack_sections, platform_list_version, system_titles from packs.standalone import standalone_copies, standalone_layouts @@ -782,15 +783,19 @@ def generate_install_list( (install/standalone/.json) and fetched only by a run given --standalone. - A manifest narrowed by a target, a case fold or --one-per-slot is no - list install.py reads by default and gets neither. + A manifest whose name carries a narrowing tag (manifest_suffix), or + built under a case fold override, is no list install.py reads by default + and gets neither. """ settings = _ManifestSettings(**options) built: dict = {} result = generate_manifest(platform_name, platforms_dir, db, bios_dir, registry_path, build_out=built, **options) - if (settings.source != "full" or settings.target_cores is not None - or settings.fold_case is not None or settings.one_per_slot): + narrowed = manifest_suffix( + settings.source, settings.regions, settings.target_name, settings.required_only, + one_per_slot=settings.one_per_slot, no_game_data=settings.no_game_data, + ) + if narrowed or settings.target_cores is not None or settings.fold_case is not None: return result truth_options: InstallListOptions = {**options, "source": "truth"} truth = generate_manifest( diff --git a/scripts/packs/manifestrun.py b/scripts/packs/manifestrun.py index c39eb9c82..22d02902e 100644 --- a/scripts/packs/manifestrun.py +++ b/scripts/packs/manifestrun.py @@ -13,7 +13,7 @@ from model.registry import load_platform_registry from model.safeparse import require_yaml from packs.datatrees import uncached_warning from packs.manifest import generate_install_list -from packs.naming import pack_narrowings, platform_target +from packs.naming import manifest_suffix, platform_target from packs.scope import platform_list_version from packs.standalone import STANDALONE_DIR, standalone_copies from packs.variants import run_variants, skip_empty_truth @@ -116,16 +116,12 @@ def run_manifest_mode( uncached_out=uncached, ) report_uncached(uncached, getattr(args, "uncached_trees", None)) - narrow_suffix = "".join( - tag.lower() - for tag, _label in pack_narrowings( - source, - getattr(args, "regions", None), - platform_target(representative, args.target, args.platforms_dir), - False, - required_only, - no_game_data=getattr(args, "no_game_data", False), - ) + narrow_suffix = manifest_suffix( + source, + getattr(args, "regions", None), + platform_target(representative, args.target, args.platforms_dir), + required_only, + no_game_data=getattr(args, "no_game_data", False), ) out_path = os.path.join( args.output_dir, @@ -137,7 +133,8 @@ def run_manifest_mode( f"{manifest['total_size']} bytes, " f"{manifest['total_omitted']} safely omitted" ) - for plat in group_platforms if layouts else (): + # The layouts file carries no tag: only the default list writes it. + for plat in group_platforms if layouts and not narrow_suffix else (): print(f" {write_standalone_layouts(args.output_dir, plat, layouts)}: " f"{len(layouts)} standalone builds") # Create aliases for grouped platforms (e.g., lakka -> retroarch) diff --git a/scripts/packs/naming.py b/scripts/packs/naming.py index 3012ad634..b56022763 100644 --- a/scripts/packs/naming.py +++ b/scripts/packs/naming.py @@ -58,6 +58,31 @@ def pack_narrowings( return applied +def manifest_suffix( + source: str, + regions: list[str] | None, + target_name: str | None, + required_only: bool, + *, + one_per_slot: bool = False, + no_game_data: bool = False, +) -> str: + """The narrowing tags an install manifest's file name carries. + + Empty names the default list install.py reads. Only that run builds the + truth list and writes standalone/.json, which carries no tag: + a --required-only run rewrote the layouts every --standalone install + reads. + """ + return "".join( + tag.lower() + for tag, _label in pack_narrowings( + source, regions, target_name, one_per_slot, required_only, + no_game_data=no_game_data, + ) + ) + + def _target_tag(target_name: str) -> str: """Filename tag for a hardware target. diff --git a/tests/test_manifest_narrowings.py b/tests/test_manifest_narrowings.py new file mode 100644 index 000000000..81e91f35b --- /dev/null +++ b/tests/test_manifest_narrowings.py @@ -0,0 +1,107 @@ +"""A narrowed manifest run writes no artifact under the default list's name. + +standalone/.json carries no tag. A --required-only run wrote it +beside myminui_required.json from the narrowed list, and with --output-dir +install/ it replaced the layouts every --standalone install reads. +""" + +from __future__ import annotations + +import tests + +import argparse +import contextlib +import io +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +from packs import manifest as packs_manifest +from packs import manifestrun + +REPO_ROOT = Path(__file__).resolve().parent.parent +PLATFORM = "retroarch" + +NARROWINGS: dict[str, dict] = { + "platform source": {"source": "platform"}, + "truth source": {"source": "truth"}, + "region": {"regions": ["north-america"]}, + "target": {"target": "switch"}, + "required only": {"required_only": True}, + "no game data": {"no_game_data": True}, +} + + +def _listed(*_args, **options) -> dict: + if options.get("build_out") is not None: + options["build_out"].update(slot_choices={}, profiles={}) + return { + "files": [], "omitted_files": [], "total_files": 0, + "total_size": 0, "total_omitted": 0, + } + + +def _run(out: str, **flags) -> bool: + args = argparse.Namespace( + platforms_dir=str(REPO_ROOT / "platforms"), output_dir=out, + bios_dir=str(REPO_ROOT / "bios"), emulators_dir=str(REPO_ROOT / "emulators"), + target=None, offline=True, regions=None, no_game_data=False, + uncached_trees=None, all_variants=False, source="full", required_only=False, + ) + for key, value in flags.items(): + setattr(args, key, value) + tc = {PLATFORM: {"fbneo"}} if args.target else {} + with ( + mock.patch.object(packs_manifest, "generate_manifest", side_effect=_listed), + mock.patch.object(packs_manifest, "_mark_truth"), + mock.patch.object(packs_manifest, "standalone_layouts", + return_value={"dolphin": {"files": []}}), + mock.patch.object(manifestrun, "skip_empty_truth", return_value=False), + contextlib.redirect_stdout(io.StringIO()), + ): + return manifestrun.run_manifest_mode(args, [([PLATFORM], PLATFORM)], {}, {}, {}, tc) + + +def _written(out: str) -> list[str]: + return sorted(str(p.relative_to(out)) for p in Path(out).rglob("*.json")) + + +class NarrowedRunsKeepTheDefaultNames(unittest.TestCase): + def test_the_default_run_writes_the_list_and_its_layouts(self): + with tempfile.TemporaryDirectory() as out: + self.assertTrue(_run(out)) + self.assertEqual( + _written(out), [f"{PLATFORM}.json", f"standalone/{PLATFORM}.json"] + ) + + def test_no_narrowing_writes_an_untagged_artifact(self): + for label, flags in NARROWINGS.items(): + with self.subTest(label), tempfile.TemporaryDirectory() as out: + self.assertTrue(_run(out, **flags)) + written = _written(out) + self.assertEqual(len(written), 1, written) + self.assertNotIn("standalone", written[0]) + self.assertNotEqual(written[0], f"{PLATFORM}.json") + + def test_a_narrowed_list_builds_no_layouts(self): + options = { + "source": "truth", "regions": ["north-america"], "target_name": "switch", + "required_only": True, "no_game_data": True, "one_per_slot": True, + } + for key, value in options.items(): + with self.subTest(key), mock.patch.object( + packs_manifest, "generate_manifest", side_effect=_listed + ), mock.patch.object(packs_manifest, "_mark_truth"), mock.patch.object( + packs_manifest, "standalone_layouts", return_value={"dolphin": {}} + ): + layouts: dict = {} + result = packs_manifest.generate_install_list( + PLATFORM, "p", {}, "b", "r", standalone_out=layouts, **{key: value} + ) + self.assertEqual(layouts, {}) + self.assertNotIn("standalone_builds", result) + + +if __name__ == "__main__": + unittest.main() diff --git a/wiki/testing-guide.md b/wiki/testing-guide.md index b2f02ad07..7118660aa 100644 --- a/wiki/testing-guide.md +++ b/wiki/testing-guide.md @@ -66,7 +66,7 @@ Every module in `tests/`, by the area it guards. | Import layers | the source of `scripts/` | `test_layers` | | File resolution and identity | synthetic + collection | `test_adler32_resolution`, `test_agnostic_scan`, `test_agnostic_scan_mode`, `test_agnostic_scope`, `test_agnostic_substitute`, `test_archive_build`, `test_archive_choice`, `test_archive_recipes`, `test_bios_companions`, `test_bundled_identity`, `test_casefold_cache`, `test_db_aliases`, `test_declared_names`, `test_derivations`, `test_directory_entries`, `test_extra_identity`, `test_foreign_tree`, `test_foreign_tree_names`, `test_frontend_digest`, `test_game_data_homonyms`, `test_hashing`, `test_held_record`, `test_identity`, `test_maker_folder_names`, `test_md5_pack_context`, `test_name_tiebreak`, `test_nec_filing`, `test_np2_fonts`, `test_owner_resolution`, `test_path_suffix`, `test_proven_name`, `test_resolution_evidence`, `test_sega_filing`, `test_shipped_content`, `test_switch_nca`, `test_twin_declaration_status`, `test_twin_declarations`, `test_validated_choice`, `test_variant_archives`, `test_variant_copies`, `test_variant_choice`, `test_variant_identity`, `test_zipped_member` | | Verification, cross-reference and profile checks | synthetic + profiles | `test_bios_layout`, `test_cache_independent_counts`, `test_case_insensitive_platforms`, `test_checks_have_values`, `test_content_checks`, `test_content_declarations`, `test_core_file_fills_declaration`, `test_core_size_refusal`, `test_cross_reference_sources`, `test_crypto_aes`, `test_crypto_unique_data`, `test_crypto_verify`, `test_data_only_refs`, `test_entry_categories`, `test_file_consumers`, `test_fileless_audit`, `test_flycast_layout`, `test_gap_settlement`, `test_hidden_extras`, `test_launcher_aliases`, `test_launcher_evidence`, `test_launcher_gaps`, `test_launcher_layer`, `test_launcher_paths`, `test_launcher_placement`, `test_native_mode`, `test_no_case_collisions`, `test_path_conflict_status`, `test_path_null_copies`, `test_profile_checks`, `test_profile_names`, `test_profile_paths`, `test_profile_repositories`, `test_romm_hash_rule`, `test_shared_groups`, `test_standalone_links`, `test_standalone_mode`, `test_undeclared_dedup`, `test_unplaced_extras`, `test_validation_scope`, `test_verify_all_dir`, `test_verify_data_dir_notice`, `test_verify_emulator_evidence`, `test_verify_listing`, `test_verify_pack_choice`, `test_verify_release_asset` | -| Packs and manifests | synthetic + real packs | `test_artifact_lock`, `test_atomic_artifacts`, `test_batocera_cores`, `test_core_data_trees`, `test_deterministic_zip`, `test_emulator_pack_counts`, `test_finalize_pack_names`, `test_large_file_cache`, `test_libretro_layout`, `test_manifest_entry`, `test_minui_platform`, `test_no_game_data`, `test_pack_conformance_dirs`, `test_pack_core_extras`, `test_pack_counts`, `test_pack_destinations`, `test_pack_failures`, `test_pack_file_names`, `test_pack_grouping`, `test_pack_integrity`, `test_pack_member_identity`, `test_pack_readme`, `test_platform_inheritance`, `test_platform_keys`, `test_release_packs`, `test_required_only_archives`, `test_required_only_twins`, `test_save_root`, `test_split_extras`, `test_split_names`, `test_split_pack`, `test_system_pack_extras`, `test_system_pack_parity`, `test_torrentzip`, `test_which_pack` | +| Packs and manifests | synthetic + real packs | `test_artifact_lock`, `test_atomic_artifacts`, `test_batocera_cores`, `test_core_data_trees`, `test_deterministic_zip`, `test_emulator_pack_counts`, `test_finalize_pack_names`, `test_large_file_cache`, `test_libretro_layout`, `test_manifest_entry`, `test_manifest_narrowings`, `test_minui_platform`, `test_no_game_data`, `test_pack_conformance_dirs`, `test_pack_core_extras`, `test_pack_counts`, `test_pack_destinations`, `test_pack_failures`, `test_pack_file_names`, `test_pack_grouping`, `test_pack_integrity`, `test_pack_member_identity`, `test_pack_readme`, `test_platform_inheritance`, `test_platform_keys`, `test_release_packs`, `test_required_only_archives`, `test_required_only_twins`, `test_save_root`, `test_split_extras`, `test_split_names`, `test_split_pack`, `test_system_pack_extras`, `test_system_pack_parity`, `test_torrentzip`, `test_which_pack` | | Slots and regions | synthetic + profiles | `test_region`, `test_region_agnostic_scan`, `test_region_groups`, `test_region_held`, `test_region_platform_index`, `test_region_required_only`, `test_slot`, `test_slots`, `test_slots_shipped_file` | | Hardware targets and systems | synthetic + target files | `test_amberelec_targets`, `test_emuelec_targets`, `test_extract_targets`, `test_lakka_targets`, `test_libretro_slugs`, `test_system_ids`, `test_system_selection`, `test_target_names`, `test_target_scrapers`, `test_target_systems`, `test_target_verify` | | Installer and downloads | loopback server | `test_build_installer`, `test_check_release`, `test_download`, `test_install`, `test_install_cores`, `test_install_experience`, `test_install_expert`, `test_install_filesystems`, `test_install_app`, `test_install_from`, `test_install_games`, `test_install_journeys`, `test_install_offline`, `test_install_pack`, `test_install_removal`, `test_install_selection`, `test_install_tui`, `test_pypi_package` |