Lightweight coding agent that runs in your terminal
Rust
app-server: make thread/shellCommand tests shell-aware (#16635)
Michael Bolin862158b9e990
diff --git a/codex-rs/app-server/tests/suite/v2/thread_shell_command.rs b/codex-rs/app-server/tests/suite/v2/thread_shell_command.rsindex 4e8a40fca2..d5e6903272 100644--- a/codex-rs/app-server/tests/suite/v2/thread_shell_command.rs+++ b/codex-rs/app-server/tests/suite/v2/thread_shell_command.rs@@ -26,6 +26,7 @@ use codex_app_server_protocol::TurnCompletedNotification;use codex_app_server_protocol::TurnStartParams;use codex_app_server_protocol::TurnStartResponse;use codex_app_server_protocol::UserInput as V2UserInput;+use codex_core::shell::default_user_shell;use codex_features::FEATURES;use codex_features::Feature;use pretty_assertions::assert_eq;@@ -67,11 +68,12 @@ async fn thread_shell_command_runs_as_standalone_turn_and_persists_history() ->).await??;let ThreadStartResponse { thread, .. } = to_response::<ThreadStartResponse>(start_resp)?;+ let (shell_command, expected_output) = current_shell_output_command("hello from bang")?;let shell_id = mcp.send_thread_shell_command_request(ThreadShellCommandParams {thread_id: thread.id.clone(),- command: "printf 'hello from bang\\n'".to_string(),+ command: shell_command,}).await?;let shell_resp: JSONRPCResponse = timeout(@@ -93,7 +95,7 @@ async fn thread_shell_command_runs_as_standalone_turn_and_persists_history() ->assert_eq!(status, &CommandExecutionStatus::InProgress);let delta = wait_for_command_execution_output_delta(&mut mcp, &command_id).await?;- assert_eq!(delta.delta, "hello from bang\n");+ assert_eq!(delta.delta, expected_output);let completed = wait_for_command_execution_completed(&mut mcp, Some(&command_id)).await?;let ThreadItem::CommandExecution {@@ -110,7 +112,7 @@ async fn thread_shell_command_runs_as_standalone_turn_and_persists_history() ->assert_eq!(id, &command_id);assert_eq!(source, &CommandExecutionSource::UserShell);assert_eq!(status, &CommandExecutionStatus::Completed);- assert_eq!(aggregated_output.as_deref(), Some("hello from bang\n"));+ assert_eq!(aggregated_output.as_deref(), Some(expected_output.as_str()));assert_eq!(*exit_code, Some(0));timeout(@@ -147,7 +149,7 @@ async fn thread_shell_command_runs_as_standalone_turn_and_persists_history() ->};assert_eq!(source, &CommandExecutionSource::UserShell);assert_eq!(status, &CommandExecutionStatus::Completed);- assert_eq!(aggregated_output.as_deref(), Some("hello from bang\n"));+ assert_eq!(aggregated_output.as_deref(), Some(expected_output.as_str()));Ok(())}@@ -196,6 +198,7 @@ async fn thread_shell_command_uses_existing_active_turn() -> Result<()> {).await??;let ThreadStartResponse { thread, .. } = to_response::<ThreadStartResponse>(start_resp)?;+ let (shell_command, expected_output) = current_shell_output_command("active turn bang")?;let turn_id = mcp.send_turn_start_request(TurnStartParams {@@ -240,7 +243,7 @@ async fn thread_shell_command_uses_existing_active_turn() -> Result<()> {let shell_id = mcp.send_thread_shell_command_request(ThreadShellCommandParams {thread_id: thread.id.clone(),- command: "printf 'active turn bang\\n'".to_string(),+ command: shell_command,}).await?;let shell_resp: JSONRPCResponse = timeout(@@ -269,7 +272,7 @@ async fn thread_shell_command_uses_existing_active_turn() -> Result<()> {unreachable!("helper returns command execution item");};assert_eq!(source, &CommandExecutionSource::UserShell);- assert_eq!(aggregated_output.as_deref(), Some("active turn bang\n"));+ assert_eq!(aggregated_output.as_deref(), Some(expected_output.as_str()));mcp.send_response(request_id,@@ -309,7 +312,7 @@ async fn thread_shell_command_uses_existing_active_turn() -> Result<()> {source: CommandExecutionSource::UserShell,aggregated_output,..- } if aggregated_output.as_deref() == Some("active turn bang\n")+ } if aggregated_output.as_deref() == Some(expected_output.as_str()))}),"expected active-turn shell command to be persisted on the existing turn"@@ -318,6 +321,24 @@ async fn thread_shell_command_uses_existing_active_turn() -> Result<()> {Ok(())}+fn current_shell_output_command(text: &str) -> Result<(String, String)> {+ let command_and_output = match default_user_shell().name() {+ "powershell" => {+ let escaped_text = text.replace('\'', "''");+ (+ format!("Write-Output '{escaped_text}'"),+ format!("{text}\r\n"),+ )+ }+ "cmd" => (format!("echo {text}"), format!("{text}\r\n")),+ _ => {+ let quoted_text = shlex::try_quote(text)?;+ (format!("printf '%s\\n' {quoted_text}"), format!("{text}\n"))+ }+ };+ Ok(command_and_output)+}+async fn wait_for_command_execution_started(mcp: &mut McpProcess,expected_id: Option<&str>,