From 9353ba788774c7d82905db9feebf374937487715 Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Tue, 29 Jul 2025 09:40:59 -0300 Subject: [PATCH] Fix remaining agent server integration tests (#35222) Release Notes: - N/A --- crates/acp_thread/src/acp_thread.rs | 1 + crates/acp_thread/src/old_acp_support.rs | 6 +++- crates/agent_servers/src/codex.rs | 2 +- crates/agent_servers/src/e2e_tests.rs | 43 ++++++++++++++---------- crates/agent_servers/src/gemini.rs | 1 + 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs index d572992c54..7203580410 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.rs index 44cd00348f..571023239f 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>, + pub current_thread: Rc>>, } 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.rs index b10ce9cf54..d713f0d11c 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.rs index aca9001c79..e9c72eabc9 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 TestAppCon 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!" >> 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 TestAppCon panic!("{:?}", 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.rs index 8b9fed5777..a97ff3f462 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)