From d9554c8191c78fc660c771c3d5c6ec19764276c2 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 15 Dec 2025 18:23:04 -0600 Subject: [PATCH] Fixes mcp elicitation test that fails for me when run locally (#8020) --- codex-rs/Cargo.lock | 1 - codex-rs/core/src/auth.rs | 2 ++ codex-rs/exec-server/Cargo.toml | 1 - .../tests/suite/accept_elicitation.rs | 25 +++++++++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index dbb195a85..707fd9d43 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -1395,7 +1395,6 @@ dependencies = [ "tokio-util", "tracing", "tracing-subscriber", - "which", ] [[package]] diff --git a/codex-rs/core/src/auth.rs b/codex-rs/core/src/auth.rs index 933c80548..8b4448106 100644 --- a/codex-rs/core/src/auth.rs +++ b/codex-rs/core/src/auth.rs @@ -32,8 +32,10 @@ use crate::token_data::parse_id_token; use crate::util::try_parse_error_message; use codex_client::CodexHttpClient; use codex_protocol::account::PlanType as AccountPlanType; +#[cfg(any(test, feature = "test-support"))] use once_cell::sync::Lazy; use serde_json::Value; +#[cfg(any(test, feature = "test-support"))] use tempfile::TempDir; use thiserror::Error; diff --git a/codex-rs/exec-server/Cargo.toml b/codex-rs/exec-server/Cargo.toml index a0bd53493..4f8df05db 100644 --- a/codex-rs/exec-server/Cargo.toml +++ b/codex-rs/exec-server/Cargo.toml @@ -61,4 +61,3 @@ exec_server_test_support = { workspace = true } maplit = { workspace = true } pretty_assertions = { workspace = true } tempfile = { workspace = true } -which = { workspace = true } diff --git a/codex-rs/exec-server/tests/suite/accept_elicitation.rs b/codex-rs/exec-server/tests/suite/accept_elicitation.rs index 9632800d6..b703eaf4a 100644 --- a/codex-rs/exec-server/tests/suite/accept_elicitation.rs +++ b/codex-rs/exec-server/tests/suite/accept_elicitation.rs @@ -24,6 +24,7 @@ use serde_json::json; use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::symlink; use tempfile::TempDir; +use tokio::process::Command; /// Verify that when using a read-only sandbox and an execpolicy that prompts, /// the proper elicitation is sent. Upon auto-approving the elicitation, the @@ -53,11 +54,11 @@ prefix_rule( // Create an MCP client that approves expected elicitation messages. let project_root = TempDir::new()?; - let git = which::which("git")?; let project_root_path = project_root.path().canonicalize().unwrap(); + let git_path = resolve_git_path().await?; let expected_elicitation_message = format!( "Allow agent to run `{} init .` in `{}`?", - git.display(), + git_path, project_root_path.display() ); let elicitation_requests: Arc>> = Default::default(); @@ -175,3 +176,23 @@ fn ensure_codex_cli() -> Result { Ok(codex_cli) } + +async fn resolve_git_path() -> Result { + let git = Command::new("bash") + .arg("-lc") + .arg("command -v git") + .output() + .await + .context("failed to resolve git via login shell")?; + ensure!( + git.status.success(), + "failed to resolve git via login shell: {}", + String::from_utf8_lossy(&git.stderr) + ); + let git_path = String::from_utf8(git.stdout) + .context("git path was not valid utf8")? + .trim() + .to_string(); + ensure!(!git_path.is_empty(), "git path should not be empty"); + Ok(git_path) +}