From 3a6f1b6f75f8f5561a82d45adc68aca8d29511a2 Mon Sep 17 00:00:00 2001 From: pakrym-oai Date: Tue, 7 Apr 2026 09:58:07 -0700 Subject: [PATCH] codex: keep config cwd strictness in core --- codex-rs/app-server/src/config_api.rs | 13 ++++++++++++- codex-rs/core/src/config/service.rs | 2 +- codex-rs/core/src/config/service_tests.rs | 14 -------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/codex-rs/app-server/src/config_api.rs b/codex-rs/app-server/src/config_api.rs index 75c64cd21a..a8e54fd152 100644 --- a/codex-rs/app-server/src/config_api.rs +++ b/codex-rs/app-server/src/config_api.rs @@ -164,8 +164,19 @@ impl ConfigApi { pub(crate) async fn read( &self, - params: ConfigReadParams, + mut params: ConfigReadParams, ) -> Result { + if let Some(cwd) = &mut params.cwd { + let absolute_cwd = + AbsolutePathBuf::relative_to_current_dir(cwd.as_str()).map_err(|err| { + JSONRPCErrorError { + code: INTERNAL_ERROR_CODE, + message: format!("invalid config cwd: {err}"), + data: None, + } + })?; + *cwd = absolute_cwd.to_string_lossy().into_owned(); + } let fallback_cwd = params.cwd.as_ref().map(PathBuf::from); let mut response = self .config_service() diff --git a/codex-rs/core/src/config/service.rs b/codex-rs/core/src/config/service.rs index 62787b56e1..b13c2fa53b 100644 --- a/codex-rs/core/src/config/service.rs +++ b/codex-rs/core/src/config/service.rs @@ -156,7 +156,7 @@ impl ConfigService { ) -> Result { let layers = match params.cwd.as_deref() { Some(cwd) => { - let cwd = AbsolutePathBuf::relative_to_current_dir(cwd).map_err(|err| { + let cwd = AbsolutePathBuf::try_from(PathBuf::from(cwd)).map_err(|err| { ConfigServiceError::io("failed to resolve config cwd to an absolute path", err) })?; crate::config::ConfigBuilder::default() diff --git a/codex-rs/core/src/config/service_tests.rs b/codex-rs/core/src/config/service_tests.rs index d3fe651a7e..ae62326605 100644 --- a/codex-rs/core/src/config/service_tests.rs +++ b/codex-rs/core/src/config/service_tests.rs @@ -232,20 +232,6 @@ async fn read_includes_origins_and_layers() { )); } -#[tokio::test] -async fn read_accepts_relative_cwd() { - let tmp = tempdir().expect("tempdir"); - let service = ConfigService::without_managed_config_for_tests(tmp.path().to_path_buf()); - - service - .read(ConfigReadParams { - include_layers: false, - cwd: Some(".".to_string()), - }) - .await - .expect("relative cwd should resolve"); -} - #[cfg(target_os = "macos")] #[tokio::test] async fn write_value_succeeds_when_managed_preferences_expand_home_directory_paths() -> Result<()> {