Testing
The gate, and the tenant-isolation suites that block a merge.
On this page
The gate
pnpm typecheck && pnpm lint && pnpm test
All three pass before every commit, in every repository you touched. The server also has pnpm test:e2e.
What to test
Test what would actually break: boundaries, contracts, isolation and error paths. Not getters.
The tenant-isolation suites: merge blockers
| Suite | Level |
|---|---|
src/db/rls.spec.ts | Database: policies hold for every table in POLICY_PROTECTED_TABLES |
organizations/tenant-isolation.spec.ts | HTTP: one workspace's API cannot reach another's rows |
*.isolation.spec.ts per feature | Each feature's own tables (e.g. webhooks.isolation.spec.ts) |
Every new tenant table adds its own test:
- 1Seed a row in org A
- 2Seed a row in org B
- 3From org B: select A's rowmust be invisible
- 4From org B: update / delete itmust affect nothing
Why they need a real Postgres, as ikazebot_app
RLS exists only in the database, and it is inert for a superuser, for a BYPASSRLS role and, without FORCE, for the table owner. A suite that passed as the migrator would prove nothing. So:
- The suites connect as
ikazebot_app, the same restricted role production uses. - Any other role fails the run. It does not skip, because a privileged run passes whether or not isolation holds.
- They use
DATABASE_URL;TEST_DATABASE_URLoverrides it. With neither set, they skip and warn, and a skipped run means RLS is unverified. - With
NODE_ENV=productionthey refuse to run, since they write and delete rows.
Sharing the development database safely
For now there is one database, so the suites are built to share it:
- Every row they write is named
ikazebot-rls-test …with a run-scoped UUID, and emails use@example.invalid, so nothing can be mistaken for real data. - They delete only the ids they created, never by predicate and never with a truncate, and cleanup runs even if setup fails partway.
- If a delete fails, the exact ids are printed to stderr for manual removal.
Find leftovers from a crashed run:
SELECT id, name FROM organizations WHERE name LIKE 'ikazebot-rls-test%';
SELECT id, email FROM users WHERE email LIKE 'ikazebot-rls-test%';
Before the first real signup, database-backed tests move to their own database. Sharing is a recorded, temporary decision.
Fakes that never leave the machine
Tests never send mail (test/recording-mail-transport.ts), never touch a bucket (test/in-memory-storage.ts), and never call OpenRouter (a deterministic fake embedder).
Data inventory test
data-inventory.spec.ts fails when a table exists without a privacy entry, or when an export and the inventory disagree. A new table does not ship until someone has decided what personal data it holds, how long it lives and how it is exported.