feat(bindings): expose sqlite builtin to Python and JS bindings#1510
Merged
feat(bindings): expose sqlite builtin to Python and JS bindings#1510
Conversation
PR B of the post-launch follow-up plan (#1502). Mirrors the existing `python=True` opt-in pattern so SDK users can reach the Turso-backed SQLite builtin without dropping down to bash builders. ### Python (PyO3) - `Bash(sqlite=True)` and `Bash.from_snapshot(..., sqlite=True)` now register the builtin and inject `BASHKIT_ALLOW_INPROCESS_SQLITE=1` so the runtime gate is satisfied transparently. - New `apply_sqlite_config()` helper centralises the wiring for both `new()` and `reset()`, mirroring `apply_python_config()`. - The `sqlite` flag is preserved on the struct and reapplied across `reset()` (regression-tested). - `_bashkit.pyi` updated with the new keyword and a docstring entry describing the default policy (script/DB caps, deadline, ATTACH and resource-PRAGMAs rejected). ### JavaScript / TypeScript (NAPI) - `BashOptions.sqlite?: boolean` added to the public option struct; `default_opts()` now includes it, and `shared_state_from_opts()` threads it through `SharedState`. - The builder hook applies `.sqlite()` and the env opt-in symmetrically to the existing python branch. - The `.d.ts` is regenerated by NAPI from the struct, no manual stub edits. ### Tests - `crates/bashkit-python/tests/test_sqlite.py`: 12 cases covering opt-in gate, basic queries, output modes, VFS persistence, dot-commands, ATTACH/PRAGMA policy surfacing, and reset preservation. - `crates/bashkit-js/__test__/runtime-compat/sqlite.test.mjs`: 8 cases covering the same surface from JS. - All previously-green tests still green: 2289 lib + 95 CLI + sqlite module tests. - `cargo vet --locked` succeeds (no new transitive deps; sqlite already in the audit set from the original PR). ### Cargo features - `bashkit-python` and `bashkit-js` now include `sqlite` in the `bashkit` feature list. Neither binding had previously enabled it.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | e04f17c | Commit Preview URL Branch Preview URL |
May 02 2026, 05:11 PM |
The JS binding wraps NAPI's `BashOptions` with a hand-written
`toNativeOptions()` mapper in `wrapper.ts` that explicitly enumerates
every field forwarded to native code. The previous commit added
`sqlite?: boolean` to the public `BashOptions` and to the Rust struct,
but forgot to thread the field through `toNativeOptions()` — so JS
callers passing `{ sqlite: true }` had the flag silently dropped.
Both binding tests caught this in CI: `sqlite: command not found` on
node 20/22/24/latest and bun latest/canary, because the constructor
options never reached Rust.
Add `sqlite: options?.sqlite` to the mapper and a corresponding doc'd
field on the `BashOptions` interface in wrapper.ts. Verified locally:
cargo run --... build:cjs && build:ts
node --test __test__/runtime-compat/sqlite.test.mjs
→ 9 pass, 0 fail
bun test __test__/runtime-compat/sqlite.test.mjs
→ 9 pass, 0 fail
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Expose the embedded SQLite builtin (#1502) to the Python (PyO3) and JavaScript (NAPI) SDKs by mirroring the existing
python=Trueopt-in pattern. PR B of the post-launch plan.Why
After #1502 / #1507, the builtin only reached users via the Rust API or the
bashkitCLI. Anyone consuming bashkit through the language bindings (the primary surface for LLM agent integrations) had to hand-rollBash::builder().sqlite()or shell out to the CLI. This closes the gap.How
Python (
bashkit-python)Bash.__init__(..., sqlite: bool = False)and the matchingfrom_snapshotstatic constructor accept the new keyword.apply_sqlite_config()helper, called from bothnew()and thereset()rebuild path. Sets up the builtin and injectsBASHKIT_ALLOW_INPROCESS_SQLITE=1so the runtime gate is satisfied transparently — same shape asapply_python_config().reset()(covered bytest_sqlite_survives_reset)._bashkit.pyiupdated with the keyword + docstring describing the default policy (4 MiB script cap, 256 MiB DB cap, 30 s deadline, ATTACH and resource-PRAGMAs rejected).JavaScript (
bashkit-js)BashOptions.sqlite?: booleanadded to the public option struct.default_opts()includes it;shared_state_from_opts()threads it throughSharedState..sqlite()+ env opt-in symmetrically to the existing python branch..d.tsregenerated by NAPI from the struct (no manual stub).Cargo features
Both
bashkit-python/Cargo.tomlandbashkit-js/Cargo.tomlnow includesqlitein thebashkitfeature list. Neither had previously enabled it, so the binding now actually pulls in turso when built.Tests
tests/test_sqlite.py(Python, 12 cases): opt-in gate, basic queries (CRUD, headers, CSV, JSON), VFS persistence, dot-commands (.tables,.dump/.readround-trip), security policy surfacing (ATTACH/DETACH, PRAGMA deny), reset preservation.__test__/runtime-compat/sqlite.test.mjs(JS, 8 cases): same shape from JS.ruff checkandruff format --checkclean.cargo vet --lockedsucceeds.Test plan
cargo build -p bashkit-python→ okcargo build -p bashkit-js→ okcargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo test --features sqlite -p bashkit --lib→ 2289 passedcargo test -p bashkit-cli→ 95 passedcargo vet --locked→ succeedsruff check crates/bashkit-python && ruff format --check crates/bashkit-python→ cleanGenerated by Claude Code