generated from coulomb/repo-seed
feat(adapters): writable FolderAdapter + positive write conformance (WP-0008 T1)
FolderAdapter(writable=True) declares WRITE+PER_PAGE, implements write() and current_rev() (mtime token for drift detection). Conformance gains a content-preserving positive write probe for WRITE-claiming adapters. 5 tests green, full suite green, pyflakes clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
41
tests/test_writable_adapter.py
Normal file
41
tests/test_writable_adapter.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""Tests for the writable FolderAdapter + positive write conformance (SHARD-WP-0008 T1)."""
|
||||
|
||||
import pytest
|
||||
|
||||
from shard_wiki.adapters import FolderAdapter, assert_conformant, run_conformance
|
||||
from shard_wiki.model import NotSupported, Verb
|
||||
|
||||
|
||||
def test_writable_round_trip(tmp_path):
|
||||
shard = FolderAdapter("w", tmp_path, writable=True)
|
||||
rev_before = shard.current_rev("New")
|
||||
assert rev_before is None
|
||||
page = shard.write("New", "hello")
|
||||
assert page.body == "hello"
|
||||
assert shard.read("New").body == "hello"
|
||||
assert shard.current_rev("New") is not None
|
||||
|
||||
|
||||
def test_writable_profile_supports_write(tmp_path):
|
||||
prof = FolderAdapter("w", tmp_path, writable=True).profile()
|
||||
assert prof.supports(Verb.WRITE)
|
||||
|
||||
|
||||
def test_read_only_still_rejects_write(tmp_path):
|
||||
(tmp_path / "Home.md").write_text("x", encoding="utf-8")
|
||||
with pytest.raises(NotSupported):
|
||||
FolderAdapter("ro", tmp_path).write("Home", "y")
|
||||
|
||||
|
||||
def test_conformance_passes_for_writable(tmp_path):
|
||||
(tmp_path / "Home.md").write_text("body", encoding="utf-8")
|
||||
report = assert_conformant(FolderAdapter("w", tmp_path, writable=True))
|
||||
assert report.ok
|
||||
assert any(c.name == "write-round-trips" and c.ok for c in report.checks)
|
||||
|
||||
|
||||
def test_conformance_write_probe_is_content_preserving(tmp_path):
|
||||
(tmp_path / "Home.md").write_text("keep me", encoding="utf-8")
|
||||
shard = FolderAdapter("w", tmp_path, writable=True)
|
||||
run_conformance(shard)
|
||||
assert shard.read("Home").body == "keep me" # probe did not alter content
|
||||
Reference in New Issue
Block a user