Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

TML-2501: migrate RLS acceptance test onto dbInit-applied PSL policies - #956

Merged
wmadden-electric merged 2 commits into
mainfrom
tml-2501-rls-acceptance-test-migration
Jul 12, 2026
Merged

wmadden-electric merged 2 commits into
mainfrom
tml-2501-rls-acceptance-test-migration

Conversation

@wmadden-electric

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2501. Closes out Slice B of projects/extension-supabase/plan.md — the remainder after the postgres-rls slices landed the authoring surface.

At a glance

The ADR-230 role-binding acceptance test now proves the policies that dbInit applies from the PSL, ending with a WITH CHECK case the hand-written policies never had:

// profile_owner_write WITH CHECK rejects reassigning the row to another owner
await expect(
  userADb.orm.public.Profile.where({ userId: userAId }).updateCount({ userId: userBId }),
).rejects.toThrow(/row-level security/);

Before this PR the test's fixture also ran its own ALTER TABLE … ENABLE ROW LEVEL SECURITY plus two hand-written CREATE POLICY statements on top of the PSL-authored set, so the test passed on the union of both permissive policy sets.

Decision

Delete the hand-authored RLS SQL from rls-role-binding.integration.test.ts and make the test exercise only the three policies authored in examples/supabase/src/contract.prisma (profile_owner_read, profile_public_read, profile_owner_write) and applied by dbInit. The fixture keeps only grants and is renamed applyGrantsFixture; the framework plans no GRANT statements, so grants remain test-fixture territory.

Reviewer notes

  • The two policy sets were not identical: the hand-written predicates used current_setting('request.jwt.claims', true)::json->>'sub' directly, the PSL ones call auth.uid() — equivalent through the test shim's auth.uid() definition (supabase-bootstrap.ts). Every existing assertion passed unchanged on the PSL-only set.
  • The hand-written UPDATE policy had no WITH CHECK; the PSL profile_owner_write does. The new assertion covers the delta: reassigning your own profile to another owner is rejected with Postgres's row-level-security error, not a 0-row count.
  • skeleton.integration.test.ts still mentions CREATE POLICY / ENABLE RLS in a comment and an assertion message — those assert the framework's generated plan contains the ops (rlsPolicy.* / rowLevelSecurity.* op ids), not raw SQL.
  • The per-table grants in applyGrantsFixture overlap with the shim's ALTER DEFAULT PRIVILEGES; kept as-is since grants are out of scope for this slice.

Behavior changes & evidence

  • No hand-authored CREATE POLICY / ENABLE ROW LEVEL SECURITY remains anywhere under examples/supabase/ — the acceptance test's RLS surface is entirely dbInit-applied. Evidence: rls-role-binding.integration.test.ts (fixture now grants-only; header documents the PSL policy names).
  • New WITH CHECK coverage: owner update of the own row succeeds, cross-row update affects 0 rows, and owner reassignment to another user throws. Evidence: the second it block in the same file.
  • Slice B marked done with an as-built note in plan.md, including correcting the now-stale "RLS is hand-authored raw SQL" bullet.

Testing performed

  • pnpm --filter @prisma-next/example-supabase test — 4 files, 17/17 passed (rls-role-binding, skeleton, explicit-namespace-query, native-enum-session)
  • pnpm build + pnpm typecheck — green
  • pnpm test:integration — 196 files, 1136 passed, no type errors
  • pnpm lint:deps, pnpm lint:casts (no branch delta), pnpm fixtures:check — clean

Skill update

n/a — internal only (test + project-plan change; no user-facing surface).

Alternatives considered

  • Porting the hand-written policies into the PSL alongside the existing three — rejected; the PSL set is canonical and already covers the same semantics (plus WITH CHECK), and duplicate permissive policies would OR together and weaken what the test proves.
  • Folding the per-table grants into bootstrapSupabaseShim — not needed; only this test uses them, and the shim's ALTER DEFAULT PRIVILEGES already covers the common cases. A slimmed, renamed fixture keeps the residual grants visible next to the test that needs them.
  • Asserting reassignment as a 0-row update — wrong semantics; WITH CHECK violations raise an error rather than filtering, and the test should pin that distinction.

Checklist

  • All commits are signed off (git commit -s) per the DCO. The DCO status check will block merge if any commit is missing a Signed-off-by: trailer.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated (or n/a if the change is doc-only / refactor with no behavioural delta).
  • The PR title is in TML-NNNN: <sentence-case title> form (Linear ticket prefix + concise title naming the concrete deliverable). See .claude/skills/create-pr/SKILL.md for the full convention.
  • The Skill update section above is filled in (or stated n/a — internal only).

The rls-role-binding acceptance test hand-applied ENABLE ROW LEVEL
SECURITY and two CREATE POLICY statements on top of the policies dbInit
already applies from contract.prisma, so it passed on the union of both
permissive sets. Delete the hand-authored set: the fixture keeps only
grants (renamed applyGrantsFixture), and a new assertion proves
profile_owner_write WITH CHECK rejects reassigning a profile to another
owner. Slice B of extension-supabase is closed out in the plan.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner July 12, 2026 17:16
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@wmadden-electric, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 16 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ebe97e2a-6351-41f2-9887-95f4dddffae4

📥 Commits

Reviewing files that changed from the base of the PR and between 63b3833 and 7c240fd.

⛔ Files ignored due to path filters (1)
  • projects/extension-supabase/plan.md is excluded by !projects/**
📒 Files selected for processing (2)
  • examples/supabase/test/rls-role-binding.integration.test.ts
  • skills/upgrade/prisma-next-upgrade/upgrades/0.14-to-0.15/instructions.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2501-rls-acceptance-test-migration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 154.91 KB (0%)
postgres / emit 129.93 KB (0%)
mongo / no-emit 98.64 KB (0%)
mongo / emit 89.41 KB (0%)
cf-worker / no-emit 182.11 KB (0%)
cf-worker / emit 154.64 KB (0%)

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric added this pull request to the merge queue Jul 12, 2026
Merged via the queue into main with commit 3b9da2e Jul 12, 2026
19 of 20 checks passed
@wmadden-electric
wmadden-electric deleted the tml-2501-rls-acceptance-test-migration branch July 12, 2026 18:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants