Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix remaining agent server integration tests (#35222)
Agus Zubiaga9353ba788774
diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rsindex d572992c548..72035804101 100644--- a/crates/acp_thread/src/acp_thread.rs+++ b/crates/acp_thread/src/acp_thread.rs@@ -1597,6 +1597,7 @@ mod tests {name: "test",connection,child_status: io_task,+ current_thread: thread_rc,};AcpThread::new(diff --git a/crates/acp_thread/src/old_acp_support.rs b/crates/acp_thread/src/old_acp_support.rsindex 44cd00348fa..571023239f1 100644--- a/crates/acp_thread/src/old_acp_support.rs+++ b/crates/acp_thread/src/old_acp_support.rs@@ -7,6 +7,7 @@ use gpui::{AppContext as _, AsyncApp, Entity, Task, WeakEntity};use project::Project;use std::{cell::RefCell, error::Error, fmt, path::Path, rc::Rc};use ui::App;+use util::ResultExt as _;use crate::{AcpThread, AgentConnection};@@ -46,7 +47,7 @@ impl acp_old::Client for OldAcpClientDelegate {thread.push_assistant_content_block(thought.into(), true, cx)}})- .ok();+ .log_err();})?;Ok(())@@ -364,6 +365,7 @@ pub struct OldAcpAgentConnection {pub name: &'static str,pub connection: acp_old::AgentConnection,pub child_status: Task<Result<()>>,+ pub current_thread: Rc<RefCell<WeakEntity<AcpThread>>>,}impl AgentConnection for OldAcpAgentConnection {@@ -383,6 +385,7 @@ impl AgentConnection for OldAcpAgentConnection {}.into_any(),);+ let current_thread = self.current_thread.clone();cx.spawn(async move |cx| {let result = task.await?;let result = acp_old::InitializeParams::response_from_any(result)?;@@ -396,6 +399,7 @@ impl AgentConnection for OldAcpAgentConnection {let session_id = acp::SessionId("acp-old-no-id".into());AcpThread::new(self.clone(), project, session_id, cx)});+ current_thread.replace(thread.downgrade());thread})})diff --git a/crates/agent_servers/src/codex.rs b/crates/agent_servers/src/codex.rsindex b10ce9cf54b..d713f0d11cb 100644--- a/crates/agent_servers/src/codex.rs+++ b/crates/agent_servers/src/codex.rs@@ -310,7 +310,7 @@ pub(crate) mod tests {AgentServerCommand {path: cli_path,- args: vec!["mcp".into()],+ args: vec![],env: None,}}diff --git a/crates/agent_servers/src/e2e_tests.rs b/crates/agent_servers/src/e2e_tests.rsindex aca9001c79d..e9c72eabc92 100644--- a/crates/agent_servers/src/e2e_tests.rs+++ b/crates/agent_servers/src/e2e_tests.rs@@ -12,7 +12,6 @@ use futures::{FutureExt, StreamExt, channel::mpsc, select};use gpui::{Entity, TestAppContext};use indoc::indoc;use project::{FakeFs, Project};-use serde_json::json;use settings::{Settings, SettingsStore};use util::path;@@ -27,7 +26,11 @@ pub async fn test_basic(server: impl AgentServer + 'static, cx: &mut TestAppCont.unwrap();thread.read_with(cx, |thread, _| {- assert_eq!(thread.entries().len(), 2);+ assert!(+ thread.entries().len() >= 2,+ "Expected at least 2 entries. Got: {:?}",+ thread.entries()+ );assert!(matches!(thread.entries()[0],AgentThreadEntry::UserMessage(_)@@ -108,19 +111,19 @@ pub async fn test_path_mentions(server: impl AgentServer + 'static, cx: &mut Tes}pub async fn test_tool_call(server: impl AgentServer + 'static, cx: &mut TestAppContext) {- let fs = init_test(cx).await;- fs.insert_tree(- path!("/private/tmp"),- json!({"foo": "Lorem ipsum dolor", "bar": "bar", "baz": "baz"}),- )- .await;- let project = Project::test(fs, [path!("/private/tmp").as_ref()], cx).await;+ let _fs = init_test(cx).await;++ let tempdir = tempfile::tempdir().unwrap();+ let foo_path = tempdir.path().join("foo");+ std::fs::write(&foo_path, "Lorem ipsum dolor").expect("failed to write file");++ let project = Project::example([tempdir.path()], &mut cx.to_async()).await;let thread = new_test_thread(server, project.clone(), "/private/tmp", cx).await;thread.update(cx, |thread, cx| {thread.send_raw(- "Read the '/private/tmp/foo' file and tell me what you see.",+ &format!("Read {} and tell me what you see.", foo_path.display()),cx,)})@@ -143,6 +146,8 @@ pub async fn test_tool_call(server: impl AgentServer + 'static, cx: &mut TestApp.any(|entry| { matches!(entry, AgentThreadEntry::AssistantMessage(_)) }));});++ drop(tempdir);}pub async fn test_tool_call_with_confirmation(@@ -155,7 +160,7 @@ pub async fn test_tool_call_with_confirmation(let thread = new_test_thread(server, project.clone(), "/private/tmp", cx).await;let full_turn = thread.update(cx, |thread, cx| {thread.send_raw(- r#"Run `touch hello.txt && echo "Hello, world!" | tee hello.txt`"#,+ r#"Run exactly `touch hello.txt && echo "Hello, world!" | tee hello.txt` in the terminal."#,cx,)});@@ -175,10 +180,10 @@ pub async fn test_tool_call_with_confirmation().await;- let tool_call_id = thread.read_with(cx, |thread, _cx| {+ let tool_call_id = thread.read_with(cx, |thread, cx| {let AgentThreadEntry::ToolCall(ToolCall {id,- content,+ label,status: ToolCallStatus::WaitingForConfirmation { .. },..}) = &thread@@ -190,7 +195,8 @@ pub async fn test_tool_call_with_confirmation(panic!();};- assert!(content.iter().any(|c| c.to_markdown(_cx).contains("touch")));+ let label = label.read(cx).source();+ assert!(label.contains("touch"), "Got: {}", label);id.clone()});@@ -242,7 +248,7 @@ pub async fn test_cancel(server: impl AgentServer + 'static, cx: &mut TestAppConlet thread = new_test_thread(server, project.clone(), "/private/tmp", cx).await;let full_turn = thread.update(cx, |thread, cx| {thread.send_raw(- r#"Run `touch hello.txt && echo "Hello, world!" >> hello.txt`"#,+ r#"Run exactly `touch hello.txt && echo "Hello, world!" | tee hello.txt` in the terminal."#,cx,)});@@ -262,10 +268,10 @@ pub async fn test_cancel(server: impl AgentServer + 'static, cx: &mut TestAppCon).await;- thread.read_with(cx, |thread, _cx| {+ thread.read_with(cx, |thread, cx| {let AgentThreadEntry::ToolCall(ToolCall {id,- content,+ label,status: ToolCallStatus::WaitingForConfirmation { .. },..}) = &thread.entries()[first_tool_call_ix]@@ -273,7 +279,8 @@ pub async fn test_cancel(server: impl AgentServer + 'static, cx: &mut TestAppConpanic!("{:?}", thread.entries()[1]);};- assert!(content.iter().any(|c| c.to_markdown(_cx).contains("touch")));+ let label = label.read(cx).source();+ assert!(label.contains("touch"), "Got: {}", label);id.clone()});diff --git a/crates/agent_servers/src/gemini.rs b/crates/agent_servers/src/gemini.rsindex 8b9fed5777f..a97ff3f462d 100644--- a/crates/agent_servers/src/gemini.rs+++ b/crates/agent_servers/src/gemini.rs@@ -107,6 +107,7 @@ impl AgentServer for Gemini {name,connection,child_status,+ current_thread: thread_rc,});Ok(connection)