#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Phase-1.0BZ exact failed-stage cleanup 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 Phase10BZGuardrails(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.data = json.loads((root / "manifests/retroarch/phase-1.0bz-exact-sdl-stage-cleanup-gate.json").read_text(encoding="utf-8")) def test_parent_and_four_hashes_are_exact(self) -> None: parent = root / "manifests/retroarch/phase-1.0by-windows-git-stage-fixture-failure-and-file-hash-gate.json" self.assertEqual(hashlib.sha256(parent.read_bytes()).hexdigest(), self.data["source_bindings"]["phase10by_manifest_sha256"]) hashes = self.data["fixture_result"]["patch_target_sha256"] self.assertEqual(len(hashes), 4) for value in hashes.values(): self.assertRegex(value, r"^[0-9a-f]{64}$") def test_cleanup_is_one_exact_worktree_only(self) -> None: cleanup = self.data["cleanup"] self.assertEqual(cleanup["attempts_authorized"], 1) self.assertEqual(cleanup["argv"][-3:], [ "remove", "--force", "/mnt/c/Projects/chimera-retroarch-phase10az/build/phase10bd/sdl-source"]) self.assertEqual(cleanup["timeout_seconds"], 900) self.assertFalse(cleanup["automatic_retry"]) def test_only_exact_cleanup_is_open(self) -> None: auth = self.data["authorizations"] self.assertTrue(auth["exact_failed_stage_cleanup_authorized"]) for key, value in auth.items(): if key != "exact_failed_stage_cleanup_authorized": self.assertFalse(value, key) self.assertFalse(self.data["decision"]["source_change_allowed"]) self.assertFalse(self.data["decision"]["materialization_allowed"]) if __name__ == "__main__": unittest.main(argv=[__file__])