fix: seed the fixture user in DB integration setup (by Wren) - #439
fix: seed the fixture user in DB integration setup (by Wren)#439conoremclaughlin wants to merge 1 commit into
Conversation
The DB integration suites (task-handlers, strategy-*) insert rows whose user_id FKs to users.id, using the userId from ~/.ink/config.json. A freshly-migrated isolated Supabase has no user rows, so every one of those inserts died on task_groups_user_id_fkey — 11 failures that looked like product bugs but were a missing fixture. Seed it in the integration setup, at runtime: the id is per-developer and user ids must never be committed, so this can't live in supabase/seed.sql. Guards: localhost-only (never write fixture rows into a remote DB, even with INK_ALLOW_REMOTE_INTEGRATION_DB=1); idempotent check-then-insert tolerating a 23505 race between parallel workers; no-op without a config (CI, where the suites self-skip anyway since canRun requires TEST_USER_ID). A failed users query now raises a clear error naming the likely cause (an empty SUPABASE_SECRET_KEY makes PostgREST fall back to anon → 'permission denied') rather than resurfacing downstream as a confusing FK violation. Verified against the isolated stack: FK failures gone, 136 passing (was 122). Co-Authored-By: Wren <noreply@anthropic.com>
conoremclaughlin
left a comment
There was a problem hiding this comment.
Thanks for chasing this down. The local fixture part does work: on my machine the isolated DB run reached 136 passed / 15 failed / 20 skipped, and the previous task_groups_user_id_fkey failures were gone.
I found one remaining blocker before this can be considered the DB-CI fix, though: the setup no-ops before it validates the service-role key when CI has no ~/.ink/config.json. The current PR run (29457600559) still has Unit + Runtime green but DB Integration red with permission denied for table users coming from DataComposer.initialize, not from the new clearer setup error. So the PR does not yet fix the CI failure it targets. Details inline.
Validation:
git diff --check origin/main...HEADcleanyarn workspace @inklabs/api type-checkfails only on known baselinegateway.tsJson assignments andmcp/server.tsthisyarn test:integration:db:local=> 136 passed, 15 failed, 20 skipped; no FK failures; residual failures includeidx_task_groups_user_group_number, repoRoot assumptions, echo identity cardinality, and HTTP 406 test expectation- GitHub Actions run 29457600559: Unit Tests ✅, Integration Runtime ✅, Integration DB ❌ (
permission denied for table users)
| if (!LOCALHOST_HOSTS.has(hostname)) return; | ||
|
|
||
| const configPath = join(homedir(), '.ink', 'config.json'); | ||
| if (!existsSync(configPath)) return; |
There was a problem hiding this comment.
This early return means the new setup never validates the Supabase key in CI, because the Actions runner has no ~/.ink/config.json. But many DB integration suites do not self-skip on TEST_USER_ID (for example agent-gateway, session/thread/memory suites call getDataComposer() directly), so the current PR run still fails later with Database connection test failed: permission denied for table users instead of either passing or surfacing the clearer setup error. Please move a lightweight localhost users access/service-role validation before this config-based no-op (or fix the script extraction so CI reliably exports a real service-role key). As written, the PR still leaves the targeted DB Integration job red with the same permission-denied failure mode.
Why
Conor asked me to find and fix what was making the Integration DB Tests (Local Supabase) job red. Reproduced it against the isolated stack: 11 failures across
task-handlersandstrategy-*integration tests, all the same root cause —Those suites insert rows whose
user_idFKs tousers.id, using the userId from~/.ink/config.json. A freshly-migrated isolated Supabase has no user rows, so every insert died on the FK. It looked like a pile of product bugs; it was a missing fixture.What
Seed the fixture user in the DB integration setup, at runtime.
This can't live in
supabase/seed.sql: the id is per-developer, and user ids must never be committed to the repo (AGENTS.md). So we read it the same way the tests do and upsert it.Guards:
INK_ALLOW_REMOTE_INTEGRATION_DB=1, since a remote target is assumed to be a real DB that already has its users.23505if a parallel vitest worker wins the race.canRunrequiresTEST_USER_ID.beforeAllhook rather than top-level await (this package compiles to CommonJS).usersquery now raises a clear error naming the likely cause instead of resurfacing downstream as a confusing FK violation: "permission denied" here almost always meansSUPABASE_SECRET_KEYis empty, making PostgREST fall back to theanonrole — which matches thepermission denied for table userssymptom Lumen saw from the CI side.Verified
Against the isolated stack (
yarn test:integration:db:local):task_groups_user_id_fkey.Honest scope
This does not turn the whole job green. With the FK gone, a second, distinct pre-existing issue surfaces:
duplicate key value violates unique constraint "idx_task_groups_user_group_number"— the per-user group number is assigned non-atomically, so parallel group creation collides. That's arguably a real product concurrency bug (two agents creating task groups for the same user would race), not a fixture problem, and deserves its own fix. Flagging rather than bundling.🤖 Generated with Claude Code