feat(governance): 新增 P2-143 owner response 預檢
All checks were successful
Code Review / ai-code-review (push) Successful in 13s
CD Pipeline / tests (push) Successful in 1m28s
CD Pipeline / build-and-deploy (push) Successful in 4m46s
CD Pipeline / post-deploy-checks (push) Successful in 1m48s

This commit is contained in:
Your Name
2026-06-14 14:37:04 +08:00
parent 1a2c9e36c7
commit 755b0a8d30
12 changed files with 1366 additions and 7 deletions

View File

@@ -0,0 +1,110 @@
from __future__ import annotations
import copy
import json
from pathlib import Path
import pytest
from src.services.ai_agent_result_capture_release_decision_owner_response_preflight import (
load_latest_ai_agent_result_capture_release_decision_owner_response_preflight,
)
def test_load_latest_release_decision_owner_response_preflight_snapshot() -> None:
snapshot = load_latest_ai_agent_result_capture_release_decision_owner_response_preflight()
assert snapshot["schema_version"] == "ai_agent_result_capture_release_decision_owner_response_preflight_v1"
assert snapshot["program_status"]["current_task_id"] == "P2-143"
assert snapshot["program_status"]["next_task_id"] == "P2-144"
assert snapshot["program_status"]["overall_completion_percent"] == 100
assert snapshot["program_status"]["runtime_authority"] == (
"result_capture_release_decision_owner_response_preflight_only_no_live_write"
)
rollups = snapshot["rollups"]
assert rollups["response_intake_lane_count"] == 5
assert rollups["required_owner_field_count"] == 18
assert rollups["intake_validation_check_count"] == 6
assert rollups["rejection_guard_count"] == 6
assert rollups["operator_action_count"] == 5
assert rollups["waiting_external_response_count"] == 5
assert rollups["owner_response_received_count"] == 0
assert rollups["owner_response_accepted_count"] == 0
assert rollups["redacted_payload_ingested_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["production_write_count"] == 0
def test_owner_response_preflight_truth_keeps_all_runtime_gates_closed() -> None:
snapshot = load_latest_ai_agent_result_capture_release_decision_owner_response_preflight()
truth = snapshot["owner_response_preflight_truth"]
assert truth["p2_141_input_prep_loaded"] is True
assert truth["p2_142_war_room_baseline_preserved"] is True
assert truth["preflight_only_mode"] is True
assert truth["rejection_policy_active"] is True
assert truth["owner_response_received"] is False
assert truth["owner_response_accepted"] is False
assert truth["redacted_payload_ingested"] is False
assert truth["release_authorization_granted"] is False
assert truth["reviewer_queue_write_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_missing_response_intake_lane(tmp_path: Path) -> None:
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_decision_owner_response_preflight())
snapshot["response_intake_lanes"] = snapshot["response_intake_lanes"][:-1]
snapshot["rollups"]["response_intake_lane_count"] = 4
_write_snapshot(tmp_path, snapshot)
with pytest.raises(ValueError, match="response intake lanes ids mismatch"):
load_latest_ai_agent_result_capture_release_decision_owner_response_preflight(tmp_path)
def test_rejects_owner_response_received_drift(tmp_path: Path) -> None:
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_decision_owner_response_preflight())
snapshot["owner_response_preflight_truth"]["owner_response_received"] = True
_write_snapshot(tmp_path, snapshot)
with pytest.raises(ValueError, match="flags must remain false"):
load_latest_ai_agent_result_capture_release_decision_owner_response_preflight(tmp_path)
def test_rejects_gateway_write_drift(tmp_path: Path) -> None:
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_decision_owner_response_preflight())
snapshot["rollups"]["gateway_queue_write_count"] = 1
_write_snapshot(tmp_path, snapshot)
with pytest.raises(ValueError, match="rollups mismatch"):
load_latest_ai_agent_result_capture_release_decision_owner_response_preflight(tmp_path)
def test_rejects_forbidden_display_terms(tmp_path: Path) -> None:
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_decision_owner_response_preflight())
snapshot["operator_actions"][0]["operator_instruction"] = "不要顯示 raw_prompt"
_write_snapshot(tmp_path, snapshot)
with pytest.raises(ValueError, match="forbidden display terms leaked"):
load_latest_ai_agent_result_capture_release_decision_owner_response_preflight(tmp_path)
def test_rejects_chinese_forbidden_display_terms(tmp_path: Path) -> None:
snapshot = copy.deepcopy(load_latest_ai_agent_result_capture_release_decision_owner_response_preflight())
snapshot["operator_actions"][0]["operator_instruction"] = "不要顯示工作視窗內容"
_write_snapshot(tmp_path, snapshot)
with pytest.raises(ValueError, match="forbidden display terms leaked"):
load_latest_ai_agent_result_capture_release_decision_owner_response_preflight(tmp_path)
def _write_snapshot(directory: Path, payload: dict) -> None:
path = directory / "ai_agent_result_capture_release_decision_owner_response_preflight_2099-01-01.json"
path.write_text(json.dumps(payload, ensure_ascii=False), encoding="utf-8")

View File

@@ -0,0 +1,49 @@
from __future__ import annotations
from fastapi.testclient import TestClient
from src.main import app
def test_release_decision_owner_response_preflight_endpoint() -> None:
client = TestClient(app)
response = client.get("/api/v1/agents/agent-result-capture-release-decision-owner-response-preflight")
assert response.status_code == 200
payload = response.json()
assert payload["schema_version"] == "ai_agent_result_capture_release_decision_owner_response_preflight_v1"
assert payload["program_status"]["current_task_id"] == "P2-143"
assert payload["program_status"]["next_task_id"] == "P2-144"
assert payload["program_status"]["overall_completion_percent"] == 100
assert payload["program_status"]["runtime_authority"] == (
"result_capture_release_decision_owner_response_preflight_only_no_live_write"
)
assert payload["prior_decision_input_prep"]["schema_version"] == (
"ai_agent_result_capture_release_decision_input_prep_v1"
)
assert payload["prior_decision_input_prep"]["next_task_id"] == "P2-142"
assert payload["rollups"]["response_intake_lane_count"] == 5
assert payload["rollups"]["required_owner_field_count"] == 18
assert payload["rollups"]["intake_validation_check_count"] == 6
assert payload["rollups"]["rejection_guard_count"] == 6
assert payload["rollups"]["operator_action_count"] == 5
assert payload["rollups"]["owner_response_received_count"] == 0
assert payload["rollups"]["owner_response_accepted_count"] == 0
assert payload["rollups"]["redacted_payload_ingested_count"] == 0
assert payload["rollups"]["reviewer_queue_write_count"] == 0
assert payload["rollups"]["gateway_queue_write_count"] == 0
assert payload["rollups"]["telegram_send_count"] == 0
assert payload["rollups"]["bot_api_call_count"] == 0
assert payload["rollups"]["production_write_count"] == 0
owner_lane = payload["response_intake_lanes"][0]
assert owner_lane["lane_id"] == "owner_release_response_preflight"
assert owner_lane["required_fields"] == [
"owner_role_team",
"owner_decision",
"decision_reason",
"affected_scope",
"redacted_evidence_refs",
"followup_owner",
]