from pathlib import Path


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


def test_ppt_audit_uses_compact_visual_qa_workbench_contract():
    template = (ROOT / "templates/admin/ppt_audit_history.html").read_text(encoding="utf-8")

    assert 'data-density-guardrail="compact-ppt-workbench"' in template
    assert 'aria-label="AI 視覺 QA 狀態模式"' in template
    assert "預覽就緒" in template
    assert "視覺審核" in template
    assert "修復閉環" in template


def test_ppt_audit_keeps_visual_qa_signals_and_hides_explanatory_copy():
    template = (ROOT / "templates/admin/ppt_audit_history.html").read_text(encoding="utf-8")
    css = (ROOT / "web/static/css/page-ppt-audit-history.css").read_text(encoding="utf-8")

    for marker in ["最新簡報", "產線健康度", "最近可預覽簡報", "工作隊列"]:
        assert marker in template

    for marker in [".ppt-subtitle", ".ppt-hero-note", ".ppt-signal small", ".ppt-runtime-copy", ".ppt-footer-copy"]:
        assert marker in css
    assert "ppt-footer-copy" in template


def test_ppt_audit_preserves_visual_qa_workflow_and_non_raw_wording():
    template = (ROOT / "templates/admin/ppt_audit_history.html").read_text(encoding="utf-8")
    route_source = (ROOT / "routes/admin_observability_routes.py").read_text(encoding="utf-8")
    service_source = (ROOT / "services/ppt_auto_generation_service.py").read_text(encoding="utf-8")

    for marker in [
        "視覺 QA 執行條件",
        "預覽工作台",
        "簡報產線控制台",
        "紀錄 / 預覽 / 視覺 QA / 交付",
        "線上預覽",
        "立即視覺 QA",
        "補齊缺漏簡報",
    ]:
        assert marker in template

    for forbidden in [
        "Latest Deck",
        "Preview Workbench",
        "Inline PDF Preview",
        "runtime checklist",
        "Vision model",
        "Runtime dependency",
        "PPT_AUTO_GENERATION_ENABLED",
        "data-source-table",
        "AiderHeal",
        "{{ 'DB' }}",
        "DB / 預覽",
    ]:
        assert forbidden not in template

    for forbidden in ["DB 寫入失敗", "DB 已寫入", "待 DB 寫入"]:
        assert forbidden not in route_source
    assert "產出紀錄失敗" in route_source
    assert "紀錄已保留" in route_source
    assert "待保留紀錄" in route_source

    assert "尚未找到符合定義的檔案或 DB 紀錄。" not in service_source
    assert "尚未找到符合定義的檔案或產出紀錄。" in service_source
