Repository navigation
Use the bundled npm and npx for server-side package-manager calls - #3914
Conversation
The bb-app artifact builder passed a bare "npm" to execFile, so packing the enrolled host runtime required npm on the server process's PATH. A macOS Desktop server launched from Finder inherits PATH=/usr/bin:/bin: /usr/sbin:/sbin, so /install/bb-app.tgz threw `spawn npm ENOENT` and returned HTTP 500, blocking `bb machine setup` for Modal sandboxes and any other fresh machine enrollment. Resolve npm through the bundled CLI and run it under process.execPath, matching runInstallCommand in the plugin install service, and drop inherited npm script-policy env. Rename resolvePluginNpmCli to resolveBundledNpmCli now that it serves more than plugin installs. Fixes #3773 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The bb-app artifact fix left two more server paths resolving a package manager through PATH, so both still break on a GUI-launched macOS Desktop whose PATH is /usr/bin:/bin:/usr/sbin:/sbin. server-move's runPackCommand was a byte-for-byte copy of the artifact service's PATH-dependent runner. Delete it and default createFullBbAppArtifactService to the shared runner, matching createBbAppArtifactService. Registry skill installs spawned bare npx with an env allowlist. Run the bundled npx-cli.js under process.execPath and forward ELECTRON_RUN_AS_NODE so it works when the server runs under Electron. Add resolveBundledNpxCli beside resolveBundledNpmCli, and widen the registry-skill-install child_process mock to pass through the real module instead of only spawn. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#3566 shipped because electron-builder dropped part of the bundled npm tree while source builds and the bb-app tarball smoke stayed green. The afterPack gate added to catch that only resolved and ran bin/npm-cli.js, so the bin/npx-cli.js this branch now depends on had no packaging coverage. Resolve both CLIs through insideArtifact, which realpaths them and asserts containment, and run npx --version through the packaged Electron with an empty PATH exactly as npm is checked. This also adds a missing-file check for npm-cli.js, which was previously only path-joined. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Added a third commit after reviewing how #3566 broke 0.43.0. That release shipped bundled npm without its nested
Verified against the installed signed release:
Caveat worth stating plainly: the end-to-end validation in the PR description used
|
|
Ran the real packaging, closing the gap I flagged above.
Then drove the packaged app itself. Ran its server as Desktop does —
This was the mode that let #3566 ship — source builds and the tarball smoke passed while packaging was broken. It is now exercised directly.
|
Human comments
What was wrong
A macOS Desktop server launched from Finder inherits
PATH=/usr/bin:/bin:/usr/sbin:/sbin. Three server-side code paths resolved a package manager through that PATH instead of the npm that bb already bundles, so each failed withENOENTon any machine without Node on the system PATH — which is exactly the population bb bundles npm for.bb-app-artifact.tspassed a bare"npm"toexecFile, soGET /install/bb-app.tgzthrewspawn npm ENOENTand returned HTTP 500, blockingbb machine setupfor Modal sandboxes and every other fresh machine enrollment (#3773).server-move/full-artifact.tscarriedrunPackCommand, a byte-for-byte copy of the same PATH-dependent runner, so a server move failed the same way while packing the full bb-app.skills/registry-skill-install.tsspawned barenpxand failed withspawn npx ENOENT.What changed
apps/server/src/services/install/bb-app-artifact.ts—defaultCommandRunnerresolves the bundled npm CLI and runs it underprocess.execPath, dropping inherited npm script-policy env. This matchesrunInstallCommandin the plugin install service, which already used this pattern. Exported so the one runner can be shared.apps/server/src/services/server-move/full-artifact.ts— deleted the duplicaterunPackCommand;createFullBbAppArtifactServicenow defaultscommandRunnerto the shared runner, matchingcreateBbAppArtifactService.environment.tsno longer wires one explicitly.apps/server/src/services/skills/registry-skill-install.ts— runs the bundlednpx-cli.jsunderprocess.execPathand forwardsELECTRON_RUN_AS_NODEthrough the env allowlist so it works when the server runs under Electron.packages/plugin-build/src/npm-cli.ts— addedresolveBundledNpxClibeside the npm resolver; renamedresolvePluginNpmClitoresolveBundledNpmClinow that it serves more than plugin installs (5 call sites updated).No wire, CLI, or configuration changes, so no
HOST_DAEMON_PROTOCOL_VERSIONbump.Deliberately unchanged:
provider-maintenance-kit.ts(npmCommand()installs provider CLIs into the user's global prefix and renders a copy-pasteable command; provider processes get a login-shell PATH),host-daemon/protocol-self-update.ts(installs into the machine's npm prefix, already prependsdirname(process.execPath)),apps/cli(runs in the user's terminal against their project), andinstall-machine.sh(runs on the target machine). These need the user's npm by design.How you verified
Tests (each verified to fail before the fix and pass after):
apps/server/test/app/bb-app-artifact.test.ts— builds a real artifact withPATH="". Without the fix:Error: spawn npm ENOENT.apps/server/test/server-move/full-artifact.test.ts— same, throughcreateFullBbAppArtifactServiceand its production default runner.apps/server/test/skills/registry-skill-install.test.ts— asserts the spawned command isprocess.execPathwith an existingnpx-cli.jsand a forwardedELECTRON_RUN_AS_NODE. Without the fix:expected 'npx' to be '/…/node'.Suites:
pnpm exec turbo run typecheck lint test --filter='...[origin/main]'— 97 tasks, all green except one pre-existing parallel-load flake inbb-plugin-provider-codex(cancels an open SSE body after a terminal failure event), which passes on its own re-run.@bb/server2980 pass,@bb/plugin-build139 pass.End-to-end against a real packaged install (
npm pack+npm install -g --prefix), running the server under Electron withELECTRON_RUN_AS_NODE=1andPATH=/usr/bin:/bin:/usr/sbin:/sbin:GET /install/bb-app.tgz— pre-fix HTTP 500 reproducing the issue's log verbatim ("message": "spawn npm ENOENT",spawnargs: ["pack","--pack-destination",…]); post-fix HTTP 200, byte-identical artifact (sha256=779a2b46…) across node/Electron hosts and restricted/full PATH. The downloaded artifact installs and runs (bb --version→0.43.1).bb machine setupover the network onto a second Mac —✓ Downloaded the server's bb-app package→✓ Installed→✓ Joined successfully→● bb machine is ready.bb server moveto that machine — thePacking bb 0.43.1step producedbb-app-full-0.43.1-9fd32ebe….tgz(47 MB) with no npm on PATH, and the target downloaded, installed, and took over.Known gap, pre-existing and not a regression: registry skill install now gets past
spawn npx ENOENTand runs the bundled npx, but the third-partyskillsCLI it fetches carries#!/usr/bin/env node, so on a bare PATH it fails one step later withenv: node: No such file or directory. That is #2343 (the packaged login-shell PATH probe timing out), plus a residual gap for users with no Node at all. Left for a follow-up.Fixes #3773
🤖 Generated with Claude Code