From 26d3d3ace3654f50770d72ed06bf11a933577ed5 Mon Sep 17 00:00:00 2001 From: Ravitez Dondeti Date: Mon, 30 Mar 2026 10:11:36 -0500 Subject: [PATCH] fix: use build_host_url for GCP Vertex AI location fallback (#8185) Signed-off-by: rdondeti --- crates/goose/src/providers/gcpvertexai.rs | 56 ++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/crates/goose/src/providers/gcpvertexai.rs b/crates/goose/src/providers/gcpvertexai.rs index 4f2df3ec..987d53a2 100644 --- a/crates/goose/src/providers/gcpvertexai.rs +++ b/crates/goose/src/providers/gcpvertexai.rs @@ -72,7 +72,7 @@ fn build_vertex_url( let host_url = if configured_location == target_location { host.to_string() } else { - host.replace(configured_location, target_location) + GcpVertexAIProvider::build_host_url(target_location) }; let base_url = @@ -735,6 +735,60 @@ mod tests { assert!(url.as_str().contains("locations/europe-west1")); } + #[test] + fn test_build_vertex_url_global_location_fallback() { + // When configured_location is "global", the host is + // "https://aiplatform.googleapis.com" which does not contain "global". + // Falling back to a regional target_location must rebuild the host + // via build_host_url rather than string replacement. + let url = build_vertex_url( + "https://aiplatform.googleapis.com", + "global", + "test-project", + "claude-haiku-4-5@20251001", + ModelProvider::Anthropic, + "us-east5", + true, + ) + .unwrap(); + + assert!( + url.as_str() + .starts_with("https://us-east5-aiplatform.googleapis.com"), + "Expected regional host for us-east5, got: {}", + url + ); + assert!( + url.as_str().contains("locations/us-east5"), + "Expected locations/us-east5 in path, got: {}", + url + ); + assert!(url.as_str().contains(":streamRawPredict")); + } + + #[test] + fn test_build_vertex_url_global_location_same() { + // When both configured and target are "global", the host should stay as-is. + let url = build_vertex_url( + "https://aiplatform.googleapis.com", + "global", + "test-project", + "claude-haiku-4-5@20251001", + ModelProvider::Anthropic, + "global", + true, + ) + .unwrap(); + + assert!( + url.as_str() + .starts_with("https://aiplatform.googleapis.com"), + "Expected global host, got: {}", + url + ); + assert!(url.as_str().contains("locations/global")); + } + #[test] fn test_provider_metadata() { let metadata = GcpVertexAIProvider::metadata();