generated from coulomb/repo-seed
Expose backlinks(name), recent_changes(), all_pages(), site_map() on InformationSpace. Integration test exercises all four over two shards (BackLinks aggregate across shards, AllPages/SiteMap span the union, RecentChanges merges an alias decision with shard edits). SCOPE updated; WP-0010 done. 152 tests green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""Integration: derived views exposed on InformationSpace over two shards (SHARD-WP-0010 T5)."""
|
|
|
|
from shard_wiki.adapters import FolderAdapter
|
|
from shard_wiki.model import Identity
|
|
from shard_wiki.space import InformationSpace
|
|
|
|
|
|
def _shard(tmp_path, name, files):
|
|
root = tmp_path / name
|
|
for rel, text in files.items():
|
|
p = root / rel
|
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
p.write_text(text, encoding="utf-8")
|
|
return FolderAdapter(name, root)
|
|
|
|
|
|
def _space(tmp_path):
|
|
space = InformationSpace("space")
|
|
space.attach(
|
|
_shard(tmp_path, "wiki", {"Home.md": "welcome, see [[Guide]]", "Guide.md": "the guide"})
|
|
)
|
|
space.attach(_shard(tmp_path, "notes", {"Daily.md": "today I read [[Guide]]"}))
|
|
return space
|
|
|
|
|
|
def test_backlinks_across_two_shards(tmp_path):
|
|
space = _space(tmp_path)
|
|
sources = {bl.source for bl in space.backlinks("Guide")}
|
|
assert sources == {Identity("wiki", "Home"), Identity("notes", "Daily")}
|
|
|
|
|
|
def test_all_pages_and_site_map_over_union(tmp_path):
|
|
space = _space(tmp_path)
|
|
names = {e.name for e in space.all_pages()}
|
|
assert names == {"Home", "Guide", "Daily"}
|
|
leaves = {p.key for p in space.site_map().pages}
|
|
assert {"Home", "Guide", "Daily"} <= leaves
|
|
|
|
|
|
def test_recent_changes_includes_alias_and_edits(tmp_path):
|
|
space = _space(tmp_path)
|
|
space.alias("Start", "wiki:Home", actor="ana")
|
|
feed = space.recent_changes()
|
|
kinds = {e.kind for e in feed}
|
|
assert "alias" in kinds and "edit" in kinds
|
|
alias = next(e for e in feed if e.kind == "alias")
|
|
assert alias.source == "coordination" and alias.actor == "ana"
|
|
|
|
|
|
def test_red_link_creates_no_backlink_via_space(tmp_path):
|
|
space = _space(tmp_path)
|
|
assert space.backlinks("Nonexistent") == ()
|