from __future__ import annotations

import json

from src.services.ai_agent_market_radar_readback import (
    load_latest_ai_agent_market_radar_readback,
)


def test_ai_agent_market_radar_readback_committed_snapshot_is_safe():
    payload = load_latest_ai_agent_market_radar_readback()

    assert payload["schema_version"] == "ai_agent_market_radar_readback_v1"
    assert payload["summary"]["overall_completion_percent"] == 42.2
    assert payload["summary"]["market_candidates"] == 13
    assert payload["summary"]["market_sources"] == 36
    assert payload["summary"]["changed_candidates"] == 5
    assert payload["summary"]["integration_blocked_candidates"] == 5
    assert payload["summary"]["source_failures"] == 0
    assert payload["summary"]["replacement_decisions_approved"] == 0
    assert "gitea_main_deploy_marker" not in payload["source_scope"]
    assert payload["source_scope"]["gitea_main_evidence_basis_commit"] == "61cf5024"

    policy = payload["policy"]
    assert policy["read_only"] is True
    assert policy["sdk_installation_approved"] is False
    assert policy["paid_api_calls_approved"] is False
    assert policy["replay_candidate_approved"] is False
    assert policy["shadow_or_canary_approved"] is False
    assert policy["production_routing_approved"] is False
    assert policy["telegram_send_approved"] is False
    assert policy["host_write_approved"] is False
    assert policy["workflow_modification_approved"] is False
    assert policy["openclaw_replacement_approved"] is False

    serialized = json.dumps(payload, ensure_ascii=False)
    assert "/Users/" not in serialized
    assert ".claude/projects" not in serialized
    assert ".codex" not in serialized
    assert "192.168." not in serialized
    assert "auth.json" not in serialized


def test_ai_agent_market_radar_readback_contains_market_practice_plan():
    payload = load_latest_ai_agent_market_radar_readback()

    practices = {
        row["practice"]: row["awoooi_status"]
        for row in payload["market_practice_alignment"]
    }
    assert practices["多 Agent handoff / specialist delegation"] == "partially_modeled"
    assert practices["Durable execution / persistence / human-in-the-loop"] == (
        "needed_for_incident_loop"
    )

    candidates = {
        row["candidate_id"]: row
        for row in payload["candidate_role_plan"]
    }
    assert candidates["openclaw_incumbent"]["gate_status"] == "production_baseline"
    assert candidates["nemo_nemotron_fabric"]["gate_status"] == "integration_blocked"
    assert candidates["langgraph_incident_kernel"]["gate_status"] == "registered_no_review"
