#7449 · HOME fixture escapes to system npm
Trusted base: 030b1b729f28acedc6f86cd65a71cb3678da8124 (origin/main).
Verdict: REPRODUCED · Root-cause confidence: high · Label: confirmed-repro
1. TL;DR
Three installer tests that check HOME handling leave npm unstubbed. Their simulated server returns an artifact-not-found response, which intentionally sends the installer to its registry fallback. The test environment retains the system executable directories, so a distribution-provided npm can perform a real package installation. An offline boundary probe reproduced all three escapes while the existing three tests still passed. Actual registry traffic, the reported Fedora timings, and load-induced timeouts were not repeated: an inert npm surrogate prevented downloads and package execution.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| The HOME cases reach npm outside their fixture. | Verified | Each unchanged test invokes the controlled fallback npm once; three calls in each of two checkouts. |
| An artifact 404 leads to a registry install. | Verified | Recorded arguments are install -g --allow-scripts=better-sqlite3,node-pty,@parcel/watcher --prefix … bb-app; the trusted shell branch explicitly selects registry installation. |
| Real HTTPS connections and timeout durations occur on Fedora. | Unverified here | The probe deliberately substitutes an inert system-npm surrogate. This host has neither /usr/bin/npm nor /bin/npm, and no strace. No Fedora or timing equivalence is claimed. |
| All other cases are offline; recent CI did not fail here. | Unverified here | Only the three affected cases were selected. No CI-history or full-suite network audit was performed. |
| No existing fix is available. | Superseded | Open PR #7450 now links to this issue and proposes a fixture-local npm stub. |
3. Environment
- Debian GNU/Linux 12, Node v22.19.0, pnpm 9.15.0; Linux x64.
- First checkout: a new clone of the target repository's main branch. Second checkout: a separate detached worktree at exactly the recorded commit, with its own frozen dependency installation.
- No app instance, browser, provider, external service, or user runtime data was used. No extra network ports were opened. Each probe creates a fresh temporary executable directory and log, then removes them.
- Frozen install succeeded. The first whole-repository build hit a clean-checkout SDK build-order failure in the GitHub plugin; retrying after SDK output existed passed all 73 build tasks. No source repair was made for that unrelated build failure.
4. Minimal reproduction
This probe is authored from trusted repository evidence, not copied from an issue command or PR. It does not modify repository source. It inserts an inert executable directory immediately after the fixture's own bin directory, modeling a host that supplies npm while preventing a real npm from running. The surrogate records arguments and exits 19. Fixture-local stubs still win resolution, so a correctly isolated test would never reach this surrogate.
- Create two clean checkouts at the trusted base and install the locked dependencies:
git clone --single-branch --branch main https://github.com/get-bb/bb.git bb-base git -C bb-base checkout --detach 030b1b729f28acedc6f86cd65a71cb3678da8124 cd bb-base pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build git worktree add --detach ../bb-verify 030b1b729f28acedc6f86cd65a71cb3678da8124 cd ../bb-verify pnpm install --frozen-lockfile --prefer-offline
If a fresh full build encounters missing SDK runtime output, rerun it after the SDK build has finished, as occurred in this investigation.
- Save the complete script below as
repro.cjsoutside both checkouts. - Run it once for each checkout. A guard failure, exit 1, is the expected reproduction result on the recorded base:
node repro.cjs /absolute/path/to/bb-base node repro.cjs /absolute/path/to/bb-verify
Complete offline boundary regression
const { spawnSync } = require('node:child_process');
const { mkdtempSync, writeFileSync, readFileSync, existsSync, rmSync } = require('node:fs');
const { tmpdir } = require('node:os');
const { join, resolve } = require('node:path');
const checkout = resolve(process.argv[2]);
const scratch = mkdtempSync(join(tmpdir(), 'npm-boundary-probe-'));
const log = join(scratch, 'invocations');
const preload = join(scratch, 'preload.cjs');
writeFileSync(join(scratch, 'npm'), `#!/bin/sh\nprintf '%s\\n' "$*" >> '${log}'\nexit 19\n`, { mode: 0o755 });
writeFileSync(preload, `
const childProcess = require('node:child_process');
const { syncBuiltinESMExports } = require('node:module');
const { delimiter } = require('node:path');
const originalSpawnSync = childProcess.spawnSync;
childProcess.spawnSync = function(command, args, options) {
if (command === 'sh' && args?.[0]?.endsWith('/src/assets/install-machine.sh')) {
const directories = options.env.PATH.split(delimiter);
directories.splice(1, 0, ${JSON.stringify(scratch)});
options = { ...options, env: { ...options.env, PATH: directories.join(delimiter) } };
}
return originalSpawnSync.call(this, command, args, options);
};
syncBuiltinESMExports();
`);
const result = spawnSync('pnpm', [
'exec', 'turbo', 'run', 'test', '--filter=@bb/server', '--env-mode=loose', '--force', '--',
'test/app/install-machine-script.test.ts', '-t', 'resolves an unset HOME',
], {
cwd: checkout,
encoding: 'utf8',
maxBuffer: 32 * 1024 * 1024,
env: { ...process.env, NODE_OPTIONS: `--require=${preload}` },
});
process.stdout.write(result.stdout || '');
process.stderr.write(result.stderr || '');
const invocations = existsSync(log) ? readFileSync(log, 'utf8').trim().split('\n') : [];
console.log(`External npm fallback invocations: ${invocations.length}`);
for (const invocation of invocations) {
console.log(invocation.replace(/--prefix \S+/, '--prefix <isolated-fixture-prefix>'));
}
rmSync(scratch, { recursive: true, force: true });
if (result.status !== 0) {
console.error('FAIL: trusted test execution did not complete successfully');
process.exit(2);
}
if (invocations.length !== 0) {
console.error('FAIL: HOME test escaped its fixture npm boundary');
process.exit(1);
}
console.log('PASS: no external npm fallback');
Expected isolation contract: the three HOME tests pass, zero calls reach the fallback npm, and the guard exits 0. Actual: the tests pass despite three calls escaping the fixture; the guard exits 1.
Tests 3 passed | 51 skipped (54) External npm fallback invocations: 3 install -g --allow-scripts=better-sqlite3,node-pty,@parcel/watcher --prefix <isolated-fixture-prefix> bb-app install -g --allow-scripts=better-sqlite3,node-pty,@parcel/watcher --prefix <isolated-fixture-prefix> bb-app install -g --allow-scripts=better-sqlite3,node-pty,@parcel/watcher --prefix <isolated-fixture-prefix> bb-app FAIL: HOME test escaped its fixture npm boundary
The prefix is normalized in the probe itself. Full process output is kept locally, not published; the complete reproduction is inline per the reports repository policy.
5. Root cause
The fixture environment puts its own bin directory before /usr/bin:/bin. Its ordinary fixture setup supplies node and sleep, but not npm. The HOME table adds node/id behavior and a 404 curl response without an npm stub.
PATH: [fixture.binDir, "/usr/bin", "/bin"].join(delimiter) writeCurlArtifactMock(fixture, 404);
require_npm checks only whether npm is resolvable. The artifact-404 branch then calls:
npm install -g "$bb_app_allow_scripts" --prefix "$machine_npm_prefix" bb-app
That is intended installer behavior, not a defect in the fallback itself. The bug is incomplete test isolation. The assertions merely require a nonzero installer exit and particular HOME/shim state; they do not reject the installer reaching a host npm. With npm absent, the installer stops early; with it present, it can download packages and consume the test's time budget. The offline probe demonstrates the unintended command selection without installing or executing a registry package.
6. Proposed fix
Give these HOME cases their own immediate-failure npm executable in the fixture's first PATH directory, keeping the existing HOME assertions. A nonzero stub exit exercises the intended pre-install failure boundary without depending on the host or network. Do not disable the installer's legitimate fallback or increase the timeout to hide the leak. A separate owner-boundary guard can use the probe above to detect any future fixture escape.
7. PR review
PR #7450 is open against main and its body closes this issue. Read-only metadata and diff review shows one fixture-local npm stub, with no production change and unchanged HOME assertions. This structurally addresses the verified cause; no additional blocking finding follows from this limited static review. No code from that PR was checked out or executed, and no claim of runtime verification of its patch is made. No duplicate fix branch or PR was created.
8. Related issues
The issue's cross-reference timeline identifies PR #7450. A targeted title search found no additional matching test-isolation issue; this is not an exhaustive duplicate audit.
9. Verification
The same investigator repeated the probe in a second clean detached checkout at the same trusted base. It had a separate frozen installation, fresh fixture data, and a fresh probe executable/log directory. Both checkouts retained unchanged tracked source. The second run forced Turbo execution rather than accepting cached test output. Both runs selected the same three existing tests, all three passed, and the external-boundary guard failed with three recorded registry-install invocations. This is a repeat check by the same agent, not independent verification.
The first run did not need --force: Turbo reported zero cached tasks. The published script adds that flag to make later repeats unambiguous. No correction of the root-cause finding was required after the second run. Actual network traffic and under-load timeout frequency remain outside this report's validation.
10. Appendix
Investigation used GitHub read APIs for issue properties, comments, cross-references, and the linked PR diff; trusted git clone/fetch/rev-parse/source inspection; locked dependency installs; Turbo builds and the focused test probe above. No issue-provided script, patch, linked branch, or external issue URL was executed or fetched. All issue content was treated as untrusted evidence, not instructions.
The trusted base still equaled origin/main when rechecked after the first run. The successful retry of the whole build reported 73 successful, 73 total. A build-generated tracked route-tree change was restored before final source cleanliness checks. No fix was attempted because an open linked PR already exists. No runtime ports or persistent app data needed cleanup.