#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Phase-1.0BV request-correction 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 Phase10BVGuardrails(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.data = json.loads((root / "manifests/retroarch/phase-1.0bv-windows-git-fixture-result-and-request-correction-gate.json").read_text(encoding="utf-8")) def test_parent_and_fixture_result_are_exact(self) -> None: parent = root / "manifests/retroarch/phase-1.0bu-wsl-git-status-timeout-and-windows-git-fixture-gate.json" self.assertEqual(hashlib.sha256(parent.read_bytes()).hexdigest(), self.data["source_bindings"]["phase10bu_manifest_sha256"]) result = self.data["fixture_result"] self.assertEqual(result["attempts"], 1) self.assertEqual(result["observed_commit"], "0baf4ac49382b537ba449901b5b6d0d189bb1fbb") self.assertEqual(result["porcelain_status"], "") self.assertEqual(result["rev_parse_exit_code"], 0) self.assertEqual(result["status_exit_code"], 0) for key in ("worktree_created", "patch_invoked", "cmake_invoked", "sdl_build_invoked", "retroarch_build_invoked", "device_action_invoked"): self.assertFalse(result[key], key) def test_correction_is_exact_and_offline(self) -> None: correction = self.data["authorized_source_correction"] self.assertEqual(correction["read_only_git_executable"], "/mnt/c/Program Files/Git/cmd/git.exe") self.assertEqual(correction["read_only_git_source_path"], "C:/Projects/chimera-gfx/work/upstream/SDL") self.assertEqual(correction["read_only_timeout_seconds"], 30) self.assertEqual(correction["read_only_output_limit"], 4096) self.assertEqual(correction["detached_stage_timeout_seconds"], 900) self.assertTrue(correction["hash_bind_windows_git_in_runner"]) self.assertTrue(correction["detached_stage_add_quiet"]) self.assertFalse(correction["automatic_retry"]) def test_only_source_change_is_open(self) -> None: auth = self.data["authorizations"] self.assertTrue(auth["request_graph_source_change_authorized"]) for key, value in auth.items(): if key != "request_graph_source_change_authorized": self.assertFalse(value, key) self.assertFalse(self.data["decision"]["materialization_allowed"]) if __name__ == "__main__": unittest.main(argv=[__file__])