Skip to content

Commit 2bf2c2e

Browse files
committed
Keep real HOME and SOCKET_* off npm/Bun kids
From /code-review high: the Bun redirect suite ran its bun fixture installs under the cache sandbox's home but the CLI under the real one, so a registry or scope in the developer's ~/.npmrc would make the two disagree. The CLI now gets the stand-in HOME (jvm_env::isolate_cli), as run_with_env gives every other suite. Its --no-telemetry flag goes: hermetic::command already forces telemetry off, and the flag would override a caller opting back in. e2e_npm's npm installs now drop ambient SOCKET_* vars too (hermetic::scrub_socket_vars), like the package-manager children of the other converted suites. Refs #823 Assisted-by: Claude Code:claude-opus-5-5
1 parent 1d06435 commit 2bf2c2e

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎crates/socket-patch-cli/tests/e2e_npm.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn assert_run_ok(cwd: &Path, args: &[&str], context: &str) -> (String, String) {
9696
fn npm_run(cwd: &Path, args: &[&str]) {
9797
let mut cmd = Command::new("npm");
9898
cmd.args(args).current_dir(cwd);
99+
hermetic::scrub_socket_vars(&mut cmd);
99100
cache_env::isolate(&mut cmd);
100101
let out = cmd.output().expect("failed to run npm");
101102
assert!(
@@ -345,6 +346,7 @@ fn test_npm_global_lifecycle() {
345346
]);
346347
// `--prefix` is a flag, so it still decides where the package lands; the
347348
// sandbox only moves the download cache off the caller's home.
349+
hermetic::scrub_socket_vars(&mut cmd);
348350
cache_env::isolate(&mut cmd);
349351
let out = cmd.output().expect("failed to run npm install -g");
350352
assert!(

‎crates/socket-patch-cli/tests/e2e_redirect_bun_build.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,23 @@ fn bun_env(cwd: &Path, args: &[&str], cache_dir: &Path, env: &[(String, String)]
300300
cmd.output().expect("failed to run bun")
301301
}
302302

303-
/// The real binary with `--no-telemetry` appended: nothing in this suite
304-
/// should ever post a telemetry event, mocked API or not.
303+
/// The real binary. `hermetic::command` forces telemetry off: nothing in
304+
/// this suite should ever post a telemetry event, mocked API or not.
305305
fn run_socket(cwd: &Path, args: &[&str]) -> (i32, String, String) {
306306
run_socket_env(cwd, args, &[])
307307
}
308308

309309
/// [`run_socket`] with extra env applied after the scrub: the hermetic
310-
/// `SOCKET_*` environment (`hermetic::command`) plus the bun suites' shared
311-
/// scrub of every other ambient bun / npm registry setting.
310+
/// `SOCKET_*` environment (`hermetic::command`), the bun suites' shared
311+
/// scrub of every other ambient bun / npm registry setting, and a stand-in
312+
/// `HOME` (`jvm_env::isolate_cli`). The `bun` fixture children run under the
313+
/// cache sandbox's home, so the CLI must not read the developer's real
314+
/// `~/.npmrc` either: a registry or scope there would make the two disagree.
312315
fn run_socket_env(cwd: &Path, args: &[&str], env: &[(String, String)]) -> (i32, String, String) {
313316
let mut cmd = hermetic::command(&binary());
314-
cmd.args(args).arg("--no-telemetry").current_dir(cwd);
317+
cmd.args(args).current_dir(cwd);
315318
cache_env::scrub_ambient_bun_tool_env(&mut cmd);
319+
common::jvm_env::isolate_cli(&mut cmd);
316320
for (k, v) in env {
317321
cmd.env(k, v);
318322
}

0 commit comments

Comments
 (0)