Skip to content

Commit 89adf9d

Browse files
test(cli): use tests/common's helpers instead of local copies (T55) (#2241)
* Start T55 #1959: tests/common helper copies Assisted-by: Claude Code:claude-opus-5-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 * 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 * test(cli): drop imports left unused by the dedup Assisted-by: Claude Code:claude-opus-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 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e57b93c commit 89adf9d

23 files changed

Lines changed: 46 additions & 298 deletions

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@
2424
use crate::apply_fixture::{run_apply, write_sourceless_npm_patches};
2525
use crate::common::envelope::{codes_in, json_string, parse_json_envelope};
2626

27-
/// Non-error stderr lines: drop the unconditional core API-token warning
28-
/// (both its lead line and its "Got: ... Continuing anyway" continuation)
29-
/// and blank lines, keep everything else.
30-
fn stderr_chatter(stderr: &str) -> Vec<String> {
31-
stderr
32-
.lines()
33-
.filter(|l| {
34-
!l.contains("SOCKET_API_TOKEN")
35-
&& !l.contains("Continuing anyway")
36-
&& !l.trim().is_empty()
37-
})
38-
.map(|l| l.to_string())
39-
.collect()
40-
}
41-
4227
/// A guaranteed-unreachable local endpoint: bind an ephemeral port, then
4328
/// release it, so every request fails fast with connection-refused.
4429
fn dead_endpoint() -> String {
@@ -65,9 +50,8 @@ fn apply_silent_offline_missing_source_keeps_error_output() {
6550
stdout.trim().is_empty(),
6651
"silent human mode writes errors to stderr, not stdout: {stdout}"
6752
);
68-
let chatter = stderr_chatter(&stderr);
6953
assert!(
70-
chatter.iter().any(|l| l.contains("no local source")),
54+
stderr.contains("no local source"),
7155
"--silent must keep the offline no-source error (errors only, \
7256
never nothing); stderr was: {stderr:?}"
7357
);
@@ -102,16 +86,13 @@ fn apply_silent_online_download_failure_keeps_error_output() {
10286
stdout.trim().is_empty(),
10387
"silent human mode writes errors to stderr, not stdout: {stdout}"
10488
);
105-
let chatter = stderr_chatter(&stderr);
10689
assert!(
107-
chatter
108-
.iter()
109-
.any(|l| l.contains("could not be downloaded")),
90+
stderr.contains("could not be downloaded"),
11091
"--silent must keep the download-failure error (errors only, \
11192
never nothing); stderr was: {stderr:?}"
11293
);
11394
assert!(
114-
chatter.iter().any(|l| l.contains("Failed to download")),
95+
stderr.contains("Failed to download"),
11596
"--silent must keep the per-blob failure reasons with the error; \
11697
stderr was: {stderr:?}"
11798
);
@@ -155,9 +136,8 @@ fn apply_json_offline_missing_source_keeps_stderr_clean() {
155136
0,
156137
"the bail must not stage anything into .socket/blobs"
157138
);
158-
let chatter = stderr_chatter(&stderr);
159139
assert!(
160-
chatter.is_empty(),
140+
stderr.is_empty(),
161141
"--json suppresses the staging diagnostics on stderr (the \
162142
envelope is the machine channel); stderr was: {stderr:?}"
163143
);

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

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
//! 4. `apply --check --silent` with real redirect drift exited 1 with zero
1616
//! output (the OUT OF SYNC report was muted).
1717
//!
18-
//! Stderr assertions ignore the "No SOCKET_API_TOKEN set" client warning:
19-
//! it's printed by `get_api_client_with_overrides` in core when an ONLINE
20-
//! command builds its API client (offline runs suppress it) and is out of
21-
//! scope for `apply`'s `--silent` gating. `apply` builds that client only
22-
//! when it has something to download — see
23-
//! `apply_prints_the_public_proxy_notice_only_when_it_fetches` — so the
24-
//! no-manifest hook path, `--check` and a fully cached apply never print
25-
//! it at all.
18+
//! The core client's "No SOCKET_API_TOKEN set" notice is an info notice,
19+
//! muted under `--silent` and `--json`, and is printed only when an online
20+
//! `apply` builds its API client (see
21+
//! `apply_prints_the_public_proxy_notice_only_when_it_fetches`), so these
22+
//! runs' stderr never holds it.
2623
2724
#[path = "common/mod.rs"]
2825
mod common;
@@ -44,21 +41,6 @@ fn run_apply(cwd: &Path, args: &[&str]) -> (i32, String, String) {
4441
)
4542
}
4643

