#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Phase-1.0BG repository guardrails.""" import argparse, hashlib, json, subprocess from pathlib import Path import unittest parser = argparse.ArgumentParser() parser.add_argument("--root", type=Path, required=True) parser.add_argument("--retroarch-root", type=Path) args = parser.parse_args() class Phase10BGGuardrails(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.data = json.loads((args.root / "manifests/retroarch/phase-1.0bg-dormant-sdl-request-compiler.json").read_text(encoding="utf-8")) def test_parent_and_optional_source(self) -> None: bind = self.data["source_bindings"] parent = args.root / "manifests/retroarch/phase-1.0bf-live-sdl-adapter-boundary-audit.json" self.assertEqual(hashlib.sha256(parent.read_bytes()).hexdigest(), bind["phase10bf_manifest_sha256"]) if args.retroarch_root: def git(*values: str) -> str: return subprocess.run(["git", *values], cwd=args.retroarch_root, check=True, capture_output=True, text=True).stdout.strip() self.assertEqual(git("rev-parse", "HEAD"), bind["retroarch_commit"]) self.assertEqual(git("rev-parse", bind["remote_ref"]), bind["retroarch_commit"]) def test_graph_and_authority(self) -> None: graph = self.data["request_graph"] self.assertEqual(graph["operation_count"], 8) self.assertTrue(graph["fixed_argv"]) self.assertTrue(graph["canonical_output_containment"]) for key in ("shell_present", "package_manager_present", "retroarch_build_present", "network_present", "device_action_present", "executor_present"): self.assertFalse(graph[key]) auth = self.data["authorizations"] self.assertTrue(auth["bounded_executor_source_authorized"]) for key, value in auth.items(): if key != "bounded_executor_source_authorized": self.assertFalse(value, key) if __name__ == "__main__": unittest.main(argv=[__file__])