From f1a3c44427c7f59701fcd15d7d3971b6f478919a Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Sun, 14 Jun 2026 00:56:16 +0000 Subject: [PATCH] app-server: preserve foreign environment cwd syntax --- .../app-server-protocol/src/protocol/v2/tests.rs | 5 +++-- .../app-server/tests/suite/v2/thread_start.rs | 6 +++++- codex-rs/app-server/tests/suite/v2/turn_start.rs | 11 +++++++++-- codex-rs/core/src/thread_manager.rs | 16 +++++----------- codex-rs/core/src/thread_manager_tests.rs | 16 ++++++++-------- .../remote_env_windows_test.rs | 2 +- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs b/codex-rs/app-server-protocol/src/protocol/v2/tests.rs index cf5c54fa04..48e14c7435 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2/tests.rs @@ -3723,7 +3723,8 @@ fn thread_settings_update_params_preserve_field_level_experimental_gates() { #[test] fn turn_start_params_round_trip_environments() { - let cwd = ApiPathString::new(r"C:\workspace"); + let cwd: ApiPathString = + serde_json::from_value(json!(r"C:\workspace")).expect("API path should deserialize"); let params: TurnStartParams = serde_json::from_value(json!({ "threadId": "thread_123", "input": [], @@ -3823,7 +3824,7 @@ fn turn_start_params_preserve_relative_environment_cwd_for_boundary_validation() params.environments, Some(vec![TurnEnvironmentParams { environment_id: "local".to_string(), - cwd: ApiPathString::new("relative"), + cwd: serde_json::from_value(json!("relative")).expect("API path should deserialize"), }]) ); } diff --git a/codex-rs/app-server/tests/suite/v2/thread_start.rs b/codex-rs/app-server/tests/suite/v2/thread_start.rs index cbe0f07dc1..6b6464fd27 100644 --- a/codex-rs/app-server/tests/suite/v2/thread_start.rs +++ b/codex-rs/app-server/tests/suite/v2/thread_start.rs @@ -34,6 +34,7 @@ use codex_protocol::config_types::SERVICE_TIER_DEFAULT_REQUEST_VALUE; use codex_protocol::config_types::TrustLevel; use codex_protocol::openai_models::ReasoningEffort; use codex_utils_path_uri::ApiPathString; +use codex_utils_path_uri::PathConvention; use pretty_assertions::assert_eq; use serde_json::Value; use serde_json::json; @@ -294,7 +295,10 @@ async fn thread_start_rejects_unknown_environment_as_invalid_request() -> Result .send_thread_start_request(ThreadStartParams { environments: Some(vec![TurnEnvironmentParams { environment_id: "missing".to_string(), - cwd: ApiPathString::new(codex_home.path().to_string_lossy()), + cwd: ApiPathString::from_abs_path( + &codex_home.path().to_path_buf().try_into()?, + PathConvention::native(), + )?, }]), ..Default::default() }) diff --git a/codex-rs/app-server/tests/suite/v2/turn_start.rs b/codex-rs/app-server/tests/suite/v2/turn_start.rs index 663a868519..e82c97baca 100644 --- a/codex-rs/app-server/tests/suite/v2/turn_start.rs +++ b/codex-rs/app-server/tests/suite/v2/turn_start.rs @@ -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_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; @@ -1327,7 +1328,10 @@ async fn turn_start_rejects_unknown_environment_before_starting_turn() -> Result }], environments: Some(vec![TurnEnvironmentParams { environment_id: "missing".to_string(), - cwd: ApiPathString::new(codex_home.path().to_string_lossy()), + cwd: ApiPathString::from_abs_path( + &codex_home.path().to_path_buf().try_into()?, + PathConvention::native(), + )?, }]), ..Default::default() }) @@ -2745,7 +2749,10 @@ fn environment_params( .map(|id| { Ok(TurnEnvironmentParams { environment_id: (*id).to_string(), - cwd: ApiPathString::new(cwd.to_string_lossy()), + cwd: ApiPathString::from_abs_path( + &cwd.to_path_buf().try_into()?, + PathConvention::native(), + )?, }) }) .collect() diff --git a/codex-rs/core/src/thread_manager.rs b/codex-rs/core/src/thread_manager.rs index a04113ffa5..74ebac84fe 100644 --- a/codex-rs/core/src/thread_manager.rs +++ b/codex-rs/core/src/thread_manager.rs @@ -473,7 +473,7 @@ impl ThreadManager { Ok(()) } - /// Resolves environment-native cwd strings using metadata from each selected environment. + /// Resolves environment-native cwd strings without applying the Codex host's path rules. pub async fn resolve_native_environment_selections( &self, environments: impl IntoIterator, @@ -487,8 +487,7 @@ impl ThreadManager { "duplicate turn environment id `{environment_id}`" ))); } - let environment = self - .state + self.state .environment_manager .get_environment(&environment_id) .ok_or_else(|| { @@ -496,17 +495,12 @@ impl ThreadManager { "unknown turn environment id `{environment_id}`" )) })?; - let info = environment.info().await.map_err(|err| { + let convention = cwd.infer_absolute_path_convention().ok_or_else(|| { CodexErr::InvalidRequest(format!( - "failed to get info for environment `{environment_id}`: {err}" + "invalid cwd for environment `{environment_id}`: path `{cwd}` does not use absolute POSIX or Windows path syntax" )) })?; - crate::shell::Shell::from_environment_shell_info(info.shell).map_err(|err| { - CodexErr::InvalidRequest(format!( - "failed to resolve shell for environment `{environment_id}`: {err}" - )) - })?; - let cwd = cwd.to_path_uri(info.path_convention).map_err(|err| { + let cwd = cwd.to_path_uri(convention).map_err(|err| { CodexErr::InvalidRequest(format!( "invalid cwd for environment `{environment_id}`: {err}" )) diff --git a/codex-rs/core/src/thread_manager_tests.rs b/codex-rs/core/src/thread_manager_tests.rs index df68a30c32..13f9d6738f 100644 --- a/codex-rs/core/src/thread_manager_tests.rs +++ b/codex-rs/core/src/thread_manager_tests.rs @@ -353,7 +353,7 @@ async fn start_thread_rejects_explicit_local_environment_when_default_provider_i } #[tokio::test] -async fn native_environment_selections_use_selected_environment_metadata() { +async fn native_environment_selections_preserve_selected_path_syntax() { let temp_dir = tempdir().expect("tempdir"); let mut config = test_config().await; config.codex_home = temp_dir.path().join("codex-home").abs(); @@ -370,7 +370,8 @@ async fn native_environment_selections_use_selected_environment_metadata() { let selections = manager .resolve_native_environment_selections([( "local".to_string(), - ApiPathString::new(config.cwd.display().to_string()), + ApiPathString::from_abs_path(&config.cwd, PathConvention::native()) + .expect("render native cwd"), )]) .await .expect("resolve local selection"); @@ -398,7 +399,8 @@ async fn native_environment_selections_reject_duplicate_ids() { config.codex_home.to_path_buf(), Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()), ); - let native_cwd = ApiPathString::new(config.cwd.display().to_string()); + let native_cwd = ApiPathString::from_abs_path(&config.cwd, PathConvention::native()) + .expect("render native cwd"); let error = manager .resolve_native_environment_selections([ ("local".to_string(), native_cwd.clone()), @@ -412,16 +414,14 @@ async fn native_environment_selections_reject_duplicate_ids() { let error = manager .resolve_native_environment_selections([( "local".to_string(), - ApiPathString::new("relative"), + serde_json::from_value(serde_json::json!("relative")) + .expect("API path should deserialize"), )]) .await .expect_err("relative cwd must fail at the environment boundary"); assert_eq!( error.to_string(), - format!( - "invalid cwd for environment `local`: path `relative` is not absolute using {} path syntax", - PathConvention::native() - ) + "invalid cwd for environment `local`: path `relative` does not use absolute POSIX or Windows path syntax" ); } diff --git a/codex-rs/core/tests/remote_env_windows/remote_env_windows_test.rs b/codex-rs/core/tests/remote_env_windows/remote_env_windows_test.rs index 24efb8e7ed..26de7d3a81 100644 --- a/codex-rs/core/tests/remote_env_windows/remote_env_windows_test.rs +++ b/codex-rs/core/tests/remote_env_windows/remote_env_windows_test.rs @@ -162,7 +162,7 @@ async fn windows_exec_server_runs_with_native_shell_and_cwd() -> Result<()> { } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn app_server_rejects_windows_environment_cwd() -> Result<()> { +async fn app_server_starts_thread_with_windows_environment_native_cwd() -> Result<()> { WineExecServer .scope(|exec_server_url| async move { let codex_home = TempDir::new()?;