47-
/// Non-error stderr lines: drop the unconditional core API-token warning
48-
/// (both its lead line and its "Got: ... Continuing anyway" continuation)
49-
/// and blank lines, keep everything else.
50-
fn stderr_chatter(stderr: &str) -> Vec<String> {
51-
stderr
52-
.lines()
53-
.filter(|l| {
54-
!l.contains("SOCKET_API_TOKEN")
55-
&& !l.contains("Continuing anyway")
56-
&& !l.trim().is_empty()
57-
})
58-
.map(|l| l.to_string())
59-
.collect()
60-
}
61-
6244
fn write_corrupt_manifest(root: &Path) {
6345
let socket = root.join(".socket");
6446
std::fs::create_dir_all(&socket).unwrap();
@@ -176,9 +158,8 @@ fn apply_silent_unreadable_manifest_keeps_error_output() {
176158
stdout.trim().is_empty(),
177159
"silent human mode writes errors to stderr, not stdout: {stdout}"
178160
);
179-
let chatter = stderr_chatter(&stderr);
180161
assert!(
181-
chatter.iter().any(|l| l.contains("Error")),
162+
stderr.contains("Error"),
182163
"--silent must keep the error output (errors only, never nothing); \
183164
stderr was: {stderr:?}"
184165
);
@@ -193,11 +174,8 @@ fn apply_check_silent_unreadable_manifest_keeps_error_output() {
193174

194175
let (code, _stdout, stderr) = run_apply(tmp.path(), &["--check", "--silent"]);
195176
assert_eq!(code, 1, "unreadable manifest must fail closed: {stderr}");
196-
let chatter = stderr_chatter(&stderr);
197177
assert!(
198-
chatter
199-
.iter()
200-
.any(|l| l.contains("could not read the manifest")),
178+
stderr.contains("could not read the manifest"),
201179
"--check --silent must keep the fail-closed error output; \
202180
stderr was: {stderr:?}"
203181
);
@@ -233,9 +211,8 @@ fn apply_check_silent_drift_keeps_error_output() {
233211
code, 1,
234212
"missing go-patches copy must report drift: {stderr}"
235213
);
236-
let chatter = stderr_chatter(&stderr);
237214
assert!(
238-
chatter.iter().any(|l| l.contains("OUT OF SYNC")),
215+
stderr.contains("OUT OF SYNC"),
239216
"--check --silent must keep the drift error output; stderr was: {stderr:?}"
240217
);
241218
}

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

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
//! The apply-flow test runs against a wiremock API (same fixture shape
1010
//! as `scan_sync_e2e.rs`) so the full human-mode scan→select→download→
1111
//! apply pipeline is exercised without the network.
12-
//!
13-
//! Stderr assertions ignore the "No SOCKET_API_TOKEN set" client
14-
//! warning: it's printed unconditionally by
15-
//! `get_api_client_with_overrides` in core for every command and is
16-
//! out of scope for `scan`'s `--silent` gating.
1712
1813
#[path = "common/mod.rs"]
1914
mod common;
@@ -63,21 +58,6 @@ fn run_scan(cwd: &Path, args: &[&str]) -> (i32, String, String) {
6358
)
6459
}
6560

66-
/// Non-error stderr lines: drop the unconditional core API-token warning
67-
/// (both its lead line and its "Got: ... Continuing anyway" continuation)
68-
/// and blank lines, keep everything else.
69-
fn stderr_chatter(stderr: &str) -> Vec<String> {
70-
stderr
71-
.lines()
72-
.filter(|l| {
73-
!l.contains("SOCKET_API_TOKEN")
74-
&& !l.contains("Continuing anyway")
75-
&& !l.trim().is_empty()
76-
})
77-
.map(|l| l.to_string())
78-
.collect()
79-
}
80-
8161
/// Mount the three endpoints the human-mode apply flow hits: batch
8262
/// discovery, per-package search, and the full patch view (inline blob).
8363
/// Fixture shape mirrors `scan_sync_e2e.rs`.
@@ -171,10 +151,9 @@ fn scan_silent_no_packages_produces_no_output() {
171151
stdout.trim().is_empty(),
172152
"--silent must produce no stdout; got {stdout:?}"
173153
);
174-
let chatter = stderr_chatter(&stderr);
175154
assert!(
176-
chatter.is_empty(),
177-
"--silent must produce no stderr chatter on success; got {chatter:?}"
155+
stderr.is_empty(),
156+
"--silent must produce no stderr chatter on success; got {stderr:?}"
178157
);
179158

