mirror of
https://github.com/openai/codex.git
synced 2026-12-06 01:10:58 +00:00
app-server: preserve foreign environment cwd syntax
This commit is contained in:
@@ -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"),
|
||||
}])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<Item = (String, ApiPathString)>,
|
||||
@@ -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}"
|
||||
))
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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()?;
|
||||
|
||||
Reference in New Issue
Block a user