from pathlib import Path


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


def test_pchome_dashboard_ai_first_viewport_uses_product_language():
    route_source = (ROOT / "routes/dashboard_routes.py").read_text(encoding="utf-8")
    dashboard = (ROOT / "templates/dashboard_v2.html").read_text(encoding="utf-8")
    first_viewport = dashboard.split('<div class="growth-automation-panel"', 1)[1].split(
        '<div class="growth-command-grid"',
        1,
    )[0]

    assert "找同款 · 決策 · 證據 · 落地 · 回讀 · 留存" in first_viewport
    assert "主流程阻斷 0 · 回讀待建立 · 證據留存待建立" in route_source
    assert "· 異動 {controlled_apply_drift_count} · 留存" in route_source
    assert "'label': '最新回讀'" in route_source
    assert "'label': '證據留存'" in route_source
    assert "資料寫入" in route_source
    assert "清理建議" in route_source

    forbidden_first_viewport_terms = [
        "retention",
        "Compact",
        "Artifact",
        "DB writes",
        "prune",
        "endpoint",
        "commit",
        "JSON",
        "table",
    ]
    for marker in forbidden_first_viewport_terms:
        assert marker not in first_viewport

    forbidden_visible_route_literals = [
        "· drift ",
        "· retention ",
        "'Compact 回讀'",
        "'Artifact retention'",
        "DB writes",
        "prune 候選",
        "retention 待建立",
    ]
    for marker in forbidden_visible_route_literals:
        assert marker not in route_source
