feat(rules)!: retire rulebook subscriptions and per-project suppressions (#4052)
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
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
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
"""Real-Postgres tests for WHICH rules reach a session (milestone 307 step 5,
|
||||
narrowed by 394).
|
||||
"""Real-Postgres tests for WHICH rules a project's listing names (milestone
|
||||
307 step 5, narrowed by 394 and 414).
|
||||
|
||||
What mocks can't prove, and what this design must not get wrong:
|
||||
A session receives rules by retrieval, scoped by a rule's home (see
|
||||
test_integration_rule_scope). This is the other surface — the listing a
|
||||
planning read carries — and what mocks can't prove about it:
|
||||
|
||||
1. A rule is invisible to a project that doesn't work in its area, and
|
||||
arrives — binding, not suggested — to one that does. Area matching is
|
||||
DETERMINISTIC: a tag comparison, never a similarity score.
|
||||
2. A `co_surfaces` partner arrives with its other half, which is the failure
|
||||
that made merging rule 144 into rule 46 look like the only fix.
|
||||
3. An explicit suppression outranks an edge.
|
||||
1. A global rule tagged to an area arrives in the listing of a project that
|
||||
works in that area, and not before. Area matching is DETERMINISTIC: a tag
|
||||
comparison, never a similarity score.
|
||||
2. An UNTAGGED global rule is not listed: it applies everywhere and arrives by
|
||||
retrieval, and listing every one under every project would say nothing.
|
||||
3. A `co_surfaces` partner arrives with its other half — the failure that made
|
||||
merging rule 144 into rule 46 look like the only fix — unless the partner
|
||||
lives on a different project, because an edge is not a way in.
|
||||
|
||||
TWO CLAIMS WERE DROPPED HERE BY MILESTONE 394, and it is worth saying which
|
||||
rather than leaving a shorter list. "A rule with no tier binds exactly as
|
||||
before" and "a conditional rule is reachable, not resident" were both about
|
||||
the always-on tier. There is no tier and no resident payload, so neither
|
||||
states anything that can now be true or false — they were not failing, they
|
||||
had stopped being claims.
|
||||
Milestone 414 dropped the suppression claim ("an explicit suppression outranks
|
||||
an edge") with suppressions themselves.
|
||||
"""
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
@@ -32,40 +32,27 @@ pytestmark = [pytest.mark.integration, pytest.mark.usefixtures("_dispose_engine"
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def world():
|
||||
"""A project with two rulebooks — one subscribed, one not.
|
||||
|
||||
Both are ordinary rulebooks since milestone 394; the fixture used to flag
|
||||
one always-on because that was a second, separate way to reach a project.
|
||||
Keeping two is still worth it: a rulebook nobody subscribed to must
|
||||
contribute nothing, and a fixture with only the subscribed one could not
|
||||
tell "correctly scoped" from "returns everything".
|
||||
"""
|
||||
"""A project with one rule of its own, and a rulebook of global rules."""
|
||||
async with async_session() as s:
|
||||
owner = await ensure_user(s, "surfacing_owner")
|
||||
project = Project(user_id=owner.id, title="Surfacing target")
|
||||
s.add(project)
|
||||
elsewhere = Project(user_id=owner.id, title="Another project")
|
||||
s.add_all([project, elsewhere])
|
||||
await s.flush()
|
||||
ids = {"owner": owner.id, "pid": project.id}
|
||||
ids = {"owner": owner.id, "pid": project.id, "elsewhere": elsewhere.id}
|
||||
await s.commit()
|
||||
|
||||
always = await rulebooks_svc.create_rulebook(ids["owner"], "Family standards")
|
||||
always_topic = await rulebooks_svc.create_topic(always.id, ids["owner"], "git")
|
||||
await rulebooks_svc.create_rule(
|
||||
always_topic.id, ids["owner"], "dev is home", "Work on dev.",
|
||||
)
|
||||
|
||||
book = await rulebooks_svc.create_rulebook(ids["owner"], "Subscribed practices")
|
||||
book = await rulebooks_svc.create_rulebook(ids["owner"], "Family standards")
|
||||
topic = await rulebooks_svc.create_topic(book.id, ids["owner"], "release")
|
||||
plain = await rulebooks_svc.create_rule(
|
||||
topic.id, ids["owner"], "Between batches, keep stacking", "Keep going.",
|
||||
await rulebooks_svc.create_rule(
|
||||
topic.id, ids["owner"], "dev is home", "Work on dev.",
|
||||
when_to_apply="before pushing a branch",
|
||||
)
|
||||
await rulebooks_svc.subscribe_project(
|
||||
project_id=ids["pid"], rulebook_id=book.id, user_id=ids["owner"],
|
||||
own = await rulebooks_svc.create_project_rule(
|
||||
ids["pid"], ids["owner"], "Between batches, keep stacking", "Keep going.",
|
||||
when_to_apply="when a batch goes green",
|
||||
)
|
||||
ids.update({
|
||||
"always": always.id, "always_topic": always_topic.id,
|
||||
"book": book.id, "topic": topic.id, "plain": plain.id,
|
||||
})
|
||||
ids.update({"book": book.id, "topic": topic.id, "own": own.id})
|
||||
return ids
|
||||
|
||||
|
||||
@@ -74,12 +61,18 @@ async def _titles(ids) -> set[str]:
|
||||
return {r["title"] for r in applicable["rules"]}
|
||||
|
||||
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
async def test_an_untagged_global_rule_is_not_listed(world):
|
||||
"""It applies here — and everywhere — so naming it under this project says
|
||||
nothing a reader can act on. The project's own rule is always listed."""
|
||||
applicable = await rulebooks_svc.get_applicable_rules(world["pid"], world["owner"])
|
||||
assert "dev is home" not in await _titles(world)
|
||||
assert [r["title"] for r in applicable["project_rules"]] == [
|
||||
"Between batches, keep stacking"]
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
async def test_a_conditional_rule_binds_a_project_that_works_in_its_area(world):
|
||||
async def test_a_tagged_global_rule_is_listed_for_a_project_that_works_in_its_area(world):
|
||||
"""The payoff: the tag match carries it in deterministically. The project
|
||||
reaches the area through its own System's canonical_id — its local NAME is
|
||||
irrelevant, which is the whole reason the catalog exists."""
|
||||
@@ -103,7 +96,7 @@ async def test_a_conditional_rule_binds_a_project_that_works_in_its_area(world):
|
||||
|
||||
surfaced = await rulebooks_svc.get_applicable_rules(world["pid"], world["owner"])
|
||||
hit = [r for r in surfaced["rules"] if r["title"] == "Release tagging"]
|
||||
assert hit, "a tagged conditional rule must bind a project working in that area"
|
||||
assert hit, "a tagged global rule must be listed for a project working in that area"
|
||||
assert [s["name"] for s in hit[0]["systems"]] == ["CI & Release"]
|
||||
|
||||
|
||||
@@ -118,12 +111,8 @@ async def test_co_surfaces_drags_in_the_half_that_would_have_been_missed(world):
|
||||
"A name decides nothing.",
|
||||
when_to_apply="when naming a build",
|
||||
)
|
||||
# TAGGED TO AN AREA THIS PROJECT DOES NOT WORK IN, which is what makes the
|
||||
# test able to fail at all. Since milestone 394 an UNTAGGED rule in a
|
||||
# subscribed rulebook applies on its own, so an untagged partner arrives
|
||||
# through the ordinary query and the edge is never exercised — the
|
||||
# assertion below passed while proving nothing, which is how this was
|
||||
# noticed. Tagging it puts it out of reach of everything except the edge.
|
||||
# Tagged to an area this project does NOT work in, so nothing but the edge
|
||||
# can bring it in — otherwise this test could pass without the edge.
|
||||
area = await canonical_svc.find_by_name("CI & Release")
|
||||
assert area is not None, "migration 0087 seeds the standard vocabulary"
|
||||
await rulebooks_svc.set_rule_systems(partner.id, world["owner"], [area.id])
|
||||
@@ -132,7 +121,7 @@ async def test_co_surfaces_drags_in_the_half_that_would_have_been_missed(world):
|
||||
)
|
||||
|
||||
await rulebooks_svc.add_rule_relation(
|
||||
world["owner"], world["plain"], partner.id, "co_surfaces",
|
||||
world["owner"], world["own"], partner.id, "co_surfaces",
|
||||
note="they fail together",
|
||||
)
|
||||
surfaced = await rulebooks_svc.get_applicable_rules(world["pid"], world["owner"])
|
||||
@@ -142,20 +131,16 @@ async def test_co_surfaces_drags_in_the_half_that_would_have_been_missed(world):
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
async def test_a_suppression_outranks_an_edge(world):
|
||||
"""The edge says these belong together; the suppression says this project
|
||||
does not want that one. An explicit decision beats an inferred one."""
|
||||
# Untagged on purpose, unlike the partner above: this test is about the
|
||||
# SUPPRESSION winning, so the partner should be one that would otherwise
|
||||
# arrive by every available route — the ordinary query AND the edge.
|
||||
partner = await rulebooks_svc.create_rule(
|
||||
world["topic"], world["owner"], "Muted partner", "Should not arrive.",
|
||||
async def test_an_edge_is_not_a_way_into_another_project(world):
|
||||
"""A partner that lives on a different project belongs to that project.
|
||||
The edge says the two fail together; it does not make one project's rule
|
||||
apply to another."""
|
||||
foreign = await rulebooks_svc.create_project_rule(
|
||||
world["elsewhere"], world["owner"], "Another project's rule", "Not here.",
|
||||
when_to_apply="working on the other project",
|
||||
)
|
||||
await rulebooks_svc.add_rule_relation(
|
||||
world["owner"], world["plain"], partner.id, "co_surfaces",
|
||||
)
|
||||
await rulebooks_svc.suppress_rule_for_project(
|
||||
world["pid"], partner.id, world["owner"],
|
||||
world["owner"], world["own"], foreign.id, "co_surfaces",
|
||||
)
|
||||
surfaced = await rulebooks_svc.get_applicable_rules(world["pid"], world["owner"])
|
||||
assert "Muted partner" not in {r["title"] for r in surfaced["rules"]}
|
||||
assert "Another project's rule" not in {r["title"] for r in surfaced["rules"]}
|
||||
|
||||
Reference in New Issue
Block a user