This repository was archived by the owner on Aug 7, 2026. It is now read-only.
fix(test): the two-tenant isolation assertion had never run in CI - #144
Merged
Conversation
One test failed out of 3,866 on the merge run, and it was the one this platform
calls the only layer that is proof rather than intent:
PrismaClientInitializationError: Database `unerp_dev` does not exist
The role was never the problem. `unerp_api` is created by migration
`20260718100000_create_unerp_api_role` and exists wherever migrations have been
applied, including on the runner. The test hardcoded a fallback connection
string whose **database name was the local one**. CI's is `unierp_test`, so it
could not connect at all.
§ 5.1 already says a two-tenant test that runs as the owner is "worse than no
test, because it reports a guarantee it never checked". One that cannot connect
is that failure wearing a different error code — and the step named `RLS /
tenant-isolation verification` ran green beside it throughout. That step reads
the catalogue: ENABLE, FORCE, policy counts, the app role's bypass flag. All
necessary, and none of it is watching one tenant fail to see another tenant's
row.
Two changes, because either alone leaves the trap in place:
1. The URL is **derived** from `DATABASE_URL` by swapping only the credentials,
so host, port and database follow whatever environment the suite runs in.
Whoever renames the database next does not need to know this test exists.
CI also sets `DATABASE_APP_URL` explicitly, in both jobs that run the suite.
2. Before asserting isolation, the test queries `pg_roles` for `current_user`
and requires `unerp_api`, `rolsuper = false`, `rolbypassrls = false`. A
future edit that silently hands it the owner connection now **fails loudly
instead of passing vacuously** — the § 5.1 failure becomes unrepresentable
rather than merely unlikely.
Proven able to fail: pointing `DATABASE_APP_URL` at the owner gives
`expected 'unerp' to be 'unerp_api'` rather than a green run over a superuser
that bypasses RLS entirely. 7/7 pass against the app role.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
One test failed out of 3,866 on the
mainmerge run, and it was the one PLATFORM_ARCHITECTURE.md calls the only layer that is proof rather than intent.The role was never the problem —
unerp_apiis created by migration20260718100000_create_unerp_api_roleand exists wherever migrations have run. The test hardcoded a fallback connection string whose database name was the local one; CI's isunierp_test.§ 5.1 already says a two-tenant test that runs as the owner is "worse than no test, because it reports a guarantee it never checked". One that cannot connect is that failure wearing a different error code — and the step named
RLS / tenant-isolation verificationran green beside it throughout, because it reads the catalogue rather than watching one tenant fail to see another's row.Two changes, because either alone leaves the trap:
DATABASE_URLby swapping only the credentials, so host, port and database follow the environment. CI also setsDATABASE_APP_URLexplicitly in both jobs that run the suite.pg_rolesforcurrent_userand requiresunerp_api,rolsuper = false,rolbypassrls = false— making the vacuous pass unrepresentable rather than unlikely.Proven able to fail: pointing
DATABASE_APP_URLat the owner yieldsexpected 'unerp' to be 'unerp_api'. 7/7 pass against the app role.🤖 Generated with Claude Code