from pathlib import Path


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


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

    assert 'data-density-guardrail="compact-knowledge-workbench"' in template
    assert 'aria-label="AI 知識狀態模式"' in template
    assert "知識命中" in template
    assert "省模閉環" in template
    assert "回饋學習" in template


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

    for marker in ["查詢數", "命中率", "省模型", "回饋分"]:
        assert marker in template

    assert ".qa-subtitle,.qa-note,.qa-footer-copy{display:none}" in template
    assert 'class="qa-subtitle"' in template
    assert "qa-footer-copy" in template


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

    for marker in [
        "查詢串流",
        "最近 50 筆查詢詳情",
        "各使用情境知識表現",
        "知識命中內容",
        "查命中",
    ]:
        assert marker in template

    for forbidden in [
        "top_k",
        "<code>{{ q.caller }}</code>",
        "manual_required",
        "raw payload",
        "raw endpoint",
        "資料表:",
    ]:
        assert forbidden not in template
