"""Tests for the CRA snapshot Markdown builder (pure; DB path verified live)."""
from compliance.services.cra_snapshot_store import assessment_markdown


def test_markdown_contains_summary_findings_and_cross_links():
    a = {
        "findings_total": 2, "coverage_pct": 100.0,
        "by_risk": {"CRITICAL": 1, "HIGH": 1, "MEDIUM": 0, "LOW": 0},
        "requirements_touched": ["CRA-AI-8", "CRA-AI-15"],
        "mapped": [{"finding_id": "x", "priority_tier": "P0",
                    "primary_requirement": "CRA-AI-8", "priority_reason": "P0 — kritisch"}],
        "cross_links": [{"safety_ref": "Zweihandschaltung", "cyber_finding_ids": ["x"]}],
    }
    md = assessment_markdown(a)
    assert "CRA-Cyber-Risikobeurteilung" in md
    assert "Befunde gesamt: 2" in md
    assert "2 / 40" in md
    assert "[P0] x → CRA-AI-8" in md
    assert "Cyber trifft Safety" in md
    assert "Zweihandschaltung" in md


def test_markdown_handles_empty_assessment():
    md = assessment_markdown({})
    assert "Befunde gesamt: 0" in md
