Home

boring / v2

publicBoring-Software-Inc/v2
Overview Code History Branches Pull requestsIssuesInsights Campfire Docs
main
HomeOverview Code PRsIssues

feat(rules): block deleting a custom rule while a workflow uses it

3 months ago

6e104ad
Authored
grim7/24/2026, 9:39:29 AM
deleting a custom rule that a workflow references leaves the workflow pointing
at a rule that no longer exists. rather than handle that broken state, make it
unreachable.

- server guard (the correctness fix), at the lowest shared point so no caller
  can bypass it: repoServices.deleteCustomRule refuses while ANY workflow —
  enabled OR disabled — references the rule, returning { deleted, blockedBy }.
  a disabled workflow blocks too: it breaks the moment it is re-enabled.
- workflowsReferencingRule scans every workflow definition for the repo (not
  resolveRuleManagement, which is enabled-only). the match is a pure contracts
  helper, definitionReferencesRule (version-agnostic), shared by the guard.
- the web fn names the blocking workflows: "this rule is active inside X and Y.
  remove it from those workflows before deleting." flows through the existing
  toast, no new pattern.
- the card keeps the delete control visible but DISABLED when referenced, with
  the blocking workflows named as links (the shipped edit-in-workflow pattern).
  a missing button reads as a bug; a disabled one with a reason reads intended.
- the escape hatch works: remove the last reference, deletion succeeds.

no pending/invalid-node/broken-workflow state — those become unreachable. the
workflow model, rule model, and evaluator are untouched.

tests: refused by an enabled workflow, refused by a DISABLED one, names every
workflow, allowed once the last reference is removed (integration, real pg);
plus a pure unit test for definitionReferencesRule.

Parentf32fad5

8 files changed
  • apps/web/src/components/rules/rule-card.test.tsx+1−0
  • apps/web/src/components/rules/rule-card.tsx+40−9
  • apps/web/src/lib/custom-rules.functions.ts+24−1
  • apps/web/src/lib/rules.functions.ts+16−0
  • packages/contracts/src/custom-rules.test.ts+40−0
  • packages/contracts/src/custom-rules.ts+14−1
  • packages/db/src/services/delete-custom-rule.integration.test.ts+129−0
packages/db/src/services/repos.ts
+46
−1