CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / TypeScript typecheck (push) Successful in 10s
CI & Build / integration (push) Successful in 15s
CI & Build / Python tests (push) Successful in 41s
CI & Build / Build & push image (push) Successful in 26s
Milestone #254 step 4 (#2290). Eleven capabilities, both surfaces, one service. Design systems are owner-scoped top-level records rather than project-scoped ones, so these do not nest under /api/projects/ the way systems do — routes/rulebooks.py was the closer shape. The one exception is the project pointer, which is genuinely about a project: PUT /api/projects/<id>/design-system, PUT rather than PATCH because clearing it is a first-class outcome and not an omission. `/resolved` and `/tokens` are deliberately separate endpoints. One answers "what does this system CHANGE", the other "what does it end up BEING", and a system that overrides nothing has an empty token list and a full resolved set. Shipping only one would have made the other a client-side computation of exactly the kind the record model exists to remove. ResolvedToken.to_dict carries the SHADOWED contributions, not just the winner. Dropping them at the serialisation boundary would have discarded the one thing step 2 was built to preserve, and it would have been invisible — the payload still looks complete. Three sentinel translations on the MCP side, each tested, because an agent cannot omit an argument and a wrong mapping here is silent: - parent_id: 0 = unchanged, -1 = clear (become a family system), positive = set. Renaming a system must not silently re-root it. - order_index: -1 = unchanged, since 0 is a valid position. - value_by_mode: guarded on `is not None`, not truthiness, so `{}` can strip every mode from a token instead of being unreachable. DesignSystemCycle maps to 400 on REST and to a ValueError carrying the message on MCP — kept apart from 404 throughout. An agent told "not found" retries the same call; one told what the loop is can fix it. Two structural guards beyond the parity list: every endpoint must be reachable on the app (catching a decorator copied without its path, where the second handler silently never runs), and every public coroutine in the tools module must be registered (a tool written but never registered is invisible to an agent, and nothing else would notice).
107 lines
4.0 KiB
Python
107 lines
4.0 KiB
Python
"""Structural tests for the design-systems blueprint + the parity guard.
|
|
|
|
Modelled on tests/test_routes_snippets.py. The enumerations below are
|
|
deliberate: relaxing one to a pattern would stop it catching the thing it was
|
|
written for, which is a capability landing on one surface and not the other.
|
|
"""
|
|
import inspect
|
|
|
|
|
|
def test_design_systems_blueprint_registered():
|
|
from scribe.routes.design_systems import design_systems_bp
|
|
assert design_systems_bp.name == "design_systems"
|
|
assert design_systems_bp.url_prefix == "/api"
|
|
|
|
|
|
def test_design_systems_blueprint_registered_in_app():
|
|
from scribe.app import create_app
|
|
app = create_app()
|
|
assert "design_systems" in app.blueprints
|
|
|
|
|
|
def test_route_handlers_callable():
|
|
from scribe.routes import design_systems as routes
|
|
for name in (
|
|
"list_design_systems", "create_design_system", "get_design_system",
|
|
"update_design_system", "delete_design_system", "resolve_design_system",
|
|
"list_design_tokens", "create_design_token", "update_design_token",
|
|
"delete_design_token", "set_project_design_system",
|
|
):
|
|
assert callable(getattr(routes, name))
|
|
|
|
|
|
def test_every_endpoint_is_reachable_on_the_app():
|
|
"""The handlers existing is not the same as them being routed. This catches
|
|
a decorator that was copied without its path changing — two handlers on one
|
|
rule, where the second silently never runs."""
|
|
from scribe.app import create_app
|
|
app = create_app()
|
|
rules = {
|
|
str(r.rule) for r in app.url_map.iter_rules()
|
|
if r.endpoint.startswith("design_systems.")
|
|
}
|
|
assert rules == {
|
|
"/api/design-systems",
|
|
"/api/design-systems/<int:design_system_id>",
|
|
"/api/design-systems/<int:design_system_id>/resolved",
|
|
"/api/design-systems/<int:design_system_id>/tokens",
|
|
"/api/design-tokens/<int:token_id>",
|
|
"/api/projects/<int:project_id>/design-system",
|
|
}
|
|
|
|
|
|
def test_service_functions_take_user_id():
|
|
"""Routes must call the services with user_id — verify the contract (#33)."""
|
|
from scribe.services import design_systems as svc
|
|
for fn_name in (
|
|
"create_design_system", "list_design_systems", "get_design_system",
|
|
"update_design_system", "delete_design_system", "resolve_design_system",
|
|
"create_token", "list_tokens", "update_token", "delete_token",
|
|
"set_project_design_system",
|
|
):
|
|
fn = getattr(svc, fn_name)
|
|
assert callable(fn)
|
|
assert "user_id" in inspect.signature(fn).parameters
|
|
|
|
|
|
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 (rule #33).
|
|
|
|
This guard exists because the snippet surfaces drifted apart once — MCP had
|
|
no delete, the web side had no near-duplicate gate — and neither failed
|
|
anything until someone went looking.
|
|
"""
|
|
from scribe.mcp.tools import design_systems as tools
|
|
from scribe.routes import design_systems as routes
|
|
|
|
for name in (
|
|
"create_design_system", "list_design_systems", "get_design_system",
|
|
"resolve_design_system", "update_design_system", "delete_design_system",
|
|
"create_design_token", "list_design_tokens", "update_design_token",
|
|
"delete_design_token", "set_project_design_system",
|
|
):
|
|
assert callable(getattr(tools, name)), f"MCP tool missing: {name}"
|
|
assert callable(getattr(routes, name)), f"REST route missing: {name}"
|
|
|
|
|
|
def test_every_mcp_tool_in_the_module_is_registered():
|
|
"""A tool written but never registered is invisible to an agent, and nothing
|
|
else in the codebase would notice."""
|
|
from scribe.mcp.tools import design_systems as tools
|
|
|
|
registered = []
|
|
|
|
class _Recorder:
|
|
def tool(self, name):
|
|
registered.append(name)
|
|
return lambda fn: fn
|
|
|
|
tools.register(_Recorder())
|
|
|
|
public = {
|
|
name for name, obj in vars(tools).items()
|
|
if inspect.iscoroutinefunction(obj) and not name.startswith("_")
|
|
}
|
|
assert set(registered) == public
|