Repository navigation
Probe native add-ons for real after install and self-update - #1816
SawyerHood wants to merge 1 commit into
Conversation
Address the SlopCop review on #1805: - The installer probe now opens and closes an in-memory better-sqlite3 database. A plain require loads only JavaScript; the binding loads in the Database constructor. node-pty loads pty.node at module load. - The daemon self-updater runs the same probe (via `npm root -g` and a node child process) after `npm install -g` and throws before it reports "updated", so ignore-scripts=true cannot swap a working daemon for a broken package silently. The process runner now returns stdout. - The fake npm in the installer test keeps the add-on JavaScript and omits only the native output, per module, so the test covers "only better-sqlite3 blocked". - The README ignore-scripts recovery commands also pass --allow-scripts. Co-Authored-By: Claude <[email protected]>
|
🚨 SLOP COP 🚨 · I am the SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior. |
| }, | ||
| { env }, | ||
| ); | ||
| await verifyInstalledNativeModules(prefixArgs, runProcess, env); |
There was a problem hiding this comment.
🚨 slopcop/review — High: the failed probe leaves a broken package on disk.
npm install -g has already replaced the package in the service prefix before this probe runs. If the probe fails, the updater returns failed, but it does not restore the prior package. The current Node process can stay alive with cached modules. However, the next service restart uses the broken on-disk install and can enter a restart loop. Please install into a staging prefix and promote it after the probe passes, or restore the prior package before this path returns.
| const root = process.argv[1]; | ||
| const Database = require(root + "/node_modules/better-sqlite3"); | ||
| new Database(":memory:").close(); | ||
| require(root + "/node_modules/node-pty"); |
There was a problem hiding this comment.
🚨 slopcop/review — Medium: the probe omits one native add-on from its own policy list.
BB_APP_NATIVE_MODULES includes @parcel/watcher, but this probe loads only SQLite and PTY. @parcel/watcher loads its native binding during require, so a missing watcher binary can pass this check. The new daemon can then start with a watcher child that fails repeatedly. Please require root + "/node_modules/@parcel/watcher" here and in the shell probe. Add a test that omits only its native output.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain-English summary: This PR tests real native module loads after an install or self-update. It also fixes npm recovery commands.
I found two correctness problems.
- High: A failed post-install probe leaves the broken package in the service prefix. The current process survives, but a later restart can fail.
- Medium: The policy lists
@parcel/watcher, but both probes omit it. A broken watcher can pass the probe and fail after restart.
I left inline comments with the exact failure paths and fixes.
Two small maintenance issues also remain. The probe policy now exists in shell, TypeScript, and the native repair script. A shared probe script would prevent drift. The published packages/bb-app/README.md also lacks the new ignore-scripts recovery command.
The security review found no injection or unsafe path use. The performance review found no material cost or tight retry loop.
Validation passed at the exact head SHA:
- Host-daemon typecheck and server typecheck.
- Host-daemon self-update test: 14 tests.
- Machine installer test: 19 tests, including three blocked-native cases.
- All current GitHub CI checks.
No web route changed. A browser test cannot exercise these host-local install paths. The shell installer test covers the applicable end-to-end path.
I posted a comment-only review. I did not approve or request changes.
Follow-up to #1805 (issue #1120). It addresses the three correctness findings from the SlopCop review on that PR, which merged before the fixes landed.
What was wrong
require("better-sqlite3"). That loads JavaScript only; the native binding loads in theDatabaseconstructor. With npm 12 and only thebetter-sqlite3script blocked, npm and the probe both returned 0, and bb still failed at startup withCould not locate the bindings file.ignore-scripts=truein an npmrc overrides--allow-scripts, npm returns 0, and the daemon reportedupdatedand restarted into a package with missing bindings.ignore-scriptsrecovery commands in the README omitted--allow-scripts, so on npm 12 they still produced a broken install.What changed
apps/server/src/assets/install-machine.sh: the probe opens and closes an in-memorybetter-sqlite3database, then requiresnode-pty(which loadspty.nodeat module load).apps/host-daemon/src/protocol-self-update.ts: afternpm install -g, the updater runsnpm root -g [--prefix ...], then runs the same probe in anodechild process against<root>/bb-app. If it fails,installTarballthrows with a message that names the add-ons and thenpm_config_allow_scripts=... npm_config_ignore_scripts=falsefix, sohandleProtocolMismatchreturnsfailedand keeps the current daemon running.SelfUpdateProcessRunnernow returns{ stdout }.apps/server/test/app/install-machine-script.test.ts: the fake npm keeps the add-on JavaScript and models the native output asbuild/Release/*.nodefiles that the fake modules load like the real ones.FAKE_NPM_SKIP_NATIVE_MODULESnames the modules whose native output is missing. Three cases: both, onlybetter-sqlite3, onlynode-pty.apps/host-daemon/src/protocol-self-update.test.ts: asserts thenpm root -gand probe calls, and that a probe failure yieldsfailedwith the loud error.README.md: theignore-scriptsrecovery commands set both controls (npm_config_ignore_scripts=false npx --allow-scripts=... bb-app@latest, and thenpm install -gform).Not done: the "single policy manifest" note. The list lives in shell (installer) and TypeScript (daemon) with no shared build step between them; a manifest would need a generation step, which is more than this follow-up. Both sites carry a keep-in-sync comment.
How I verified
better-sqlite3's native output missing, the installer testfails loudly when npm skipped the install scripts for better-sqlite3failed (installer exit 0). After: all 19 installer tests pass.pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/host-daemon→ pass.pnpm exec turbo run test --filter=@bb/host-daemon→ 585 passed (includes the two new self-updater tests).pnpm exec turbo run test --filter=@bb/server→ 1726 passed, 1 failed:internal-skill-trees.test.tsexpects file mode 420 and gets 436 (local umask); unrelated and green in CI.Refs #1120