From 77fec98a2eee781488b5837b16af0a6998256c8f Mon Sep 17 00:00:00 2001 From: pakrym-oai Date: Tue, 7 Apr 2026 13:06:11 -0700 Subject: [PATCH] codex: fix windows absolute path fixtures --- codex-rs/app-server/src/transport/auth.rs | 9 +++--- codex-rs/app-server/src/transport/mod.rs | 3 +- codex-rs/core/tests/common/lib.rs | 12 +++++++- codex-rs/protocol/src/permissions.rs | 3 ++ .../src/app_server_approval_conversions.rs | 5 ++-- .../tui/src/bottom_pane/approval_overlay.rs | 4 ++- codex-rs/tui/src/test_support.rs | 29 +++++++++++++++++-- 7 files changed, 53 insertions(+), 12 deletions(-) diff --git a/codex-rs/app-server/src/transport/auth.rs b/codex-rs/app-server/src/transport/auth.rs index a67c692b7d..0825e1b3c5 100644 --- a/codex-rs/app-server/src/transport/auth.rs +++ b/codex-rs/app-server/src/transport/auth.rs @@ -405,6 +405,8 @@ mod tests { use super::*; use base64::Engine; use base64::engine::general_purpose::URL_SAFE_NO_PAD; + use core_test_support::test_absolute_path; + use core_test_support::test_path_buf; use hmac::Hmac; use hmac::Mac; use serde_json::json; @@ -459,7 +461,7 @@ mod tests { #[test] fn signed_bearer_args_require_mode_when_mode_specific_flags_are_set() { let err = AppServerWebsocketAuthArgs { - ws_shared_secret_file: Some(PathBuf::from("/tmp/secret")), + ws_shared_secret_file: Some(test_path_buf("/tmp/secret")), ..Default::default() } .try_into_settings() @@ -474,7 +476,7 @@ mod tests { fn signed_bearer_args_default_clock_skew_and_trim_optional_claims() { let settings = AppServerWebsocketAuthArgs { ws_auth: Some(WebsocketAuthCliMode::SignedBearerToken), - ws_shared_secret_file: Some(PathBuf::from("/tmp/secret")), + ws_shared_secret_file: Some(test_path_buf("/tmp/secret")), ws_issuer: Some(" issuer ".to_string()), ws_audience: Some(" ".to_string()), ..Default::default() @@ -486,8 +488,7 @@ mod tests { settings, AppServerWebsocketAuthSettings { config: Some(AppServerWebsocketAuthConfig::SignedBearerToken { - shared_secret_file: AbsolutePathBuf::from_absolute_path("/tmp/secret") - .expect("absolute path"), + shared_secret_file: test_absolute_path("/tmp/secret"), issuer: Some("issuer".to_string()), audience: None, max_clock_skew_seconds: DEFAULT_MAX_CLOCK_SKEW_SECONDS, diff --git a/codex-rs/app-server/src/transport/mod.rs b/codex-rs/app-server/src/transport/mod.rs index 7e1512a794..0f1b8bec8d 100644 --- a/codex-rs/app-server/src/transport/mod.rs +++ b/codex-rs/app-server/src/transport/mod.rs @@ -399,6 +399,7 @@ mod tests { use codex_app_server_protocol::RequestId; use codex_app_server_protocol::ServerNotification; use codex_utils_absolute_path::AbsolutePathBuf; + use core_test_support::test_absolute_path; use pretty_assertions::assert_eq; use serde_json::json; use std::path::PathBuf; @@ -406,7 +407,7 @@ mod tests { use tokio::time::timeout; fn absolute_path(path: &str) -> AbsolutePathBuf { - AbsolutePathBuf::from_absolute_path(path).expect("absolute path") + test_absolute_path(path) } #[test] diff --git a/codex-rs/core/tests/common/lib.rs b/codex-rs/core/tests/common/lib.rs index 8aff42e96f..883d3503d1 100644 --- a/codex-rs/core/tests/common/lib.rs +++ b/codex-rs/core/tests/common/lib.rs @@ -111,7 +111,17 @@ pub trait PathExt { impl PathExt for Path { fn abs(&self) -> AbsolutePathBuf { - AbsolutePathBuf::try_from(self.to_path_buf()).expect("path should already be absolute") + if let Ok(path) = AbsolutePathBuf::try_from(self.to_path_buf()) { + return path; + } + if cfg!(windows) + && let Some(path) = self.to_str() + && path.starts_with('/') + { + return AbsolutePathBuf::try_from(test_path_buf(path)) + .expect("windows test path should be absolute"); + } + panic!("path should already be absolute"); } } diff --git a/codex-rs/protocol/src/permissions.rs b/codex-rs/protocol/src/permissions.rs index 84db365e13..c758e2f348 100644 --- a/codex-rs/protocol/src/permissions.rs +++ b/codex-rs/protocol/src/permissions.rs @@ -1049,6 +1049,9 @@ fn resolve_file_system_special_path( } } FileSystemSpecialPath::SlashTmp => { + if !cfg!(unix) { + return None; + } #[allow(clippy::expect_used)] let slash_tmp = AbsolutePathBuf::from_absolute_path("/tmp").expect("/tmp is absolute"); if !slash_tmp.as_path().is_dir() { diff --git a/codex-rs/tui/src/app_server_approval_conversions.rs b/codex-rs/tui/src/app_server_approval_conversions.rs index 8d2335eb7d..d03b3f8225 100644 --- a/codex-rs/tui/src/app_server_approval_conversions.rs +++ b/codex-rs/tui/src/app_server_approval_conversions.rs @@ -55,10 +55,11 @@ mod tests { use codex_protocol::request_permissions::RequestPermissionProfile as CoreRequestPermissionProfile; use codex_utils_absolute_path::AbsolutePathBuf; use pretty_assertions::assert_eq; - use std::path::PathBuf; + + use crate::test_support::test_path_display; fn absolute_path(path: &str) -> AbsolutePathBuf { - AbsolutePathBuf::try_from(PathBuf::from(path)).expect("path must be absolute") + AbsolutePathBuf::from_absolute_path(test_path_display(path)).expect("path must be absolute") } #[test] diff --git a/codex-rs/tui/src/bottom_pane/approval_overlay.rs b/codex-rs/tui/src/bottom_pane/approval_overlay.rs index 82e74888f9..fa1fbf6fc2 100644 --- a/codex-rs/tui/src/bottom_pane/approval_overlay.rs +++ b/codex-rs/tui/src/bottom_pane/approval_overlay.rs @@ -856,8 +856,10 @@ mod tests { use pretty_assertions::assert_eq; use tokio::sync::mpsc::unbounded_channel; + use crate::test_support::test_path_display; + fn absolute_path(path: &str) -> AbsolutePathBuf { - AbsolutePathBuf::from_absolute_path(path).expect("absolute path") + AbsolutePathBuf::from_absolute_path(test_path_display(path)).expect("absolute path") } fn render_overlay_lines(view: &ApprovalOverlay, width: u16) -> String { diff --git a/codex-rs/tui/src/test_support.rs b/codex-rs/tui/src/test_support.rs index 790fc805ea..1d63c95065 100644 --- a/codex-rs/tui/src/test_support.rs +++ b/codex-rs/tui/src/test_support.rs @@ -8,8 +8,17 @@ pub(crate) trait PathExt { impl PathExt for Path { fn abs(&self) -> AbsolutePathBuf { - AbsolutePathBuf::try_from(self.to_path_buf()) - .unwrap_or_else(|_| panic!("path should already be absolute")) + if let Ok(path) = AbsolutePathBuf::try_from(self.to_path_buf()) { + return path; + } + if cfg!(windows) + && let Some(path) = self.to_str() + && path.starts_with('/') + { + return AbsolutePathBuf::try_from(test_path_buf(path)) + .expect("windows test path should be absolute"); + } + panic!("path should already be absolute"); } } @@ -24,5 +33,19 @@ impl PathBufExt for PathBuf { } pub(crate) fn test_path_display(path: &str) -> String { - Path::new(path).abs().display().to_string() + test_path_buf(path).abs().display().to_string() +} + +pub(crate) fn test_path_buf(path: &str) -> PathBuf { + if cfg!(windows) { + let mut platform_path = PathBuf::from(r"C:\"); + platform_path.extend( + path.trim_start_matches('/') + .split('/') + .filter(|segment| !segment.is_empty()), + ); + platform_path + } else { + PathBuf::from(path) + } }