Skip to content

[Testing 16] ci: run the RLS/stack integration suite on every PR - #256

Open
amal66 wants to merge 1 commit into
Open-Legal-Products:mainfrom
amal66:olp-pr/stack-tests-ci
Open

[Testing 16] ci: run the RLS/stack integration suite on every PR#256
amal66 wants to merge 1 commit into
Open-Legal-Products:mainfrom
amal66:olp-pr/stack-tests-ci

Conversation

@amal66

@amal66 amal66 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

What this fixes

Mike already has integration tests that check the two security properties that matter most for a legal tool: that the database refuses to hand rows to browser clients (the "deny-all" row-level security firewall), and that login tokens resolve to the right user through the backend's auth path. But those tests only run against a real local Supabase stack, and nothing in CI ever started one — so on every PR they quietly skipped themselves. A change that broke RLS could have merged with a green checkmark.

This PR adds a Stack tests workflow that boots a disposable Supabase stack on the CI machine itself, loads the database schema, and runs that suite on every PR and every push to main. No accounts, no secrets, nothing leaves the runner — the stack is created and destroyed inside each CI run. Only the services the suite touches are started (db/auth/rest/kong), keeping the job fast.

A bonus safety property: schema-drift detection

The workflow builds the database by loading schema.sql (the fresh-install snapshot) and then applying every dated migration on top, in order. That means every PR now also proves the snapshot and the migrations still fit together — if someone edits schema.sql without a matching migration (or vice versa), CI fails before a fresh deployment can.

This paid off immediately: five existing migrations did not apply cleanly on top of today's schema.sql — three old backfills read documents.* columns that a later migration moved to document_versions (they're now guarded on column existence, so real, older deployments behave identically and fresh-snapshot databases just skip the backfill), and two overview RPCs used create or replace where the function's return shape had changed (now drop function if exists first — the exact pattern the later migrations in the series already use, and those later migrations re-create the final shape, so the sequence converges).

Verified locally end to end: fresh stack → schema.sql → all 44 migrations → all 5 stack tests passing.

Maintainer action required

Once this job has run green on a PR or two, please make it mandatory: Settings → Branches → branch protection rule for main → under "Require status checks to pass before merging" add the Stack tests job. Until you do that, the job runs and reports, but a red result won't actually block a merge.

🤖 Generated with Claude Code

@CLAassistant

CLAassistant commented Jul 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@amal66
amal66 force-pushed the olp-pr/stack-tests-ci branch from bfec767 to ce4b460 Compare July 25, 2026 21:31
@amal66
amal66 requested a review from willchen96 July 26, 2026 14:10
The gated stack tests (backend/src/__tests__/integration/*.supabase.test.ts)
prove the deny-all RLS firewall and the auth<->API contract against a real
local Supabase stack, but no CI trigger ever set the SUPABASE_TEST_* env
vars, so they silently self-skipped on every PR. Add a workflow that boots
the stack on the runner (supabase CLI pinned, minimal service set: db, auth,
rest, kong), bootstraps the database the way backend/scripts/test-stack.sh
does, and runs the suite. No secrets: everything is local to the runner.

The bootstrap loads schema.sql and then applies every dated migration on
top in filename order, which doubles as a schema-drift smoke test: the
snapshot and the migrations must apply cleanly together. Running it
surfaced five migrations that could not apply on top of the current
schema.sql — three whose backfills read documents columns that later
migrations moved to document_versions, and two overview RPCs whose return
row type `create or replace` cannot change. Guard the backfills on the
historical columns' existence and drop-before-create the RPCs (the pattern
20260703_02 already uses); behavior on era deployments is unchanged, and
the full sequence now applies cleanly end to end (verified locally: fresh
stack, schema + 44 migrations, 5/5 stack tests green).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@amal66
amal66 force-pushed the olp-pr/stack-tests-ci branch from ce4b460 to 6f4f321 Compare August 3, 2026 01:57
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.

2 participants