#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Phase-1.0BR exact script-entrypoint gate guardrails.""" import argparse import hashlib import json from pathlib import Path import unittest parser = argparse.ArgumentParser() parser.add_argument("--root", type=Path, required=True) root = parser.parse_args().root class Phase10BRGuardrails(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.data = json.loads((root / "manifests/retroarch/phase-1.0br-script-entrypoint-one-shot-gate.json").read_text(encoding="utf-8")) def test_parent_entrypoint_and_absent_outputs(self) -> None: parent = root / "manifests/retroarch/phase-1.0bq-inline-invocation-failure.json" self.assertEqual(hashlib.sha256(parent.read_bytes()).hexdigest(), self.data["source_bindings"]["phase10bq_manifest_sha256"]) self.assertRegex(self.data["source_bindings"]["entrypoint_sha256"], r"^[0-9a-f]{64}$") preflight = self.data["preflight"] self.assertTrue(preflight["entrypoint_argument_free"]) self.assertEqual(preflight["run_once_call_count"], 1) for key in ("stage_absent", "build_absent", "archive_absent"): self.assertTrue(preflight[key], key) def test_new_gate_is_exactly_one_nonautomatic_attempt(self) -> None: invocation = self.data["invocation"] self.assertEqual(invocation["argv"], ["/usr/bin/python3.14", "tools/phase10bq_sdl_materializer_entrypoint.py"]) self.assertEqual(invocation["attempts_authorized"], 1) self.assertFalse(invocation["automatic_retry"]) self.assertFalse(invocation["cleanup_authorized"]) self.assertFalse(self.data["decision"]["new_attempt_is_automatic_retry"]) def test_authority_stops_before_retroarch_and_device(self) -> None: auth = self.data["authorizations"] for key in ("exact_script_entrypoint_invocation_authorized", "materializer_invocation_authorized", "cmake_invocation_authorized", "sdl_build_authorized"): self.assertTrue(auth[key], key) for key, value in auth.items(): if key not in ("exact_script_entrypoint_invocation_authorized", "materializer_invocation_authorized", "cmake_invocation_authorized", "sdl_build_authorized"): self.assertFalse(value, key) self.assertFalse(self.data["decision"]["device_action_allowed"]) if __name__ == "__main__": unittest.main(argv=[__file__])