chore: adapt command cwd layer to current APIs

This commit is contained in:
Adam Perry
2026-06-16 17:45:42 +00:00
parent 4a4c8fad12
commit 7da4e6a9ae
11 changed files with 22 additions and 46 deletions
@@ -58,13 +58,8 @@ fn command_cwd_for_api_and_actions(cwd: &PathUri) -> (ApiPathString, AbsolutePat
(api_cwd, host_cwd)
}
#[expect(
clippy::expect_used,
reason = "guardian command paths are native to the app-server host"
)]
fn api_path_from_host(cwd: &AbsolutePathBuf) -> ApiPathString {
ApiPathString::from_abs_path(cwd, PathConvention::native())
.expect("guardian command cwd should render using the host path convention")
ApiPathString::from_abs_path(cwd)
}
pub fn build_file_change_approval_request_item(
@@ -1279,7 +1279,6 @@ mod tests {
use codex_utils_absolute_path::test_support::PathBufExt;
use codex_utils_absolute_path::test_support::test_path_buf;
use codex_utils_path_uri::ApiPathString;
use codex_utils_path_uri::PathConvention;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
use std::path::PathBuf;
@@ -1287,8 +1286,7 @@ mod tests {
use uuid::Uuid;
fn test_api_path(path: &str) -> ApiPathString {
ApiPathString::from_abs_path(&test_path_buf(path).abs(), PathConvention::native())
.expect("API path")
ApiPathString::from_abs_path(&test_path_buf(path).abs())
}
#[test]
@@ -2338,11 +2338,7 @@ mod tests {
fn command_execution_completion_item(command: &str) -> CommandExecutionCompletionItem {
CommandExecutionCompletionItem {
command: command.to_string(),
cwd: ApiPathString::from_abs_path(
&test_path_buf("/tmp").abs(),
PathConvention::native(),
)
.expect("API cwd"),
cwd: ApiPathString::from_abs_path(&test_path_buf("/tmp").abs()),
command_actions: vec![V2ParsedCommand::Unknown {
command: command.to_string(),
}],
+1 -2
View File
@@ -6,7 +6,6 @@ use codex_app_server_protocol::ThreadRealtimeStartedNotification;
use codex_protocol::protocol::RealtimeConversationVersion;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::ApiPathString;
use codex_utils_path_uri::PathConvention;
use pretty_assertions::assert_eq;
use serde_json::json;
use tokio::time::Duration;
@@ -17,7 +16,7 @@ fn absolute_path(path: &str) -> AbsolutePathBuf {
}
fn api_path(path: &str) -> ApiPathString {
ApiPathString::from_abs_path(&absolute_path(path), PathConvention::native()).expect("API path")
ApiPathString::from_abs_path(&absolute_path(path))
}
fn thread_realtime_started_notification() -> ServerNotification {
@@ -77,6 +77,7 @@ use codex_protocol::models::ImageDetail;
use codex_protocol::openai_models::ReasoningEffort;
use codex_protocol::user_input::MAX_USER_INPUT_TEXT_CHARS;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::ApiPathString;
use core_test_support::responses;
use core_test_support::skip_if_no_network;
use pretty_assertions::assert_eq;
@@ -2440,10 +2441,7 @@ async fn turn_start_updates_sandbox_and_cwd_between_turns_v2() -> Result<()> {
unreachable!("loop ensures we break on command execution items");
};
let second_cwd = codex_utils_absolute_path::AbsolutePathBuf::from_absolute_path(second_cwd)?;
assert_eq!(
cwd,
ApiPathString::from_abs_path(&second_cwd, PathConvention::native())?
);
assert_eq!(cwd, ApiPathString::from_abs_path(&second_cwd));
let expected_command = format_with_current_shell_display("echo second turn");
assert_eq!(command, expected_command);
assert_eq!(status, CommandExecutionStatus::InProgress);
@@ -34,7 +34,6 @@ use codex_features::FEATURES;
use codex_features::Feature;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::ApiPathString;
use codex_utils_path_uri::PathConvention;
use core_test_support::responses;
use core_test_support::skip_if_no_network;
use pretty_assertions::assert_eq;
@@ -171,10 +170,7 @@ async fn turn_start_shell_zsh_fork_executes_command_v2() -> Result<()> {
assert!(command.contains("sleep 0.01"));
assert!(command.contains(&release_marker.display().to_string()));
let workspace = AbsolutePathBuf::try_from(workspace)?;
assert_eq!(
cwd,
ApiPathString::from_abs_path(&workspace, PathConvention::native())?
);
assert_eq!(cwd, ApiPathString::from_abs_path(&workspace));
mcp.interrupt_turn_and_wait_for_aborted(thread.id, turn.id, DEFAULT_READ_TIMEOUT)
.await?;
@@ -340,12 +340,12 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
&env,
req.additional_permissions.clone(),
)
.map_err(|error| match error {
ToolError::Rejected(_) => {
ToolError::Rejected("missing command line for PTY".to_string())
}
error @ ToolError::Codex(_) => error,
})?;
.map_err(|error| match error {
ToolError::Rejected(_) => {
ToolError::Rejected("missing command line for PTY".to_string())
}
error @ ToolError::Codex(_) => error,
})?;
let options = unified_exec_options(attempt.network_denial_cancellation_token.clone());
let mut exec_env = attempt
.env_for(command, options, managed_network)
@@ -401,12 +401,12 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
&env,
req.additional_permissions.clone(),
)
.map_err(|error| match error {
ToolError::Rejected(_) => {
ToolError::Rejected("missing command line for PTY".to_string())
}
error @ ToolError::Codex(_) => error,
})?;
.map_err(|error| match error {
ToolError::Rejected(_) => {
ToolError::Rejected("missing command line for PTY".to_string())
}
error @ ToolError::Codex(_) => error,
})?;
let options = unified_exec_options(attempt.network_denial_cancellation_token.clone());
let mut exec_env = attempt
.env_for(command, options, managed_network)
@@ -80,7 +80,7 @@ fn exec_server_params_use_path_uri_and_env_policy_overlay_contract() {
let permission_profile = codex_protocol::models::PermissionProfile::Disabled;
let request = ExecRequest {
command: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
cwd: command_cwd.clone(),
cwd: command_cwd,
env: HashMap::from([
("HOME".to_string(), "/client-home".to_string()),
("PATH".to_string(), "/sandbox-path".to_string()),
@@ -3,7 +3,6 @@
use anyhow::Context;
use anyhow::Result;
use app_test_support::TestAppServer;
use app_test_support::PathBufExt;
use app_test_support::create_mock_responses_server_sequence;
use app_test_support::to_response;
use app_test_support::write_mock_responses_config_toml;
@@ -36,7 +36,6 @@ use codex_protocol::protocol::SessionConfiguredEvent;
use codex_utils_absolute_path::test_support::PathBufExt;
use codex_utils_absolute_path::test_support::test_path_buf;
use codex_utils_path_uri::ApiPathString;
use codex_utils_path_uri::PathConvention;
use pretty_assertions::assert_eq;
use serde_json::json;
@@ -77,10 +76,8 @@ use codex_exec::TurnStartedEvent;
use codex_exec::Usage;
use codex_exec::WebSearchItem;
#[expect(clippy::expect_used, reason = "test paths are absolute")]
fn api_path(path: &str) -> ApiPathString {
ApiPathString::from_abs_path(&test_path_buf(path).abs(), PathConvention::native())
.expect("API path")
ApiPathString::from_abs_path(&test_path_buf(path).abs())
}
#[test]
+1 -3
View File
@@ -7,7 +7,6 @@ use codex_protocol::openai_models::ModelPreset;
pub(crate) use codex_utils_absolute_path::test_support::PathBufExt;
pub(crate) use codex_utils_absolute_path::test_support::test_path_buf;
use codex_utils_path_uri::ApiPathString;
use codex_utils_path_uri::PathConvention;
use serde::Serialize;
use serde::de::DeserializeOwned;
@@ -25,8 +24,7 @@ pub(crate) fn test_path_display(path: &str) -> String {
}
pub(crate) fn test_api_path(path: &str) -> ApiPathString {
ApiPathString::from_abs_path(&test_path_buf(path).abs(), PathConvention::native())
.expect("API path")
ApiPathString::from_abs_path(&test_path_buf(path).abs())
}
pub(crate) fn session_source_cli<T>() -> T