feat(coordination): patch rendering (unified diff) (WP-0008 T3)

render_patch(overlay, base_body) → Patch (pure difflib unified diff, target-
labelled); is_empty when unchanged. 3 tests green, pyflakes clean. (ADR-05)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 12:32:47 +02:00
parent d797bc5ee4
commit 715ab1ca00
4 changed files with 71 additions and 1 deletions

29
tests/test_patch.py Normal file
View File

@@ -0,0 +1,29 @@
"""Tests for patch rendering (SHARD-WP-0008 T3)."""
from shard_wiki.coordination import Overlay, Patch, render_patch
from shard_wiki.model import Identity
def _overlay(body: str) -> Overlay:
return Overlay("ov1", Identity("shardA", "Home"), base_rev="r1", body=body)
def test_patch_shows_the_change():
patch = render_patch(_overlay("line one\nline TWO\n"), "line one\nline two\n")
assert isinstance(patch, Patch)
assert not patch.is_empty
assert "-line two" in patch.diff
assert "+line TWO" in patch.diff
assert patch.target == Identity("shardA", "Home")
def test_empty_patch_when_unchanged():
patch = render_patch(_overlay("same\n"), "same\n")
assert patch.is_empty
assert patch.diff == ""
def test_patch_labels_name_the_target():
patch = render_patch(_overlay("new\n"), "old\n")
assert "a/shardA:Home" in patch.diff
assert "b/shardA:Home" in patch.diff