"""Tests for the FolderAdapter (SHARD-WP-0007 T3).""" import pytest from shard_wiki.adapters import FolderAdapter from shard_wiki.model import Identity, NotSupported, Verb def _make_shard(tmp_path, files: dict[str, str]) -> FolderAdapter: for rel, text in files.items(): p = tmp_path / rel p.parent.mkdir(parents=True, exist_ok=True) p.write_text(text, encoding="utf-8") return FolderAdapter("shardA", tmp_path) def test_keys_and_read(tmp_path): shard = _make_shard(tmp_path, {"Home.md": "# Home", "sub/Topic.md": "topic body"}) assert set(shard.keys()) == {"Home", "sub/Topic"} page = shard.read("sub/Topic") assert page.identity == Identity("shardA", "sub/Topic") assert page.body == "topic body" assert page.envelope.source_shard == "shardA" assert page.envelope.source_rev is not None # mtime stamp assert page.placements[0].path == "sub/Topic.md" def test_read_missing_raises_keyerror(tmp_path): shard = _make_shard(tmp_path, {"Home.md": "x"}) with pytest.raises(KeyError): shard.read("Nope") def test_profile_is_valid_and_read_only(tmp_path): shard = _make_shard(tmp_path, {"Home.md": "x"}) prof = shard.profile() # .validate() already called inside assert prof.supports(Verb.READ) assert not prof.supports(Verb.WRITE) def test_unsupported_write_is_honest(tmp_path): shard = _make_shard(tmp_path, {"Home.md": "x"}) with pytest.raises(NotSupported): shard.write("Home", "new")