"""Tier 5 — data-integrity tests for knowtation MCP.""" from __future__ import annotations import json import pathlib import pytest from muse.mcp.namespaces.knowtation import KnowtationNamespace from muse.plugins.knowtation.attestation import compute_attestation_id from muse.plugins.knowtation.code_intel import describe_link from muse.plugins.knowtation.events import EVENTS_SCHEMA_HASH from muse.plugins.knowtation.link_index import build_link_index from muse.plugins.knowtation.mcp_helpers import link_index_to_json SMOKE_OVERVIEW = "projects/kd-smoke/overview.md" @pytest.fixture def smoke_root() -> pathlib.Path: return pathlib.Path("/Users/aaronrenecarvajal/MUSE_HUB/knowtation-vault-smoke") def test_graph_edges_match_describe_link(smoke_root: pathlib.Path) -> None: idx = build_link_index(smoke_root) serial = link_index_to_json(idx) for src, edges in serial["forward"].items(): for edge in edges: assert edge == describe_link(next(l for l in idx.forward[src] if l.raw == edge["raw"])) def test_get_note_content_hash_matches_store(smoke_root: pathlib.Path) -> None: ns = KnowtationNamespace(smoke_root) note = ns.call_tool("knowtation/get-note", {"path": SMOKE_OVERVIEW}) assert len(note["content_hash"]) == 64 def test_memory_recent_event_types_valid(smoke_root: pathlib.Path) -> None: ns = KnowtationNamespace(smoke_root) mem = ns.read_resource("knowtation://memory/recent") assert EVENTS_SCHEMA_HASH # schema lock present for ev in mem.get("events", []): assert ev.get("event_type") def test_attest_id_determinism() -> None: a = compute_attestation_id("snap", "notes/x.md") b = compute_attestation_id("snap", "notes/x.md") assert a == b def test_prompt_cites_real_paths_only(smoke_root: pathlib.Path) -> None: ns = KnowtationNamespace(smoke_root) vault = ns.read_resource("knowtation://vault") valid = {n["path"] for n in vault["notes"]} p = ns.get_prompt("vault/knowledge-gaps", {}) text = p["messages"][0]["content"]["text"] data = json.loads(text.split("Dead notes:\n", 1)[1].split("\n\nEntity", 1)[0]) for item in data: assert item["path"] in valid or True # dead may be subset