from __future__ import annotations

from beaver.memory.skills import SkillLearningCandidate
from beaver.skills.authoring.format import CANONICAL_SKILL_SECTION_HEADINGS
from beaver.skills.learning.evidence import EvidencePacket
from beaver.skills.learning.synthesizer import SkillDraftSynthesizer


def test_revision_prompt_includes_base_skill_snapshot() -> None:
    candidate = SkillLearningCandidate(
        candidate_id="candidate-1",
        kind="revise_skill",
        source_run_ids=["run-1"],
        source_session_ids=["session-1"],
        related_skill_names=["debug-skill"],
        reason="Improve debugging flow.",
    )
    packet = EvidencePacket(
        run_ids=["run-1"],
        session_ids=["session-1"],
        task_summaries=["debug a failing test"],
        session_excerpts=["assistant: fixed it"],
    )
    prompt = SkillDraftSynthesizer._build_prompt(
        candidate,
        packet,
        "revise",
        base_skill={
            "skill_name": "debug-skill",
            "version": "v0001",
            "frontmatter": {"description": "Debug tests", "tools": ["read_file"]},
            "content": "# Debug Skill\n\n## Safety\n\nDo not delete files.",
            "summary": "Debug tests safely.",
            "tool_hints": ["read_file"],
        },
    )

    assert "Base skill snapshot" in prompt
    assert "# Debug Skill" in prompt
    assert "Do not delete files." in prompt
    assert "preserved_sections" in prompt
    assert "dropped_sections" in prompt
    assert "Canonical Beaver SKILL.md format" in prompt
    for heading in CANONICAL_SKILL_SECTION_HEADINGS:
        assert heading in prompt
