fix: load bun:sqlite at runtime with node:sqlite fallback - #347
Open
thatdudealso wants to merge 3 commits into
Open
fix: load bun:sqlite at runtime with node:sqlite fallback#347thatdudealso wants to merge 3 commits into
thatdudealso wants to merge 3 commits into
Conversation
Vitest runs the storage layer under Node, but src/storage/db.ts had
a static `import { Database } from "bun:sqlite"`, which Node cannot
resolve. Load bun:sqlite via createRequire at runtime and fall back
to node:sqlite's DatabaseSync when Bun is unavailable, so the
storage tests can run under Node/Vitest as well as Bun.
Add a self-governance section and note that src/storage/db.ts now supports Node via a node:sqlite fallback, and that bunx vitest still runs under Bun so the Node path requires an explicit node invocation.
Contributor License AgreementAll contributors are covered by a CLA. |
The node:sqlite DatabaseSync path prepared statements without calling
setAllowBareNamedParameters(true), so callers binding objects like
{ id } against @id placeholders (as workspaces.ts and sessions.ts do)
could fail to bind under Node, unlike Bun's strict: true mode. Add a
regression test that exercises the exact fallback path and verifies
both persistence and that the API is actually invoked.
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e221bce. Configure here.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
src/storage/db.tsstatically importedbun:sqlite, which only resolves under the Bun runtime. This blocked running storage tests under plain Node (e.g.node node_modules/.bin/vitest run), sincebunx vitest runitself still executes under Bun.bun:sqlitelazily viacreateRequireand falls back to Node's built-innode:sqlite(DatabaseSync) when Bun isn't available. Both backends satisfy the same internalDatabaseshape, so the publicSQLiteDatabaseinterface and all callers are unchanged.src/storage/db.test.ts, a regression test that initializes the database and round-trips a write/read (including insidewithTransaction), proving the storage layer now works under Node/Vitest.Fixes #346
Test plan
bun run typecheckbun run lintbun run formatbunx vitest run(Bun runtime) — 250/250 tests passnode node_modules/.bin/vitest run(plain Node runtime) — 250/250 tests pass, confirming thenode:sqlitefallback path works end-to-endNote
Medium Risk
Touches core persistence and parameter binding on experimental node:sqlite; behavior must stay aligned with Bun’s strict mode for all existing callers.
Overview
Storage SQLite no longer statically imports
bun:sqlite, so Vitest and other tooling can run under plain Node.db.tsloads Bun’s driver viacreateRequirewhen available and otherwise usesnode:sqlite(DatabaseSync) behind the same internalDatabaseshape, leaving the publicSQLiteDatabaseAPI unchanged.The Node path enables bare named parameter binding (
{ id }→@id) viasetAllowBareNamedParameters(true)and implements transactions with explicitBEGIN/COMMIT/ROLLBACK. Newsrc/storage/db.test.tscovers init/read-write, named params, the Node-only spy onsetAllowBareNamedParameters, andwithTransaction.AGENTS.mddocuments the dual-runtime behavior and test commands;CLAUDE.mdpoints agents atAGENTS.md.Reviewed by Cursor Bugbot for commit e221bce. Configure here.