180159
// 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() {
228207
stdout.trim().is_empty(),
229208
"--silent must produce no stdout; got {stdout:?}"
230209
);
231-
let chatter = stderr_chatter(&stderr);
232210
assert!(
233-
chatter.is_empty(),
234-
"--silent must produce no stderr chatter on success; got {chatter:?}"
211+
stderr.is_empty(),
212+
"--silent must produce no stderr chatter on success; got {stderr:?}"
235213
);
236214

237215
// Silent suppresses output, not the mutation: the patch must have
@@ -392,10 +370,9 @@ async fn scan_vendor_silent_gc_prints_nothing() {
392370
"--silent must produce no stdout (regression: the vendor path's \
393371
GC line printed unconditionally); got {stdout:?}"
394372
);
395-
let chatter = stderr_chatter(&stderr);
396373
assert!(
397-
chatter.is_empty(),
398-
"--silent must produce no stderr chatter on success; got {chatter:?}"
374+
stderr.is_empty(),
375+
"--silent must produce no stderr chatter on success; got {stderr:?}"
399376
);
400377

401378
// Silent suppresses output, not the work: the prune and the vendoring

‎crates/socket-patch-cli/tests/common/mod.rs‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
1414
#![allow(dead_code)]
1515

16-
use std::collections::HashMap;
1716
use std::path::{Path, PathBuf};
1817
use std::process::{Command, Output};
1918

