from __future__ import annotations

from beaver.skills.learning.preservation import check_preservation


def test_preservation_passes_when_base_sections_remain() -> None:
    base = "# Skill\n\n## Workflow\n\n- Read first.\n\n## Safety\n\n- Do not delete files.\n"
    draft = "# Skill\n\n## Workflow\n\n- Read first.\n- Then write.\n\n## Safety\n\n- Do not delete files.\n"

    report = check_preservation(base_content=base, draft_content=draft)

    assert report["passed"] is True
    assert report["risk_level"] == "low"
    assert "Workflow" in report["preserved_sections"]
    assert "Safety" in report["preserved_sections"]
    assert report["dropped_sections"] == []


def test_preservation_flags_dropped_section() -> None:
    base = "# Skill\n\n## Workflow\n\n- Read first.\n\n## Safety\n\n- Do not delete files.\n"
    draft = "# Skill\n\n## Workflow\n\n- Read first.\n"

    report = check_preservation(base_content=base, draft_content=draft)

    assert report["passed"] is False
    assert report["risk_level"] == "high"
    assert "Safety" in report["dropped_sections"]
