from pathlib import Path


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


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

    assert 'data-density-guardrail="compact-quality-workbench"' in template
    assert 'aria-label="AI 品質狀態模式"' in template
    assert "品質回饋" in template
    assert "知識可靠" in template
    assert "行動成效" in template


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

    for marker in ["反饋總量", "最低均分", "蒸餾樣本", "知識評分"]:
        assert marker in template

    assert ".quality-subtitle,.quality-signal-note,.quality-footer-copy{display:none}" in template
    assert 'class="quality-subtitle"' in template
    assert 'class="text-muted quality-signal-note"' in template
    assert "quality-footer-copy" in template


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

    for marker in ["使用情境反饋分佈", "知識分數分布", "知識根因建議", "實際動作成效"]:
        assert marker in template

    for forbidden in ["<code>{{ caller }}</code>", "<code>{{ rc.caller }}</code>", "<code>{{ rec.caller }}</code>", "top_k"]:
        assert forbidden not in template
