Fixes mcp elicitation test that fails for me when run locally (#8020)

This commit is contained in:
Eric Traut
2025-12-15 18:23:04 -06:00
committed by GitHub
parent 3ee5c40261
commit d9554c8191
4 changed files with 25 additions and 4 deletions

View File

@@ -61,4 +61,3 @@ exec_server_test_support = { workspace = true }
maplit = { workspace = true }
pretty_assertions = { workspace = true }
tempfile = { workspace = true }
which = { workspace = true }

View File

@@ -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<Mutex<Vec<CreateElicitationRequestParam>>> = Default::default();
@@ -175,3 +176,23 @@ fn ensure_codex_cli() -> Result<PathBuf> {
Ok(codex_cli)
}
async fn resolve_git_path() -> Result<String> {
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)
}