from pathlib import Path


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


def _read(path: str) -> str:
    return (ROOT / path).read_text(encoding="utf-8")


def test_ai_intelligence_first_viewport_has_benchmark_golden_signals():
    template = _read("templates/ai_intelligence.html")
    strip = template.split('aria-label="AI 自動化狀態"', 1)[1].split(
        '<div class="growth-command-focus"',
        1,
    )[0]

    assert 'data-benchmark-guardrail="golden-signals"' in strip
    assert 'data-signal="automated-landing"' in strip
    assert 'data-signal="verified"' in strip
    assert 'data-signal="change-state"' in strip
    assert 'data-signal="next-machine-action"' in strip
    assert "已自動落地" in strip
    assert "已驗證" in strip
    assert "異動狀態" in strip
    assert "下一步" in strip
    assert "loadAutomationBenchmarkStrip()" in template
    assert "/api/ai/pchome-growth/ai-automation-surface-summary" in template
    assert "golden_signals" in template


def test_observability_overview_first_viewport_has_benchmark_golden_signals():
    template = _read("templates/admin/observability_overview.html")
    strip = template.split('aria-label="AI 自動化狀態"', 1)[1].split(
        '<div class="obs-command-strip">',
        1,
    )[0]

    assert 'data-benchmark-guardrail="golden-signals"' in strip
    assert 'data-signal="automated-landing"' in strip
    assert 'data-signal="verified"' in strip
    assert 'data-signal="change-state"' in strip
    assert 'data-signal="next-machine-action"' in strip
    assert "已自動落地" in strip
    assert "已驗證" in strip
    assert "異動狀態" in strip
    assert "下一步" in strip
    assert "維持監控" in strip
    assert "先處理風險" in strip


def test_benchmark_guardrail_surfaces_keep_evidence_on_demand_language():
    combined = "\n".join(
        [
            _read("templates/ai_intelligence.html").split('aria-label="AI 自動化狀態"', 1)[1].split(
                '<div class="growth-command-focus"',
                1,
            )[0],
            _read("templates/admin/observability_overview.html").split('aria-label="AI 自動化狀態"', 1)[1].split(
                '<div class="obs-command-strip">',
                1,
            )[0],
        ]
    )

    forbidden_visible_terms = [
        "DB writes",
        "Artifact",
        "endpoint",
        "JSON",
        "table",
        "manual review",
        "human gate",
    ]
    for term in forbidden_visible_terms:
        assert term not in combined
