fix(heal): deterministic native better-sqlite3 via escalation ladder - #19
Merged
Merged
Conversation
Plain 'npm install' only yields a native binding when npm's content store
happens to hold an already-built copy of the exact version — cache history,
not scripts. On a cold store, npm >=11.17's allow-scripts skips the build
script and the heal raced whatever eventually built the binding (transient
FAILED noise, WASM-fallback windows).
ensureNativeBsq3(dir) now escalates, verifying after each rung:
1. plain install (npm <11.17, or warm content store)
2. npm approve-scripts better-sqlite3 + npm rebuild — npm's sanctioned
path; approve-scripts pins the exact version into the location's
package.json (harmless no-op on older npm); rebuild also recovers a
stale half-built build/ dir
3. npm run install in the resolved package root — explicit 'npm run' is
user-invoked and never gated by allow-scripts
natives.mjs: extract bsq3Root() from bsq3IsNative() for reuse.
tests/kit/natives.test.mjs: hermetic fixture tests for both helpers.
E2E-verified against a script-skipped install: pre-state no binding,
ladder returns 'native rebuilt (scripts approved)', binding present.
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.
Problem
healNativesdid one plainnpm installand hoped. Investigation showed a plain install only yields a native binding when npm's content store already holds a built copy of that exact version (verified: a fresh scratch install materialized a binding whose timestamps predate the project) — cache history, not scripts. On a cold store, npm ≥11.17's allow-scripts skipsbetter-sqlite3's build script, leaving the location on WASM fallback and sync reporting transient FAILED noise that later self-resolves nondeterministically.Fix
ensureNativeBsq3(dir)— an escalation ladder, verifyingbsq3IsNativeafter each rung and stopping at the first binding:npm approve-scripts better-sqlite3+npm rebuild better-sqlite3— npm's own sanctioned path (what its warning tells you to run); pins the exact version into the location'spackage.json, harmless no-op on older npm. Rebuild also recovers a stale half-builtbuild/dir.npm run installin the resolved package root — explicitnpm runis user-invoked, never gated by allow-scripts; fully deterministic.The detail string names which rung succeeded; FAILED (with stderr tail) only if all three miss.
bsq3Root()is extracted frombsq3IsNative()in natives.mjs for reuse.Verification
pnpm test— 32 node:test pass (incl. new hermetic fixture tests forbsq3Root/bsq3IsNative) + statusline 20/20--ignore-scripts, binding absent): rung 1 no-ops (package already present), rung 2 builds it —{"ok":true,"how":"native rebuilt (scripts approved)"}, binding verified on disknpm run install→ binding built)healNatives()on a healthy machine:already native everywhere(idempotent)🤖 Generated with Claude Code