Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions crates/socket-patch-cli/tests/e2e_hosted_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -433,26 +433,41 @@ fn hosted_pin_count(env: &serde_json::Value) -> u64 {
// Toolchain invocation
// ---------------------------------------------------------------------------

/// 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 = Command::new(program);
hermetic::scrub_socket_vars(&mut cmd);
hermetic::scrub_extra(&mut cmd, &[hermetic::Extra::Venv]);
cmd.env_remove("YARN_NODE_LINKER");
cmd.env_remove("npm_config_node_linker");
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
// home alone.
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}"))
}
Expand Down
34 changes: 22 additions & 12 deletions crates/socket-patch-cli/tests/e2e_vendored_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -307,7 +307,7 @@ fn has_command(cmd: &str) -> bool {
/// `corepack <pm> --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);
Expand Down Expand Up @@ -497,14 +497,31 @@ fn vendor_revert(cwd: &Path, leg: &str) -> u64 {
// Toolchain invocation
// ---------------------------------------------------------------------------

/// 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 = Command::new(program);
hermetic::scrub_socket_vars(&mut cmd);
hermetic::scrub_extra(&mut cmd, &[hermetic::Extra::Venv]);
cmd.env_remove("YARN_NODE_LINKER");
cmd.env_remove("npm_config_node_linker");
cmd
}

/// Run `bundle <args>` 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.
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();
Expand All @@ -525,30 +542,23 @@ 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}"))
}

/// Run `corepack <pm> <args>` 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);
}
Expand Down
Loading