Files
FabledGrimoire/tests/test_routes_snippets.py
T
bvandeusenandClaude Opus 5.5 2a4d73176e test(8249): signature and source-text batch, the hook tests run the hook
- The caller-scoping property now covers services/family, family_adoption and
  platforms, with the seven reads that need no caller named and why. The
  hand-written platform list goes.
- The snippet location keys: one test checks every door (service, MCP tool,
  web route) takes them; the route-only copy goes.
- The write-path hook: the payload-shape and skip-list tests searched the
  shell script for strings. They now run the hook against a local listener and
  check what it sends: the code from each of the four payload field names, and
  nothing for a note, JSON or SVG while a YAML file and a .py are still asked about.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 07:10:02 -05:00

86 lines
4.0 KiB
Python

"""Structural tests for the snippets blueprint — registration + handler/service
contracts. Full HTTP integration needs a live DB + auth the unit env lacks."""
import inspect
def test_snippets_blueprint_registered():
from grimoire.routes.snippets import snippets_bp
assert snippets_bp.name == "snippets"
assert snippets_bp.url_prefix == "/api/snippets"
def test_snippets_blueprint_registered_in_app():
from grimoire.app import create_app
app = create_app()
assert "snippets" in app.blueprints
def test_snippet_handlers_callable():
from grimoire.routes import snippets as routes
for name in (
"list_snippets_route", "create_snippet_route", "get_snippet_route",
"update_snippet_route", "delete_snippet_route", "merge_snippet_route",
"verify_snippet_route", "duplicate_snippets_route",
"unmerge_snippet_route",
):
assert callable(getattr(routes, name))
def test_agent_and_web_surfaces_stay_at_parity():
"""The MCP tools and the REST routes are two callers of one service; a
capability on one has to exist on the other. Two doors maintained
separately drift — a delete on one, a near-duplicate gate on the other."""
from grimoire.mcp.tools import snippets as tools
from grimoire.routes import snippets as routes
# Every write verb the web surface offers, the agent surface offers too.
for verb in ("create", "get", "list", "update", "delete", "merge", "verify",
"unmerge"):
assert callable(getattr(tools, f"{verb}_snippets", None) or
getattr(tools, f"{verb}_snippet", None)), f"MCP lacks {verb}"
# Multi-location records are reachable from both.
assert "locations" in inspect.signature(tools.create_snippet).parameters
assert "locations" in inspect.signature(tools.update_snippet).parameters
assert "locations" in inspect.getsource(routes.create_snippet_route)
assert "locations" in inspect.getsource(routes.update_snippet_route)
# System association and the duplicate gate reach both.
assert "system_ids" in inspect.signature(tools.create_snippet).parameters
for route in (routes.create_snippet_route, routes.update_snippet_route):
assert "system_ids" in inspect.getsource(route)
assert "find_duplicate_note" in inspect.getsource(routes.create_snippet_route)
# The drift check reaches both: recording a verdict, and filtering
# the list by one. A verdict an agent records has to be visible to the human
# looking at the same corpus, or the two surfaces disagree about what's rotten.
assert "verification" in inspect.signature(tools.list_snippets).parameters
assert "verification" in inspect.getsource(routes.list_snippets_route)
# The near-duplicate report reaches both. The web side can only hand
# a group to the merge flow if it can get the groups in the first place.
assert callable(getattr(tools, "find_duplicate_snippets", None))
assert callable(getattr(routes, "duplicate_snippets_route", None))
def test_project_scoping_reaches_every_caller():
"""A snippet search has to be narrowable to one project from both surfaces."""
from grimoire.mcp.tools import snippets as tools
from grimoire.routes import snippets as routes
from grimoire.services import snippets as svc
assert "project_id" in inspect.signature(svc.list_snippets).parameters
assert "project_id" in inspect.signature(tools.list_snippets).parameters
assert "project_id" in inspect.getsource(routes.list_snippets_route)
def test_update_field_map_matches_service_kwargs():
"""Every field the PATCH route forwards must be a real update_snippet kwarg
(interface-contract parity)."""
from grimoire.routes import snippets as routes
from grimoire.services import snippets as svc
params = inspect.signature(svc.update_snippet).parameters
for field in routes._STR_FIELDS:
assert field in params, f"update_snippet has no '{field}' kwarg"
assert "tags" in params
assert "project_id" in params