codex: fix windows absolute path fixtures

This commit is contained in:
pakrym-oai
2026-04-07 13:06:11 -07:00
parent 9dcff29344
commit 77fec98a2e
7 changed files with 53 additions and 12 deletions
+5 -4
View File
@@ -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,
+2 -1
View File
@@ -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]
+11 -1
View File
@@ -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");
}
}
+3
View File
@@ -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() {
@@ -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]
@@ -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 {
+26 -3
View File
@@ -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)
}
}