from pathlib import Path


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


def test_ai_automation_smoke_uses_compact_workbench_density_contract():
    template = (ROOT / "templates/ai_automation_smoke.html").read_text(encoding="utf-8")

    assert 'data-density-guardrail="compact-smoke-workbench"' in template
    assert "AI 自動化健康檢查" in template
    assert "AI 巡檢" in template
    assert "風險優先" in template
    assert "推播摘要" in template

    assert ".smoke-lede,\n    .smoke-help-copy,\n    .detail-box" in template
    assert ".detail-box {\n        display: none;" in template


def test_ai_automation_smoke_keeps_status_numbers_and_hides_explanatory_copy():
    template = (ROOT / "templates/ai_automation_smoke.html").read_text(encoding="utf-8")

    for marker in ["正常", "注意", "嚴重", "產生時間", "最近健康檢查趨勢", "每日摘要"]:
        assert marker in template

    assert 'id="historySummary"' in template
    assert 'id="trendStrip"' in template
    assert 'id="dailySummaryRows"' in template
    assert 'class="mb-0 text-muted smoke-lede"' in template
    assert 'class="text-muted small smoke-help-copy"' in template


def test_ai_automation_smoke_preserves_runtime_summary_without_raw_details():
    template = (ROOT / "templates/ai_automation_smoke.html").read_text(encoding="utf-8")

    assert "${escapeHtml(item.summary)}" in template
    assert 'class="detail-box" aria-hidden="true"' in template
    assert "JSON.stringify(item.details" not in template
    assert "JSONL" not in template
    assert "健康檢查 API" not in template
