CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / integration (push) Successful in 49s
CI & Build / TypeScript typecheck (push) Successful in 57s
CI & Build / Python tests (push) Failing after 1m3s
CI & Build / Build & push image (push) Skipped
A rule's home is its scope now: a rule in a rulebook topic is global, a rule on a project applies to that project, and retrieval reads that directly (#4074). A subscription had stopped changing anything a session received; a suppression muted rules from a subscription. Operator, 2026-09-15: "we have global and project scoped rules, we don't need the subscriptions now." What goes, whole (rule 22): - Migration 0101 drops project_rulebook_subscriptions, project_rule_suppressions and project_topic_suppressions, and strips subscribe_rulebooks (and 394's leftover exclude_always_on_rulebooks) from stored inception choices. - Service, MCP and REST: subscribe/unsubscribe and the four suppress/unsuppress operations. The Subscribers checklist, the subscribe chips, the skip buttons and the Suppressed section in the rules UI. - Inception asks two questions (design system, seed Systems). create_project and decide_project_inception lose subscribe_rulebooks. - Backup v15 stops exporting the three sections; older archives still restore, the keys simply unread. Trash no longer hard-deletes suppression rows. What changes meaning: - get_applicable_rules is a project's LISTING: its own rules, plus the global rules tagged to an area it works in. Untagged global rules apply everywhere and arrive by retrieval, so they are not listed. A co_surfaces partner on a different project is not dragged in. - list_rules(project_id) lists that project's own rules. - rules_payload drops subscribed_rulebooks and suppressed_*; the handshake's brief form is project_rules alone. - using-scribe's "Where a new rule goes" and inception sections, tool docstrings and docs say global vs project. Plugin 2026.09.15.1620. Milestone 414 step 2. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01821k5B3Ysecp9fNYs92Kuy
125 lines
5.2 KiB
Python
125 lines
5.2 KiB
Python
"""Route-level tests for the rulebooks blueprint.
|
|
|
|
Mirrors the structural-tests pattern in tests/test_events_routes.py:
|
|
covers blueprint registration, callable handlers, and service-signature
|
|
contracts. Full HTTP integration requires a live DB and auth machinery
|
|
that the unit-test environment doesn't provide.
|
|
"""
|
|
import inspect
|
|
|
|
|
|
def test_rulebooks_blueprint_registered():
|
|
from scribe.routes.rulebooks import rulebooks_bp
|
|
assert rulebooks_bp.name == "rulebooks"
|
|
assert rulebooks_bp.url_prefix == "/api"
|
|
|
|
|
|
def test_rulebooks_blueprint_registered_in_app():
|
|
from scribe.app import create_app
|
|
app = create_app()
|
|
assert "rulebooks" in app.blueprints
|
|
|
|
|
|
def test_rulebook_handlers_callable():
|
|
from scribe.routes import rulebooks as rb_routes
|
|
for name in (
|
|
"list_rulebooks", "create_rulebook", "get_rulebook",
|
|
"update_rulebook", "delete_rulebook",
|
|
):
|
|
assert callable(getattr(rb_routes, name))
|
|
|
|
|
|
def test_topic_handlers_callable():
|
|
from scribe.routes import rulebooks as rb_routes
|
|
for name in (
|
|
"list_topics", "create_topic", "update_topic", "delete_topic",
|
|
):
|
|
assert callable(getattr(rb_routes, name))
|
|
|
|
|
|
def test_service_signatures_require_user_id():
|
|
"""Routes must call services with user_id — verify the contract."""
|
|
from scribe.services import rulebooks as svc
|
|
for fn_name in (
|
|
"create_rulebook", "list_rulebooks", "get_rulebook",
|
|
"update_rulebook", "delete_rulebook", "find_rulebook_by_title",
|
|
"create_topic", "list_topics", "get_topic", "update_topic", "delete_topic",
|
|
"create_rule", "create_project_rule", "rule_detail",
|
|
"set_rule_systems", "add_rule_relation", "remove_rule_relation",
|
|
"list_rules",
|
|
"get_rule", "update_rule", "delete_rule",
|
|
"get_applicable_rules",
|
|
):
|
|
sig = inspect.signature(getattr(svc, fn_name))
|
|
assert "user_id" in sig.parameters, f"{fn_name} missing user_id param"
|
|
|
|
|
|
def test_rule_model_carries_project_id_and_topic_id_nullable():
|
|
"""Migration 0059 made topic_id nullable and added project_id."""
|
|
from scribe.models.rulebook import Rule
|
|
assert "project_id" in Rule.__table__.columns
|
|
assert Rule.__table__.columns["topic_id"].nullable is True
|
|
assert Rule.__table__.columns["project_id"].nullable is True
|
|
|
|
|
|
def test_create_project_rule_route_exists():
|
|
"""POST /api/projects/<id>/rules — the frontend fast-path endpoint."""
|
|
from scribe.routes import rulebooks as rb_routes
|
|
assert callable(getattr(rb_routes, "create_project_rule"))
|
|
|
|
|
|
def test_subscriptions_and_suppressions_are_gone():
|
|
"""Milestone 414: a rule's home is its scope. Nothing subscribes a project
|
|
to a rulebook or mutes a rule for one — not a route, a service function or
|
|
a table. A partial removal would leave a door that 500s on a missing table.
|
|
"""
|
|
from scribe.models import rulebook as rb_models
|
|
from scribe.routes import rulebooks as rb_routes
|
|
from scribe.services import rulebooks as svc
|
|
for name in ("subscribe_project", "unsubscribe_project",
|
|
"suppress_project_rule", "unsuppress_project_rule",
|
|
"suppress_project_topic", "unsuppress_project_topic"):
|
|
assert not hasattr(rb_routes, name), f"route handler still present: {name}"
|
|
for name in ("subscribe_project", "unsubscribe_project",
|
|
"suppress_rule_for_project", "unsuppress_rule_for_project",
|
|
"suppress_topic_for_project", "unsuppress_topic_for_project"):
|
|
assert not hasattr(svc, name), f"service function still present: {name}"
|
|
for name in ("project_rulebook_subscriptions", "project_rule_suppressions",
|
|
"project_topic_suppressions"):
|
|
assert not hasattr(rb_models, name), f"table still declared: {name}"
|
|
|
|
|
|
def test_rule_handlers_callable():
|
|
from scribe.routes import rulebooks as rb_routes
|
|
for name in (
|
|
"list_rules", "create_rule", "get_rule", "update_rule", "delete_rule",
|
|
"get_project_rules",
|
|
# The typed edges — both doors carry them (rule 33).
|
|
"relate_rules", "unrelate_rules",
|
|
):
|
|
assert callable(getattr(rb_routes, name))
|
|
|
|
|
|
def test_the_rule_list_zero_fills_usage_on_every_row():
|
|
"""Milestone 333 step 5, asserted the only way this harness allows.
|
|
|
|
There is no live-HTTP fixture here (see this module's docstring), so this
|
|
reads the handler's source. What it can still prove is the property that
|
|
gets forgotten: the route must attach the key to EVERY row, zero-filled,
|
|
rather than only to rows that happen to have events. Every rule on every
|
|
existing install predates `rule_usage_events`, so a route that only
|
|
attached the key when it found something would leave the badge component
|
|
reading `undefined` on almost every row — and the difference between "no
|
|
events" and "no field" is exactly the distinction #2663 is about.
|
|
"""
|
|
import inspect
|
|
|
|
from scribe.routes import rulebooks as rb_routes
|
|
|
|
src = inspect.getsource(rb_routes.list_rules)
|
|
assert "usage_for_rules" in src, "the rule list does not read usage at all"
|
|
assert "empty_rule_usage()" in src, (
|
|
"the rule list does not zero-fill — a rule with no events would come "
|
|
"back without the key rather than with an empty one"
|
|
)
|