feat(governance): 新增 owner acceptance preflight hold
This commit is contained in:
@@ -130,6 +130,9 @@ from src.services.ai_agent_result_capture_owner_approved_execution_rehearsal imp
|
||||
from src.services.ai_agent_result_capture_owner_acceptance_maintenance_gate import (
|
||||
load_latest_ai_agent_result_capture_owner_acceptance_maintenance_gate,
|
||||
)
|
||||
from src.services.ai_agent_result_capture_owner_acceptance_readback_preflight_hold import (
|
||||
load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold,
|
||||
)
|
||||
from src.services.ai_agent_result_capture_promotion_approval_gate import (
|
||||
load_latest_ai_agent_result_capture_promotion_approval_gate,
|
||||
)
|
||||
@@ -1917,6 +1920,36 @@ async def get_agent_result_capture_owner_acceptance_maintenance_gate() -> dict[s
|
||||
) from exc
|
||||
|
||||
|
||||
@router.get(
|
||||
"/agent-result-capture-owner-acceptance-readback-preflight-hold",
|
||||
response_model=dict[str, Any],
|
||||
summary="取得 AI Agent result capture owner acceptance readback preflight hold",
|
||||
description=(
|
||||
"讀取最新已提交的 P2-128 owner acceptance readback / preflight hold;"
|
||||
"此端點只回傳 owner acceptance readback、live-apply preflight hold、"
|
||||
"live apply hold gate、rollback preflight、blocked apply transition 與 operator handoff,"
|
||||
"不釋放 live apply、不套用 writer、不寫 receipt、不寫 result capture、learning、PlayBook trust、"
|
||||
"reviewer queue、Gateway queue,不送 Telegram、不呼叫 Bot API、不讀 secret。"
|
||||
),
|
||||
)
|
||||
async def get_agent_result_capture_owner_acceptance_readback_preflight_hold() -> dict[str, Any]:
|
||||
"""Return the latest read-only owner acceptance readback / preflight hold package."""
|
||||
try:
|
||||
payload = await asyncio.to_thread(load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold)
|
||||
return redact_public_lan_topology(payload)
|
||||
except FileNotFoundError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
except (json.JSONDecodeError, ValueError) as exc:
|
||||
logger.error("ai_agent_result_capture_owner_acceptance_readback_preflight_hold_invalid", error=str(exc))
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="AI Agent result capture owner acceptance readback preflight hold 無效",
|
||||
) from exc
|
||||
|
||||
|
||||
@router.get(
|
||||
"/agent-owner-approved-fixture-dry-run",
|
||||
response_model=dict[str, Any],
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
"""
|
||||
AI Agent result capture owner acceptance readback preflight hold snapshot.
|
||||
|
||||
Loads the latest committed P2-128 owner acceptance readback / preflight hold
|
||||
package. This module validates committed evidence only; it never releases live
|
||||
apply, applies writers, writes receipts, writes result captures, writes
|
||||
learning records, updates PlayBook trust, writes reviewer / Gateway queues,
|
||||
sends Telegram messages, reads secrets, or performs destructive operations.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from src.services.snapshot_paths import default_evaluations_dir
|
||||
|
||||
_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__))
|
||||
_SNAPSHOT_PATTERN = "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_*.json"
|
||||
_SCHEMA_VERSION = "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_v1"
|
||||
_RUNTIME_AUTHORITY = "result_capture_owner_acceptance_readback_preflight_hold_only_no_live_write"
|
||||
|
||||
|
||||
def load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold(
|
||||
evaluations_dir: Path | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Load the newest committed owner acceptance readback / preflight hold package."""
|
||||
directory = evaluations_dir or _DEFAULT_EVALUATIONS_DIR
|
||||
candidates = sorted(directory.glob(_SNAPSHOT_PATTERN))
|
||||
if not candidates:
|
||||
raise FileNotFoundError(f"no AI Agent result capture owner acceptance readback preflight hold snapshots found in {directory}")
|
||||
|
||||
latest = candidates[-1]
|
||||
with latest.open(encoding="utf-8") as handle:
|
||||
payload = json.load(handle)
|
||||
|
||||
if not isinstance(payload, dict):
|
||||
raise ValueError(f"{latest}: expected JSON object")
|
||||
|
||||
label = str(latest)
|
||||
_require_schema(payload, label)
|
||||
_require_prior(payload, label)
|
||||
_require_truth(payload, label)
|
||||
_require_acceptance_readbacks(payload, label)
|
||||
_require_preflight_holds(payload, label)
|
||||
_require_live_apply_hold_gates(payload, label)
|
||||
_require_rollback_preflights(payload, label)
|
||||
_require_blocked_transitions(payload, label)
|
||||
_require_actions(payload, label)
|
||||
_require_display_redaction(payload, label)
|
||||
_require_no_forbidden_display_terms(payload, label)
|
||||
_require_rollup_consistency(payload, label)
|
||||
return payload
|
||||
|
||||
|
||||
def _require_schema(payload: dict[str, Any], label: str) -> None:
|
||||
if payload.get("schema_version") != _SCHEMA_VERSION:
|
||||
raise ValueError(f"{label}: expected schema_version={_SCHEMA_VERSION}")
|
||||
status = payload.get("program_status") or {}
|
||||
expected = {
|
||||
"current_priority": "P2",
|
||||
"current_task_id": "P2-128",
|
||||
"next_task_id": "P2-129",
|
||||
"read_only_mode": True,
|
||||
"runtime_authority": _RUNTIME_AUTHORITY,
|
||||
"overall_completion_percent": 100,
|
||||
}
|
||||
mismatches = _mismatches(status, expected)
|
||||
if mismatches:
|
||||
raise ValueError(f"{label}: program_status mismatch: {mismatches}")
|
||||
if not status.get("status_note"):
|
||||
raise ValueError(f"{label}: program_status.status_note is required")
|
||||
|
||||
|
||||
def _require_prior(payload: dict[str, Any], label: str) -> None:
|
||||
prior = payload.get("prior_owner_acceptance_maintenance_gate") or {}
|
||||
expected = {
|
||||
"schema_version": "ai_agent_result_capture_owner_acceptance_maintenance_gate_v1",
|
||||
"owner_acceptance_packet_count": 5,
|
||||
"maintenance_window_count": 5,
|
||||
"rollback_owner_check_count": 5,
|
||||
"post_apply_verifier_gate_count": 5,
|
||||
"blocked_live_write_count": 6,
|
||||
"operator_action_count": 5,
|
||||
"approval_required_total": 8,
|
||||
"blocked_total": 9,
|
||||
"owner_acceptance_received_count": 0,
|
||||
"maintenance_window_approved_count": 0,
|
||||
"rollback_owner_confirmed_count": 0,
|
||||
"post_apply_verifier_ready_count": 0,
|
||||
"writer_apply_count": 0,
|
||||
"execution_apply_count": 0,
|
||||
"receipt_write_count": 0,
|
||||
"result_capture_write_count": 0,
|
||||
"learning_write_count": 0,
|
||||
"playbook_trust_write_count": 0,
|
||||
"reviewer_queue_write_count": 0,
|
||||
"gateway_queue_write_count": 0,
|
||||
"telegram_send_count": 0,
|
||||
"bot_api_call_count": 0,
|
||||
"report_receipt_write_count": 0,
|
||||
}
|
||||
mismatches = _mismatches(prior, expected)
|
||||
if mismatches:
|
||||
raise ValueError(f"{label}: prior_owner_acceptance_maintenance_gate mismatch: {mismatches}")
|
||||
if not prior.get("readiness_note"):
|
||||
raise ValueError(f"{label}: prior_owner_acceptance_maintenance_gate.readiness_note is required")
|
||||
|
||||
|
||||
def _require_truth(payload: dict[str, Any], label: str) -> None:
|
||||
truth = payload.get("readback_truth") or {}
|
||||
required_true = {
|
||||
"p2_127_owner_acceptance_gate_loaded",
|
||||
"owner_acceptance_readback_ready",
|
||||
"preflight_hold_required",
|
||||
"live_apply_hold_active",
|
||||
"rollback_preflight_required",
|
||||
"post_apply_verifier_required",
|
||||
"redaction_review_required",
|
||||
"readback_only",
|
||||
}
|
||||
missing = sorted(field for field in required_true if truth.get(field) is not True)
|
||||
if missing:
|
||||
raise ValueError(f"{label}: readback ready flags must remain true: {missing}")
|
||||
|
||||
required_false = {
|
||||
"owner_acceptance_received",
|
||||
"maintenance_window_approved",
|
||||
"rollback_owner_confirmed",
|
||||
"post_apply_verifier_ready",
|
||||
"live_apply_preflight_passed",
|
||||
"writer_apply_enabled",
|
||||
"execution_apply_enabled",
|
||||
"receipt_write_enabled",
|
||||
"reviewer_queue_write_enabled",
|
||||
"gateway_queue_write_enabled",
|
||||
"telegram_send_enabled",
|
||||
"bot_api_call_enabled",
|
||||
"report_receipt_write_enabled",
|
||||
"result_capture_write_enabled",
|
||||
"learning_write_enabled",
|
||||
"playbook_trust_write_enabled",
|
||||
"production_write_enabled",
|
||||
"secret_read_enabled",
|
||||
"destructive_operation_enabled",
|
||||
}
|
||||
unsafe = sorted(field for field in required_false if truth.get(field) is not False)
|
||||
if unsafe:
|
||||
raise ValueError(f"{label}: live release/send/write flags must remain false: {unsafe}")
|
||||
|
||||
zero_counts = {
|
||||
"owner_acceptance_received_count",
|
||||
"maintenance_window_approved_count",
|
||||
"rollback_owner_confirmed_count",
|
||||
"post_apply_verifier_ready_count",
|
||||
"live_apply_preflight_pass_count",
|
||||
"writer_apply_count",
|
||||
"execution_apply_count",
|
||||
"receipt_write_count",
|
||||
"reviewer_queue_write_count",
|
||||
"gateway_queue_write_count",
|
||||
"telegram_send_count",
|
||||
"bot_api_call_count",
|
||||
"report_receipt_write_count",
|
||||
"result_capture_write_count",
|
||||
"learning_write_count",
|
||||
"playbook_trust_write_count",
|
||||
"production_write_count",
|
||||
"secret_read_count",
|
||||
"destructive_operation_count",
|
||||
}
|
||||
non_zero = sorted(field for field in zero_counts if truth.get(field) != 0)
|
||||
if non_zero:
|
||||
raise ValueError(f"{label}: readback live counters must remain zero: {non_zero}")
|
||||
if not truth.get("truth_note"):
|
||||
raise ValueError(f"{label}: readback_truth.truth_note is required")
|
||||
|
||||
|
||||
def _require_acceptance_readbacks(payload: dict[str, Any], label: str) -> None:
|
||||
items = payload.get("owner_acceptance_readbacks") or []
|
||||
required = {
|
||||
"readback_result_capture_writer",
|
||||
"readback_learning_writer",
|
||||
"readback_playbook_trust_writer",
|
||||
"readback_reviewer_queue_writer",
|
||||
"readback_gateway_queue_writer",
|
||||
}
|
||||
ids = {item.get("readback_id") for item in items}
|
||||
if ids != required:
|
||||
raise ValueError(f"{label}: owner acceptance readbacks must match {sorted(required)}")
|
||||
for item in items:
|
||||
item_id = item.get("readback_id")
|
||||
if item.get("readback_mode") != "owner_acceptance_status_readback":
|
||||
raise ValueError(f"{label}: readback {item_id} must remain owner acceptance status readback")
|
||||
if item.get("owner_acceptance_received") is not False:
|
||||
raise ValueError(f"{label}: readback {item_id} must not mark owner acceptance received")
|
||||
if item.get("status") not in {"ready_for_preflight_review", "approval_required", "blocked_by_policy"}:
|
||||
raise ValueError(f"{label}: readback {item_id} status is invalid")
|
||||
if not item.get("readback_summary") or not _is_redacted_sha256(item.get("source_hash")):
|
||||
raise ValueError(f"{label}: readback {item_id} must include summary and redacted source_hash")
|
||||
|
||||
|
||||
def _require_preflight_holds(payload: dict[str, Any], label: str) -> None:
|
||||
items = payload.get("preflight_hold_checks") or []
|
||||
required = {
|
||||
"preflight_result_capture_writer",
|
||||
"preflight_learning_writer",
|
||||
"preflight_playbook_trust_writer",
|
||||
"preflight_reviewer_queue_writer",
|
||||
"preflight_gateway_queue_writer",
|
||||
}
|
||||
ids = {item.get("check_id") for item in items}
|
||||
if ids != required:
|
||||
raise ValueError(f"{label}: preflight hold checks must match {sorted(required)}")
|
||||
for item in items:
|
||||
item_id = item.get("check_id")
|
||||
if item.get("preflight_mode") != "live_apply_preflight_hold":
|
||||
raise ValueError(f"{label}: preflight {item_id} must remain live apply preflight hold")
|
||||
if item.get("hold_required") is not True or item.get("preflight_passed") is not False:
|
||||
raise ValueError(f"{label}: preflight {item_id} must stay held and unpassed")
|
||||
if item.get("status") not in {"ready_for_preflight_review", "approval_required", "blocked_by_policy"}:
|
||||
raise ValueError(f"{label}: preflight {item_id} status is invalid")
|
||||
if not item.get("required_before_release"):
|
||||
raise ValueError(f"{label}: preflight {item_id} required_before_release is required")
|
||||
|
||||
|
||||
def _require_live_apply_hold_gates(payload: dict[str, Any], label: str) -> None:
|
||||
items = payload.get("live_apply_hold_gates") or []
|
||||
required = {
|
||||
"hold_gate_result_capture",
|
||||
"hold_gate_learning",
|
||||
"hold_gate_playbook_trust",
|
||||
"hold_gate_reviewer_queue",
|
||||
"hold_gate_gateway_queue",
|
||||
}
|
||||
ids = {item.get("gate_id") for item in items}
|
||||
if ids != required:
|
||||
raise ValueError(f"{label}: live apply hold gates must match {sorted(required)}")
|
||||
for item in items:
|
||||
item_id = item.get("gate_id")
|
||||
if item.get("gate_mode") != "live_apply_hold_gate":
|
||||
raise ValueError(f"{label}: hold gate {item_id} must remain live apply hold gate")
|
||||
if item.get("live_apply_enabled") is not False:
|
||||
raise ValueError(f"{label}: hold gate {item_id} must not enable live apply")
|
||||
if item.get("status") not in {"ready_for_preflight_review", "approval_required", "blocked_by_policy"}:
|
||||
raise ValueError(f"{label}: hold gate {item_id} status is invalid")
|
||||
if not item.get("hold_reason") or not item.get("release_condition"):
|
||||
raise ValueError(f"{label}: hold gate {item_id} hold_reason and release_condition are required")
|
||||
|
||||
|
||||
def _require_rollback_preflights(payload: dict[str, Any], label: str) -> None:
|
||||
items = payload.get("rollback_preflight_checks") or []
|
||||
required = {
|
||||
"rollback_preflight_result_capture",
|
||||
"rollback_preflight_learning",
|
||||
"rollback_preflight_playbook_trust",
|
||||
"rollback_preflight_reviewer_queue",
|
||||
"rollback_preflight_gateway_queue",
|
||||
}
|
||||
ids = {item.get("check_id") for item in items}
|
||||
if ids != required:
|
||||
raise ValueError(f"{label}: rollback preflight checks must match {sorted(required)}")
|
||||
for item in items:
|
||||
item_id = item.get("check_id")
|
||||
if item.get("rollback_owner_required") is not True or item.get("rollback_preflight_passed") is not False:
|
||||
raise ValueError(f"{label}: rollback preflight {item_id} must stay required and unpassed")
|
||||
if item.get("status") not in {"ready_for_preflight_review", "approval_required", "blocked_by_policy"}:
|
||||
raise ValueError(f"{label}: rollback preflight {item_id} status is invalid")
|
||||
if not item.get("rollback_scope") or not item.get("hold_reason"):
|
||||
raise ValueError(f"{label}: rollback preflight {item_id} scope and hold_reason are required")
|
||||
|
||||
|
||||
def _require_blocked_transitions(payload: dict[str, Any], label: str) -> None:
|
||||
items = payload.get("blocked_apply_transitions") or []
|
||||
required = {
|
||||
"blocked_writer_apply_release",
|
||||
"blocked_execution_apply_release",
|
||||
"blocked_receipt_write_release",
|
||||
"blocked_result_capture_write_release",
|
||||
"blocked_gateway_queue_write_release",
|
||||
"blocked_telegram_send_release",
|
||||
}
|
||||
ids = {item.get("blocker_id") for item in items}
|
||||
if ids != required:
|
||||
raise ValueError(f"{label}: blocked apply transitions must match {sorted(required)}")
|
||||
for item in items:
|
||||
item_id = item.get("blocker_id")
|
||||
if item.get("status") not in {"approval_required", "blocked_by_policy"}:
|
||||
raise ValueError(f"{label}: blocker {item_id} status is invalid")
|
||||
if item.get("severity") not in {"high", "critical"}:
|
||||
raise ValueError(f"{label}: blocker {item_id} severity is invalid")
|
||||
if not item.get("blocked_action") or not item.get("blocked_until"):
|
||||
raise ValueError(f"{label}: blocker {item_id} must include blocked_action and blocked_until")
|
||||
if not _is_redacted_sha256(item.get("evidence_hash")):
|
||||
raise ValueError(f"{label}: blocker {item_id} must expose redacted evidence_hash")
|
||||
|
||||
|
||||
def _require_actions(payload: dict[str, Any], label: str) -> None:
|
||||
actions = payload.get("operator_actions") or []
|
||||
required = {
|
||||
"review_acceptance_readbacks",
|
||||
"hold_preflight_release",
|
||||
"verify_rollback_preflight",
|
||||
"verify_gateway_telegram_hold",
|
||||
"prepare_p2_129_release_package",
|
||||
}
|
||||
ids = {action.get("action_id") for action in actions}
|
||||
if ids != required:
|
||||
raise ValueError(f"{label}: operator actions must match {sorted(required)}")
|
||||
for action in actions:
|
||||
action_id = action.get("action_id")
|
||||
if action.get("runtime_write_allowed") is not False:
|
||||
raise ValueError(f"{label}: action {action_id} must not allow runtime write")
|
||||
if not action.get("operator_instruction"):
|
||||
raise ValueError(f"{label}: action {action_id} operator_instruction is required")
|
||||
|
||||
|
||||
def _require_display_redaction(payload: dict[str, Any], label: str) -> None:
|
||||
contract = payload.get("display_redaction_contract") or {}
|
||||
expected = {
|
||||
"redaction_required": True,
|
||||
"raw_prompt_display_allowed": False,
|
||||
"private_reasoning_display_allowed": False,
|
||||
"secret_value_display_allowed": False,
|
||||
"raw_runtime_payload_display_allowed": False,
|
||||
"internal_collaboration_content_display_allowed": False,
|
||||
}
|
||||
mismatches = _mismatches(contract, expected)
|
||||
if mismatches:
|
||||
raise ValueError(f"{label}: display_redaction_contract mismatch: {mismatches}")
|
||||
if not contract.get("frontend_display_policy"):
|
||||
raise ValueError(f"{label}: display_redaction_contract.frontend_display_policy is required")
|
||||
|
||||
|
||||
def _require_rollup_consistency(payload: dict[str, Any], label: str) -> None:
|
||||
rollups = payload.get("rollups") or {}
|
||||
readbacks = payload.get("owner_acceptance_readbacks") or []
|
||||
preflights = payload.get("preflight_hold_checks") or []
|
||||
hold_gates = payload.get("live_apply_hold_gates") or []
|
||||
rollbacks = payload.get("rollback_preflight_checks") or []
|
||||
blockers = payload.get("blocked_apply_transitions") or []
|
||||
actions = payload.get("operator_actions") or []
|
||||
expected = {
|
||||
"owner_acceptance_readback_count": len(readbacks),
|
||||
"preflight_hold_check_count": len(preflights),
|
||||
"live_apply_hold_gate_count": len(hold_gates),
|
||||
"rollback_preflight_check_count": len(rollbacks),
|
||||
"blocked_apply_transition_count": len(blockers),
|
||||
"operator_action_count": len(actions),
|
||||
"approval_required_readback_count": sum(1 for item in readbacks if item.get("status") == "approval_required"),
|
||||
"blocked_readback_count": sum(1 for item in readbacks if item.get("status") == "blocked_by_policy"),
|
||||
"approval_required_preflight_count": sum(1 for item in preflights if item.get("status") == "approval_required"),
|
||||
"blocked_preflight_count": sum(1 for item in preflights if item.get("status") == "blocked_by_policy"),
|
||||
"approval_required_hold_gate_count": sum(1 for item in hold_gates if item.get("status") == "approval_required"),
|
||||
"blocked_hold_gate_count": sum(1 for item in hold_gates if item.get("status") == "blocked_by_policy"),
|
||||
"approval_required_rollback_count": sum(1 for item in rollbacks if item.get("status") == "approval_required"),
|
||||
"blocked_rollback_count": sum(1 for item in rollbacks if item.get("status") == "blocked_by_policy"),
|
||||
"critical_blocker_count": sum(1 for item in blockers if item.get("severity") == "critical"),
|
||||
"owner_acceptance_received_count": 0,
|
||||
"maintenance_window_approved_count": 0,
|
||||
"rollback_owner_confirmed_count": 0,
|
||||
"post_apply_verifier_ready_count": 0,
|
||||
"live_apply_preflight_pass_count": 0,
|
||||
"writer_apply_count": 0,
|
||||
"execution_apply_count": 0,
|
||||
"receipt_write_count": 0,
|
||||
"reviewer_queue_write_count": 0,
|
||||
"gateway_queue_write_count": 0,
|
||||
"telegram_send_count": 0,
|
||||
"bot_api_call_count": 0,
|
||||
"report_receipt_write_count": 0,
|
||||
"result_capture_write_count": 0,
|
||||
"learning_write_count": 0,
|
||||
"playbook_trust_write_count": 0,
|
||||
"production_write_count": 0,
|
||||
"secret_read_count": 0,
|
||||
"destructive_operation_count": 0,
|
||||
}
|
||||
mismatches = _mismatches(rollups, expected)
|
||||
if mismatches:
|
||||
raise ValueError(f"{label}: rollup counts mismatch: {mismatches}")
|
||||
|
||||
|
||||
def _require_no_forbidden_display_terms(payload: dict[str, Any], label: str) -> None:
|
||||
serialized = json.dumps(payload, ensure_ascii=False)
|
||||
forbidden = {
|
||||
"work_window_transcript",
|
||||
"session_id",
|
||||
"browser_context",
|
||||
"authorization_header",
|
||||
"raw Telegram payload",
|
||||
"private reasoning",
|
||||
"raw prompt",
|
||||
"chain-of-thought",
|
||||
}
|
||||
hits = sorted(term for term in forbidden if term in serialized)
|
||||
if hits:
|
||||
raise ValueError(f"{label}: forbidden display terms present: {hits}")
|
||||
|
||||
|
||||
def _is_redacted_sha256(value: Any) -> bool:
|
||||
if not isinstance(value, str) or not value.startswith("sha256:"):
|
||||
return False
|
||||
digest = value.removeprefix("sha256:")
|
||||
return len(digest) == 64 and all(char in "0123456789abcdef" for char in digest)
|
||||
|
||||
|
||||
def _mismatches(payload: dict[str, Any], expected: dict[str, Any]) -> dict[str, dict[str, Any]]:
|
||||
return {
|
||||
key: {"expected": value, "actual": payload.get(key)}
|
||||
for key, value in expected.items()
|
||||
if payload.get(key) != value
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.services.ai_agent_result_capture_owner_acceptance_readback_preflight_hold import (
|
||||
load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold,
|
||||
)
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[3]
|
||||
FIXTURE = REPO_ROOT / "docs/evaluations/ai_agent_result_capture_owner_acceptance_readback_preflight_hold_2026-06-14.json"
|
||||
|
||||
|
||||
def test_load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold_snapshot() -> None:
|
||||
data = load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold()
|
||||
|
||||
assert data["schema_version"] == "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_v1"
|
||||
assert data["program_status"]["current_task_id"] == "P2-128"
|
||||
assert data["program_status"]["next_task_id"] == "P2-129"
|
||||
assert data["program_status"]["runtime_authority"] == "result_capture_owner_acceptance_readback_preflight_hold_only_no_live_write"
|
||||
|
||||
rollups = data["rollups"]
|
||||
assert rollups["owner_acceptance_readback_count"] == 5
|
||||
assert rollups["preflight_hold_check_count"] == 5
|
||||
assert rollups["live_apply_hold_gate_count"] == 5
|
||||
assert rollups["rollback_preflight_check_count"] == 5
|
||||
assert rollups["blocked_apply_transition_count"] == 6
|
||||
assert rollups["operator_action_count"] == 5
|
||||
assert rollups["critical_blocker_count"] == 5
|
||||
assert rollups["owner_acceptance_received_count"] == 0
|
||||
assert rollups["maintenance_window_approved_count"] == 0
|
||||
assert rollups["rollback_owner_confirmed_count"] == 0
|
||||
assert rollups["post_apply_verifier_ready_count"] == 0
|
||||
assert rollups["live_apply_preflight_pass_count"] == 0
|
||||
assert rollups["writer_apply_count"] == 0
|
||||
assert rollups["execution_apply_count"] == 0
|
||||
assert rollups["receipt_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["result_capture_write_count"] == 0
|
||||
assert rollups["learning_write_count"] == 0
|
||||
assert rollups["playbook_trust_write_count"] == 0
|
||||
assert rollups["production_write_count"] == 0
|
||||
assert {item["owner_acceptance_received"] for item in data["owner_acceptance_readbacks"]} == {False}
|
||||
assert {item["preflight_passed"] for item in data["preflight_hold_checks"]} == {False}
|
||||
assert {item["live_apply_enabled"] for item in data["live_apply_hold_gates"]} == {False}
|
||||
assert {item["rollback_preflight_passed"] for item in data["rollback_preflight_checks"]} == {False}
|
||||
|
||||
|
||||
def _copy_fixture(tmp_path: Path) -> dict:
|
||||
source = json.loads(FIXTURE.read_text(encoding="utf-8"))
|
||||
target = tmp_path / "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_2026-06-14.json"
|
||||
target.write_text(json.dumps(source, ensure_ascii=False), encoding="utf-8")
|
||||
return source
|
||||
|
||||
|
||||
def test_result_capture_owner_acceptance_readback_preflight_hold_rejects_owner_acceptance_received(tmp_path: Path) -> None:
|
||||
source = _copy_fixture(tmp_path)
|
||||
source["owner_acceptance_readbacks"][0]["owner_acceptance_received"] = True
|
||||
target = tmp_path / "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_2026-06-14.json"
|
||||
target.write_text(json.dumps(source, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
with pytest.raises(ValueError, match="must not mark owner acceptance received"):
|
||||
load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold(tmp_path)
|
||||
|
||||
|
||||
def test_result_capture_owner_acceptance_readback_preflight_hold_rejects_preflight_passed(tmp_path: Path) -> None:
|
||||
source = _copy_fixture(tmp_path)
|
||||
source["preflight_hold_checks"][0]["preflight_passed"] = True
|
||||
target = tmp_path / "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_2026-06-14.json"
|
||||
target.write_text(json.dumps(source, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
with pytest.raises(ValueError, match="must stay held and unpassed"):
|
||||
load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold(tmp_path)
|
||||
|
||||
|
||||
def test_result_capture_owner_acceptance_readback_preflight_hold_rejects_live_apply_enabled(tmp_path: Path) -> None:
|
||||
source = _copy_fixture(tmp_path)
|
||||
source["live_apply_hold_gates"][0]["live_apply_enabled"] = True
|
||||
target = tmp_path / "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_2026-06-14.json"
|
||||
target.write_text(json.dumps(source, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
with pytest.raises(ValueError, match="must not enable live apply"):
|
||||
load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold(tmp_path)
|
||||
|
||||
|
||||
def test_result_capture_owner_acceptance_readback_preflight_hold_rejects_rollup_drift(tmp_path: Path) -> None:
|
||||
source = _copy_fixture(tmp_path)
|
||||
source["rollups"]["owner_acceptance_readback_count"] = 4
|
||||
target = tmp_path / "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_2026-06-14.json"
|
||||
target.write_text(json.dumps(source, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
with pytest.raises(ValueError, match="rollup counts mismatch"):
|
||||
load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold(tmp_path)
|
||||
|
||||
|
||||
def test_result_capture_owner_acceptance_readback_preflight_hold_rejects_forbidden_display_terms(tmp_path: Path) -> None:
|
||||
source = _copy_fixture(tmp_path)
|
||||
source["operator_actions"][0]["operator_instruction"] = "work_window_transcript must never show"
|
||||
target = tmp_path / "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_2026-06-14.json"
|
||||
target.write_text(json.dumps(source, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
with pytest.raises(ValueError, match="forbidden display terms"):
|
||||
load_latest_ai_agent_result_capture_owner_acceptance_readback_preflight_hold(tmp_path)
|
||||
@@ -0,0 +1,45 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from src.main import app
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_agent_result_capture_owner_acceptance_readback_preflight_hold_api() -> None:
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://testserver") as client:
|
||||
response = await client.get("/api/v1/agents/agent-result-capture-owner-acceptance-readback-preflight-hold")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["schema_version"] == "ai_agent_result_capture_owner_acceptance_readback_preflight_hold_v1"
|
||||
assert data["program_status"]["current_task_id"] == "P2-128"
|
||||
assert data["program_status"]["next_task_id"] == "P2-129"
|
||||
|
||||
rollups = data["rollups"]
|
||||
assert rollups["owner_acceptance_readback_count"] == 5
|
||||
assert rollups["preflight_hold_check_count"] == 5
|
||||
assert rollups["live_apply_hold_gate_count"] == 5
|
||||
assert rollups["rollback_preflight_check_count"] == 5
|
||||
assert rollups["blocked_apply_transition_count"] == 6
|
||||
assert rollups["operator_action_count"] == 5
|
||||
assert rollups["owner_acceptance_received_count"] == 0
|
||||
assert rollups["maintenance_window_approved_count"] == 0
|
||||
assert rollups["rollback_owner_confirmed_count"] == 0
|
||||
assert rollups["post_apply_verifier_ready_count"] == 0
|
||||
assert rollups["live_apply_preflight_pass_count"] == 0
|
||||
assert rollups["writer_apply_count"] == 0
|
||||
assert rollups["execution_apply_count"] == 0
|
||||
assert rollups["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["gateway_queue_write_count"] == 0
|
||||
assert rollups["telegram_send_count"] == 0
|
||||
assert rollups["bot_api_call_count"] == 0
|
||||
assert rollups["production_write_count"] == 0
|
||||
assert {item["owner_acceptance_received"] for item in data["owner_acceptance_readbacks"]} == {False}
|
||||
assert {item["preflight_passed"] for item in data["preflight_hold_checks"]} == {False}
|
||||
assert {item["live_apply_enabled"] for item in data["live_apply_hold_gates"]} == {False}
|
||||
Reference in New Issue
Block a user