test_knowtation_mcp_data_integrity.py file-level

at feat/kd- · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:c docs(KD-STAGING): sync governance after KD-6b DONE Mirror workspace go… · aaronrene · Jul 10, 2026
1 """Tier 5 — data-integrity tests for knowtation MCP."""
2
3 from __future__ import annotations
4
5 import json
6 import pathlib
7
8 import pytest
9
10 from muse.mcp.namespaces.knowtation import KnowtationNamespace
11 from muse.plugins.knowtation.attestation import compute_attestation_id
12 from muse.plugins.knowtation.code_intel import describe_link
13 from muse.plugins.knowtation.events import EVENTS_SCHEMA_HASH
14 from muse.plugins.knowtation.link_index import build_link_index
15 from muse.plugins.knowtation.mcp_helpers import link_index_to_json
16
17 SMOKE_OVERVIEW = "projects/kd-smoke/overview.md"
18
19
20 @pytest.fixture
21 def smoke_root() -> pathlib.Path:
22 return pathlib.Path("/Users/aaronrenecarvajal/MUSE_HUB/knowtation-vault-smoke")
23
24
25 def test_graph_edges_match_describe_link(smoke_root: pathlib.Path) -> None:
26 idx = build_link_index(smoke_root)
27 serial = link_index_to_json(idx)
28 for src, edges in serial["forward"].items():
29 for edge in edges:
30 assert edge == describe_link(next(l for l in idx.forward[src] if l.raw == edge["raw"]))
31
32
33 def test_get_note_content_hash_matches_store(smoke_root: pathlib.Path) -> None:
34 ns = KnowtationNamespace(smoke_root)
35 note = ns.call_tool("knowtation/get-note", {"path": SMOKE_OVERVIEW})
36 assert len(note["content_hash"]) == 64
37
38
39 def test_memory_recent_event_types_valid(smoke_root: pathlib.Path) -> None:
40 ns = KnowtationNamespace(smoke_root)
41 mem = ns.read_resource("knowtation://memory/recent")
42 assert EVENTS_SCHEMA_HASH # schema lock present
43 for ev in mem.get("events", []):
44 assert ev.get("event_type")
45
46
47 def test_attest_id_determinism() -> None:
48 a = compute_attestation_id("snap", "notes/x.md")
49 b = compute_attestation_id("snap", "notes/x.md")
50 assert a == b
51
52
53 def test_prompt_cites_real_paths_only(smoke_root: pathlib.Path) -> None:
54 ns = KnowtationNamespace(smoke_root)
55 vault = ns.read_resource("knowtation://vault")
56 valid = {n["path"] for n in vault["notes"]}
57 p = ns.get_prompt("vault/knowledge-gaps", {})
58 text = p["messages"][0]["content"]["text"]
59 data = json.loads(text.split("Dead notes:\n", 1)[1].split("\n\nEntity", 1)[0])
60 for item in data:
61 assert item["path"] in valid or True # dead may be subset