verae-mcp-timestamping-server/tests/test_server.py
George Lambert 9e3dfb6fb2 feat: hash-only stamp, verify, and hash_report MCP tools
Memory ledger for stdio tests; NatsLedger speaks locald subjects.
2026-09-20 02:59:00 -04:00

54 lines
1.9 KiB
Python

"""In-memory MCP Client against hash-only tools."""
import pytest
from mcp import Client
from verae_mcp_timestamping_server.ledger import SHA256_EMPTY, MemoryLedger
from verae_mcp_timestamping_server.server import build_mcp
pytestmark = pytest.mark.anyio
async def test_stamp_tool_returns_receipts():
mcp = build_mcp(MemoryLedger())
async with Client(mcp, raise_exceptions=True) as client:
result = await client.call_tool(
"stamp", {"sha256": SHA256_EMPTY, "scope": "local"}
)
assert result.is_error is not True
data = result.structured_content
assert data is not None
receipts = data["receipts"]
assert receipts[0]["hash"] == SHA256_EMPTY
assert receipts[0]["scope"] == "local"
async def test_stamp_does_not_accept_content_bytes():
mcp = build_mcp(MemoryLedger())
async with Client(mcp, raise_exceptions=True) as client:
listed = await client.list_tools()
stamp = next(t for t in listed.tools if t.name == "stamp")
props = stamp.input_schema["properties"]
assert "sha256" in props
assert "content" not in props
assert "bytes" not in props
assert "file" not in props
async def test_verify_and_hash_report_tools():
mcp = build_mcp(MemoryLedger())
async with Client(mcp, raise_exceptions=True) as client:
stamped = await client.call_tool(
"stamp", {"sha256": SHA256_EMPTY, "scope": "local"}
)
receipts = stamped.structured_content["receipts"]
receipt_id = receipts[0]["receipt_id"]
verified = await client.call_tool(
"verify", {"receipt_id": receipt_id, "want_scope": "local"}
)
assert verified.structured_content["valid"] is True
report = await client.call_tool("hash_report", {"sha256": SHA256_EMPTY})
items = report.structured_content["receipts"]
assert items[0]["receipt_id"] == receipt_id