From 17dbd25a437f2aa8a067938e8ca88a670e287dc7 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 14 Oct 2026 11:53:41 +0000 Subject: [PATCH 1/3] Start fix for #823 (slice 22) Assisted-by: Claude Code:claude-opus-5-5 From a1237dce050d9e332057243e17f257f8d0a60fc4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 14 Oct 2026 12:08:39 +0000 Subject: [PATCH 2/3] Hermetic env for production suites' tool spawns The live production suites spawned uv, pnpm, yarn, corepack and bundle with their own scrubs, which had drifted from the shared hermetic helpers: none removed ambient SOCKET_* vars, corepack() kept an ambient npm_config_node_linker, and the hosted tool() removed VIRTUAL_ENV after applying a leg's env, so the uv legs' own VIRTUAL_ENV pin never reached uv. Every package-manager child and its probe now goes through one pm_command builder per suite: tool_command, scrub_socket_vars and the hermetic::Extra scrubs, then cache_env::isolate, then the leg's env last. bundle() keeps its own GEM_*/RUBYOPT sweep. Refs #823 Assisted-by: Claude Code:claude-opus-5-5 --- .../tests/e2e_hosted_production.rs | 35 ++++++++++--- .../tests/e2e_vendored_production.rs | 51 +++++++++++++------ 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/crates/socket-patch-cli/tests/e2e_hosted_production.rs b/crates/socket-patch-cli/tests/e2e_hosted_production.rs index ecc3b88ed..241c5d048 100644 --- a/crates/socket-patch-cli/tests/e2e_hosted_production.rs +++ b/crates/socket-patch-cli/tests/e2e_hosted_production.rs @@ -281,7 +281,7 @@ fn has_command(cmd: &str) -> bool { } else { &["--version"] }; - let mut probe_cmd = Command::new(cmd); + let mut probe_cmd = pm_command(cmd); probe_cmd .args(probe) .stdout(std::process::Stdio::null()) @@ -433,12 +433,37 @@ fn hosted_pin_count(env: &serde_json::Value) -> u64 { // Toolchain invocation // --------------------------------------------------------------------------- +/// Every ambient tool config a package-manager child must not inherit: an +/// activated venv (uv would install into the wrong interpreter), the yarn +/// and pnpm/npm linker and mirror overrides, bundler, PDM, Poetry and +/// Composer settings. See [`hermetic::Extra`]. +const PM_EXTRAS: &[hermetic::Extra] = &[ + hermetic::Extra::Venv, + hermetic::Extra::Yarn, + hermetic::Extra::YarnClassic, + hermetic::Extra::Pnpm, + hermetic::Extra::Bundle, + hermetic::Extra::Pdm, + hermetic::Extra::Poetry, + hermetic::Extra::Composer, +]; + +/// A package-manager child (and its `has_command` probe) with the shared +/// hermetic scrubs: every ambient `SOCKET_*` and every [`PM_EXTRAS`] config. +/// Callers run `cache_env::isolate` next and their own env last. +fn pm_command(program: &str) -> Command { + let mut cmd = hermetic::tool_command(program); + hermetic::scrub_socket_vars(&mut cmd); + hermetic::scrub_extra(&mut cmd, PM_EXTRAS); + cmd +} + /// Run an external package manager. Returns the `Output` without asserting, so /// callers can distinguish "the registry was unreachable" (soft-skip material /// during fixture setup) from "the install of the redirected lock failed" /// (always a hard failure — that is the thing under test). fn tool(cwd: &Path, program: &str, args: &[&str], env: &[(&str, &str)]) -> Output { - let mut cmd = Command::new(program); + let mut cmd = pm_command(program); cmd.args(args).current_dir(cwd); // Sandbox everything the per-leg `env` below does not name — corepack's // downloaded package managers most of all — so a run leaves the caller's @@ -446,13 +471,11 @@ fn tool(cwd: &Path, program: &str, args: &[&str], env: &[(&str, &str)]) -> Outpu cache_env::isolate(&mut cmd); // Keep every toolchain's cache inside the fixture so the reinstall leg // starts genuinely cold and cannot be satisfied from a warm host cache - // holding the *pristine* artifact. + // holding the *pristine* artifact. Applied last, so a leg's own pin + // (the uv legs' `VIRTUAL_ENV`) survives the scrub. for (k, v) in env { cmd.env(k, v); } - // A `VIRTUAL_ENV` inherited from the developer's shell makes uv install - // into the wrong interpreter. - cmd.env_remove("VIRTUAL_ENV"); cmd.output() .unwrap_or_else(|e| panic!("failed to spawn `{program}`: {e}")) } diff --git a/crates/socket-patch-cli/tests/e2e_vendored_production.rs b/crates/socket-patch-cli/tests/e2e_vendored_production.rs index 6a1f6e76b..5a6c08baf 100644 --- a/crates/socket-patch-cli/tests/e2e_vendored_production.rs +++ b/crates/socket-patch-cli/tests/e2e_vendored_production.rs @@ -295,7 +295,7 @@ fn has_command(cmd: &str) -> bool { } else { &["--version"] }; - let mut probe_cmd = Command::new(cmd); + let mut probe_cmd = pm_command(cmd); probe_cmd .args(probe) .stdout(std::process::Stdio::null()) @@ -307,7 +307,7 @@ fn has_command(cmd: &str) -> bool { /// `corepack --version` succeeds — the liveness probe for a specific yarn /// flavor (also the call that downloads it the first time, kept in the sandbox). fn has_corepack_pm(pm: &str) -> bool { - let mut cmd = Command::new("corepack"); + let mut cmd = pm_command("corepack"); cmd.args([pm, "--version"]) .env("COREPACK_ENABLE_DOWNLOAD_PROMPT", "0"); cache_env::isolate(&mut cmd); @@ -497,18 +497,46 @@ fn vendor_revert(cwd: &Path, leg: &str) -> u64 { // Toolchain invocation // --------------------------------------------------------------------------- +/// Every ambient tool config a package-manager child must not inherit: an +/// activated venv (uv/pip would install into the wrong interpreter), the +/// yarn and pnpm/npm linker and mirror overrides (a node-linker override +/// breaks yarn/pnpm), bundler, PDM, Poetry and Composer settings. See +/// [`hermetic::Extra`]. +const PM_EXTRAS: &[hermetic::Extra] = &[ + hermetic::Extra::Venv, + hermetic::Extra::Yarn, + hermetic::Extra::YarnClassic, + hermetic::Extra::Pnpm, + hermetic::Extra::Bundle, + hermetic::Extra::Pdm, + hermetic::Extra::Poetry, + hermetic::Extra::Composer, +]; + +/// A package-manager child (and its liveness probes) with the shared +/// hermetic scrubs: every ambient `SOCKET_*` and every [`PM_EXTRAS`] config. +/// Callers run `cache_env::isolate` next and their own env last. +fn pm_command(program: &str) -> Command { + let mut cmd = hermetic::tool_command(program); + hermetic::scrub_socket_vars(&mut cmd); + hermetic::scrub_extra(&mut cmd, PM_EXTRAS); + cmd +} + /// Run `bundle ` with the ambient `BUNDLE_*`/`GEM_*`/`RUBYOPT` state /// scrubbed first (a developer's global bundler config — frozen mode, a /// custom BUNDLE_PATH or gem home, a RUBYOPT require — must not leak into a /// leg that hard-asserts bundler outcomes; mirrors e2e_vendor_gem_build.rs). -/// The cache sandbox re-pins its own BUNDLE_USER_HOME/GEM_SPEC_CACHE after -/// the scrub, and the per-leg `env` is applied last so the leg's pins win. +/// `pm_command` sweeps `BUNDLE_*`; the gem home and `RUBYOPT` are this +/// helper's own. The cache sandbox re-pins its own +/// BUNDLE_USER_HOME/GEM_SPEC_CACHE after the scrub, and the per-leg `env` +/// is applied last so the leg's pins win. fn bundle(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output { - let mut cmd = Command::new("bundle"); + let mut cmd = pm_command("bundle"); cmd.args(args).current_dir(cwd); for (k, _) in std::env::vars_os() { let key = k.to_string_lossy().into_owned(); - if key.starts_with("BUNDLE_") || key.starts_with("GEM_") || key == "RUBYOPT" { + if key.starts_with("GEM_") || key == "RUBYOPT" { cmd.env_remove(&k); } } @@ -525,17 +553,12 @@ fn bundle(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output { /// during fixture setup) from "the install of the vendored lock failed" (always /// a hard failure — that is the thing under test). fn tool(cwd: &Path, program: &str, args: &[&str], env: &[(&str, &str)]) -> Output { - let mut cmd = Command::new(program); + let mut cmd = pm_command(program); cmd.args(args).current_dir(cwd); cache_env::isolate(&mut cmd); for (k, v) in env { cmd.env(k, v); } - // A `VIRTUAL_ENV` inherited from the developer's shell makes uv/pip install - // into the wrong interpreter; a node-linker override breaks yarn/pnpm. - cmd.env_remove("VIRTUAL_ENV"); - cmd.env_remove("YARN_NODE_LINKER"); - cmd.env_remove("npm_config_node_linker"); cmd.output() .unwrap_or_else(|e| panic!("failed to spawn `{program}`: {e}")) } @@ -543,12 +566,10 @@ fn tool(cwd: &Path, program: &str, args: &[&str], env: &[(&str, &str)]) -> Outpu /// Run `corepack ` in `cwd` with the download prompt disabled and /// the shared cache sandbox applied (per-leg `env` wins, applied last). fn corepack(cwd: &Path, pm: &str, args: &[&str], env: &[(&str, &str)]) -> Output { - let mut cmd = Command::new("corepack"); + let mut cmd = pm_command("corepack"); cmd.arg(pm).args(args).current_dir(cwd); cache_env::isolate(&mut cmd); cmd.env("COREPACK_ENABLE_DOWNLOAD_PROMPT", "0"); - cmd.env_remove("VIRTUAL_ENV"); - cmd.env_remove("YARN_NODE_LINKER"); for (k, v) in env { cmd.env(k, v); } From fe7b67d778acf7f9a02f8e711acd8e0ac7ae654f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 14 Oct 2026 12:13:36 +0000 Subject: [PATCH 3/3] Keep proxy config in production tool spawns The first version swept every YARN_*, npm_config_* and BUNDLE_* var from all package-manager children. That also removed the proxy and CA settings a developer behind a proxy needs to reach the live registries, so their install proofs would quietly soft-skip. pm_command now removes every ambient SOCKET_*, an activated venv and the two node-linker overrides, the scrubs these helpers already made, and spawns the program as before. bundle() keeps its own BUNDLE_*/GEM_*/RUBYOPT sweep unchanged. Refs #823 Assisted-by: Claude Code:claude-opus-5-5 --- .../tests/e2e_hosted_production.rs | 32 ++++++--------- .../tests/e2e_vendored_production.rs | 41 +++++++------------ 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/crates/socket-patch-cli/tests/e2e_hosted_production.rs b/crates/socket-patch-cli/tests/e2e_hosted_production.rs index 241c5d048..fbea29354 100644 --- a/crates/socket-patch-cli/tests/e2e_hosted_production.rs +++ b/crates/socket-patch-cli/tests/e2e_hosted_production.rs @@ -433,28 +433,20 @@ fn hosted_pin_count(env: &serde_json::Value) -> u64 { // Toolchain invocation // --------------------------------------------------------------------------- -/// Every ambient tool config a package-manager child must not inherit: an -/// activated venv (uv would install into the wrong interpreter), the yarn -/// and pnpm/npm linker and mirror overrides, bundler, PDM, Poetry and -/// Composer settings. See [`hermetic::Extra`]. -const PM_EXTRAS: &[hermetic::Extra] = &[ - hermetic::Extra::Venv, - hermetic::Extra::Yarn, - hermetic::Extra::YarnClassic, - hermetic::Extra::Pnpm, - hermetic::Extra::Bundle, - hermetic::Extra::Pdm, - hermetic::Extra::Poetry, - hermetic::Extra::Composer, -]; - -/// A package-manager child (and its `has_command` probe) with the shared -/// hermetic scrubs: every ambient `SOCKET_*` and every [`PM_EXTRAS`] config. -/// Callers run `cache_env::isolate` next and their own env last. +/// A package-manager child (and its liveness probe) with the shared +/// hermetic scrubs, applied before `cache_env::isolate` and the leg's own +/// env so a leg's pins (the uv legs' `VIRTUAL_ENV`) survive: every ambient +/// `SOCKET_*` ([`hermetic::scrub_socket_vars`]), an activated venv (uv +/// would install into the wrong interpreter) and the yarn/pnpm node-linker +/// overrides. Deliberately not the full `Extra::Yarn` / `Extra::Pnpm` +/// sweeps: those remove every `YARN_*` / `npm_config_*`, including the +/// proxy and CA settings these live-registry suites need behind a proxy. fn pm_command(program: &str) -> Command { - let mut cmd = hermetic::tool_command(program); + let mut cmd = Command::new(program); hermetic::scrub_socket_vars(&mut cmd); - hermetic::scrub_extra(&mut cmd, PM_EXTRAS); + hermetic::scrub_extra(&mut cmd, &[hermetic::Extra::Venv]); + cmd.env_remove("YARN_NODE_LINKER"); + cmd.env_remove("npm_config_node_linker"); cmd } diff --git a/crates/socket-patch-cli/tests/e2e_vendored_production.rs b/crates/socket-patch-cli/tests/e2e_vendored_production.rs index 5a6c08baf..a05f6d9c0 100644 --- a/crates/socket-patch-cli/tests/e2e_vendored_production.rs +++ b/crates/socket-patch-cli/tests/e2e_vendored_production.rs @@ -497,29 +497,20 @@ fn vendor_revert(cwd: &Path, leg: &str) -> u64 { // Toolchain invocation // --------------------------------------------------------------------------- -/// Every ambient tool config a package-manager child must not inherit: an -/// activated venv (uv/pip would install into the wrong interpreter), the -/// yarn and pnpm/npm linker and mirror overrides (a node-linker override -/// breaks yarn/pnpm), bundler, PDM, Poetry and Composer settings. See -/// [`hermetic::Extra`]. -const PM_EXTRAS: &[hermetic::Extra] = &[ - hermetic::Extra::Venv, - hermetic::Extra::Yarn, - hermetic::Extra::YarnClassic, - hermetic::Extra::Pnpm, - hermetic::Extra::Bundle, - hermetic::Extra::Pdm, - hermetic::Extra::Poetry, - hermetic::Extra::Composer, -]; - -/// A package-manager child (and its liveness probes) with the shared -/// hermetic scrubs: every ambient `SOCKET_*` and every [`PM_EXTRAS`] config. -/// Callers run `cache_env::isolate` next and their own env last. +/// A package-manager child (and its liveness probe) with the shared +/// hermetic scrubs, applied before `cache_env::isolate` and the leg's own +/// env so a leg's pins (the uv legs' `VIRTUAL_ENV`) survive: every ambient +/// `SOCKET_*` ([`hermetic::scrub_socket_vars`]), an activated venv (uv/pip +/// would install into the wrong interpreter) and the yarn/pnpm node-linker +/// overrides. Deliberately not the full `Extra::Yarn` / `Extra::Pnpm` +/// sweeps: those remove every `YARN_*` / `npm_config_*`, including the +/// proxy and CA settings these live-registry suites need behind a proxy. fn pm_command(program: &str) -> Command { - let mut cmd = hermetic::tool_command(program); + let mut cmd = Command::new(program); hermetic::scrub_socket_vars(&mut cmd); - hermetic::scrub_extra(&mut cmd, PM_EXTRAS); + hermetic::scrub_extra(&mut cmd, &[hermetic::Extra::Venv]); + cmd.env_remove("YARN_NODE_LINKER"); + cmd.env_remove("npm_config_node_linker"); cmd } @@ -527,16 +518,14 @@ fn pm_command(program: &str) -> Command { /// scrubbed first (a developer's global bundler config — frozen mode, a /// custom BUNDLE_PATH or gem home, a RUBYOPT require — must not leak into a /// leg that hard-asserts bundler outcomes; mirrors e2e_vendor_gem_build.rs). -/// `pm_command` sweeps `BUNDLE_*`; the gem home and `RUBYOPT` are this -/// helper's own. The cache sandbox re-pins its own -/// BUNDLE_USER_HOME/GEM_SPEC_CACHE after the scrub, and the per-leg `env` -/// is applied last so the leg's pins win. +/// The cache sandbox re-pins its own BUNDLE_USER_HOME/GEM_SPEC_CACHE after +/// the scrub, and the per-leg `env` is applied last so the leg's pins win. fn bundle(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output { let mut cmd = pm_command("bundle"); cmd.args(args).current_dir(cwd); for (k, _) in std::env::vars_os() { let key = k.to_string_lossy().into_owned(); - if key.starts_with("GEM_") || key == "RUBYOPT" { + if key.starts_with("BUNDLE_") || key.starts_with("GEM_") || key == "RUBYOPT" { cmd.env_remove(&k); } }