From ef3d314296eb49d4b87362929bb8afcd1360f811 Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Sat, 22 Aug 2026 12:22:35 +0100 Subject: [PATCH] refactor(maestro): finish moving the e2e harness off raw reqwest Restores the harness's deliberate 5s per-request budget, which the shared client's 30s default had silently replaced, and converts the last two hand-rolled daemon calls in e2e.rs (recent-dirs, gitroot). Drops reqwest from maestro-e2e entirely. Co-Authored-By: Claude Opus 5 (1M context) --- Cargo.lock | 1 - crates/maestro-e2e/Cargo.toml | 1 - crates/maestro-e2e/src/client.rs | 7 ++++++- crates/maestro-e2e/src/daemon.rs | 6 ++++-- crates/maestro-e2e/tests/e2e.rs | 22 ++++------------------ crates/maestro-web/src/proxy.rs | 3 +-- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a728869..91e054d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1123,7 +1123,6 @@ dependencies = [ "futures-util", "maestro-protocol", "maestro-tui", - "reqwest", "serde", "serde_json", "tempfile", diff --git a/crates/maestro-e2e/Cargo.toml b/crates/maestro-e2e/Cargo.toml index cdaa27d..5e44fe5 100644 --- a/crates/maestro-e2e/Cargo.toml +++ b/crates/maestro-e2e/Cargo.toml @@ -14,7 +14,6 @@ path = "src/lib.rs" chrono.workspace = true futures-util.workspace = true maestro-protocol = { workspace = true, features = ["client"] } -reqwest.workspace = true serde.workspace = true serde_json.workspace = true tempfile.workspace = true diff --git a/crates/maestro-e2e/src/client.rs b/crates/maestro-e2e/src/client.rs index 7abecf7..e247222 100644 --- a/crates/maestro-e2e/src/client.rs +++ b/crates/maestro-e2e/src/client.rs @@ -8,6 +8,7 @@ #![allow(clippy::result_large_err)] use std::sync::Arc; +use std::time::Duration; use futures_util::{SinkExt, StreamExt}; use maestro_protocol::{CatalogEvent, CreateSessionRequest, DaemonClient, Session}; @@ -33,10 +34,14 @@ pub struct TestClient { daemon: DaemonClient, } +/// Per-request budget. Well below the client default: a hung daemon should fail +/// the test, not stall the suite for 30s. +const TEST_TIMEOUT: Duration = Duration::from_secs(5); + impl TestClient { pub fn new(http_base: &str) -> Self { Self { - daemon: DaemonClient::new(http_base), + daemon: DaemonClient::with_timeouts(http_base, TEST_TIMEOUT, TEST_TIMEOUT), } } diff --git a/crates/maestro-e2e/src/daemon.rs b/crates/maestro-e2e/src/daemon.rs index d701a86..9c215a8 100644 --- a/crates/maestro-e2e/src/daemon.rs +++ b/crates/maestro-e2e/src/daemon.rs @@ -50,9 +50,11 @@ impl Daemon { format!("http://{}", self.bind_addr) } - /// Shared client bound to this daemon. + /// Shared client bound to this daemon, with the harness's tighter budget. pub fn client(&self) -> maestro_protocol::DaemonClient { - maestro_protocol::DaemonClient::new(self.http_base()) + crate::client::TestClient::new(&self.http_base()) + .daemon() + .clone() } /// Stop the underlying process, but keep its state dirs around so we can diff --git a/crates/maestro-e2e/tests/e2e.rs b/crates/maestro-e2e/tests/e2e.rs index 5a4fd7c..bc21c07 100644 --- a/crates/maestro-e2e/tests/e2e.rs +++ b/crates/maestro-e2e/tests/e2e.rs @@ -230,7 +230,6 @@ async fn spawn_records_history_and_infers_gitroot_for_form() { // (#27's recents picker), and gitroot infers the worktree base_repo from the // same dir. Exercised end to end against real tmux + git. let (daemon, client) = bring_up().await; - let daemon_base = daemon.http_base(); // A git repo as the working dir, so gitroot has a repo to infer. let repo = TempDir::new().unwrap(); @@ -250,16 +249,11 @@ async fn spawn_records_history_and_infers_gitroot_for_form() { "recent-dirs surfaces the spawned cwd", Duration::from_secs(5), || { - let url = format!("{daemon_base}/api/recent-dirs"); + let client = daemon.client(); let want = cwd.clone(); async move { - let resp = match reqwest::get(&url).await { - Ok(r) => r, - Err(_) => return false, - }; - let recents: maestro_protocol::RecentDirs = match resp.json().await { - Ok(v) => v, - Err(_) => return false, + let Ok(recents) = client.recent_dirs().await else { + return false; }; recents .dirs @@ -272,15 +266,7 @@ async fn spawn_records_history_and_infers_gitroot_for_form() { // gitroot infers the worktree base_repo from the same dir (#25/#26): the dir // is itself the repo toplevel (it holds `.git`). - let gr: maestro_protocol::GitRoot = reqwest::Client::new() - .get(format!("{daemon_base}/api/gitroot")) - .query(&[("path", cwd.as_str())]) - .send() - .await - .expect("gitroot request") - .json() - .await - .expect("gitroot json"); + let gr = daemon.client().git_root(&cwd).await.expect("gitroot"); assert_eq!( gr.root.as_deref().map(|p| p.to_string_lossy().to_string()), Some(cwd.clone()), diff --git a/crates/maestro-web/src/proxy.rs b/crates/maestro-web/src/proxy.rs index cb8b53f..fa3b5e9 100644 --- a/crates/maestro-web/src/proxy.rs +++ b/crates/maestro-web/src/proxy.rs @@ -278,8 +278,7 @@ pub async fn pump_ws(mut client: WebSocket, upstream_url: String) { const CLOSE_UPSTREAM_REJECTED: u16 = 4502; /// Turn a failed upstream WS handshake into a browser-facing close code + -/// reason. When the daemon rejected the upgrade with its structured JSON error -/// body ([`ApiError`]), +/// reason. When the daemon rejected the upgrade with an [`ApiError`] body, /// surface that message; otherwise fall back to a generic gateway reason. The /// reason rides a WS control frame, so it's truncated to the 123-byte limit. fn upstream_close_reason(e: &tokio_tungstenite::tungstenite::Error) -> (u16, String) {