from pathlib import Path

from docx import Document

from app.report_generator import AnalysisReport, generate_docx_report, generate_markdown_report


def test_generate_reports_create_markdown_and_docx(tmp_path: Path) -> None:
    report = AnalysisReport(
        source_filename="sample.docx",
        provider_name="deepseek",
        model_name="deepseek-chat",
        matched_skills=["gjb438c-software-requirements-spec-structure"],
        summary="部分通过",
        findings=[{"status": "需整改", "item": "缺少追溯性矩阵", "evidence": "未发现相关章节"}],
        recommendations=["补充需求双向追溯矩阵。"],
        raw_model_output="模型输出",
    )

    md_path = generate_markdown_report(report, tmp_path)
    docx_path = generate_docx_report(report, tmp_path)

    assert md_path.exists()
    assert "缺少追溯性矩阵" in md_path.read_text(encoding="utf-8")
    assert docx_path.exists()
    parsed = Document(docx_path)
    text = "\n".join(p.text for p in parsed.paragraphs)
    assert "DOCX 规范分析报告" in text
    assert "部分通过" in text
