diff --git a/scripts/romset_recipes.py b/scripts/romset_recipes.py index 4518fb70..b8f7d33d 100644 --- a/scripts/romset_recipes.py +++ b/scripts/romset_recipes.py @@ -437,6 +437,19 @@ def print_missing(gap: dict) -> None: print(f" NO RECIPE: {record['archive']} md5={record['md5'][:8]}") +def _resolve_modes(args: argparse.Namespace) -> None: + """Which reports run: both by default, and --missing whenever --write. + + The reconstructions --write saves are those of the missing pins: with + --identify alone beside it, nothing ran them, nothing was written, and + the run exited 0. + """ + if args.write: + args.missing = True + if not args.identify and not args.missing: + args.identify = args.missing = True + + def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--identify", action="store_true", help="label local archives") @@ -444,7 +457,8 @@ def main() -> int: "--missing", action="store_true", help="attempt pinned archives we lack" ) parser.add_argument( - "--write", action="store_true", help="write reconstructions to .variants/" + "--write", action="store_true", + help="write reconstructions to .variants/ (implies --missing)", ) parser.add_argument("--json", action="store_true", help="machine-readable output") parser.add_argument("--bios-dir", default="bios") @@ -457,9 +471,7 @@ def main() -> int: help="recipe snapshot file, or a directory of them", ) args = parser.parse_args() - - if not args.identify and not args.missing: - args.identify = args.missing = True + _resolve_modes(args) db = load_database(args.db) profiles = load_emulator_profiles(args.emulators_dir, skip_aliases=False) diff --git a/tests/test_romset_recipes.py b/tests/test_romset_recipes.py index ce03282c..f1345cbf 100644 --- a/tests/test_romset_recipes.py +++ b/tests/test_romset_recipes.py @@ -621,5 +621,25 @@ class BuildDigestsOutliveTheRun(unittest.TestCase): self.assertEqual(second.digest(recipe), digest) self.assertIsNone(second.digest([("x.rom", "deadbeef")])) +class WriteRunsTheReportItWrites(unittest.TestCase): + """--identify --write ran the identification only: the reconstructions + --write saves come from the missing-pins report, which did not run.""" + + def test_write_implies_missing(self): + import argparse # noqa: PLC0415 + + import romset_recipes # noqa: PLC0415 + + args = argparse.Namespace(identify=True, missing=False, write=True) + romset_recipes._resolve_modes(args) + self.assertEqual((args.identify, args.missing), (True, True)) + default = argparse.Namespace(identify=False, missing=False, write=False) + romset_recipes._resolve_modes(default) + self.assertEqual((default.identify, default.missing), (True, True)) + alone = argparse.Namespace(identify=True, missing=False, write=False) + romset_recipes._resolve_modes(alone) + self.assertEqual((alone.identify, alone.missing), (True, False)) + + if __name__ == "__main__": unittest.main()