|
15 | 15 |
|
16 | 16 | #[path = "common/mod.rs"] |
17 | 17 | mod common; |
18 | | -use common::{binary, git_sha256}; |
| 18 | +use common::{binary, git_sha256, hermetic}; |
19 | 19 |
|
20 | 20 | use std::path::Path; |
21 | 21 | use std::process::{Command, Output}; |
@@ -58,24 +58,12 @@ fn git_sha256_file(path: &Path) -> String { |
58 | 58 | /// Run the CLI binary with the given args, setting `cwd` as the working dir. |
59 | 59 | /// Returns `(exit_code, stdout, stderr)`. |
60 | 60 | fn run(cwd: &Path, args: &[&str]) -> (i32, String, String) { |
61 | | - let mut cmd = Command::new(binary()); |
| 61 | + // The hermetic `SOCKET_*` environment: no ambient value (SOCKET_DRY_RUN, |
| 62 | + // SOCKET_GLOBAL_PREFIX, ...) changes what these tests exercise, no token |
| 63 | + // (so the public proxy), and the config layer, update notifier and |
| 64 | + // telemetry forced off. |
| 65 | + let mut cmd = hermetic::command(&binary()); |
62 | 66 | cmd.args(args).current_dir(cwd); |
63 | | - // The binary binds a wide `SOCKET_*` env surface (SOCKET_CWD, |
64 | | - // SOCKET_DRY_RUN, SOCKET_STRICT, SOCKET_ECOSYSTEMS, SOCKET_GLOBAL_PREFIX, |
65 | | - // ...). An ambient value silently changes what these tests exercise — |
66 | | - // SOCKET_DRY_RUN=true turns every real apply into a no-op, and |
67 | | - // SOCKET_GLOBAL_PREFIX flips commands into global mode, aiming mutations |
68 | | - // at the host's *real* global node_modules. Scrub the whole prefix so |
69 | | - // only the flags each test passes are in effect; removing |
70 | | - // SOCKET_API_TOKEN also forces the public proxy (free-tier). Telemetry |
71 | | - // opt-outs are deliberately kept so an opted-out dev stays opted out. |
72 | | - for (key, _) in std::env::vars_os() { |
73 | | - let name = key.to_string_lossy(); |
74 | | - if name.starts_with("SOCKET_") && !name.contains("TELEMETRY") && name != "SOCKET_NO_CONFIG" |
75 | | - { |
76 | | - cmd.env_remove(&key); |
77 | | - } |
78 | | - } |
79 | 67 | // Partial cache isolation only — the global auto-discovery test below |
80 | 68 | // needs the binary's `npm root -g` / `yarn global dir` / `pnpm root -g` |
81 | 69 | // probes to resolve the REAL prefixes, which come out of $HOME, so a full |
@@ -108,6 +96,7 @@ fn assert_run_ok(cwd: &Path, args: &[&str], context: &str) -> (String, String) { |
108 | 96 | fn npm_run(cwd: &Path, args: &[&str]) { |
109 | 97 | let mut cmd = Command::new("npm"); |
110 | 98 | cmd.args(args).current_dir(cwd); |
| 99 | + hermetic::scrub_socket_vars(&mut cmd); |
111 | 100 | cache_env::isolate(&mut cmd); |
112 | 101 | let out = cmd.output().expect("failed to run npm"); |
113 | 102 | assert!( |
@@ -357,6 +346,7 @@ fn test_npm_global_lifecycle() { |
357 | 346 | ]); |
358 | 347 | // `--prefix` is a flag, so it still decides where the package lands; the |
359 | 348 | // sandbox only moves the download cache off the caller's home. |
| 349 | + hermetic::scrub_socket_vars(&mut cmd); |
360 | 350 | cache_env::isolate(&mut cmd); |
361 | 351 | let out = cmd.output().expect("failed to run npm install -g"); |
362 | 352 | assert!( |
|
0 commit comments