#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Phase-1.0BY exact file-hash fixture 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 Phase10BYGuardrails(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.data = json.loads((root / "manifests/retroarch/phase-1.0by-windows-git-stage-fixture-failure-and-file-hash-gate.json").read_text(encoding="utf-8")) def test_parent_and_consumed_fixture(self) -> None: parent = root / "manifests/retroarch/phase-1.0bx-changed-files-timeout-and-read-only-fixture-gate.json" self.assertEqual(hashlib.sha256(parent.read_bytes()).hexdigest(), self.data["source_bindings"]["phase10bx_manifest_sha256"]) result = self.data["consumed_fixture"] self.assertEqual(result["attempts"], 1) self.assertEqual(result["exit_code"], 1) self.assertEqual(result["failure"], "fatal: not a git repository: (NULL)") for key in ("stage_mutated", "cleanup_invoked", "cmake_invoked", "sdl_build_invoked", "device_action_invoked"): self.assertFalse(result[key], key) def test_fixture_is_four_exact_files_only(self) -> None: fixture = self.data["file_hash_fixture"] self.assertEqual(fixture["attempts_authorized"], 1) self.assertEqual(len(fixture["sha256_paths"]), 4) self.assertTrue(fixture["read_git_indirection"]) self.assertFalse(fixture["directory_enumeration_authorized"]) self.assertFalse(fixture["git_invocation_authorized"]) self.assertFalse(fixture["automatic_retry"]) def test_only_file_hash_fixture_is_open(self) -> None: auth = self.data["authorizations"] self.assertTrue(auth["exact_file_hash_fixture_authorized"]) for key, value in auth.items(): if key != "exact_file_hash_fixture_authorized": self.assertFalse(value, key) self.assertFalse(self.data["decision"]["cleanup_allowed"]) self.assertFalse(self.data["decision"]["materialization_allowed"]) if __name__ == "__main__": unittest.main(argv=[__file__])