feat(governance): 新增 owner acceptance preflight hold
This commit is contained in:
@@ -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