From 0e67f5313ef182ffedbbb09a69497bd432983e92 Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Thu, 3 Jul 2025 13:15:09 -0300 Subject: [PATCH] Fix cancel test Co-authored-by: Mikayla Maki --- crates/acp/src/acp.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/crates/acp/src/acp.rs b/crates/acp/src/acp.rs index e704cf0641..08e8ce6cf0 100644 --- a/crates/acp/src/acp.rs +++ b/crates/acp/src/acp.rs @@ -872,7 +872,7 @@ mod tests { thread.send(r#"Run `echo "Hello, world!"`"#, cx) }); - run_until_tool_call(&thread, cx).await; + run_until_first_tool_call(&thread, cx).await; let tool_call_id = thread.read_with(cx, |thread, _cx| { let AgentThreadEntryContent::ToolCall(ToolCall { @@ -941,7 +941,7 @@ mod tests { thread.send(r#"Run `echo "Hello, world!"`"#, cx) }); - run_until_tool_call(&thread, cx).await; + let first_tool_call_ix = run_until_first_tool_call(&thread, cx).await; thread.read_with(cx, |thread, _cx| { let AgentThreadEntryContent::ToolCall(ToolCall { @@ -952,7 +952,7 @@ mod tests { .. }, .. - }) = &thread.entries()[1].content + }) = &thread.entries()[first_tool_call_ix].content else { panic!("{:?}", thread.entries()[1].content); }; @@ -971,7 +971,7 @@ mod tests { let AgentThreadEntryContent::ToolCall(ToolCall { status: ToolCallStatus::Canceled, .. - }) = &thread.entries()[1].content + }) = &thread.entries()[first_tool_call_ix].content else { panic!(); }; @@ -985,24 +985,24 @@ mod tests { .unwrap(); thread.read_with(cx, |thread, _| { assert!(matches!( - &thread.entries()[3].content, - AgentThreadEntryContent::UserMessage(..), + &thread.entries().last().unwrap().content, + AgentThreadEntryContent::AssistantMessage(..), )) }); } - async fn run_until_tool_call(thread: &Entity, cx: &mut TestAppContext) { - let (mut tx, mut rx) = mpsc::channel::<()>(1); + async fn run_until_first_tool_call( + thread: &Entity, + cx: &mut TestAppContext, + ) -> usize { + let (mut tx, mut rx) = mpsc::channel::(1); let subscription = cx.update(|cx| { cx.subscribe(thread, move |thread, _, cx| { - if thread - .read(cx) - .entries - .iter() - .any(|e| matches!(e.content, AgentThreadEntryContent::ToolCall(_))) - { - tx.try_send(()).unwrap(); + for (ix, entry) in thread.read(cx).entries.iter().enumerate() { + if matches!(entry.content, AgentThreadEntryContent::ToolCall(_)) { + return tx.try_send(ix).unwrap(); + } } }) }); @@ -1011,8 +1011,9 @@ mod tests { _ = futures::FutureExt::fuse(smol::Timer::after(Duration::from_secs(10))) => { panic!("Timeout waiting for tool call") } - _ = rx.next().fuse() => { + ix = rx.next().fuse() => { drop(subscription); + ix.unwrap() } } }