parent
5e2da042ef
commit
fd68265efd
6 changed files with 73 additions and 16 deletions
|
@ -438,7 +438,7 @@ impl ClaudeAgentSession {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SdkMessage::System { .. } => {}
|
SdkMessage::System { .. } | SdkMessage::ControlResponse { .. } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,6 +642,8 @@ enum SdkMessage {
|
||||||
request_id: String,
|
request_id: String,
|
||||||
request: ControlRequest,
|
request: ControlRequest,
|
||||||
},
|
},
|
||||||
|
/// Response to a control request
|
||||||
|
ControlResponse { response: ControlResponse },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
@ -651,6 +653,12 @@ enum ControlRequest {
|
||||||
Interrupt,
|
Interrupt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
struct ControlResponse {
|
||||||
|
request_id: String,
|
||||||
|
subtype: ResultErrorType,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
enum ResultErrorType {
|
enum ResultErrorType {
|
||||||
|
@ -707,7 +715,7 @@ pub(crate) mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
crate::common_e2e_tests!(ClaudeCode);
|
crate::common_e2e_tests!(ClaudeCode, allow_option_id = "allow");
|
||||||
|
|
||||||
pub fn local_command() -> AgentServerCommand {
|
pub fn local_command() -> AgentServerCommand {
|
||||||
AgentServerCommand {
|
AgentServerCommand {
|
||||||
|
|
|
@ -42,9 +42,13 @@ impl ClaudeZedMcpServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn server_config(&self) -> Result<McpServerConfig> {
|
pub fn server_config(&self) -> Result<McpServerConfig> {
|
||||||
|
#[cfg(not(test))]
|
||||||
let zed_path = std::env::current_exe()
|
let zed_path = std::env::current_exe()
|
||||||
.context("finding current executable path for use in mcp_server")?;
|
.context("finding current executable path for use in mcp_server")?;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
let zed_path = crate::e2e_tests::get_zed_path();
|
||||||
|
|
||||||
Ok(McpServerConfig {
|
Ok(McpServerConfig {
|
||||||
command: zed_path,
|
command: zed_path,
|
||||||
args: vec![
|
args: vec![
|
||||||
|
@ -174,6 +178,7 @@ impl McpServerTool for PermissionTool {
|
||||||
updated_input: input.input,
|
updated_input: input.input,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
debug_assert_eq!(chosen_option, reject_option_id);
|
||||||
PermissionToolResponse {
|
PermissionToolResponse {
|
||||||
behavior: PermissionToolBehavior::Deny,
|
behavior: PermissionToolBehavior::Deny,
|
||||||
updated_input: input.input,
|
updated_input: input.input,
|
||||||
|
|
|
@ -302,7 +302,7 @@ pub(crate) mod tests {
|
||||||
use crate::AgentServerCommand;
|
use crate::AgentServerCommand;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
crate::common_e2e_tests!(Codex);
|
crate::common_e2e_tests!(Codex, allow_option_id = "approve");
|
||||||
|
|
||||||
pub fn local_command() -> AgentServerCommand {
|
pub fn local_command() -> AgentServerCommand {
|
||||||
let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
use std::{path::Path, sync::Arc, time::Duration};
|
use std::{
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
sync::Arc,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{AgentServer, AgentServerSettings, AllAgentServersSettings};
|
use crate::{AgentServer, AgentServerSettings, AllAgentServersSettings};
|
||||||
use acp_thread::{AcpThread, AgentThreadEntry, ToolCall, ToolCallStatus};
|
use acp_thread::{AcpThread, AgentThreadEntry, ToolCall, ToolCallStatus};
|
||||||
|
@ -79,21 +83,28 @@ pub async fn test_path_mentions(server: impl AgentServer + 'static, cx: &mut Tes
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
thread.read_with(cx, |thread, cx| {
|
thread.read_with(cx, |thread, cx| {
|
||||||
assert_eq!(thread.entries().len(), 3);
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
thread.entries()[0],
|
thread.entries()[0],
|
||||||
AgentThreadEntry::UserMessage(_)
|
AgentThreadEntry::UserMessage(_)
|
||||||
));
|
));
|
||||||
assert!(matches!(thread.entries()[1], AgentThreadEntry::ToolCall(_)));
|
let assistant_message = &thread
|
||||||
let AgentThreadEntry::AssistantMessage(assistant_message) = &thread.entries()[2] else {
|
.entries()
|
||||||
panic!("Expected AssistantMessage")
|
.iter()
|
||||||
};
|
.rev()
|
||||||
|
.find_map(|entry| match entry {
|
||||||
|
AgentThreadEntry::AssistantMessage(msg) => Some(msg),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
assistant_message.to_markdown(cx).contains("Hello, world!"),
|
assistant_message.to_markdown(cx).contains("Hello, world!"),
|
||||||
"unexpected assistant message: {:?}",
|
"unexpected assistant message: {:?}",
|
||||||
assistant_message.to_markdown(cx)
|
assistant_message.to_markdown(cx)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
drop(tempdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn test_tool_call(server: impl AgentServer + 'static, cx: &mut TestAppContext) {
|
pub async fn test_tool_call(server: impl AgentServer + 'static, cx: &mut TestAppContext) {
|
||||||
|
@ -136,6 +147,7 @@ pub async fn test_tool_call(server: impl AgentServer + 'static, cx: &mut TestApp
|
||||||
|
|
||||||
pub async fn test_tool_call_with_confirmation(
|
pub async fn test_tool_call_with_confirmation(
|
||||||
server: impl AgentServer + 'static,
|
server: impl AgentServer + 'static,
|
||||||
|
allow_option_id: acp::PermissionOptionId,
|
||||||
cx: &mut TestAppContext,
|
cx: &mut TestAppContext,
|
||||||
) {
|
) {
|
||||||
let fs = init_test(cx).await;
|
let fs = init_test(cx).await;
|
||||||
|
@ -186,7 +198,7 @@ pub async fn test_tool_call_with_confirmation(
|
||||||
thread.update(cx, |thread, cx| {
|
thread.update(cx, |thread, cx| {
|
||||||
thread.authorize_tool_call(
|
thread.authorize_tool_call(
|
||||||
tool_call_id,
|
tool_call_id,
|
||||||
acp::PermissionOptionId("0".into()),
|
allow_option_id,
|
||||||
acp::PermissionOptionKind::AllowOnce,
|
acp::PermissionOptionKind::AllowOnce,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
@ -294,7 +306,7 @@ pub async fn test_cancel(server: impl AgentServer + 'static, cx: &mut TestAppCon
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! common_e2e_tests {
|
macro_rules! common_e2e_tests {
|
||||||
($server:expr) => {
|
($server:expr, allow_option_id = $allow_option_id:expr) => {
|
||||||
mod common_e2e {
|
mod common_e2e {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -319,7 +331,12 @@ macro_rules! common_e2e_tests {
|
||||||
#[::gpui::test]
|
#[::gpui::test]
|
||||||
#[cfg_attr(not(feature = "e2e"), ignore)]
|
#[cfg_attr(not(feature = "e2e"), ignore)]
|
||||||
async fn tool_call_with_confirmation(cx: &mut ::gpui::TestAppContext) {
|
async fn tool_call_with_confirmation(cx: &mut ::gpui::TestAppContext) {
|
||||||
$crate::e2e_tests::test_tool_call_with_confirmation($server, cx).await;
|
$crate::e2e_tests::test_tool_call_with_confirmation(
|
||||||
|
$server,
|
||||||
|
::agent_client_protocol::PermissionOptionId($allow_option_id.into()),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[::gpui::test]
|
#[::gpui::test]
|
||||||
|
@ -412,3 +429,24 @@ pub async fn run_until_first_tool_call(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_zed_path() -> PathBuf {
|
||||||
|
let mut zed_path = std::env::current_exe().unwrap();
|
||||||
|
|
||||||
|
while zed_path
|
||||||
|
.file_name()
|
||||||
|
.map_or(true, |name| name.to_string_lossy() != "debug")
|
||||||
|
{
|
||||||
|
if !zed_path.pop() {
|
||||||
|
panic!("Could not find target directory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zed_path.push("zed");
|
||||||
|
|
||||||
|
if !zed_path.exists() {
|
||||||
|
panic!("\n🚨 Run `cargo build` at least once before running e2e tests\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
zed_path
|
||||||
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ pub(crate) mod tests {
|
||||||
use crate::AgentServerCommand;
|
use crate::AgentServerCommand;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
crate::common_e2e_tests!(Gemini);
|
crate::common_e2e_tests!(Gemini, allow_option_id = "0");
|
||||||
|
|
||||||
pub fn local_command() -> AgentServerCommand {
|
pub fn local_command() -> AgentServerCommand {
|
||||||
let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use acp_thread::AcpThread;
|
use acp_thread::AcpThread;
|
||||||
use agent_client_protocol as acp;
|
use agent_client_protocol as acp;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::Result;
|
||||||
use context_server::listener::{McpServerTool, ToolResponse};
|
use context_server::listener::{McpServerTool, ToolResponse};
|
||||||
use context_server::types::{
|
use context_server::types::{
|
||||||
Implementation, InitializeParams, InitializeResponse, ProtocolVersion, ServerCapabilities,
|
Implementation, InitializeParams, InitializeResponse, ProtocolVersion, ServerCapabilities,
|
||||||
|
@ -38,8 +38,14 @@ impl ZedMcpServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn server_config(&self) -> Result<acp::McpServerConfig> {
|
pub fn server_config(&self) -> Result<acp::McpServerConfig> {
|
||||||
let zed_path = std::env::current_exe()
|
#[cfg(not(test))]
|
||||||
.context("finding current executable path for use in mcp_server")?;
|
let zed_path = anyhow::Context::context(
|
||||||
|
std::env::current_exe(),
|
||||||
|
"finding current executable path for use in mcp_server",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
let zed_path = crate::e2e_tests::get_zed_path();
|
||||||
|
|
||||||
Ok(acp::McpServerConfig {
|
Ok(acp::McpServerConfig {
|
||||||
command: zed_path,
|
command: zed_path,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue