Skip to content
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
kannan19302 merged 1 commit into
mainfrom
fix/isolation-test-ci
Aug 7, 2026
Merged

fix(test): the two-tenant isolation assertion had never run in CI#144
kannan19302 merged 1 commit into
mainfrom
fix/isolation-test-ci

Conversation

@kannan19302

Copy link
Copy Markdown
Owner

One test failed out of 3,866 on the main merge run, and it was the one PLATFORM_ARCHITECTURE.md 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 run. The test hardcoded a fallback connection string whose database name was the local one; CI's is unierp_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 verification ran 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:

  1. The URL is derived from DATABASE_URL by swapping only the credentials, so host, port and database follow the environment. 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 — making the vacuous pass unrepresentable rather than unlikely.

Proven able to fail: pointing DATABASE_APP_URL at the owner yields expected 'unerp' to be 'unerp_api'. 7/7 pass against the app role.

🤖 Generated with Claude Code

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>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@kannan19302
kannan19302 merged commit 1175e5c into main Aug 7, 2026
7 of 11 checks passed
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.

1 participant