From dfa1cc31d380a55806974daeed5944d717ebec7b Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 6 Nov 2026 08:16:18 +0100 Subject: [PATCH] fix: generate_truth refuses a target it lacks --platform bizhawk --target switch printed skipped, then Done., and exited 0 with no model written. generate_truth now resolves targets through build_target_cores_cache, as verify and generate_pack do: a named platform without the target is refused with exit 1, --all leaves such platforms out and says so. --- scripts/generate_truth.py | 27 +++++++++++++++------------ tests/test_truth_diff.py | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/scripts/generate_truth.py b/scripts/generate_truth.py index ac5856667..472ae3ea7 100644 --- a/scripts/generate_truth.py +++ b/scripts/generate_truth.py @@ -14,13 +14,13 @@ import sys sys.path.insert(0, os.path.dirname(__file__)) from common import ( + build_target_cores_cache, platform_arg, list_registered_platforms, load_data_dir_registry, load_database, load_emulator_profiles, load_platform_config, - load_target_config, require_directory, require_platform, require_yaml, @@ -97,6 +97,19 @@ def main(argv: list[str] | None = None) -> None: require_platform(args.platform, args.platforms_dir) platforms = [args.platform] + # A named platform without that target is refused, as verify and + # generate_pack refuse it: skipped, it printed Done. and exited 0 with + # no model written. --all leaves such platforms out and says so. + target_cores_cache: dict[str, set[str] | None] = {} + if args.target: + try: + target_cores_cache, platforms = build_target_cores_cache( + platforms, args.target, args.platforms_dir, is_all=args.all + ) + except (FileNotFoundError, ValueError) as exc: + print(f"ERROR: {exc}", file=sys.stderr) + sys.exit(1) + # A target-narrowed model is a different artifact: written under the # platform's own name it overwrote the full one, and diff_truth then # compared a narrowed model against the whole scrape. Its directory is @@ -109,17 +122,7 @@ def main(argv: list[str] | None = None) -> None: output_dir, [name], args.target, args.platforms_dir ) os.makedirs(output_dir, exist_ok=True) - target_cores: set[str] | None = None - if args.target: - try: - target_cores = load_target_config( - name, - args.target, - args.platforms_dir, - ) - except FileNotFoundError: - print(f" {name}: no target config, skipped") - continue + target_cores = target_cores_cache.get(name) # Load platform config (with inheritance) and registry entry try: diff --git a/tests/test_truth_diff.py b/tests/test_truth_diff.py index fa48edf6e..949be7c7d 100644 --- a/tests/test_truth_diff.py +++ b/tests/test_truth_diff.py @@ -60,6 +60,22 @@ class ATargetedModelIsItsOwnArtifact(unittest.TestCase): ) + def test_a_named_platform_without_the_target_is_refused(self): + """bizhawk --target switch printed "skipped", then Done., exit 0, + and wrote no model: the diff after it failed instead.""" + repo = pathlib.Path(__file__).resolve().parent.parent + with tempfile.TemporaryDirectory(dir=str(repo / "tmp")) as directory: + proc = subprocess.run( + [sys.executable, "scripts/generate_truth.py", "--platform", "bizhawk", + "--target", "switch", "--output-dir", directory], + capture_output=True, check=False, text=True, cwd=str(repo), timeout=400, + ) + self.assertEqual(proc.returncode, 1, proc.stdout + proc.stderr) + self.assertIn("bizhawk has no hardware targets", proc.stderr) + self.assertNotIn("Done.", proc.stdout) + self.assertEqual(list(pathlib.Path(directory).iterdir()), []) + + class ADiffThatComparedNothingFails(unittest.TestCase): """diff_truth --all skipped every platform without a model and exited 0."""