79 lines
3.0 KiB
Python
79 lines
3.0 KiB
Python
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from scripts.run_automation_execution_closure_gate import REQUIRED_QUEUE_ITEMS, run_closure_gate
|
|
|
|
|
|
class AutomationExecutionClosureGateTests(unittest.TestCase):
|
|
def test_passes_when_queue_state_and_evidence_are_closed(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
root = Path(tmp_dir)
|
|
_write_closure_files(root)
|
|
|
|
payload = run_closure_gate(root=root)
|
|
|
|
self.assertEqual(payload["status"], "passed")
|
|
self.assertEqual(payload["blockers"], [])
|
|
self.assertIn("p15_pxx_queue_closed", payload["passed_checks"])
|
|
self.assertEqual(payload["post_pxx_state"]["new_phase_policy"], "require_explicit_user_product_decision")
|
|
|
|
def test_blocks_when_a_queue_item_is_not_checked(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
root = Path(tmp_dir)
|
|
_write_closure_files(root, unchecked_item="`P24` Remote Smoke And Ops Closure")
|
|
|
|
payload = run_closure_gate(root=root)
|
|
|
|
self.assertEqual(payload["status"], "blocked")
|
|
self.assertIn("p15_pxx_queue_closed", payload["blockers"])
|
|
|
|
def test_blocks_when_validation_evidence_is_missing(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
root = Path(tmp_dir)
|
|
_write_closure_files(root, include_validation=False)
|
|
|
|
payload = run_closure_gate(root=root)
|
|
|
|
self.assertEqual(payload["status"], "blocked")
|
|
self.assertIn("validation_evidence", payload["blockers"])
|
|
|
|
|
|
def _write_closure_files(root: Path, unchecked_item=None, include_validation: bool = True) -> None:
|
|
docs = root / "docs"
|
|
docs.mkdir(parents=True)
|
|
task_lines = ["## P15-PXX Finite Queue"]
|
|
for item in REQUIRED_QUEUE_ITEMS:
|
|
checkbox = "[ ]" if item == unchecked_item else "[x]"
|
|
task_lines.append(f"- {checkbox} {item}")
|
|
(root / "TASKS.md").write_text("\n".join(task_lines), encoding="utf-8")
|
|
|
|
validation = ""
|
|
if include_validation:
|
|
validation = "PXX final validation passed: unit tests, script static checks. P24 remote ops smoke passed."
|
|
(root / "SESSION.md").write_text(
|
|
"\n".join(
|
|
[
|
|
"state: automation_execution_layer_pxx_known_scope_closed",
|
|
"current_phase: Long-running Analysis Decision Monitor With Ops Rollup",
|
|
"next_execution_layer_phase: Long-running Analysis Decision Monitor With Ops Rollup",
|
|
"guards_unchanged: execution_allowed, real_live_ready, risk_governor, trust_bucket, operator_confirmation_protocol",
|
|
validation,
|
|
]
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
(docs / "AI_ICT_自动化执行层_P15-PXX闭环任务清单_v1.md").write_text(
|
|
"\n".join(
|
|
[
|
|
"new_phase_policy: require_explicit_user_product_decision",
|
|
"PXX 之后不再自动发明 P25/P26。",
|
|
]
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|