#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Phase-1.0BP one-shot materialization 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 Phase10BPGuardrails(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.data = json.loads((root / "manifests/retroarch/phase-1.0bp-one-shot-sdl-materialization-gate.json").read_text(encoding="utf-8")) def test_parent_runner_and_exact_preflight(self) -> None: parent = root / "manifests/retroarch/phase-1.0bo-patch-chain-remediation-result.json" self.assertEqual(hashlib.sha256(parent.read_bytes()).hexdigest(), self.data["source_bindings"]["phase10bo_manifest_sha256"]) self.assertRegex(self.data["source_bindings"]["runner_sha256"], r"^[0-9a-f]{64}$") preflight = self.data["preflight"] for key in ("sdl_source_clean", "stage_absent", "build_absent", "archive_absent"): self.assertTrue(preflight[key], key) self.assertEqual(preflight["request_count"], 10) self.assertEqual(len(preflight["exact_output_paths"]), 3) def test_invocation_is_one_shot_without_cleanup(self) -> None: invocation = self.data["invocation"] self.assertEqual(invocation["attempts_authorized"], 1) self.assertFalse(invocation["automatic_retry"]) self.assertFalse(invocation["cleanup_authorized"]) self.assertEqual(invocation["argv"][0], "/usr/bin/python3.14") self.assertIn("run_once", invocation["argv"][2]) def test_authority_ends_at_sdl_archive(self) -> None: auth = self.data["authorizations"] for key in ("exact_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_materializer_invocation_authorized", "cmake_invocation_authorized", "sdl_build_authorized"): self.assertFalse(value, key) self.assertFalse(self.data["decision"]["retroarch_cross_build_allowed"]) self.assertFalse(self.data["decision"]["device_action_allowed"]) if __name__ == "__main__": unittest.main(argv=[__file__])