From 90c7cf22e59752e556db3a3e2cc2b4303c11b040 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:03:45 +0000 Subject: [PATCH 1/5] Start T55 #1959: tests/common helper copies Assisted-by: Claude Code:claude-opus-5-5 From ff23c599e64fc080d17bc1ed7ad5d543f5fd8aee Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:07:18 +0000 Subject: [PATCH 2/5] test(cli): assert silent-mode stderr directly The stderr_chatter filter (4 byte-identical copies) dropped API-token warning lines that these offline and cached runs never print, so the emptiness checks now assert on the whole stderr and the presence checks read it directly. Assisted-by: Claude Code:claude-opus-5-5 --- .../apply/apply_silent_staging_errors.rs | 28 ++------------ .../tests/cli_apply_silent.rs | 38 ++++--------------- .../socket-patch-cli/tests/cli_scan_silent.rs | 35 +++-------------- .../tests/vendor/vendor_silent_errors.rs | 26 +++---------- 4 files changed, 22 insertions(+), 105 deletions(-) diff --git a/crates/socket-patch-cli/tests/apply/apply_silent_staging_errors.rs b/crates/socket-patch-cli/tests/apply/apply_silent_staging_errors.rs index e08a1c0b5..f8e2a5b6e 100644 --- a/crates/socket-patch-cli/tests/apply/apply_silent_staging_errors.rs +++ b/crates/socket-patch-cli/tests/apply/apply_silent_staging_errors.rs @@ -24,21 +24,6 @@ use crate::apply_fixture::{run_apply, write_sourceless_npm_patches}; use crate::common::envelope::{codes_in, json_string, parse_json_envelope}; -/// Non-error stderr lines: drop the unconditional core API-token warning -/// (both its lead line and its "Got: ... Continuing anyway" continuation) -/// and blank lines, keep everything else. -fn stderr_chatter(stderr: &str) -> Vec { - stderr - .lines() - .filter(|l| { - !l.contains("SOCKET_API_TOKEN") - && !l.contains("Continuing anyway") - && !l.trim().is_empty() - }) - .map(|l| l.to_string()) - .collect() -} - /// A guaranteed-unreachable local endpoint: bind an ephemeral port, then /// release it, so every request fails fast with connection-refused. fn dead_endpoint() -> String { @@ -65,9 +50,8 @@ fn apply_silent_offline_missing_source_keeps_error_output() { stdout.trim().is_empty(), "silent human mode writes errors to stderr, not stdout: {stdout}" ); - let chatter = stderr_chatter(&stderr); assert!( - chatter.iter().any(|l| l.contains("no local source")), + stderr.contains("no local source"), "--silent must keep the offline no-source error (errors only, \ never nothing); stderr was: {stderr:?}" ); @@ -102,16 +86,13 @@ fn apply_silent_online_download_failure_keeps_error_output() { stdout.trim().is_empty(), "silent human mode writes errors to stderr, not stdout: {stdout}" ); - let chatter = stderr_chatter(&stderr); assert!( - chatter - .iter() - .any(|l| l.contains("could not be downloaded")), + stderr.contains("could not be downloaded"), "--silent must keep the download-failure error (errors only, \ never nothing); stderr was: {stderr:?}" ); assert!( - chatter.iter().any(|l| l.contains("Failed to download")), + stderr.contains("Failed to download"), "--silent must keep the per-blob failure reasons with the error; \ stderr was: {stderr:?}" ); @@ -155,9 +136,8 @@ fn apply_json_offline_missing_source_keeps_stderr_clean() { 0, "the bail must not stage anything into .socket/blobs" ); - let chatter = stderr_chatter(&stderr); assert!( - chatter.is_empty(), + stderr.is_empty(), "--json suppresses the staging diagnostics on stderr (the \ envelope is the machine channel); stderr was: {stderr:?}" ); diff --git a/crates/socket-patch-cli/tests/cli_apply_silent.rs b/crates/socket-patch-cli/tests/cli_apply_silent.rs index 0a3b1bfe1..a3c9d3e76 100644 --- a/crates/socket-patch-cli/tests/cli_apply_silent.rs +++ b/crates/socket-patch-cli/tests/cli_apply_silent.rs @@ -15,14 +15,10 @@ //! 4. `apply --check --silent` with real redirect drift exited 1 with zero //! output (the OUT OF SYNC report was muted). //! -//! Stderr assertions ignore the "No SOCKET_API_TOKEN set" client warning: -//! it's printed by `get_api_client_with_overrides` in core when an ONLINE -//! command builds its API client (offline runs suppress it) and is out of -//! scope for `apply`'s `--silent` gating. `apply` builds that client only -//! when it has something to download — see -//! `apply_prints_the_public_proxy_notice_only_when_it_fetches` — so the -//! no-manifest hook path, `--check` and a fully cached apply never print -//! it at all. +//! The core client's "No SOCKET_API_TOKEN set" notice is printed only when +//! an online `apply` builds its API client to download something (see +//! `apply_prints_the_public_proxy_notice_only_when_it_fetches`), so the +//! offline, `--check` and cached runs here never print it. #[path = "common/mod.rs"] mod common; @@ -44,21 +40,6 @@ fn run_apply(cwd: &Path, args: &[&str]) -> (i32, String, String) { ) } -/// Non-error stderr lines: drop the unconditional core API-token warning -/// (both its lead line and its "Got: ... Continuing anyway" continuation) -/// and blank lines, keep everything else. -fn stderr_chatter(stderr: &str) -> Vec { - stderr - .lines() - .filter(|l| { - !l.contains("SOCKET_API_TOKEN") - && !l.contains("Continuing anyway") - && !l.trim().is_empty() - }) - .map(|l| l.to_string()) - .collect() -} - fn write_corrupt_manifest(root: &Path) { let socket = root.join(".socket"); std::fs::create_dir_all(&socket).unwrap(); @@ -176,9 +157,8 @@ fn apply_silent_unreadable_manifest_keeps_error_output() { stdout.trim().is_empty(), "silent human mode writes errors to stderr, not stdout: {stdout}" ); - let chatter = stderr_chatter(&stderr); assert!( - chatter.iter().any(|l| l.contains("Error")), + stderr.contains("Error"), "--silent must keep the error output (errors only, never nothing); \ stderr was: {stderr:?}" ); @@ -193,11 +173,8 @@ fn apply_check_silent_unreadable_manifest_keeps_error_output() { let (code, _stdout, stderr) = run_apply(tmp.path(), &["--check", "--silent"]); assert_eq!(code, 1, "unreadable manifest must fail closed: {stderr}"); - let chatter = stderr_chatter(&stderr); assert!( - chatter - .iter() - .any(|l| l.contains("could not read the manifest")), + stderr.contains("could not read the manifest"), "--check --silent must keep the fail-closed error output; \ stderr was: {stderr:?}" ); @@ -233,9 +210,8 @@ fn apply_check_silent_drift_keeps_error_output() { code, 1, "missing go-patches copy must report drift: {stderr}" ); - let chatter = stderr_chatter(&stderr); assert!( - chatter.iter().any(|l| l.contains("OUT OF SYNC")), + stderr.contains("OUT OF SYNC"), "--check --silent must keep the drift error output; stderr was: {stderr:?}" ); } diff --git a/crates/socket-patch-cli/tests/cli_scan_silent.rs b/crates/socket-patch-cli/tests/cli_scan_silent.rs index f0cc91009..32ada3760 100644 --- a/crates/socket-patch-cli/tests/cli_scan_silent.rs +++ b/crates/socket-patch-cli/tests/cli_scan_silent.rs @@ -9,11 +9,6 @@ //! The apply-flow test runs against a wiremock API (same fixture shape //! as `scan_sync_e2e.rs`) so the full human-mode scan→select→download→ //! apply pipeline is exercised without the network. -//! -//! Stderr assertions ignore the "No SOCKET_API_TOKEN set" client -//! warning: it's printed unconditionally by -//! `get_api_client_with_overrides` in core for every command and is -//! out of scope for `scan`'s `--silent` gating. #[path = "common/mod.rs"] mod common; @@ -63,21 +58,6 @@ fn run_scan(cwd: &Path, args: &[&str]) -> (i32, String, String) { ) } -/// Non-error stderr lines: drop the unconditional core API-token warning -/// (both its lead line and its "Got: ... Continuing anyway" continuation) -/// and blank lines, keep everything else. -fn stderr_chatter(stderr: &str) -> Vec { - stderr - .lines() - .filter(|l| { - !l.contains("SOCKET_API_TOKEN") - && !l.contains("Continuing anyway") - && !l.trim().is_empty() - }) - .map(|l| l.to_string()) - .collect() -} - /// Mount the three endpoints the human-mode apply flow hits: batch /// discovery, per-package search, and the full patch view (inline blob). /// Fixture shape mirrors `scan_sync_e2e.rs`. @@ -171,10 +151,9 @@ fn scan_silent_no_packages_produces_no_output() { stdout.trim().is_empty(), "--silent must produce no stdout; got {stdout:?}" ); - let chatter = stderr_chatter(&stderr); assert!( - chatter.is_empty(), - "--silent must produce no stderr chatter on success; got {chatter:?}" + stderr.is_empty(), + "--silent must produce no stderr chatter on success; got {stderr:?}" ); // Control run: the same scenario WITHOUT --silent must print the @@ -228,10 +207,9 @@ async fn scan_silent_apply_flow_produces_no_output_but_still_applies() { stdout.trim().is_empty(), "--silent must produce no stdout; got {stdout:?}" ); - let chatter = stderr_chatter(&stderr); assert!( - chatter.is_empty(), - "--silent must produce no stderr chatter on success; got {chatter:?}" + stderr.is_empty(), + "--silent must produce no stderr chatter on success; got {stderr:?}" ); // Silent suppresses output, not the mutation: the patch must have @@ -392,10 +370,9 @@ async fn scan_vendor_silent_gc_prints_nothing() { "--silent must produce no stdout (regression: the vendor path's \ GC line printed unconditionally); got {stdout:?}" ); - let chatter = stderr_chatter(&stderr); assert!( - chatter.is_empty(), - "--silent must produce no stderr chatter on success; got {chatter:?}" + stderr.is_empty(), + "--silent must produce no stderr chatter on success; got {stderr:?}" ); // Silent suppresses output, not the work: the prune and the vendoring diff --git a/crates/socket-patch-cli/tests/vendor/vendor_silent_errors.rs b/crates/socket-patch-cli/tests/vendor/vendor_silent_errors.rs index e15a6187d..c9e4e0250 100644 --- a/crates/socket-patch-cli/tests/vendor/vendor_silent_errors.rs +++ b/crates/socket-patch-cli/tests/vendor/vendor_silent_errors.rs @@ -22,25 +22,10 @@ use crate::common::envelope::{find_event, parse_json_envelope}; use crate::common::hermetic; use crate::npm_fixture::{dead_endpoint, patch_record, PURL, REG_RESOLVED}; -/// Non-error stderr lines: drop the unconditional core API-token warning -/// (both its lead line and its "Got: ... Continuing anyway" continuation) -/// and blank lines, keep everything else. -fn stderr_chatter(stderr: &str) -> Vec { +/// Whether some stderr line is the per-patch error for [`PURL`]. +fn has_patch_error_line(stderr: &str) -> bool { stderr .lines() - .filter(|l| { - !l.contains("SOCKET_API_TOKEN") - && !l.contains("Continuing anyway") - && !l.trim().is_empty() - }) - .map(|l| l.to_string()) - .collect() -} - -/// Whether some stderr line is the per-patch error for [`PURL`]. -fn has_patch_error_line(chatter: &[String]) -> bool { - chatter - .iter() .any(|l| l.starts_with("Error:") && l.contains(PURL)) } @@ -132,7 +117,7 @@ fn vendor_silent_offline_missing_source_keeps_error_output() { "silent human mode writes errors to stderr, not stdout: {stdout}" ); assert!( - has_patch_error_line(&stderr_chatter(&stderr)), + has_patch_error_line(&stderr), "--silent must keep the per-patch error line (errors only, never \ nothing); stderr was: {stderr:?}" ); @@ -152,7 +137,7 @@ fn vendor_silent_online_fetch_failure_keeps_error_output() { "silent human mode writes errors to stderr, not stdout: {stdout}" ); assert!( - has_patch_error_line(&stderr_chatter(&stderr)), + has_patch_error_line(&stderr), "--silent must keep the per-patch error line (errors only, never \ nothing); stderr was: {stderr:?}" ); @@ -171,9 +156,8 @@ fn vendor_json_online_fetch_failure_keeps_stderr_clean() { let v = parse_json_envelope(&stdout); let failed = find_event(&v, "failed", Some("apply_failed")); assert_eq!(failed["purl"], PURL, "{v}"); - let chatter = stderr_chatter(&stderr); assert!( - chatter.is_empty(), + stderr.is_empty(), "--json keeps the error lines off stderr (the envelope is the \ machine channel); stderr was: {stderr:?}" ); From 85be0a0ba9dd5604cdaca4a8fac7db10289d2182 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:07:19 +0000 Subject: [PATCH 3/5] test(cli): call tests/common helpers, not copies Delete local copies identical to tests/common's: has_command in six suites, git_sha256_file in four, sha256_hex in nine, and the yarn suites' second include of common/cache_env.rs. Delete the unused common::{env_map, npm_run} and update_fixture's raw_asset and delay_asset. Assisted-by: Claude Code:claude-opus-5-5 --- crates/socket-patch-cli/tests/common/mod.rs | 19 ++--------------- .../tests/common/update_fixture.rs | 21 +------------------ crates/socket-patch-cli/tests/e2e_gem.rs | 18 +--------------- crates/socket-patch-cli/tests/e2e_npm.rs | 18 +--------------- crates/socket-patch-cli/tests/e2e_pypi.rs | 7 +------ .../tests/e2e_redirect_cargo_build.rs | 6 +----- .../tests/e2e_redirect_yarn_berry_build.rs | 15 +------------ crates/socket-patch-cli/tests/e2e_scan.rs | 18 +--------------- .../tests/e2e_vex_lockfile/maven.rs | 6 +----- .../tests/e2e_vex_lockfile/nuget.rs | 6 +----- .../tests/e2e_vex_lockfile/poetry.rs | 5 +---- .../tests/e2e_vex_lockfile/uv.rs | 5 +---- .../socket-patch-cli/tests/e2e_vex_vendor.rs | 8 +------ .../tests/e2e_yarn4_pnpm_linker_build.rs | 16 +------------- .../tests/e2e_yarn4_workspaces_build.rs | 16 +------------- .../tests/mode_migration_cargo.rs | 6 +----- .../tests/repair/repair_vendor_e2e.rs | 6 +----- .../tests/vlt_e2e_common/mod.rs | 6 +----- 18 files changed, 19 insertions(+), 183 deletions(-) diff --git a/crates/socket-patch-cli/tests/common/mod.rs b/crates/socket-patch-cli/tests/common/mod.rs index d6b49d4c6..89f7ed406 100644 --- a/crates/socket-patch-cli/tests/common/mod.rs +++ b/crates/socket-patch-cli/tests/common/mod.rs @@ -13,7 +13,6 @@ #![allow(dead_code)] -use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; @@ -155,13 +154,8 @@ pub fn sha256_hex(content: &[u8]) -> String { // ── Toolchain runners ───────────────────────────────────────────────── -/// Run `npm` in `cwd`, panic on non-zero exit with full output. -pub fn npm_run(cwd: &Path, args: &[&str]) { - run_toolchain(cwd, "npm", args, &[]); -} - -/// Run `pnpm` in `cwd`. Same shape as `npm_run`; `extra_env` lets -/// the caller force store-dir overrides etc. +/// Run `pnpm` in `cwd`, panicking on a non-zero exit with full output; +/// `extra_env` lets the caller force store-dir overrides etc. pub fn pnpm_run(cwd: &Path, args: &[&str], extra_env: &[(&str, &str)]) { run_toolchain(cwd, "pnpm", args, extra_env); } @@ -425,12 +419,3 @@ pub fn write_blob(socket_dir: &Path, hash: &str, content: &[u8]) { std::fs::create_dir_all(&blobs).expect("create .socket/blobs"); std::fs::write(blobs.join(hash), content).expect("write blob"); } - -/// Map a slice of `(env-var-name, env-var-value)` tuples into a -/// HashMap for callers that want a stable container. -pub fn env_map(pairs: &[(&str, &str)]) -> HashMap { - pairs - .iter() - .map(|(k, v)| ((*k).to_string(), (*v).to_string())) - .collect() -} diff --git a/crates/socket-patch-cli/tests/common/update_fixture.rs b/crates/socket-patch-cli/tests/common/update_fixture.rs index 314a66cd8..d0898426a 100644 --- a/crates/socket-patch-cli/tests/common/update_fixture.rs +++ b/crates/socket-patch-cli/tests/common/update_fixture.rs @@ -334,7 +334,6 @@ pub struct FakeReleaseBuilder { omit_assets: Vec, truncate: Vec<(String, usize)>, metadata_delay: Option, - asset_delay: Option, expect_resolves: Option, expect_sums: Option, expect_asset_downloads: Option, @@ -357,13 +356,6 @@ impl FakeReleaseBuilder { self } - /// Add a raw pre-built asset (exotic shapes: garbage archives, other - /// targets). - pub fn raw_asset(mut self, filename: &str, bytes: Vec) -> Self { - self.assets.push((filename.to_string(), bytes)); - self - } - /// Flip a nibble in this asset's SHA256SUMS entry. pub fn corrupt_sums_entry_for(mut self, filename: &str) -> Self { self.corrupt_sums_for.push(filename.to_string()); @@ -400,11 +392,6 @@ impl FakeReleaseBuilder { self } - pub fn delay_asset(mut self, d: Duration) -> Self { - self.asset_delay = Some(d); - self - } - /// Pin exact hit counts (verified when the MockServer drops). pub fn expect_resolves(mut self, n: u64) -> Self { self.expect_resolves = Some(n); @@ -527,13 +514,7 @@ impl FakeReleaseBuilder { .and(urlpath(format!( "/SocketDev/socket-patch/releases/download/v{ver}/{name}" ))) - .respond_with({ - let mut resp = ResponseTemplate::new(200).set_body_bytes(body); - if let Some(d) = self.asset_delay { - resp = resp.set_delay(d); - } - resp - }); + .respond_with(ResponseTemplate::new(200).set_body_bytes(body)); if let Some(n) = self.expect_asset_downloads { asset_mock = asset_mock.expect(n); } diff --git a/crates/socket-patch-cli/tests/e2e_gem.rs b/crates/socket-patch-cli/tests/e2e_gem.rs index 3b6560f76..cfbf3206c 100644 --- a/crates/socket-patch-cli/tests/e2e_gem.rs +++ b/crates/socket-patch-cli/tests/e2e_gem.rs @@ -20,7 +20,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, git_sha256, hermetic}; +use common::{binary, git_sha256, git_sha256_file, has_command, hermetic}; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; @@ -44,22 +44,6 @@ const GEM_PURL: &str = "pkg:gem/activestorage@5.2.0?platform=ruby"; // Helpers // --------------------------------------------------------------------------- -fn has_command(cmd: &str) -> bool { - let mut probe = Command::new(cmd); - probe.arg("--version"); - cache_env::isolate(&mut probe); - probe - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) - .status() - .is_ok() -} - -fn git_sha256_file(path: &Path) -> String { - let content = std::fs::read(path).unwrap_or_else(|e| panic!("read {}: {e}", path.display())); - git_sha256(&content) -} - /// Run the binary with the hermetic `SOCKET_*` environment (no token, so the /// scans take the public-proxy path `--proxy-url` pins). The gem crawler /// reads `BUNDLE_PATH`, `BUNDLE_APP_CONFIG`, the user's `~/.bundle/config` diff --git a/crates/socket-patch-cli/tests/e2e_npm.rs b/crates/socket-patch-cli/tests/e2e_npm.rs index 3a7dce516..e345e9f1a 100644 --- a/crates/socket-patch-cli/tests/e2e_npm.rs +++ b/crates/socket-patch-cli/tests/e2e_npm.rs @@ -15,7 +15,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, git_sha256, hermetic}; +use common::{binary, git_sha256, git_sha256_file, has_command, hermetic}; use std::path::Path; use std::process::{Command, Output}; @@ -39,22 +39,6 @@ const AFTER_HASH: &str = "ec956dcafb886f14315570bf3981d44aa12c561716abb46eed8b06 // Helpers // --------------------------------------------------------------------------- -fn has_command(cmd: &str) -> bool { - let mut probe = Command::new(cmd); - probe.arg("--version"); - cache_env::isolate(&mut probe); - probe - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) - .status() - .is_ok() -} - -fn git_sha256_file(path: &Path) -> String { - let content = std::fs::read(path).unwrap_or_else(|e| panic!("read {}: {e}", path.display())); - git_sha256(&content) -} - /// Run the CLI binary with the given args, setting `cwd` as the working dir. /// Returns `(exit_code, stdout, stderr)`. fn run(cwd: &Path, args: &[&str]) -> (i32, String, String) { diff --git a/crates/socket-patch-cli/tests/e2e_pypi.rs b/crates/socket-patch-cli/tests/e2e_pypi.rs index c4646b4c2..bd9d0c3d2 100644 --- a/crates/socket-patch-cli/tests/e2e_pypi.rs +++ b/crates/socket-patch-cli/tests/e2e_pypi.rs @@ -15,7 +15,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, git_sha256, hermetic}; +use common::{binary, git_sha256, git_sha256_file, hermetic}; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; @@ -43,11 +43,6 @@ fn has_python3() -> bool { .unwrap_or(false) } -fn git_sha256_file(path: &Path) -> String { - let content = std::fs::read(path).unwrap_or_else(|e| panic!("read {}: {e}", path.display())); - git_sha256(&content) -} - /// Run the CLI binary with the given args, setting `cwd` as the working dir. /// /// The child gets the hermetic `SOCKET_*` environment, which forces the diff --git a/crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs b/crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs index bb2b8f514..9af225d25 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs @@ -68,7 +68,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, hermetic, hermetic_command}; +use common::{binary, hermetic, hermetic_command, sha256_hex}; use std::path::{Path, PathBuf}; use std::process::Output; @@ -132,10 +132,6 @@ fn cargo(cwd: &Path, args: &[&str], cargo_home: &Path) -> Output { .expect("failed to run cargo") } -fn sha256_hex(bytes: &[u8]) -> String { - hex::encode(Sha256::digest(bytes)) -} - /// The locked version of `name` in Cargo.lock (first `[[package]]` match). fn locked_version(lock_text: &str, name: &str) -> Option { let needle = format!("name = \"{name}\""); diff --git a/crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs b/crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs index 7f9b6066f..b4e122117 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs @@ -47,7 +47,7 @@ #[path = "common/mod.rs"] mod common; -use common::hermetic; +use common::{cache_env, has_command, hermetic}; use std::path::{Path, PathBuf}; use std::process::{Command, Output, Stdio}; @@ -56,8 +56,6 @@ use socket_patch_core::hash::git_sha256::compute_git_sha256_from_bytes; use wiremock::matchers::{method, path, path_regex}; use wiremock::{Mock, MockServer, ResponseTemplate}; -#[path = "common/cache_env.rs"] -mod cache_env; const ORG: &str = "test-org"; const DEP: &str = "left-pad"; @@ -115,17 +113,6 @@ fn has_corepack_pm(pm: &str) -> bool { .unwrap_or(false) } -fn has_command(cmd: &str) -> bool { - let mut probe = Command::new(cmd); - probe.arg("--version"); - cache_env::isolate(&mut probe); - probe - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status() - .is_ok() -} - fn corepack(cwd: &Path, pm: &str, args: &[&str], extra_env: &[(&str, &str)]) -> Output { let mut cmd = yarn_berry_common::corepack_command(); cmd.arg(pm).args(args).current_dir(cwd); diff --git a/crates/socket-patch-cli/tests/e2e_scan.rs b/crates/socket-patch-cli/tests/e2e_scan.rs index c1a64d548..91e916105 100644 --- a/crates/socket-patch-cli/tests/e2e_scan.rs +++ b/crates/socket-patch-cli/tests/e2e_scan.rs @@ -29,7 +29,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, git_sha256, hermetic}; +use common::{binary, git_sha256, git_sha256_file, has_command, hermetic}; use std::path::Path; use std::process::{Command, Output}; @@ -63,17 +63,6 @@ const FAKE_OLD_UUID: &str = "11111111-1111-4111-8111-111111111111"; // Helpers // --------------------------------------------------------------------------- -fn has_command(cmd: &str) -> bool { - let mut probe = Command::new(cmd); - probe.arg("--version"); - cache_env::isolate(&mut probe); - probe - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) - .status() - .is_ok() -} - /// These e2e tests are `#[ignore]`d and only execute when explicitly /// requested (`--ignored`) — at which point npm is a hard prerequisite, not /// an optional one. A silent `return` on missing npm would let the entire @@ -87,11 +76,6 @@ fn require_npm() { ); } -fn git_sha256_file(path: &Path) -> String { - let content = std::fs::read(path).unwrap_or_else(|e| panic!("read {}: {e}", path.display())); - git_sha256(&content) -} - fn run(cwd: &Path, args: &[&str]) -> (i32, String, String) { // The shared builder scrubs every ambient `SOCKET_*` (an ambient // SOCKET_DRY_RUN would turn every `scan --mode agent` into a preview, diff --git a/crates/socket-patch-cli/tests/e2e_vex_lockfile/maven.rs b/crates/socket-patch-cli/tests/e2e_vex_lockfile/maven.rs index 1ac5cb196..c762a6f1e 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_lockfile/maven.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_lockfile/maven.rs @@ -44,6 +44,7 @@ #[path = "../prebuilt_common/mod.rs"] mod prebuilt_common; +use crate::common::sha256_hex; use crate::vex_e2e_common; use std::collections::HashMap; @@ -407,11 +408,6 @@ fn write_vendor_ledger( ); } -fn sha256_hex(bytes: &[u8]) -> String { - use sha2::{Digest, Sha256}; - hex::encode(Sha256::digest(bytes)) -} - /// A zip-family artifact (`.jar` / `.nupkg`) holding `members`. fn zip_bytes(members: &[(&str, &[u8])]) -> Vec { use std::io::Write as _; diff --git a/crates/socket-patch-cli/tests/e2e_vex_lockfile/nuget.rs b/crates/socket-patch-cli/tests/e2e_vex_lockfile/nuget.rs index 31ccc5736..a3a983539 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_lockfile/nuget.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_lockfile/nuget.rs @@ -40,6 +40,7 @@ #[path = "../prebuilt_common/mod.rs"] mod prebuilt_common; +use crate::common::sha256_hex; use crate::vex_e2e_common; use std::collections::HashMap; @@ -388,11 +389,6 @@ fn write_vendor_ledger( ); } -fn sha256_hex(bytes: &[u8]) -> String { - use sha2::{Digest, Sha256}; - hex::encode(Sha256::digest(bytes)) -} - /// A zip-family artifact (`.nupkg`) holding `members`. fn zip_bytes(members: &[(&str, &[u8])]) -> Vec { use std::io::Write as _; diff --git a/crates/socket-patch-cli/tests/e2e_vex_lockfile/poetry.rs b/crates/socket-patch-cli/tests/e2e_vex_lockfile/poetry.rs index 77c0f2fc4..90bbb4a64 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_lockfile/poetry.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_lockfile/poetry.rs @@ -38,6 +38,7 @@ //! installed pristine → `not_applied`; a pin-less entry needs an //! installed tree. +use crate::common::sha256_hex; use crate::vex_e2e_common; use std::collections::HashMap; @@ -87,10 +88,6 @@ fn api_purl() -> String { format!("pkg:pypi/{PKG}@{VER}?artifact_id=py2-py3-none-any-whl") } -fn sha256_hex(bytes: &[u8]) -> String { - hex::encode(Sha256::digest(bytes)) -} - // ── the committed Poetry locks ────────────────────────────────────────── /// Every committed Poetry fixture, oldest first: lock format "0" (0.12), diff --git a/crates/socket-patch-cli/tests/e2e_vex_lockfile/uv.rs b/crates/socket-patch-cli/tests/e2e_vex_lockfile/uv.rs index 148cc8ad3..fec6fd71d 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_lockfile/uv.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_lockfile/uv.rs @@ -39,6 +39,7 @@ //! Plus the embedded entry points (`scan --mode hosted --vex`, `scan --mode vendored //! --vex`, `apply --vex`). +use crate::common::sha256_hex; use crate::vex_e2e_common; use std::collections::HashMap; @@ -79,10 +80,6 @@ const ORG: &str = "test-org"; /// The PEP 723 script a script lock belongs to. const SCRIPT: &str = "tool.py"; -fn sha256_hex(bytes: &[u8]) -> String { - hex::encode(Sha256::digest(bytes)) -} - fn base_purl(version: &str) -> String { format!("pkg:pypi/{PKG}@{version}") } diff --git a/crates/socket-patch-cli/tests/e2e_vex_vendor.rs b/crates/socket-patch-cli/tests/e2e_vex_vendor.rs index a916c263c..0efc064f9 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_vendor.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_vendor.rs @@ -41,6 +41,7 @@ const UUID: &str = "9f6b2c4e-1d3a-4f6b-8c2d-7e5a9b1c3d5f"; #[path = "common/mod.rs"] mod common; +use common::sha256_hex; /// CLI invocation through the shared hermetic builder (same rationale as /// `e2e_vex.rs`: explicit flags must be the sole source of truth). @@ -735,13 +736,6 @@ fn tampered_detached_artifact_omitted() { // 6. cross-ecosystem matrix — every vendor-backend ecosystem attests // ────────────────────────────────────────────────────────────────────── -/// Plain sha256 hex of `bytes` — the ledger's whole-file hash for -/// file-shaped artifacts (tarballs / wheels / nupkgs / jars). -fn sha256_hex(bytes: &[u8]) -> String { - use sha2::{Digest, Sha256}; - hex::encode(Sha256::digest(bytes)) -} - /// Write a single-member `.tgz` (the npm artifact shape) at `dest` and /// return its bytes for the ledger sha256. fn write_member_tgz(dest: &Path, member: &str, bytes: &[u8]) -> Vec { diff --git a/crates/socket-patch-cli/tests/e2e_yarn4_pnpm_linker_build.rs b/crates/socket-patch-cli/tests/e2e_yarn4_pnpm_linker_build.rs index 5c0c9ff2d..557805c50 100644 --- a/crates/socket-patch-cli/tests/e2e_yarn4_pnpm_linker_build.rs +++ b/crates/socket-patch-cli/tests/e2e_yarn4_pnpm_linker_build.rs @@ -42,8 +42,7 @@ #[path = "common/mod.rs"] mod common; -use common::git_sha256; -use common::hermetic; +use common::{cache_env, git_sha256, has_command, hermetic}; use std::path::{Path, PathBuf}; use std::process::{Command, Output, Stdio}; @@ -52,8 +51,6 @@ use socket_patch_core::hash::git_sha256::compute_git_sha256_from_bytes; use wiremock::matchers::{method, path, path_regex}; use wiremock::{Mock, MockServer, ResponseTemplate}; -#[path = "common/cache_env.rs"] -mod cache_env; #[path = "prebuilt_common/mod.rs"] mod prebuilt_common; @@ -110,17 +107,6 @@ fn has_corepack_pm(pm: &str) -> bool { .unwrap_or(false) } -fn has_command(cmd: &str) -> bool { - let mut probe = Command::new(cmd); - probe.arg("--version"); - cache_env::isolate(&mut probe); - probe - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status() - .is_ok() -} - fn corepack(cwd: &Path, pm: &str, args: &[&str], extra_env: &[(&str, &str)]) -> Output { let mut cmd = yarn_berry_common::corepack_command(); cmd.arg(pm).args(args).current_dir(cwd); diff --git a/crates/socket-patch-cli/tests/e2e_yarn4_workspaces_build.rs b/crates/socket-patch-cli/tests/e2e_yarn4_workspaces_build.rs index 6a697341f..af9731cd0 100644 --- a/crates/socket-patch-cli/tests/e2e_yarn4_workspaces_build.rs +++ b/crates/socket-patch-cli/tests/e2e_yarn4_workspaces_build.rs @@ -44,8 +44,7 @@ #[path = "common/mod.rs"] mod common; -use common::git_sha256; -use common::hermetic; +use common::{cache_env, git_sha256, has_command, hermetic}; use std::path::{Path, PathBuf}; use std::process::{Command, Output, Stdio}; @@ -54,8 +53,6 @@ use socket_patch_core::hash::git_sha256::compute_git_sha256_from_bytes; use wiremock::matchers::{method, path, path_regex}; use wiremock::{Mock, MockServer, ResponseTemplate}; -#[path = "common/cache_env.rs"] -mod cache_env; #[path = "prebuilt_common/mod.rs"] mod prebuilt_common; @@ -110,17 +107,6 @@ fn has_corepack_pm(pm: &str) -> bool { .unwrap_or(false) } -fn has_command(cmd: &str) -> bool { - let mut probe = Command::new(cmd); - probe.arg("--version"); - cache_env::isolate(&mut probe); - probe - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status() - .is_ok() -} - fn corepack(cwd: &Path, pm: &str, args: &[&str], extra_env: &[(&str, &str)]) -> Output { let mut cmd = yarn_berry_common::corepack_command(); cmd.arg(pm).args(args).current_dir(cwd); diff --git a/crates/socket-patch-cli/tests/mode_migration_cargo.rs b/crates/socket-patch-cli/tests/mode_migration_cargo.rs index f0875d2e0..29c2ccd51 100644 --- a/crates/socket-patch-cli/tests/mode_migration_cargo.rs +++ b/crates/socket-patch-cli/tests/mode_migration_cargo.rs @@ -40,7 +40,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, git_sha256}; +use common::{binary, git_sha256, sha256_hex}; #[path = "prebuilt_common/mod.rs"] mod prebuilt_common; @@ -125,10 +125,6 @@ fn assert_build_ok(tag: &str, out: &Output) { ); } -fn sha256_hex(bytes: &[u8]) -> String { - hex::encode(Sha256::digest(bytes)) -} - fn stage_patch(proj: &Path, purl: &str, before: &[u8], after: &[u8]) { let socket = proj.join(".socket"); std::fs::create_dir_all(socket.join("blobs")).unwrap(); diff --git a/crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs b/crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs index da29a8212..114d57780 100644 --- a/crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs +++ b/crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs @@ -10,7 +10,7 @@ //! byte-for-byte on real `bundle lock` output (bundler 4.0.15). use crate::common::envelope::{events, parse_json_envelope}; -use crate::common::{binary, git_sha256}; +use crate::common::{binary, git_sha256, sha256_hex}; use std::path::{Path, PathBuf}; @@ -29,10 +29,6 @@ const BEFORE: &[u8] = b"before\n"; const AFTER: &[u8] = b"after\n"; const AFTER_B64: &str = "YWZ0ZXIK"; -fn sha256_hex(bytes: &[u8]) -> String { - hex::encode(Sha256::digest(bytes)) -} - fn sri_of(bytes: &[u8]) -> String { use base64::Engine as _; use sha2::Sha512; diff --git a/crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs b/crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs index fc6f87c58..73a8287a2 100644 --- a/crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs +++ b/crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs @@ -1276,13 +1276,9 @@ pub fn sha512_sri(bytes: &[u8]) -> String { ) } -pub fn sha256_hex(bytes: &[u8]) -> String { - hex::encode(Sha256::digest(bytes)) -} - // Not every includer uses it. #[allow(unused_imports)] -pub use common::git_sha256; +pub use common::{git_sha256, sha256_hex}; /// A dir vlt (rc.14) renames an old tree to and deletes in the background. pub fn is_vlt_delete_staging(name: &std::ffi::OsStr) -> bool { From 727c1b1743c49a8a64a5b248ae83f4fcd54b61c2 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:15:54 +0000 Subject: [PATCH 4/5] test(cli): drop imports left unused by the dedup Assisted-by: Claude Code:claude-opus-5-5 --- crates/socket-patch-cli/tests/e2e_npm.rs | 2 +- crates/socket-patch-cli/tests/e2e_pypi.rs | 2 +- crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs | 1 - crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs | 1 - crates/socket-patch-cli/tests/e2e_scan.rs | 2 +- crates/socket-patch-cli/tests/mode_migration_cargo.rs | 2 +- crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs | 2 +- crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs | 2 +- 8 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/socket-patch-cli/tests/e2e_npm.rs b/crates/socket-patch-cli/tests/e2e_npm.rs index e345e9f1a..622a583bc 100644 --- a/crates/socket-patch-cli/tests/e2e_npm.rs +++ b/crates/socket-patch-cli/tests/e2e_npm.rs @@ -15,7 +15,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, git_sha256, git_sha256_file, has_command, hermetic}; +use common::{binary, git_sha256_file, has_command, hermetic}; use std::path::Path; use std::process::{Command, Output}; diff --git a/crates/socket-patch-cli/tests/e2e_pypi.rs b/crates/socket-patch-cli/tests/e2e_pypi.rs index bd9d0c3d2..1cc36868d 100644 --- a/crates/socket-patch-cli/tests/e2e_pypi.rs +++ b/crates/socket-patch-cli/tests/e2e_pypi.rs @@ -15,7 +15,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, git_sha256, git_sha256_file, hermetic}; +use common::{binary, git_sha256_file, hermetic}; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; diff --git a/crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs b/crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs index 9af225d25..a3c7a8cd7 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_cargo_build.rs @@ -73,7 +73,6 @@ use common::{binary, hermetic, hermetic_command, sha256_hex}; use std::path::{Path, PathBuf}; use std::process::Output; -use sha2::{Digest, Sha256}; use socket_patch_core::hash::git_sha256::compute_git_sha256_from_bytes; use wiremock::matchers::{method, path, path_regex}; use wiremock::{Mock, MockServer, ResponseTemplate}; diff --git a/crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs b/crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs index b4e122117..aa4db5b4b 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_yarn_berry_build.rs @@ -56,7 +56,6 @@ use socket_patch_core::hash::git_sha256::compute_git_sha256_from_bytes; use wiremock::matchers::{method, path, path_regex}; use wiremock::{Mock, MockServer, ResponseTemplate}; - const ORG: &str = "test-org"; const DEP: &str = "left-pad"; const DEP_VERSION: &str = "1.3.0"; diff --git a/crates/socket-patch-cli/tests/e2e_scan.rs b/crates/socket-patch-cli/tests/e2e_scan.rs index 91e916105..f1fade693 100644 --- a/crates/socket-patch-cli/tests/e2e_scan.rs +++ b/crates/socket-patch-cli/tests/e2e_scan.rs @@ -29,7 +29,7 @@ #[path = "common/mod.rs"] mod common; -use common::{binary, git_sha256, git_sha256_file, has_command, hermetic}; +use common::{binary, git_sha256_file, has_command, hermetic}; use std::path::Path; use std::process::{Command, Output}; diff --git a/crates/socket-patch-cli/tests/mode_migration_cargo.rs b/crates/socket-patch-cli/tests/mode_migration_cargo.rs index 29c2ccd51..e4e2be3e3 100644 --- a/crates/socket-patch-cli/tests/mode_migration_cargo.rs +++ b/crates/socket-patch-cli/tests/mode_migration_cargo.rs @@ -49,7 +49,7 @@ use std::path::{Path, PathBuf}; use std::process::Output; use base64::Engine as _; -use sha2::{Digest, Sha256}; +use sha2::Digest; use socket_patch_core::hash::git_sha256::compute_git_sha256_from_bytes; use wiremock::matchers::{method, path, path_regex}; use wiremock::{Mock, MockServer, ResponseTemplate}; diff --git a/crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs b/crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs index 114d57780..00a0db833 100644 --- a/crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs +++ b/crates/socket-patch-cli/tests/repair/repair_vendor_e2e.rs @@ -14,7 +14,7 @@ use crate::common::{binary, git_sha256, sha256_hex}; use std::path::{Path, PathBuf}; -use sha2::{Digest, Sha256}; +use sha2::Digest; use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; diff --git a/crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs b/crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs index 73a8287a2..17060ca8e 100644 --- a/crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs +++ b/crates/socket-patch-cli/tests/vlt_e2e_common/mod.rs @@ -37,7 +37,7 @@ use std::sync::OnceLock; use base64::Engine as _; use serde_json::{json, Value}; -use sha2::{Digest, Sha256, Sha512}; +use sha2::{Digest, Sha512}; use wiremock::matchers::{method, path, path_regex}; use wiremock::{Mock, MockServer, ResponseTemplate}; From 0d967b7becf8de103d00074b1167c89815475da7 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:28:20 +0000 Subject: [PATCH 5/5] test(cli): rush sim uses common's cache_env/hermetic Drop the second #[path] include of common/cache_env.rs and common/hermetic.rs beside mod common, and state why the silent suites' stderr never holds the proxy notice: it is an info notice, muted under --silent and --json. Assisted-by: Claude Code:claude-opus-5-5 --- crates/socket-patch-cli/tests/cli_apply_silent.rs | 9 +++++---- crates/socket-patch-cli/tests/e2e_redirect_rush_sim.rs | 6 +----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/socket-patch-cli/tests/cli_apply_silent.rs b/crates/socket-patch-cli/tests/cli_apply_silent.rs index a3c9d3e76..5eb7f8043 100644 --- a/crates/socket-patch-cli/tests/cli_apply_silent.rs +++ b/crates/socket-patch-cli/tests/cli_apply_silent.rs @@ -15,10 +15,11 @@ //! 4. `apply --check --silent` with real redirect drift exited 1 with zero //! output (the OUT OF SYNC report was muted). //! -//! The core client's "No SOCKET_API_TOKEN set" notice is printed only when -//! an online `apply` builds its API client to download something (see -//! `apply_prints_the_public_proxy_notice_only_when_it_fetches`), so the -//! offline, `--check` and cached runs here never print it. +//! The core client's "No SOCKET_API_TOKEN set" notice is an info notice, +//! muted under `--silent` and `--json`, and is printed only when an online +//! `apply` builds its API client (see +//! `apply_prints_the_public_proxy_notice_only_when_it_fetches`), so these +//! runs' stderr never holds it. #[path = "common/mod.rs"] mod common; diff --git a/crates/socket-patch-cli/tests/e2e_redirect_rush_sim.rs b/crates/socket-patch-cli/tests/e2e_redirect_rush_sim.rs index bd812e2f4..64a28a66c 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_rush_sim.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_rush_sim.rs @@ -26,7 +26,7 @@ #[path = "common/mod.rs"] mod common; -use common::binary; +use common::{binary, cache_env, hermetic}; use std::path::Path; use std::process::{Output, Stdio}; @@ -35,10 +35,6 @@ use sha2::{Digest, Sha512}; use wiremock::matchers::{method, path, path_regex}; use wiremock::{Mock, MockServer, ResponseTemplate}; -#[path = "common/cache_env.rs"] -mod cache_env; -#[path = "common/hermetic.rs"] -mod hermetic; #[path = "vex_e2e_common/mod.rs"] mod vex_e2e_common; use vex_e2e_common::{