Skip to content

Commit 108084a

Browse files
CI: share test helpers in 17 more test files (#824) (#1402)
* Share test helpers in 17 more CLI test files Seventeen CLI test files still carried their own copies of the binary() and git_sha256 helpers. They now use the shared ones in tests/common, so a fix to either helper reaches every suite at once. The helper-copy ratchet (cli/shared_helper_copies.rs) drops these files from its pending list, plus a stale entry for a deleted file, so new copies there fail the test. The scan/ and repair/ files that an open PR touches and the four shared *_common modules stay pending. Refs #824 Assisted-by: Claude Code:claude-opus-5-5 * Drop duplicate cache_env module in two tests in_process_alternate_installers and in_process_gem_apply compiled tests/common/cache_env.rs twice, once on its own and once inside mod common, so its selftests ran twice per run. Both files now use common::cache_env. Refs #824 Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fd7c243 commit 108084a

18 files changed

Lines changed: 48 additions & 175 deletions

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,16 @@
1010
//! - `apply` against installed packages writes patched content to
1111
//! node_modules and leaves `.socket/` byte-identical.
1212
13-
use std::path::{Path, PathBuf};
13+
use std::path::Path;
1414
use std::process::Command;
1515

16-
use sha2::{Digest, Sha256};
1716
use wiremock::matchers::{method, path};
1817
use wiremock::{Mock, MockServer, ResponseTemplate};
1918

20-
fn binary() -> PathBuf {
21-
env!("CARGO_BIN_EXE_socket-patch").into()
22-
}
19+
use crate::common::{binary, git_sha256};
2320

2421
const ORG_SLUG: &str = "test-org";
2522

26-
/// Git-SHA256: SHA256("blob <len>\0" ++ content). Matches the binary's
27-
/// content-addressable hashing.
28-
fn git_sha256(content: &[u8]) -> String {
29-
let header = format!("blob {}\0", content.len());
30-
let mut hasher = Sha256::new();
31-
hasher.update(header.as_bytes());
32-
hasher.update(content);
33-
hex::encode(hasher.finalize())
34-
}
35-
3623
fn write_npm_package(root: &Path, name: &str, version: &str, file_path: &str, file_content: &[u8]) {
3724
let pkg_dir = root.join("node_modules").join(name);
3825
std::fs::create_dir_all(&pkg_dir).expect("create pkg dir");

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
//! (`status`/`error`) on stdout, so a regression that turns a real API
66
//! failure into a fake success fails loudly.
77
8-
use std::path::{Path, PathBuf};
8+
use std::path::Path;
99

1010
use wiremock::matchers::{method, path};
1111
use wiremock::{Mock, MockServer, ResponseTemplate};
1212

13-
fn binary() -> PathBuf {
14-
env!("CARGO_BIN_EXE_socket-patch").into()
15-
}
13+
use crate::common::binary;
1614

1715
const ORG_SLUG: &str = "test-org";
1816
const UUID: &str = "11111111-1111-4111-8111-111111111111";

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,10 @@ use std::path::Path;
1414
/// a stale entry is not an error, so a PR that migrates one never turns
1515
/// another red.
1616
const PENDING_PRIVATE_HELPERS: &[&str] = &[
17-
"apply/apply_network.rs",
18-
"cli/api_client_errors_e2e.rs",
19-
"diff_created_file_e2e.rs",
20-
"e2e_vex_vendor.rs",
21-
"in_process_agent_reapply.rs",
22-
"in_process_alternate_installers.rs",
23-
"in_process_cargo_apply.rs",
24-
"in_process_edge_cases.rs",
25-
"in_process_gem_apply.rs",
26-
"in_process_gem_multi_platform.rs",
27-
"in_process_get_manifest_path.rs",
28-
"in_process_pypi_apply.rs",
29-
"in_process_pypi_multi_release.rs",
30-
"in_process_remote_ecosystems_apply.rs",
31-
"in_process_remove_repair_lifecycle.rs",
32-
"remove_rollback_api_overrides.rs",
3317
"repair/covgap_commands_repair.rs",
3418
"repair/covgap_commands_repair_vendor.rs",
3519
"repair/repair_invariants.rs",
36-
"rollback/rollback_multicopy_blob_gate.rs",
3720
"scan/covgap_commands_fetch_stage.rs",
38-
"scan_vendor_e2e.rs",
3921
"vex_e2e_common/mod.rs",
4022
"vlt_e2e_common/mod.rs",
4123
"vlt_hosted_common/mod.rs",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ use socket_patch_core::vendor::state::{
3939
/// the uuid path level, so fixtures must use the real shape.
4040
const UUID: &str = "9f6b2c4e-1d3a-4f6b-8c2d-7e5a9b1c3d5f";
4141

42-
fn binary() -> &'static str {
43-
env!("CARGO_BIN_EXE_socket-patch")
44-
}
42+
#[path = "common/mod.rs"]
43+
mod common;
44+
use common::binary;
4545

4646
/// CLI invocation with the ambient `SOCKET_*` environment scrubbed (same
4747
/// rationale as `e2e_vex.rs`: explicit flags must be the sole source of

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use std::path::Path;
1212

1313
use serial_test::serial;
14-
use sha2::{Digest, Sha256};
1514
use socket_patch_cli::commands::get::{run as get_run, GetArgs};
1615
use socket_patch_cli::commands::scan::{run as scan_run, ScanArgs, ScanMode};
1716
use wiremock::matchers::{method, path, path_regex};
@@ -25,12 +24,9 @@ const UUID: &str = "45445445-4544-4544-8544-454454454454";
2524
const ORIGINAL: &[u8] = b"module.exports = 'original';\n";
2625
const PATCHED: &[u8] = b"module.exports = 'patched';\n";
2726

28-
fn git_sha256(content: &[u8]) -> String {
29-
let mut hasher = Sha256::new();
30-
hasher.update(format!("blob {}\0", content.len()).as_bytes());
31-
hasher.update(content);
32-
hex::encode(hasher.finalize())
33-
}
27+
#[path = "common/mod.rs"]
28+
mod common;
29+
use common::git_sha256;
3430

3531
fn common(cwd: &Path, server: &MockServer) -> socket_patch_cli::args::GlobalArgs {
3632
socket_patch_cli::args::GlobalArgs {

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@ use std::path::{Path, PathBuf};
99
use std::process::Command;
1010

1111
use serial_test::serial;
12-
use sha2::{Digest, Sha256};
1312
use socket_patch_cli::commands::apply::{run as apply_run, ApplyArgs};
1413

15-
#[path = "common/cache_env.rs"]
16-
mod cache_env;
17-
18-
fn git_sha256(content: &[u8]) -> String {
19-
let header = format!("blob {}\0", content.len());
20-
let mut hasher = Sha256::new();
21-
hasher.update(header.as_bytes());
22-
hasher.update(content);
23-
hex::encode(hasher.finalize())
24-
}
14+
#[path = "common/mod.rs"]
15+
mod common;
16+
use common::{cache_env, git_sha256};
2517

2618
/// Strong oracle: the file at `path` must now contain EXACTLY the expected
2719
/// patched bytes, its git-sha256 must equal the manifest's afterHash, and

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::process::Command;
99

1010
use base64::Engine;
1111
use serial_test::serial;
12-
use sha2::{Digest, Sha256};
1312
use socket_patch_cli::commands::scan::{run as scan_run, ScanArgs};
1413
use wiremock::matchers::{method, path, path_regex};
1514
use wiremock::{Mock, MockServer, ResponseTemplate};
@@ -19,13 +18,9 @@ const UUID: &str = "14141414-1414-4141-8141-141414141414";
1918
const CRATE_NAME: &str = "cfg-if";
2019
const CRATE_VERSION: &str = "1.0.0";
2120

22-
fn git_sha256(content: &[u8]) -> String {
23-
let header = format!("blob {}\0", content.len());
24-
let mut hasher = Sha256::new();
25-
hasher.update(header.as_bytes());
26-
hasher.update(content);
27-
hex::encode(hasher.finalize())
28-
}
21+
#[path = "common/mod.rs"]
22+
mod common;
23+
use common::git_sha256;
2924

3025
fn has_cargo() -> bool {
3126
Command::new("cargo")

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88
use std::path::Path;
99

1010
use serial_test::serial;
11-
use sha2::{Digest, Sha256};
1211
use socket_patch_cli::commands::apply::{run as apply_run, ApplyArgs};
1312
use socket_patch_cli::commands::rollback::{run as rollback_run, RollbackArgs};
1413

15-
fn git_sha256(content: &[u8]) -> String {
16-
let header = format!("blob {}\0", content.len());
17-
let mut hasher = Sha256::new();
18-
hasher.update(header.as_bytes());
19-
hasher.update(content);
20-
hex::encode(hasher.finalize())
21-
}
14+
#[path = "common/mod.rs"]
15+
mod common;
16+
use common::git_sha256;
2217

2318
/// Identity fingerprint of a file that survives a byte-identical rewrite check.
2419
///

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,18 @@ use std::process::Command;
99

1010
use base64::Engine;
1111
use serial_test::serial;
12-
use sha2::{Digest, Sha256};
1312
use socket_patch_cli::commands::scan::{run as scan_run, ScanArgs};
1413
use wiremock::matchers::{method, path, path_regex};
1514
use wiremock::{Mock, MockServer, ResponseTemplate};
1615

17-
#[path = "common/cache_env.rs"]
18-
mod cache_env;
19-
2016
const ORG: &str = "test-org";
2117
const UUID: &str = "13131313-1313-4131-8131-131313131313";
2218
const GEM_NAME: &str = "colorize";
2319
const GEM_VERSION: &str = "1.1.0";
2420

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-
}
21+
#[path = "common/mod.rs"]
22+
mod common;
23+
use common::{cache_env, git_sha256};
3224

3325
fn has_gem() -> bool {
3426
Command::new("gem")

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use std::path::{Path, PathBuf};
2727

2828
use base64::Engine;
2929
use serial_test::serial;
30-
use sha2::{Digest, Sha256};
3130
use socket_patch_cli::commands::remove::{run as remove_run, RemoveArgs};
3231
use socket_patch_cli::commands::rollback::{run as rollback_run, RollbackArgs};
3332
use socket_patch_cli::commands::scan::{run as scan_run, ScanArgs};
@@ -69,13 +68,9 @@ fn darwin_after_bytes() -> Vec<u8> {
6968
p
7069
}
7170

72-
fn git_sha256(content: &[u8]) -> String {
73-
let header = format!("blob {}\0", content.len());
74-
let mut hasher = Sha256::new();
75-
hasher.update(header.as_bytes());
76-
hasher.update(content);
77-
hex::encode(hasher.finalize())
78-
}
71+
#[path = "common/mod.rs"]
72+
mod common;
73+
use common::git_sha256;
7974

8075
fn b64(bytes: &[u8]) -> String {
8176
base64::engine::general_purpose::STANDARD.encode(bytes)

0 commit comments

Comments
 (0)