Skip to content

amber-lsp library rule packs: Grant tenancy detected from source (v2) - #39

Draft
crimson-knight wants to merge 3 commits into
mainfrom
luna/rule-packs
Draft

crimson-knight wants to merge 3 commits into
mainfrom
luna/rule-packs

Conversation

@crimson-knight

@crimson-knight crimson-knight commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Library rule packs for amber-lsp, v2 (reworked after owner review).

What changed from v1

  • No shard.yml declaration. v1 made apps declare grant: tenancy: row in shard.yml; shard.yml is a package manifest, so that is removed. The tenancy mode is now detected from the app's own Crystal source with the Crystal parser: row mode = a model's multitenant :col macro (the column is captured per model, never assumed to be tenant_id); schema mode = Grant::SchemaTenant.with / schema_tenant_excluded.
  • Packs live at lib/<shard>/.amber-lsp/packs/*.yml (was .claude/rules/, which belongs to Claude Code). Harness-neutral: the same diagnostics reach Claude Code and Codex.
  • Rules target only what Grant cannot catch at runtime. Grant already raises NoTenantError, ScopedRawSqlError, and TenantMismatchError, so those checks are gone.

Grant tenancy pack (ships in Grant, branch luna/tenancy-pack-v2)

Two errors (block agent edits through the fleet gate):

  • grant/chained-unscoped-in-request-code: chainable Model.unscoped (no block) returns an unguarded builder; in controllers/channels/sockets/pipes.
  • grant/chained-unscoped-bulk-write: Model.unscoped...update_all/delete_all outside spec/ and db/ (silently writes every tenant's rows).

Eight warnings: chainable unscoped elsewhere, block unscoped in request code, spawn inside a tenant block (fiber loses the tenant), a tenant column without multitenant, raw connection SQL naming a tenant table, Tenant.clear in app code, schema-mode queries outside SchemaTenant.with in non-request code, both modes present.

Verification

  • crystal-alpha spec spec/amber_lsp: 233 examples, 0 failures; full suite 436, 0 failures.
  • crystal-alpha build --no-codegen src/amber_lsp.cr: GREEN. tool format --check: clean.
  • End-to-end: built amber-lsp + amber-lsp-check on a probe app with multitenant :account_id — Invoice.unscoped.delete_all in a controller produced both errors (exit 1); spawn in a tenant block produced the warning.
  • The fixture pack is byte-identical to Grant's pack.

Draft until the Grant tenancy branch lands (the pack describes Grant as of luna/final).

@crimson-knight crimson-knight changed the title amber-lsp: library rule packs (first pack: Grant row-mode tenancy) amber-lsp library rule packs: Grant tenancy detected from source (v2) Sep 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant