Skip to content
Merged
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
5 changes: 5 additions & 0 deletions crates/socket-patch-cli/tests/common/update_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ use wiremock::{Mock, MockServer, ResponseTemplate};
use socket_patch_cli::commands::update::UPDATE_TARGET;
use socket_patch_core::update::asset_name_for_target;

/// A TCP endpoint nothing listens on (port 9 = discard, never bound on a
/// dev host): any request the child makes fails fast and loudly, so a
/// "zero network" contract regressing into a fetch flips the exit code.
pub const DEAD_ENDPOINT: &str = "http://127.0.0.1:9";

/// Release asset filename for the target this test binary was built for.
pub fn asset_name_for_current_target() -> String {
asset_name_for_target(UPDATE_TARGET)
Expand Down
50 changes: 50 additions & 0 deletions crates/socket-patch-cli/tests/self_update_failures_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,56 @@ async fn asset_404_names_the_target() {
release.verify_request_hygiene().await;
}

/// A non-404 HTTP failure on the asset download (a 500 from an outage, a
/// half-published release, a WAF) aborts as `download_failed`, not
/// `asset_not_found` (reserved for 404: "no prebuilt binary for your
/// target"), names the HTTP status, and leaves the install pristine.
#[tokio::test]
async fn asset_server_error_is_download_failed() {
use wiremock::matchers::{method, path as urlpath};
use wiremock::{Mock, ResponseTemplate};

let install = staged_install();
let (served, _) = make_served_binary();
let asset = asset_name_for_current_target();

// SHA256SUMS vouches for the asset (so the pipeline gets past the
// sums fetch and reaches the archive GET), but the download route
// answers 500 instead of the bytes: `omit_asset` keeps the sums entry
// while skipping the fixture's 200 mock, and the explicit mock below
// owns the asset path.
let release = FakeReleaseBuilder::new("9.9.9")
.asset_for_current_target(&served)
.omit_asset(&asset)
.mount()
.await;
Mock::given(method("GET"))
.and(urlpath(format!(
"/SocketDev/socket-patch/releases/download/v9.9.9/{asset}"
)))
.respond_with(ResponseTemplate::new(500))
.mount(&release.server)
.await;

let (code, stdout, stderr) = run_installed(
&install,
&["--update", "--json"],
&[("SOCKET_UPDATE_BASE_URL", &release.base_url)],
);
assert_eq!(code, 1, "stdout:\n{stdout}\nstderr:\n{stderr}");
let env = common::parse_json_envelope(&stdout);
assert_eq!(common::envelope_error_code(&env), Some("download_failed"));
let message = common::envelope_error_message(&env).unwrap_or_default();
assert!(
message.contains("returned 500"),
"download_failed must carry the HTTP status: {message}"
);

install.assert_binary_intact();
install.assert_only_binary_present();
release.verify_request_hygiene().await;
}

/// SOCKET_UPDATE_TIMEOUT_MS must actually bound the run: a hung release
/// host may not turn `--update` into an indefinite stall (a hung
/// self-update is strictly worse than a hung scan).
Expand Down
71 changes: 0 additions & 71 deletions crates/socket-patch-cli/tests/update/covgap_update_download.rs

This file was deleted.

140 changes: 0 additions & 140 deletions crates/socket-patch-cli/tests/update/covgap_update_swap.rs

This file was deleted.

5 changes: 2 additions & 3 deletions crates/socket-patch-cli/tests/update/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ mod pty_io;
#[path = "../common/update_fixture.rs"]
mod update_fixture;

mod covgap_commands_update;
mod covgap_update_download;
mod covgap_update_swap;
mod self_update_channels_e2e;
mod self_update_telemetry_e2e;
mod update_json_contracts;
mod update_notifier_e2e;
mod update_render;
Loading
Loading