fix: project overrides can widen tenant-scoped-query scope (#15) - #16
Open
joao-oliveira-softtor wants to merge 1 commit into
Open
joao-oliveira-softtor wants to merge 1 commit into
joao-oliveira-softtor wants to merge 1 commit into
Conversation
Issue #15: in a project where Postgres RLS enforces tenant isolation, repository methods query by an aggregate id that is already tenant-bound (conversationId, subscriptionId, findUnique by id on an RLS-protected model). softtor/tenant-scoped-query only accepted organizationId in the enclosing method, so 138 of the pilot's 226 baseline FAILs came from it and every file had to be grandfathered with scope.exclude. Mechanism: overrides[].check.unlessInEnclosingDeclaration. The project rulebook replaces the enclosing-declaration regex of an inherited regex rule; composition rejects it on any other check kind. One field covers all three proposals in the issue because the regex is tested against the whole enclosing method, so it can name aggregate ids, the model and the where shape (prisma.<model>.findUnique({ where: { id } })) without a new check kind or per-model lists. Replace, not OR: the project states the full accepted scope, as the issue's own example does. The base rulebook is untouched, so no stamp changes and projects without the override keep the current behaviour; methods with no declared scope still fail under the override. Hooks compose the same rulebook and pick the override up with no extra code. Before the change the schema stripped the unknown check key silently and the base rule kept firing; the new spec reproduces that (red) and proves the override (green), plus the non-RLS file that still fails.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15.
What
overrides[].check.unlessInEnclosingDeclarationin the project rulebook replaces the enclosing-declaration regex of an inherited regex rule. Composition rejects the field on any other check kind (RulebookCompositionError).Lets a project on Postgres RLS declare, in one alternation, which aggregate ids and
findUnique-by-id shapes count as tenant-scoped, instead of grandfathering whole files viascope.exclude(138 of the 226 baseline FAILs in the first pilot came from this rule).Why this mechanism
enclosingContainsalready tests the regex against the whole enclosing method, so one field covers the three proposals in the issue.rulebooks/project.example.rulebook.yamland the README keeporganizationIdin the alternation and say why.checkkey, so such an override was dropped and the rule kept firing.Proof
scripts/__tests__/tenant-scoped-query-rls.spec.tsuses the shippedsofttor-conventionsrulebook: base rule still flags the RLS-shaped file (3 findings); with the override, 0; same override on a non-RLS file, still 3; invalid regex rejected. Red before the fix (2 of 4 failing), green after.bun test: 334 → 339 passing.tsc -p tsconfig.jsonclean.validate-frontmatterok.examples/under--rulebook hexagonal --strict: byte-identical tomain(0 FAIL, 1 WARN).Docs
README (override fields + RLS recipe),
project.example.rulebook.yaml,skills/onboard-project/SKILL.md(baseline step names the override before "lower to WARN"),CHANGELOG.mdunder a newUnreleasedheading. No version bump.Known limit: the example recipe's
\bprisma\.(...)branch does not cover a transaction client (tx.); projects add(?:prisma|tx)if they need it.