Skip to content

Commit 88d5c59

Browse files
Use tests/common's binary() and git_sha256 in 40 more CLI tests (#824) (#1258)
* Start refactor for #824 Assisted-by: Claude Code:claude-opus-5-5 * Use common binary() and git_sha256 in 40 tests Forty more CLI test files drop their private copies of binary() and git_sha256 and import tests/common's instead, so a change to how the tests find the binary or hash a blob is made in one place. The two pnpm build suites keep their SOCKET_PATCH_PNPM_E2E_SOCKET_BIN override as a named socket_bin() helper. No test changes what it asserts. The shared_helper_copies ratchet drops the migrated files; the 27 files open PRs change and the 4 shared modules stay listed. Assisted-by: Claude Code:claude-opus-5-5 * Reach cache_env and hermetic through common Nine standalone e2e suites now include common/mod.rs, which already declares cache_env and hermetic, yet still loaded those two files a second time through their own #[path] mods (clippy::duplicate_mod under --all-targets). They take common's modules instead. Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2309440 commit 88d5c59

41 files changed

Lines changed: 152 additions & 421 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/socket-patch-cli/tests/apply/in_process_npm_multicopy.rs‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,12 @@
1212
//! assert EVERY physical copy is patched (and later restored) AND that the
1313
//! JSON summary counts every copy.
1414
15+
use crate::common::{binary, git_sha256};
16+
1517
use std::ffi::OsStr;
1618
use std::path::{Path, PathBuf};
1719
use std::process::Command;
1820