@@ -155,13 +154,8 @@ pub fn sha256_hex(content: &[u8]) -> String {
155154

156155
// ── Toolchain runners ─────────────────────────────────────────────────
157156

158-
/// Run `npm` in `cwd`, panic on non-zero exit with full output.
159-
pub fn npm_run(cwd: &Path, args: &[&str]) {
160-
run_toolchain(cwd, "npm", args, &[]);
161-
}
162-
163-
/// Run `pnpm` in `cwd`. Same shape as `npm_run`; `extra_env` lets
164-
/// the caller force store-dir overrides etc.
157+
/// Run `pnpm` in `cwd`, panicking on a non-zero exit with full output;
158+
/// `extra_env` lets the caller force store-dir overrides etc.
165159
pub fn pnpm_run(cwd: &Path, args: &[&str], extra_env: &[(&str, &str)]) {
166160
run_toolchain(cwd, "pnpm", args, extra_env);
167161
}
@@ -426,12 +420,3 @@ pub fn write_blob(socket_dir: &Path, hash: &str, content: &[u8]) {
426420
std::fs::create_dir_all(&blobs).expect("create .socket/blobs");
427421
std::fs::write(blobs.join(hash), content).expect("write blob");
428422
}
429-
430-
/// Map a slice of `(env-var-name, env-var-value)` tuples into a
431-
/// HashMap for callers that want a stable container.
432-
pub fn env_map(pairs: &[(&str, &str)]) -> HashMap<String, String> {
433-
pairs
434-
.iter()
435-
.map(|(k, v)| ((*k).to_string(), (*v).to_string()))
436-
.collect()
437-
}

‎crates/socket-patch-cli/tests/common/update_fixture.rs‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ pub struct FakeReleaseBuilder {
334334
omit_assets: Vec<String>,
335335
truncate: Vec<(String, usize)>,
336336
metadata_delay: Option<Duration>,
337-
asset_delay: Option<Duration>,
338337
expect_resolves: Option<u64>,
339338
expect_sums: Option<u64>,
340339
expect_asset_downloads: Option<u64>,
@@ -357,13 +356,6 @@ impl FakeReleaseBuilder {
357356
self
358357
}
359358

360-
/// Add a raw pre-built asset (exotic shapes: garbage archives, other
361-
/// targets).
362-
pub fn raw_asset(mut self, filename: &str, bytes: Vec<u8>) -> Self {
363-
self.assets.push((filename.to_string(), bytes));
364-
self
365-
}
366-
367359
/// Flip a nibble in this asset's SHA256SUMS entry.
368360
pub fn corrupt_sums_entry_for(mut self, filename: &str) -> Self {
369361
self.corrupt_sums_for.push(filename.to_string());
@@ -400,11 +392,6 @@ impl FakeReleaseBuilder {
400392
self
401393
}
402394

403-
pub fn delay_asset(mut self, d: Duration) -> Self {
404-
self.asset_delay = Some(d);
405-
self
406-
}
407-
408395
/// Pin exact hit counts (verified when the MockServer drops).
409396
pub fn expect_resolves(mut self, n: u64) -> Self {
410397
self.expect_resolves = Some(n);
@@ -527,13 +514,7 @@ impl FakeReleaseBuilder {
527514
.and(urlpath(format!(
528515
"/SocketDev/socket-patch/releases/download/v{ver}/{name}"
529516
)))
530-
.respond_with({
531-
let mut resp = ResponseTemplate::new(200).set_body_bytes(body);
532-
if let Some(d) = self.asset_delay {
533-
resp = resp.set_delay(d);
534-
}
535-
resp
536-
});
517+
.respond_with(ResponseTemplate::new(200).set_body_bytes(body));
537518
if let Some(n) = self.expect_asset_downloads {
538519
asset_mock = asset_mock.expect(n);
539520
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
#[path = "common/mod.rs"]
2222
mod common;
23-
use common::{binary, git_sha256, hermetic};
23+
use common::{binary, git_sha256, git_sha256_file, has_command, hermetic};
2424

2525
use std::path::{Path, PathBuf};
2626
use std::process::{Command, Output};
@@ -44,22 +44,6 @@ const GEM_PURL: &str = "pkg:gem/activestorage@5.2.0?platform=ruby";
4444
// Helpers
4545
// ---------------------------------------------------------------------------
4646

47-
fn has_command(cmd: &str) -> bool {
48-
let mut probe = Command::new(cmd);
49-
probe.arg("--version");
50-
cache_env::isolate(&mut probe);
51-
probe
52-
.stdout(std::process::Stdio::null())
53-
.stderr(std::process::Stdio::null())
54-
.status()
55-
.is_ok()
56-
}
57-
58-
fn git_sha256_file(path: &Path) -> String {
59-
let content = std::fs::read(path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()));
60-
git_sha256(&content)
61-
}
62-
6347
/// Run the binary with the hermetic `SOCKET_*` environment (no token, so the
6448
/// scans take the public-proxy path `--proxy-url` pins). The gem crawler
6549
/// reads `BUNDLE_PATH`, `BUNDLE_APP_CONFIG`, the user's `~/.bundle/config`

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
#[path = "common/mod.rs"]
1717
mod common;
18-
use common::{binary, git_sha256, hermetic};
18+
use common::{binary, git_sha256_file, has_command, hermetic};
1919

2020
use std::path::Path;
2121
use std::process::{Command, Output};
@@ -39,22 +39,6 @@ const AFTER_HASH: &str = "ec956dcafb886f14315570bf3981d44aa12c561716abb46eed8b06
3939
// Helpers
4040
// ---------------------------------------------------------------------------
4141

42-
fn has_command(cmd: &str) -> bool {
43-
let mut probe = Command::new(cmd);
44-
probe.arg("--version");
45-
cache_env::isolate(&mut probe);
46-
probe
47-
.stdout(std::process::Stdio::null())
48-
.stderr(std::process::Stdio::null())
49-
.status()
50-
.is_ok()
51-
}
52-
53-
fn git_sha256_file(path: &Path) -> String {
54-
let content = std::fs::read(path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()));
55-
git_sha256(&content)
56-
}
57-
5842
/// Run the CLI binary with the given args, setting `cwd` as the working dir.
5943
/// Returns `(exit_code, stdout, stderr)`.
6044
fn run(cwd: &Path, args: &[&str]) -> (i32, String, String) {

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
#[path = "common/mod.rs"]
1717
mod common;
18-
use common::{binary, git_sha256, hermetic};
18+
use common::{binary, git_sha256_file, hermetic};
1919

2020
use std::path::{Path, PathBuf};
2121
use std::process::{Command, Output};
@@ -43,11 +43,6 @@ fn has_python3() -> bool {
4343
.unwrap_or(false)
4444
}
4545

46-
fn git_sha256_file(path: &Path) -> String {
47-
let content = std::fs::read(path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()));
48-
git_sha256(&content)
49-
}
50-
5146
/// Run the CLI binary with the given args, setting `cwd` as the working dir.
5247
///
5348
/// The child gets the hermetic `SOCKET_*` environment, which forces the

0 commit comments

Comments
 (0)