Files
FabledScribe/tests/test_routes_snippets.py
T
bvandeusen 85625de394
CI & Build / Python lint (push) Successful in 4s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / integration (push) Successful in 38s
CI & Build / Python tests (push) Successful in 59s
CI & Build / Build & push image (push) Successful in 1m10s
feat(scribe): merge_snippets — unify found one-off snippets into one canonical
Step 2 of the snippet-merge milestone (#231). The dedup gate only PREVENTS
new near-duplicates; merge is the CURE for the ones already scattered.

- services/snippets.py: merge_snippets(user_id, target_id, source_ids) —
  keep the target's scalar fields (name/when_to_use/signature/language/
  code), union the sources' locations + extra tags onto it (so the survivor
  carries every call site as a location), trash the sources (recoverable),
  re-embed the survivor. Pure merge_snippet_fields() factored out for unit
  testing. Returns (survivor_note, merged_ids).
- mcp/tools/snippets.py: merge_snippets(target_id, source_ids) tool (5th),
  and a create_snippet dedup-path nudge toward merge over a forced copy.
- routes/snippets.py: POST /api/snippets/<id>/merge {source_ids} — share-
  aware (can_write target + every source, rule #78) with a same-owner guard
  (cross-owner merge is out of scope).
- plugin reusing-code skill + MCP _INSTRUCTIONS: point found-duplicates at
  merge as the cure (rule #119 surfaces, not a Scribe rule). plugin.json
  0.1.13 -> 0.1.14 in the same change (the #1040 marketplace-ship lesson).
- Tests: pure merge-helper union/dedup; MCP tool (requires a source,
  survivor+merged_ids, not-found); route handler + 5-tool registration.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pa2EsuB54BuWQ8GfJq9c7t
2026-07-25 17:11:47 -04:00

46 lines
1.7 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 scribe.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 scribe.app import create_app
app = create_app()
assert "snippets" in app.blueprints
def test_snippet_handlers_callable():
from scribe.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",
):
assert callable(getattr(routes, name))
def test_service_functions_take_user_id():
"""Routes must call snippet services with user_id — verify the contract."""
from scribe.services import snippets as svc
for fn_name in ("create_snippet", "list_snippets", "get_snippet", "update_snippet"):
fn = getattr(svc, fn_name)
assert callable(fn)
assert "user_id" in inspect.signature(fn).parameters
def test_update_field_map_matches_service_kwargs():
"""Every field the PATCH route forwards must be a real update_snippet kwarg
(rule #33 interface-contract parity)."""
from scribe.routes import snippets as routes
from scribe.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