19-
use sha2::{Digest, Sha256};
20-
21-
fn binary() -> PathBuf {
22-
env!("CARGO_BIN_EXE_socket-patch").into()
23-
}
24-
25-
fn git_sha256(content: &[u8]) -> String {
26-
let header = format!("blob {}\0", content.len());
27-
let mut hasher = Sha256::new();
28-
hasher.update(header.as_bytes());
29-
hasher.update(content);
30-
hex::encode(hasher.finalize())
31-
}
32-
3321
/// Write `node_modules/.../<name>/{package.json,index.js}` at the given
3422
/// `pkg_dir` (which already encodes the nesting), returning the index.js path.
3523
fn write_copy(pkg_dir: &Path, name: &str, version: &str, index_bytes: &[u8]) -> PathBuf {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
//! stderr *text* — the "you configured the sha512- storage hash, not the
77
//! token" hint — which only a spawned process can observe.
88
9+
use crate::common::binary;
10+
911
use std::process::Command;
1012

1113
use wiremock::matchers::{method, path};
1214
use wiremock::{Mock, MockServer, ResponseTemplate};
1315

1416
const UUID: &str = "11111111-1111-4111-8111-111111111111";
1517

16-
fn binary() -> std::path::PathBuf {
17-
env!("CARGO_BIN_EXE_socket-patch").into()
18-
}
19-
2018
/// Parse the command's stdout as JSON, failing with the raw bytes on error
2119
/// (same discipline as `api_client_errors_e2e::json_stdout`).
2220
fn json_stdout(out: &std::process::Output) -> serde_json::Value {

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,12 @@
1111
//! like SOCKET_DRY_RUN — an ambient SOCKET_DRY_RUN=true turned every
1212
//! apply below into a silent no-op and failed the on-disk assertions.
1313
14-
use std::path::Path;
14+
use crate::common::git_sha256;
1515

16-
use sha2::{Digest, Sha256};
16+
use std::path::Path;
1717

1818
use crate::common;
1919

20-
fn git_sha256(content: &[u8]) -> String {
21-
let header = format!("blob {}\0", content.len());
22-
let mut hasher = Sha256::new();
23-
hasher.update(header.as_bytes());
24-
hasher.update(content);
25-
hex::encode(hasher.finalize())
26-
}
27-
2820
fn write_root(root: &Path) {
2921
std::fs::write(
3022
root.join("package.json"),

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,10 @@ use std::path::Path;
1515
/// another red.
1616
const PENDING_PRIVATE_HELPERS: &[&str] = &[
1717
"apply/apply_network.rs",
18-
"apply/in_process_npm_multicopy.rs",
1918
"cli/api_client_errors_e2e.rs",
20-
"cli/covgap_api_client.rs",
21-
"cli/output_modes_e2e.rs",
22-
"cli/telemetry_e2e.rs",
23-
"cli_scan_silent.rs",
24-
"covgap_commands_scan_mod.rs",
2519
"diff_created_file_e2e.rs",
26-
"docker_e2e_npm.rs",
27-
"docker_e2e_nuget.rs",
28-
"docker_e2e_pypi.rs",
29-
"e2e_embedded_vex.rs",
30-
"e2e_gem.rs",
31-
"e2e_hosted_production.rs",
32-
"e2e_npm.rs",
33-
"e2e_pypi.rs",
34-
"e2e_redirect_gem_build.rs",
35-
"e2e_redirect_gradle_build.rs",
36-
"e2e_redirect_npm_build.rs",
37-
"e2e_redirect_pnpm_build.rs",
38-
"e2e_scan.rs",
39-
"e2e_vendor_composer_build.rs",
40-
"e2e_vendor_npm_build.rs",
41-
"e2e_vendor_pnpm_build.rs",
42-
"e2e_vendor_pypi_build.rs",
43-
"e2e_vex_lockfile/cargo.rs",
44-
"e2e_vex_lockfile/maven.rs",
45-
"e2e_vex_lockfile/uv.rs",
46-
"e2e_vex_lockfile/yarn.rs",
4720
"e2e_vex_redirect.rs",
4821
"e2e_vex_vendor.rs",
49-
"get/get_batch_paths_e2e.rs",
5022
"get/global_packages_e2e.rs",
5123
"in_process_agent_reapply.rs",
5224
"in_process_alternate_installers.rs",
@@ -59,28 +31,16 @@ const PENDING_PRIVATE_HELPERS: &[&str] = &[
5931
"in_process_pypi_multi_release.rs",
6032
"in_process_remote_ecosystems_apply.rs",
6133
"in_process_remove_repair_lifecycle.rs",
62-
"mode_migration_cargo.rs",
6334
"mode_migration_npm.rs",
64-
"remove/covgap_commands_remove.rs",
6535
"remove_rollback_api_overrides.rs",
66-
"repair/coverage_fix_repair_vendor_predelete.rs",
6736
"repair/covgap_commands_repair.rs",
6837
"repair/covgap_commands_repair_vendor.rs",
6938
"repair/repair_invariants.rs",
70-
"repair/repair_vendor_e2e.rs",
71-
"repair/repair_vendor_flavors_e2e.rs",
72-
"rollback/rollback_invariants.rs",
7339
"rollback/rollback_multicopy_blob_gate.rs",
7440
"scan/covgap_commands_fetch_stage.rs",
75-
"scan/covgap_commands_scan_vendor_flow.rs",
76-
"scan/scan_invariants.rs",
77-
"scan/scan_paths_e2e.rs",
78-
"scan/scan_sync_e2e.rs",
79-
"scan/scan_vendor_step_error_e2e.rs",
8041
"scan_rollout_e2e.rs",
8142
"scan_vendor_e2e.rs",
8243
"vendor_ecosystem_fixtures/mod.rs",
83-
"vendor_jvm_cli.rs",
8444
"vex_e2e_common/mod.rs",
8545
"vlt_e2e_common/mod.rs",
8646
"vlt_hosted_common/mod.rs",

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
//! count). Each test runs the released binary in a tempdir against
99
//! the mock URI.
1010
11-
use std::path::{Path, PathBuf};
11+
use crate::common::binary;
12+
13+
use std::path::Path;
1214
use std::process::Command;
1315

1416
use wiremock::matchers::{method, path};
1517
use wiremock::{Mock, MockServer, ResponseTemplate};
1618

1719
const ORG_SLUG: &str = "telemetry-test-org";
1820

19-
fn binary() -> PathBuf {
20-
PathBuf::from(env!("CARGO_BIN_EXE_socket-patch"))
21-
}
22-
2321
fn write_root_package_json(root: &Path) {
2422
std::fs::write(
2523
root.join("package.json"),

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,24 @@
1515
//! `get_api_client_with_overrides` in core for every command and is
1616
//! out of scope for `scan`'s `--silent` gating.
1717
18+
#[path = "common/mod.rs"]
19+
mod common;
20+
use common::{binary, git_sha256};
21+
1822
#[path = "prebuilt_common/mod.rs"]
1923
mod prebuilt_common;
2024

21-
use std::path::{Path, PathBuf};
25+
use std::path::Path;
2226
use std::process::Command;
2327

24-
use sha2::{Digest, Sha256};
2528
use wiremock::matchers::{method, path};
2629
use wiremock::{Mock, MockServer, ResponseTemplate};
2730

2831
use socket_patch_cli::args::GLOBAL_ARG_ENV_VARS;
2932

30-
fn binary() -> PathBuf {
31-
env!("CARGO_BIN_EXE_socket-patch").into()
32-
}
33-
3433
const ORG_SLUG: &str = "test-org";
3534
const UUID: &str = "11111111-1111-4111-8111-111111111111";
3635

37-
fn git_sha256(content: &[u8]) -> String {
38-
let header = format!("blob {}\0", content.len());
39-
let mut hasher = Sha256::new();
40-
hasher.update(header.as_bytes());
41-
hasher.update(content);
42-
hex::encode(hasher.finalize())
43-
}
44-
4536
fn write_root(root: &Path) {
4637
std::fs::write(
4738
root.join("package.json"),

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,28 @@
3232
//! `cli_scan_silent.rs` pattern) so ambient developer/CI configuration
3333
//! cannot reroute the branch under test. Network tests use wiremock.
3434
35+
#[path = "common/mod.rs"]
36+
mod common;
37+
use common::{binary, git_sha256};
38+
3539
#[path = "common/pty_io.rs"]
3640
mod pty_io;
3741
#[path = "vlt_hosted_common/mod.rs"]
3842
mod vlt_hosted_common;
3943
#[path = "vlt_hosted_common/vendored.rs"]
4044
mod vlt_vendored;
41-
use std::path::{Path, PathBuf};
45+
use std::path::Path;
4246
use std::process::Command;
4347

44-
use sha2::{Digest, Sha256};
4548
use wiremock::matchers::{method, path};
4649
use wiremock::{Mock, MockServer, ResponseTemplate};
4750

4851
use socket_patch_cli::args::{GLOBAL_ARG_ENV_VARS, LOCAL_ARG_ENV_VARS};
4952

50-
fn binary() -> PathBuf {
51-
env!("CARGO_BIN_EXE_socket-patch").into()
52-
}
53-
5453
const ORG_SLUG: &str = "test-org";
5554
const UUID: &str = "11111111-1111-4111-8111-111111111111";
5655
const OLD_UUID: &str = "99999999-9999-4999-8999-999999999999";
5756

58-
fn git_sha256(content: &[u8]) -> String {
59-
let header = format!("blob {}\0", content.len());
60-
let mut hasher = Sha256::new();
61-
hasher.update(header.as_bytes());
62-
hasher.update(content);
63-
hex::encode(hasher.finalize())
64-
}
65-
6657
fn write_root_package_json(root: &Path) {
6758
std::fs::write(
6859
root.join("package.json"),

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
2626
#![cfg(feature = "docker-e2e")]
2727

28+
#[path = "common/mod.rs"]
29+
mod common;
30+
use common::git_sha256;
31+
2832
#[path = "docker_vendor_common/mod.rs"]
2933
mod docker_vendor_common;
3034

@@ -33,7 +37,6 @@ use std::path::{Path, PathBuf};
3337
use std::process::Command;
3438
use std::time::Duration;
3539

36-
use sha2::{Digest, Sha256};
3740
use wiremock::matchers::{method, path, path_regex};
3841
use wiremock::{Mock, MockServer, ResponseTemplate};
3942

@@ -50,16 +53,6 @@ const GHSA: &str = "GHSA-agent-npm-real";
5053
const PATCHED_BYTES: &[u8] =
5154
b"/* SOCKET-PATCH-E2E-MARKER */\nmodule.exports = function () { return {}; };\n";
5255

53-
/// Git-SHA256: SHA256("blob <len>\0" ++ content). Matches the binary's
54-
/// content-addressable hashing for fetched blobs.
55-
fn git_sha256(content: &[u8]) -> String {
56-
let header = format!("blob {}\0", content.len());
57-
let mut hasher = Sha256::new();
58-
hasher.update(header.as_bytes());
59-
hasher.update(content);
60-
hex::encode(hasher.finalize())
61-
}
62-
6356
/// Coverage instrumentation hook. The CI coverage-docker job sets
6457
/// SOCKET_PATCH_COV_BIN (host path to an llvm-cov-instrumented
6558
/// socket-patch binary) and SOCKET_PATCH_COV_PROFRAW_DIR (host dir

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
1616
#![cfg(feature = "docker-e2e")]
1717

18+
#[path = "common/mod.rs"]
19+
mod common;
20+
use common::git_sha256;
21+
1822
use std::process::Command;
1923

2024
use base64::Engine;
@@ -61,14 +65,6 @@ fn cov_docker_args() -> Vec<String> {
6165
]
6266
}
6367

64-
fn git_sha256(content: &[u8]) -> String {
65-
let header = format!("blob {}\0", content.len());
66-
let mut hasher = Sha256::new();
67-
hasher.update(header.as_bytes());
68-
hasher.update(content);
69-
hex::encode(hasher.finalize())
70-
}
71-
7268
/// Plain SHA-256 of the bytes (what `sha256sum` in the container
7369
/// reports). Used to verify the patched file's EXACT contents, not just
7470
/// that it contains the marker substring.

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
1818
#![cfg(feature = "docker-e2e")]
1919

20+
#[path = "common/mod.rs"]
21+
mod common;
22+
use common::git_sha256;
23+
2024
use std::process::Command;
2125

2226
use base64::Engine;
@@ -63,14 +67,6 @@ fn cov_docker_args() -> Vec<String> {
6367
]
6468
}
6569

66-
fn git_sha256(content: &[u8]) -> String {
67-
let header = format!("blob {}\0", content.len());
68-
let mut hasher = Sha256::new();
69-
hasher.update(header.as_bytes());
70-
hasher.update(content);
71-
hex::encode(hasher.finalize())
72-
}
73-
7470
/// Plain SHA256 (NOT git-blob) of the content — used as an independent
7571
/// oracle for the on-disk file after apply. The marker grep alone only
7672
/// proves the marker is *somewhere* in the file; comparing the full

0 commit comments

Comments
 (0)