mirror of
https://github.com/openai/codex.git
synced 2026-04-30 09:26:44 +00:00
Spread AbsolutePathBuf (#17792)
Mechanical change to promote absolute paths through code.
This commit is contained in:
@@ -33,10 +33,11 @@ async fn run_test_cmd(tmp: TempDir, cmd: Vec<&str>) -> Result<ExecToolCallOutput
|
||||
let sandbox_type = get_platform_sandbox(/*windows_sandbox_enabled*/ false)
|
||||
.expect("should be able to get sandbox type");
|
||||
assert_eq!(sandbox_type, SandboxType::MacosSeatbelt);
|
||||
let cwd = tmp.path().abs();
|
||||
|
||||
let params = ExecParams {
|
||||
command: cmd.iter().map(ToString::to_string).collect(),
|
||||
cwd: tmp.path().abs(),
|
||||
cwd: cwd.clone(),
|
||||
expiration: 1000.into(),
|
||||
capture_policy: ExecCapturePolicy::ShellTool,
|
||||
env: HashMap::new(),
|
||||
@@ -55,7 +56,7 @@ async fn run_test_cmd(tmp: TempDir, cmd: Vec<&str>) -> Result<ExecToolCallOutput
|
||||
&policy,
|
||||
&FileSystemSandboxPolicy::from(&policy),
|
||||
NetworkSandboxPolicy::from(&policy),
|
||||
tmp.path(),
|
||||
&cwd,
|
||||
&None,
|
||||
/*use_legacy_landlock*/ false,
|
||||
/*stdout_stream*/ None,
|
||||
|
||||
@@ -14,6 +14,7 @@ use codex_protocol::protocol::Op;
|
||||
use codex_protocol::user_input::ByteRange;
|
||||
use codex_protocol::user_input::TextElement;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use core_test_support::responses::ev_assistant_message;
|
||||
use core_test_support::responses::ev_completed;
|
||||
use core_test_support::responses::ev_image_generation_call;
|
||||
@@ -348,8 +349,8 @@ async fn image_generation_call_event_is_emitted() -> anyhow::Result<()> {
|
||||
assert_eq!(end.revised_prompt, Some("A tiny blue square".to_string()));
|
||||
assert_eq!(end.result, "Zm9v");
|
||||
assert_eq!(
|
||||
end.saved_path,
|
||||
Some(expected_saved_path.to_string_lossy().into_owned())
|
||||
end.saved_path.as_ref().map(AbsolutePathBuf::as_path),
|
||||
Some(expected_saved_path.as_path())
|
||||
);
|
||||
assert_eq!(std::fs::read(&expected_saved_path)?, b"foo");
|
||||
let _ = std::fs::remove_file(&expected_saved_path);
|
||||
|
||||
@@ -11,6 +11,7 @@ use codex_core::seatbelt::spawn_command_under_seatbelt;
|
||||
use codex_core::spawn::CODEX_SANDBOX_ENV_VAR;
|
||||
use codex_core::spawn::StdioPolicy;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use tempfile::TempDir;
|
||||
|
||||
struct TestScenario {
|
||||
@@ -174,7 +175,7 @@ async fn openpty_works_under_seatbelt() {
|
||||
}
|
||||
|
||||
let policy = SandboxPolicy::new_read_only_policy();
|
||||
let command_cwd = std::env::current_dir().expect("getcwd");
|
||||
let command_cwd = AbsolutePathBuf::current_dir().expect("getcwd");
|
||||
let sandbox_cwd = command_cwd.clone();
|
||||
|
||||
let mut child = spawn_command_under_seatbelt(
|
||||
@@ -190,7 +191,7 @@ assert os.read(master, 4) == b"ping""#
|
||||
],
|
||||
command_cwd,
|
||||
&policy,
|
||||
sandbox_cwd.as_path(),
|
||||
&sandbox_cwd,
|
||||
StdioPolicy::RedirectForShellTool,
|
||||
/*network*/ None,
|
||||
HashMap::new(),
|
||||
@@ -232,7 +233,7 @@ async fn java_home_finds_runtime_under_seatbelt() {
|
||||
}
|
||||
|
||||
let policy = SandboxPolicy::new_read_only_policy();
|
||||
let command_cwd = std::env::current_dir().expect("getcwd");
|
||||
let command_cwd = AbsolutePathBuf::current_dir().expect("getcwd");
|
||||
let sandbox_cwd = command_cwd.clone();
|
||||
|
||||
let mut env: HashMap<String, String> = std::env::vars().collect();
|
||||
@@ -243,7 +244,7 @@ async fn java_home_finds_runtime_under_seatbelt() {
|
||||
vec![java_home_path.to_string_lossy().to_string()],
|
||||
command_cwd,
|
||||
&policy,
|
||||
sandbox_cwd.as_path(),
|
||||
&sandbox_cwd,
|
||||
StdioPolicy::RedirectForShellTool,
|
||||
/*network*/ None,
|
||||
env,
|
||||
@@ -291,7 +292,7 @@ fn create_test_scenario(tmp: &TempDir) -> TestScenario {
|
||||
/// Note that `path` must be absolute.
|
||||
async fn touch(path: &Path, policy: &SandboxPolicy) -> bool {
|
||||
assert!(path.is_absolute(), "Path must be absolute: {path:?}");
|
||||
let command_cwd = std::env::current_dir().expect("getcwd");
|
||||
let command_cwd = AbsolutePathBuf::current_dir().expect("getcwd");
|
||||
let sandbox_cwd = command_cwd.clone();
|
||||
let mut child = spawn_command_under_seatbelt(
|
||||
vec![
|
||||
@@ -300,7 +301,7 @@ async fn touch(path: &Path, policy: &SandboxPolicy) -> bool {
|
||||
],
|
||||
command_cwd,
|
||||
policy,
|
||||
sandbox_cwd.as_path(),
|
||||
&sandbox_cwd,
|
||||
StdioPolicy::RedirectForShellTool,
|
||||
/*network*/ None,
|
||||
HashMap::new(),
|
||||
|
||||
@@ -384,7 +384,7 @@ async fn unified_exec_emits_exec_command_begin_event() -> Result<()> {
|
||||
|
||||
assert_command(&begin_event.command, "-lc", "/bin/echo hello unified exec");
|
||||
|
||||
assert_eq!(begin_event.cwd, cwd);
|
||||
assert_eq!(begin_event.cwd.as_path(), cwd.as_path());
|
||||
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
@@ -449,7 +449,8 @@ async fn unified_exec_resolves_relative_workdir() -> Result<()> {
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
begin_event.cwd, workdir,
|
||||
begin_event.cwd.as_path(),
|
||||
workdir.as_path(),
|
||||
"exec_command cwd should resolve relative workdir against turn cwd",
|
||||
);
|
||||
|
||||
@@ -511,7 +512,8 @@ async fn unified_exec_respects_workdir_override() -> Result<()> {
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
begin_event.cwd, workdir,
|
||||
begin_event.cwd.as_path(),
|
||||
workdir.as_path(),
|
||||
"exec_command cwd should reflect the requested workdir override"
|
||||
);
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ async fn view_image_tool_attaches_local_image() -> anyhow::Result<()> {
|
||||
_ => unreachable!("stored event must be ViewImageToolCall"),
|
||||
};
|
||||
assert_eq!(tool_event.call_id, call_id);
|
||||
assert_eq!(tool_event.path, abs_path.to_path_buf());
|
||||
assert_eq!(tool_event.path, abs_path);
|
||||
|
||||
let req = mock.single_request();
|
||||
let body = req.body_json();
|
||||
|
||||
Reference in New Issue
Block a user