#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Phase-1.0CB hash-verified materializer 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 Phase10CBGuardrails(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.data = json.loads((root / "manifests/retroarch/phase-1.0cb-hash-verified-sdl-materializer-one-shot-gate.json").read_text(encoding="utf-8")) def test_parent_and_sources_are_bound(self) -> None: parent = root / "manifests/retroarch/phase-1.0ca-cleanup-result-and-hash-verifier-correction-gate.json" self.assertEqual(hashlib.sha256(parent.read_bytes()).hexdigest(), self.data["source_bindings"]["phase10ca_manifest_sha256"]) bindings = self.data["source_bindings"] self.assertEqual(bindings["retroarch_commit"], "a4b1fb0ca125b23c6a22069f2937f69b055b6cab") for key, value in bindings.items(): if key.endswith("_sha256"): self.assertRegex(value, r"^[0-9a-f]{64}$", key) def test_one_shot_is_exact_and_nonretrying(self) -> None: one_shot = self.data["one_shot"] self.assertEqual(one_shot["attempts_authorized"], 1) self.assertEqual(one_shot["argv"][-1], "tools/phase10bq_sdl_materializer_entrypoint.py") self.assertFalse(one_shot["automatic_retry"]) self.assertFalse(one_shot["cleanup_on_failure_authorized"]) def test_scope_ends_at_offline_sdl(self) -> None: auth = self.data["authorizations"] for key in ("output_path_reuse_authorized", "materializer_invocation_authorized", "detached_sdl_stage_authorized", "offline_patch_application_authorized", "cmake_invocation_authorized", "sdl_build_authorized"): self.assertTrue(auth[key], key) for key in ("retroarch_target_build_authorized", "network_access_authorized", "ps5_connection_authorized", "device_transfer_authorized", "device_execution_authorized"): self.assertFalse(auth[key], key) if __name__ == "__main__": unittest.main(argv=[__file__])