FORGE-89: in-process D1 test database (FG_TEST_DB=d1) with a transaction guard #725
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gmackie/ForgeGraph!725
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "FORGE-89-d1-test-db"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
FORGE-89 (D1 Phase 4), step 2 of 5. Stacked on #721 (contains its commit until #721 merges; review the top commit).
What
FG_TEST_DB=d1runs the API's DB-backed suites (the samedatabaseTestslist the Postgres lane runs) on an in-process D1: Miniflare, i.e. Cloudflare's own D1 implementation inside workerd. Chosen over better-sqlite3 for fidelity: it enforces D1's 100-bound-parameter limit and statement-length limit, uses D1's batch semantics and error text, and authorises functions the way D1 does. Locally a query costs ~9 ms, so the lane takes ~80 s.database-test-config.ts: withFG_TEST_DB=d1, generates the STRICT SQLite DDL once (@forgegraph/db/schema-sqlite/ddl, from #721), passes it to workers, and aliases@forgegraph/db/schema→@forgegraph/db/schema-sqliteso application code under test writes through the SQLite tables. The Postgres path is unchanged.helpers/test-db.ts:createTestDb()returns a drizzle d1 client over one shared Miniflare D1 (helpers/d1-test-db.ts), withexecute()returning rows like the postgres-js client; the availability probe usessqlite_schema.assertNoTransactionControl, which throwsD1TransactionGuardErroron BEGIN / COMMIT / ROLLBACK / SAVEPOINT / RELEASE / END. Remote D1 rejects them with 7500 and local D1 versions differ (the Miniflare 5 in this repo rejects BEGIN with a Durable Objects message; older ones accept it), so the lane fails the same way production would.db.transaction()therefore fails on D1.d1-known-failures.txt: the 20 files that fail on D1 today, each tagged with its cause (14 transactions, Postgres-only SQL such asextract(epoch),DISTINCT ON,TRUNCATE … CASCADE, and >100 bound parameters / statement too long).pnpm --filter @forgegraph/api test:d1skips them and must be green;test:d1:knownruns only them and prints a::warning::for any that now pass, so FORGE-88 removes entries as it converts code. The config rejects list entries that aren't database tests.helpers/d1-test-db.test.ts(guard, unit lane) andd1-transaction-guard.database.test.ts(D1 lane only:db.transaction()fails with the guard error as its cause; a batch with a mid-batch PK violation leaves no rows). Skipped on Postgres.Verification (local)
test:d1: 24 files, 136 passed, 16 skipped, 0 failed (82 s).test:d1:known: 20 listed, 20 still failing, 0 now passing.test:database(PGlite): 44 passed, 1 skipped (the D1-only file); 342 tests passed.pnpm --filter @forgegraph/api typecheck: clean; oxlint clean on the new files.Next: the non-required CI job (separate PR, coordinated with FORGE-68's ci.yml layout).
🤖 Generated with Claude Code
0142c748d98333114e1f