acp: Have AcpThread handle all interrupting (#36417)
The view was cancelling the generation, but `AcpThread` already handles that, so we removed that extra code and fixed a bug where an update from the first user message would appear after the second one. Release Notes: - N/A Co-authored-by: Danilo <danilo@zed.dev>
This commit is contained in:
@@ -4283,7 +4283,7 @@ pub(crate) mod tests {
|
||||
},
|
||||
cx,
|
||||
);
|
||||
connection.end_turn(session_id);
|
||||
connection.end_turn(session_id, acp::StopReason::EndTurn);
|
||||
});
|
||||
|
||||
thread_view.read_with(cx, |view, _cx| {
|
||||
@@ -4302,4 +4302,137 @@ pub(crate) mod tests {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_interrupt(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
|
||||
let connection = StubAgentConnection::new();
|
||||
|
||||
let (thread_view, cx) =
|
||||
setup_thread_view(StubAgentServer::new(connection.clone()), cx).await;
|
||||
add_to_workspace(thread_view.clone(), cx);
|
||||
|
||||
let message_editor = cx.read(|cx| thread_view.read(cx).message_editor.clone());
|
||||
message_editor.update_in(cx, |editor, window, cx| {
|
||||
editor.set_text("Message 1", window, cx);
|
||||
});
|
||||
thread_view.update_in(cx, |thread_view, window, cx| {
|
||||
thread_view.send(window, cx);
|
||||
});
|
||||
|
||||
let (thread, session_id) = thread_view.read_with(cx, |view, cx| {
|
||||
let thread = view.thread().unwrap();
|
||||
|
||||
(thread.clone(), thread.read(cx).session_id().clone())
|
||||
});
|
||||
|
||||
cx.run_until_parked();
|
||||
|
||||
cx.update(|_, cx| {
|
||||
connection.send_update(
|
||||
session_id.clone(),
|
||||
acp::SessionUpdate::AgentMessageChunk {
|
||||
content: "Message 1 resp".into(),
|
||||
},
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
||||
cx.run_until_parked();
|
||||
|
||||
thread.read_with(cx, |thread, cx| {
|
||||
assert_eq!(
|
||||
thread.to_markdown(cx),
|
||||
indoc::indoc! {"
|
||||
## User
|
||||
|
||||
Message 1
|
||||
|
||||
## Assistant
|
||||
|
||||
Message 1 resp
|
||||
|
||||
"}
|
||||
)
|
||||
});
|
||||
|
||||
message_editor.update_in(cx, |editor, window, cx| {
|
||||
editor.set_text("Message 2", window, cx);
|
||||
});
|
||||
thread_view.update_in(cx, |thread_view, window, cx| {
|
||||
thread_view.send(window, cx);
|
||||
});
|
||||
|
||||
cx.update(|_, cx| {
|
||||
// Simulate a response sent after beginning to cancel
|
||||
connection.send_update(
|
||||
session_id.clone(),
|
||||
acp::SessionUpdate::AgentMessageChunk {
|
||||
content: "onse".into(),
|
||||
},
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
||||
cx.run_until_parked();
|
||||
|
||||
// Last Message 1 response should appear before Message 2
|
||||
thread.read_with(cx, |thread, cx| {
|
||||
assert_eq!(
|
||||
thread.to_markdown(cx),
|
||||
indoc::indoc! {"
|
||||
## User
|
||||
|
||||
Message 1
|
||||
|
||||
## Assistant
|
||||
|
||||
Message 1 response
|
||||
|
||||
## User
|
||||
|
||||
Message 2
|
||||
|
||||
"}
|
||||
)
|
||||
});
|
||||
|
||||
cx.update(|_, cx| {
|
||||
connection.send_update(
|
||||
session_id.clone(),
|
||||
acp::SessionUpdate::AgentMessageChunk {
|
||||
content: "Message 2 response".into(),
|
||||
},
|
||||
cx,
|
||||
);
|
||||
connection.end_turn(session_id.clone(), acp::StopReason::EndTurn);
|
||||
});
|
||||
|
||||
cx.run_until_parked();
|
||||
|
||||
thread.read_with(cx, |thread, cx| {
|
||||
assert_eq!(
|
||||
thread.to_markdown(cx),
|
||||
indoc::indoc! {"
|
||||
## User
|
||||
|
||||
Message 1
|
||||
|
||||
## Assistant
|
||||
|
||||
Message 1 response
|
||||
|
||||
## User
|
||||
|
||||
Message 2
|
||||
|
||||
## Assistant
|
||||
|
||||
Message 2 response
|
||||
|
||||
"}
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user