from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]


def test_pchome_ai_dashboard_encodes_external_benchmark_guardrails():
    benchmark = (ROOT / "docs/guides/external_professional_benchmark.md").read_text(encoding="utf-8")
    route_source = (ROOT / "routes/dashboard_routes.py").read_text(encoding="utf-8")
    dashboard = (ROOT / "templates/dashboard_v2.html").read_text(encoding="utf-8")

    assert "2026-07-02 AI automation dashboard benchmark" in benchmark
    assert "Grafana" in benchmark
    assert "Datadog" in benchmark
    assert "New Relic" in benchmark
    assert "Atlassian Statuspage" in benchmark
    assert "狀態分層" in benchmark
    assert "下一步優先" in benchmark
    assert "證據按需" in benchmark
    assert "golden signals" in benchmark

    assert "'status_layering': True" in route_source
    assert "'next_action_first': True" in route_source
    assert "'evidence_on_demand': True" in route_source
    assert "'golden_signal_summary': True" in route_source
    assert "today_status = [" in route_source
    assert "'label': '已自動落地'" in route_source
    assert "'label': '已驗證'" in route_source
    assert "'label': '異動狀態'" in route_source
    assert "'label': '下一步'" in route_source
    assert "_machine_action_label" in route_source

    assert 'aria-label="今日 AI 自動化狀態"' in dashboard
    assert "ai_first_viewport.today_status" in dashboard
    assert "status.label" in dashboard
    assert "status.detail" in dashboard
    assert "growth.automation_pipeline" in dashboard
