From fe83492090e85ee2651bb0db856850358a1fb40e Mon Sep 17 00:00:00 2001 From: asiantuntija Date: Wed, 19 Aug 2026 22:55:40 +0000 Subject: [PATCH] test(providers): isolate environment-proxy test in its own binary (#11262) Co-authored-by: tsih --- crates/goose-providers/src/api_client.rs | 29 --------------- .../tests/loopback_proxy_env.rs | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 crates/goose-providers/tests/loopback_proxy_env.rs diff --git a/crates/goose-providers/src/api_client.rs b/crates/goose-providers/src/api_client.rs index d5df392ff..43ac83b1f 100644 --- a/crates/goose-providers/src/api_client.rs +++ b/crates/goose-providers/src/api_client.rs @@ -827,35 +827,6 @@ mod tests { ); } - #[tokio::test] - async fn loopback_transport_does_not_use_environment_proxy() { - let proxy = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let proxy_uri = format!("http://{}", proxy.local_addr().unwrap()); - let _guard = env_lock::lock_env([ - ("HTTP_PROXY", Some(proxy_uri.as_str())), - ("http_proxy", Some(proxy_uri.as_str())), - ("NO_PROXY", Some("")), - ("no_proxy", Some("")), - ]); - let client = ApiClient::new_with_tls( - "http://127.0.0.1:9".to_string(), - AuthMethod::BearerToken("secret".to_string()), - None, - ) - .unwrap() - .with_loopback_http_only() - .unwrap() - .with_header("x-test", "value") - .unwrap(); - - assert!(client.response_get("models").await.is_err()); - assert!( - tokio::time::timeout(Duration::from_millis(100), proxy.accept()) - .await - .is_err() - ); - } - #[tokio::test] async fn loopback_transport_rejects_remote_http_redirect() { for status in ["307 Temporary Redirect", "308 Permanent Redirect"] { diff --git a/crates/goose-providers/tests/loopback_proxy_env.rs b/crates/goose-providers/tests/loopback_proxy_env.rs new file mode 100644 index 000000000..22d8f4c71 --- /dev/null +++ b/crates/goose-providers/tests/loopback_proxy_env.rs @@ -0,0 +1,37 @@ +//! Isolated in its own test binary: this test mutates process-wide proxy +//! environment variables, which would otherwise be observed by unrelated +//! tests in the same process that build HTTP clients. + +use std::time::Duration; + +use goose_providers::api_client::{ApiClient, AuthMethod}; +use tokio::net::TcpListener; + +#[tokio::test] +async fn loopback_transport_does_not_use_environment_proxy() { + let proxy = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let proxy_uri = format!("http://{}", proxy.local_addr().unwrap()); + let _guard = env_lock::lock_env([ + ("HTTP_PROXY", Some(proxy_uri.as_str())), + ("http_proxy", Some(proxy_uri.as_str())), + ("NO_PROXY", Some("")), + ("no_proxy", Some("")), + ]); + let client = ApiClient::new_with_tls( + "http://127.0.0.1:9".to_string(), + AuthMethod::BearerToken("secret".to_string()), + None, + ) + .unwrap() + .with_loopback_http_only() + .unwrap() + .with_header("x-test", "value") + .unwrap(); + + assert!(client.response_get("models").await.is_err()); + assert!( + tokio::time::timeout(Duration::from_millis(100), proxy.accept()) + .await + .is_err() + ); +}