54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
from beaver.skills.learning.preservation import check_plugin_merge_preservation, 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"]
|
|
|
|
|
|
def test_plugin_merge_preservation_checks_local_and_upstream_and_conflicts() -> None:
|
|
report = check_plugin_merge_preservation(
|
|
local_content="# Local\n\n## Review\n\nKeep review.\n",
|
|
upstream_content="# Upstream\n\n## Safety\n\nDo not leak secrets.\n",
|
|
draft_content="# Draft\n\n## Review\n\nKeep review.\n\n## Safety\n\nDo not leak secrets.\n",
|
|
merge_decisions={"resolved_conflicts": ["ordering"], "unresolved_conflicts": []},
|
|
)
|
|
|
|
assert report["mode"] == "plugin_three_way"
|
|
assert report["passed"] is True
|
|
assert report["local"]["passed"] is True
|
|
assert report["upstream"]["passed"] is True
|
|
|
|
|
|
def test_plugin_merge_preservation_fails_unresolved_conflicts() -> None:
|
|
report = check_plugin_merge_preservation(
|
|
local_content="# Local\n\n## Review\n\nKeep review.\n",
|
|
upstream_content="# Upstream\n\n## Safety\n\nDo not leak secrets.\n",
|
|
draft_content="# Draft\n\n## Review\n\nKeep review.\n",
|
|
merge_decisions={"unresolved_conflicts": ["Safety conflict"]},
|
|
)
|
|
|
|
assert report["passed"] is False
|
|
assert report["unresolved_conflicts"] == ["Safety conflict"]
|