Fix remaining agent server integration tests (#35222)

Agus Zubiaga created

Release Notes:

- N/A

Change summary

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(-)

Detailed changes

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
             })
         })

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()
     });