feat(governance): 新增 release authorization hold
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.services.ai_agent_result_capture_release_authorization_hold import (
|
||||
load_latest_ai_agent_result_capture_release_authorization_hold,
|
||||
)
|
||||
|
||||
|
||||
def test_load_latest_release_authorization_hold_snapshot() -> None:
|
||||
snapshot = load_latest_ai_agent_result_capture_release_authorization_hold()
|
||||
|
||||
assert snapshot["schema_version"] == "ai_agent_result_capture_release_authorization_hold_v1"
|
||||
assert snapshot["program_status"]["current_task_id"] == "P2-134"
|
||||
assert snapshot["program_status"]["next_task_id"] == "P2-135"
|
||||
assert snapshot["program_status"]["overall_completion_percent"] == 100
|
||||
assert snapshot["program_status"]["runtime_authority"] == "result_capture_release_authorization_hold_only_no_live_write"
|
||||
|
||||
rollups = snapshot["rollups"]
|
||||
assert rollups["release_authorization_hold_count"] == 5
|
||||
assert rollups["rollback_authorization_hold_count"] == 5
|
||||
assert rollups["release_window_hold_count"] == 5
|
||||
assert rollups["live_apply_authorization_hold_count"] == 5
|
||||
assert rollups["blocked_authorization_transition_count"] == 6
|
||||
assert rollups["operator_action_count"] == 5
|
||||
assert (
|
||||
rollups["approval_required_authorization_count"]
|
||||
+ rollups["approval_required_rollback_count"]
|
||||
+ rollups["approval_required_release_window_count"]
|
||||
+ rollups["approval_required_live_apply_count"]
|
||||
) == 8
|
||||
assert (
|
||||
rollups["blocked_authorization_count"]
|
||||
+ rollups["blocked_rollback_count"]
|
||||
+ rollups["blocked_release_window_count"]
|
||||
+ rollups["blocked_live_apply_count"]
|
||||
+ rollups["critical_blocker_count"]
|
||||
) == 9
|
||||
|
||||
assert rollups["owner_release_authorized_count"] == 0
|
||||
assert rollups["release_authorization_granted_count"] == 0
|
||||
assert rollups["release_authorization_pass_count"] == 0
|
||||
assert rollups["writer_apply_count"] == 0
|
||||
assert rollups["execution_apply_count"] == 0
|
||||
assert rollups["receipt_write_count"] == 0
|
||||
assert rollups["reviewer_queue_write_count"] == 0
|
||||
assert rollups["gateway_queue_write_count"] == 0
|
||||
assert rollups["telegram_send_count"] == 0
|
||||
assert rollups["bot_api_call_count"] == 0
|
||||
assert rollups["report_receipt_write_count"] == 0
|
||||
assert rollups["result_capture_write_count"] == 0
|
||||
assert rollups["learning_write_count"] == 0
|
||||
assert rollups["playbook_trust_write_count"] == 0
|
||||
assert rollups["production_write_count"] == 0
|
||||
|
||||
|
||||
def test_release_authorization_truth_keeps_all_live_paths_closed() -> None:
|
||||
snapshot = load_latest_ai_agent_result_capture_release_authorization_hold()
|
||||
truth = snapshot["release_authorization_truth"]
|
||||
|
||||
assert truth["p2_133_final_candidate_loaded"] is True
|
||||
assert truth["release_authorization_hold_ready"] is True
|
||||
assert truth["live_apply_authorization_hold_active"] is True
|
||||
assert truth["owner_release_authorized"] is False
|
||||
assert truth["owner_release_approved"] is False
|
||||
assert truth["maintenance_window_approved"] is False
|
||||
assert truth["rollback_owner_confirmed"] is False
|
||||
assert truth["post_release_verifier_ready"] is False
|
||||
assert truth["final_release_candidate_approved"] is False
|
||||
assert truth["final_release_candidate_passed"] is False
|
||||
assert truth["release_authorization_granted"] is False
|
||||
assert truth["release_authorization_passed"] is False
|
||||
assert truth["live_apply_release_passed"] is False
|
||||
assert truth["writer_apply_enabled"] is False
|
||||
assert truth["gateway_queue_write_enabled"] is False
|
||||
assert truth["telegram_send_enabled"] is False
|
||||
assert truth["production_write_enabled"] is False
|
||||
assert truth["secret_read_enabled"] is False
|
||||
assert truth["destructive_operation_enabled"] is False
|
||||
|
||||
|
||||
def test_rejects_granted_release_authorization(tmp_path: Path) -> None:
|
||||
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_authorization_hold())
|
||||
snapshot["release_authorization_truth"]["release_authorization_granted"] = True
|
||||
_write_snapshot(tmp_path, snapshot)
|
||||
|
||||
with pytest.raises(ValueError, match="must remain false"):
|
||||
load_latest_ai_agent_result_capture_release_authorization_hold(tmp_path)
|
||||
|
||||
|
||||
def test_rejects_live_apply_release_enabled(tmp_path: Path) -> None:
|
||||
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_authorization_hold())
|
||||
snapshot["live_apply_authorization_holds"][0]["live_apply_release_enabled"] = True
|
||||
_write_snapshot(tmp_path, snapshot)
|
||||
|
||||
with pytest.raises(ValueError, match="must stay ungranted and disabled"):
|
||||
load_latest_ai_agent_result_capture_release_authorization_hold(tmp_path)
|
||||
|
||||
|
||||
def test_rejects_rollup_drift(tmp_path: Path) -> None:
|
||||
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_authorization_hold())
|
||||
snapshot["rollups"]["release_authorization_hold_count"] = 4
|
||||
_write_snapshot(tmp_path, snapshot)
|
||||
|
||||
with pytest.raises(ValueError, match="rollups mismatch"):
|
||||
load_latest_ai_agent_result_capture_release_authorization_hold(tmp_path)
|
||||
|
||||
|
||||
def test_rejects_forbidden_display_terms(tmp_path: Path) -> None:
|
||||
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_authorization_hold())
|
||||
snapshot["operator_actions"][0]["operator_instruction"] = "不要顯示 work_window_transcript"
|
||||
_write_snapshot(tmp_path, snapshot)
|
||||
|
||||
with pytest.raises(ValueError, match="forbidden display terms leaked"):
|
||||
load_latest_ai_agent_result_capture_release_authorization_hold(tmp_path)
|
||||
|
||||
|
||||
def _write_snapshot(directory: Path, payload: dict) -> None:
|
||||
path = directory / "ai_agent_result_capture_release_authorization_hold_2099-01-01.json"
|
||||
path.write_text(json.dumps(payload, ensure_ascii=False), encoding="utf-8")
|
||||
@@ -0,0 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from src.main import app
|
||||
|
||||
|
||||
def test_release_authorization_hold_endpoint() -> None:
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/api/v1/agents/agent-result-capture-release-authorization-hold")
|
||||
|
||||
assert response.status_code == 200
|
||||
payload = response.json()
|
||||
assert payload["schema_version"] == "ai_agent_result_capture_release_authorization_hold_v1"
|
||||
assert payload["program_status"]["current_task_id"] == "P2-134"
|
||||
assert payload["program_status"]["next_task_id"] == "P2-135"
|
||||
assert payload["program_status"]["overall_completion_percent"] == 100
|
||||
assert payload["program_status"]["runtime_authority"] == "result_capture_release_authorization_hold_only_no_live_write"
|
||||
assert payload["rollups"]["release_authorization_hold_count"] == 5
|
||||
assert payload["rollups"]["rollback_authorization_hold_count"] == 5
|
||||
assert payload["rollups"]["release_window_hold_count"] == 5
|
||||
assert payload["rollups"]["live_apply_authorization_hold_count"] == 5
|
||||
assert payload["rollups"]["blocked_authorization_transition_count"] == 6
|
||||
assert payload["rollups"]["operator_action_count"] == 5
|
||||
assert payload["rollups"]["owner_release_authorized_count"] == 0
|
||||
assert payload["rollups"]["release_authorization_granted_count"] == 0
|
||||
assert payload["rollups"]["gateway_queue_write_count"] == 0
|
||||
assert payload["rollups"]["telegram_send_count"] == 0
|
||||
assert payload["rollups"]["production_write_count"] == 0
|
||||
Reference in New Issue
Block a user