Skip to content
Open
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
28 changes: 4 additions & 24 deletions crates/socket-patch-cli/tests/apply/apply_silent_staging_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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 {
Expand All @@ -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:?}"
);
Expand Down Expand Up @@ -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:?}"
);
Expand Down Expand Up @@ -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:?}"
);
Expand Down
39 changes: 8 additions & 31 deletions crates/socket-patch-cli/tests/cli_apply_silent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
//! 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 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;
Expand All @@ -44,21 +41,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<String> {
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();
Expand Down Expand Up @@ -176,9 +158,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:?}"
);
Expand All @@ -193,11 +174,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:?}"
);
Expand Down Expand Up @@ -233,9 +211,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:?}"
);
}
Expand Down
35 changes: 6 additions & 29 deletions crates/socket-patch-cli/tests/cli_scan_silent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> {
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`.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 2 additions & 17 deletions crates/socket-patch-cli/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#![allow(dead_code)]

use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<String, String> {
pairs
.iter()
.map(|(k, v)| ((*k).to_string(), (*v).to_string()))
.collect()
}
21 changes: 1 addition & 20 deletions crates/socket-patch-cli/tests/common/update_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ pub struct FakeReleaseBuilder {
omit_assets: Vec<String>,
truncate: Vec<(String, usize)>,
metadata_delay: Option<Duration>,
asset_delay: Option<Duration>,
expect_resolves: Option<u64>,
expect_sums: Option<u64>,
expect_asset_downloads: Option<u64>,
Expand All @@ -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<u8>) -> 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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
18 changes: 1 addition & 17 deletions crates/socket-patch-cli/tests/e2e_gem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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`
Expand Down
18 changes: 1 addition & 17 deletions crates/socket-patch-cli/tests/e2e_npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#[path = "common/mod.rs"]
mod common;
use common::{binary, git_sha256, hermetic};
use common::{binary, git_sha256_file, has_command, hermetic};

use std::path::Path;
use std::process::{Command, Output};
Expand All @@ -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) {
Expand Down
7 changes: 1 addition & 6 deletions crates/socket-patch-cli/tests/e2e_pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#[path = "common/mod.rs"]
mod common;
use common::{binary, git_sha256, hermetic};
use common::{binary, git_sha256_file, hermetic};

use std::path::{Path, PathBuf};
use std::process::{Command, Output};
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading