#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Phase-1.0BQ invocation-failure 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 Phase10BQGuardrails(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.data = json.loads((root / "manifests/retroarch/phase-1.0bq-inline-invocation-failure.json").read_text(encoding="utf-8")) def test_parent_and_pre_python_stop(self) -> None: parent = root / "manifests/retroarch/phase-1.0bp-one-shot-sdl-materialization-gate.json" self.assertEqual(hashlib.sha256(parent.read_bytes()).hexdigest(), self.data["source_bindings"]["phase10bp_manifest_sha256"]) result = self.data["consumed_attempt"] self.assertEqual((result["attempts"], result["exit_code"]), (1, 1)) for key in ("python_started", "runner_imported", "runner_consumed", "retroarch_build_invoked", "device_action_invoked"): self.assertFalse(result[key], key) self.assertEqual(result["materializer_requests_started"], 0) for key in ("stage_absent_after", "build_absent_after", "archive_absent_after"): self.assertTrue(result[key], key) def test_only_entrypoint_source_is_open(self) -> None: auth = self.data["authorizations"] self.assertTrue(auth["exact_entrypoint_source_authorized"]) for key, value in auth.items(): if key != "exact_entrypoint_source_authorized": self.assertFalse(value, key) self.assertFalse(self.data["decision"]["materialization_allowed"]) if __name__ == "__main__": unittest.main(argv=[__file__])