Migrate ExecutorFileSystem create_directory to PathUri

This commit is contained in:
Codex
2026-06-10 22:15:03 +00:00
committed by Adam Perry
parent 3f075fccbb
commit aea014d745
20 changed files with 65 additions and 35 deletions
@@ -97,9 +97,10 @@ impl FsRequestProcessor {
&self,
params: FsCreateDirectoryParams,
) -> Result<FsCreateDirectoryResponse, JSONRPCErrorError> {
let path = PathUri::from_abs_path(&params.path).map_err(map_fs_error)?;
self.file_system()?
.create_directory(
&params.path,
&path,
CreateDirectoryOptions {
recursive: params.recursive.unwrap_or(true),
},
+2 -1
View File
@@ -633,8 +633,9 @@ async fn write_file_with_missing_parent_retry(
Ok(()) => Ok(()),
Err(err) if err.kind() == io::ErrorKind::NotFound => {
if let Some(parent_abs) = path_abs.parent() {
let parent_uri = PathUri::from_abs_path(&parent_abs)?;
fs.create_directory(
&parent_abs,
&parent_uri,
CreateDirectoryOptions { recursive: true },
sandbox,
)
+1 -1
View File
@@ -45,7 +45,7 @@ impl ExecutorFileSystem for TestFileSystem {
async fn create_directory(
&self,
_path: &AbsolutePathBuf,
_path: &PathUri,
_create_directory_options: CreateDirectoryOptions,
_sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
+7 -3
View File
@@ -136,10 +136,11 @@ pub async fn test_env() -> Result<TestEnv> {
let environment =
codex_exec_server::Environment::create_for_tests(Some(websocket_url.clone()))?;
let cwd = remote_aware_cwd_path();
let cwd_uri = PathUri::from_path(&cwd)?;
environment
.get_filesystem()
.create_directory(
&cwd,
&cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -908,10 +909,11 @@ impl TestCodexHarness {
) -> Result<()> {
let abs_path = self.path_abs(rel);
if let Some(parent) = abs_path.parent() {
let parent_uri = PathUri::from_path(&parent)?;
self.test
.fs()
.create_directory(
&parent,
&parent_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -940,10 +942,12 @@ impl TestCodexHarness {
}
pub async fn create_dir_all(&self, rel: impl AsRef<Path>) -> Result<()> {
let path = self.path_abs(rel);
let path_uri = PathUri::from_path(&path)?;
self.test
.fs()
.create_directory(
&self.path_abs(rel),
&path_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
+4 -2
View File
@@ -149,9 +149,10 @@ async fn configured_fallback_is_used_when_agents_candidate_is_directory() -> Res
.with_workspace_setup(|cwd, fs| async move {
let agents_dir = cwd.join("AGENTS.md");
let fallback = cwd.join("WORKFLOW.md");
let agents_dir_uri = PathUri::from_path(&agents_dir)?;
let fallback_uri = PathUri::from_path(&fallback)?;
fs.create_directory(
&agents_dir,
&agents_dir_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -191,12 +192,13 @@ async fn agents_docs_are_concatenated_from_project_root_to_cwd() -> Result<()> {
let root_agents = root.join("AGENTS.md");
let git_marker = root.join(".git");
let nested_agents = nested.join("AGENTS.md");
let nested_uri = PathUri::from_path(&nested)?;
let root_agents_uri = PathUri::from_path(&root_agents)?;
let git_marker_uri = PathUri::from_path(&git_marker)?;
let nested_agents_uri = PathUri::from_path(&nested_agents)?;
fs.create_directory(
&nested,
&nested_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
+4 -2
View File
@@ -1330,8 +1330,9 @@ async fn apply_patch_turn_diff_paths_stay_repo_relative_when_session_cwd_is_nest
config.cwd = config.cwd.join("subdir");
})
.with_workspace_setup(|cwd, fs| async move {
let cwd_uri = PathUri::from_path(&cwd)?;
fs.create_directory(
&cwd,
&cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -1581,6 +1582,7 @@ async fn apply_patch_turn_diff_tracks_local_and_remote_environment_paths() -> Re
SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis()
))
.abs();
let shared_cwd_uri = PathUri::from_path(&shared_cwd)?;
let _ = fs::remove_dir_all(shared_cwd.as_path());
test.fs()
.remove(
@@ -1595,7 +1597,7 @@ async fn apply_patch_turn_diff_tracks_local_and_remote_environment_paths() -> Re
fs::create_dir_all(shared_cwd.as_path())?;
test.fs()
.create_directory(
&shared_cwd,
&shared_cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
+12 -6
View File
@@ -297,10 +297,11 @@ async fn exec_command_routes_to_selected_remote_environment() -> Result<()> {
))
.abs();
let remote_marker_name = "marker.txt";
let remote_cwd_uri = PathUri::from_path(&remote_cwd)?;
let remote_marker_uri = PathUri::from_path(remote_cwd.join(remote_marker_name))?;
test.fs()
.create_directory(
&remote_cwd,
&remote_cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -393,9 +394,10 @@ async fn remote_request_permissions_grant_unblocks_later_remote_exec() -> Result
let local_write_root = local_cwd.path().join(relative_write_root);
let local_target_path = local_cwd.path().join(relative_target_path);
fs::create_dir(&local_write_root)?;
let remote_write_root_uri = PathUri::from_path(&remote_write_root)?;
test.fs()
.create_directory(
&remote_write_root,
&remote_write_root_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -573,9 +575,10 @@ async fn apply_patch_freeform_routes_to_selected_remote_environment() -> Result<
SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis()
))
.abs();
let remote_cwd_uri = PathUri::from_path(&remote_cwd)?;
test.fs()
.create_directory(
&remote_cwd,
&remote_cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -660,9 +663,10 @@ async fn apply_patch_approvals_are_remembered_per_environment() -> Result<()> {
SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis()
))
.abs();
let remote_cwd_uri = PathUri::from_path(&remote_cwd)?;
test.fs()
.create_directory(
&remote_cwd,
&remote_cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -842,9 +846,10 @@ async fn apply_patch_intercepted_exec_command_routes_to_selected_remote_environm
SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis()
))
.abs();
let remote_cwd_uri = PathUri::from_path(&remote_cwd)?;
test.fs()
.create_directory(
&remote_cwd,
&remote_cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -932,10 +937,11 @@ async fn remote_test_env_sandboxed_read_allows_readable_root() -> Result<()> {
let allowed_dir = PathBuf::from(format!("/tmp/codex-remote-readable-{}", std::process::id()));
let file_path = allowed_dir.join("note.txt");
let allowed_dir_uri = PathUri::from_path(&allowed_dir)?;
let file_path_uri = PathUri::from_path(&file_path)?;
file_system
.create_directory(
&absolute_path(allowed_dir.clone()),
&allowed_dir_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
+4 -1
View File
@@ -45,6 +45,7 @@ use codex_protocol::protocol::McpToolCallBeginEvent;
use codex_protocol::protocol::Op;
use codex_protocol::user_input::UserInput;
use codex_utils_cargo_bin::cargo_bin;
use codex_utils_path_uri::PathUri;
use core_test_support::assert_regex_match;
use core_test_support::remote_env_env_var;
use core_test_support::responses;
@@ -617,8 +618,10 @@ async fn stdio_server_uses_configured_cwd_before_runtime_fallback() -> anyhow::R
let fixture = test_codex()
.with_workspace_setup(|cwd, fs| async move {
let configured_cwd = cwd.join("mcp-configured-cwd");
let configured_cwd_uri = PathUri::from_path(&configured_cwd)?;
fs.create_directory(
&cwd.join("mcp-configured-cwd"),
&configured_cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
+2 -1
View File
@@ -30,8 +30,9 @@ async fn write_repo_skill(
body: &str,
) -> Result<()> {
let skill_dir = cwd.join(".agents").join("skills").join(name);
let skill_dir_uri = PathUri::from_path(&skill_dir)?;
fs.create_directory(
&skill_dir,
&skill_dir_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
+3 -1
View File
@@ -17,6 +17,7 @@ use codex_protocol::protocol::ExecCommandSource;
use codex_protocol::protocol::ExecCommandStatus;
use codex_protocol::protocol::Op;
use codex_protocol::user_input::UserInput;
use codex_utils_path_uri::PathUri;
use core_test_support::TempDirExt;
use core_test_support::assert_regex_match;
use core_test_support::managed_network_requirements_loader;
@@ -228,9 +229,10 @@ async fn create_workspace_directory(
rel_path: impl AsRef<std::path::Path>,
) -> Result<std::path::PathBuf> {
let abs_path = test.config.cwd.join(rel_path.as_ref());
let abs_path_uri = PathUri::from_path(&abs_path)?;
test.fs()
.create_directory(
&abs_path,
&abs_path_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
+6 -3
View File
@@ -134,9 +134,10 @@ fn png_bytes(width: u32, height: u32, rgba: [u8; 4]) -> anyhow::Result<Vec<u8>>
async fn create_workspace_directory(test: &TestCodex, rel_path: &str) -> anyhow::Result<PathBuf> {
let abs_path = test.config.cwd.join(rel_path);
let abs_path_uri = PathUri::from_path(&abs_path)?;
test.fs()
.create_directory(
&abs_path,
&abs_path_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -151,9 +152,10 @@ async fn write_workspace_file(
) -> anyhow::Result<PathBuf> {
let abs_path = test.config.cwd.join(rel_path);
if let Some(parent) = abs_path.parent() {
let parent_uri = PathUri::from_path(&parent)?;
test.fs()
.create_directory(
&parent,
&parent_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -579,9 +581,10 @@ async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()
))
.abs();
let image_path = remote_cwd.join("remote.png");
let remote_cwd_uri = PathUri::from_path(&remote_cwd)?;
test.fs()
.create_directory(
&remote_cwd,
&remote_cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
+3 -1
View File
@@ -214,9 +214,11 @@ pub(crate) async fn run_direct_request(
Ok(FsHelperPayload::WriteFile(FsWriteFileResponse {}))
}
FsHelperRequest::CreateDirectory(params) => {
let path =
codex_utils_path_uri::PathUri::from_abs_path(&params.path).map_err(map_fs_error)?;
file_system
.create_directory(
&params.path,
&path,
CreateDirectoryOptions {
recursive: params.recursive.unwrap_or(true),
},
@@ -110,7 +110,7 @@ impl ExecutorFileSystem for LocalFileSystem {
async fn create_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
options: CreateDirectoryOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
@@ -194,7 +194,7 @@ impl ExecutorFileSystem for UnsandboxedFileSystem {
async fn create_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
options: CreateDirectoryOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
@@ -299,11 +299,12 @@ impl ExecutorFileSystem for DirectFileSystem {
async fn create_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
options: CreateDirectoryOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
reject_sandbox_context(sandbox)?;
let path = path.to_abs_path()?;
if options.recursive {
tokio::fs::create_dir_all(path.as_path()).await?;
} else {
@@ -104,15 +104,16 @@ impl ExecutorFileSystem for RemoteFileSystem {
async fn create_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
options: CreateDirectoryOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
trace!("remote fs create_directory");
let path = path.to_abs_path()?;
let client = self.client.get().await.map_err(map_remote_error)?;
client
.fs_create_directory(FsCreateDirectoryParams {
path: path.clone(),
path,
recursive: Some(options.recursive),
sandbox: remote_sandbox_context(sandbox),
})
@@ -121,7 +121,7 @@ impl ExecutorFileSystem for SandboxedFileSystem {
async fn create_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
options: CreateDirectoryOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
@@ -129,7 +129,7 @@ impl ExecutorFileSystem for SandboxedFileSystem {
self.run_sandboxed(
sandbox,
FsHelperRequest::CreateDirectory(FsCreateDirectoryParams {
path: path.clone(),
path: path.to_abs_path()?,
recursive: Some(options.recursive),
sandbox: None,
}),
@@ -86,9 +86,10 @@ impl FileSystemHandler {
params: FsCreateDirectoryParams,
) -> Result<FsCreateDirectoryResponse, JSONRPCErrorError> {
let recursive = params.recursive.unwrap_or(true);
let path = PathUri::from_abs_path(&params.path).map_err(map_fs_error)?;
self.file_system
.create_directory(
&params.path,
&path,
CreateDirectoryOptions { recursive },
params.sandbox.as_ref(),
)
@@ -96,7 +96,7 @@ async fn file_system_create_directory_creates_nested_directories(
file_system
.create_directory(
&absolute_path(&nested_dir),
&PathUri::from_path(&nested_dir)?,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -475,7 +475,7 @@ async fn file_system_create_directory_rejects_symlink_escape(
let sandbox = workspace_write_sandbox(allowed_dir);
let error = match file_system
.create_directory(
&absolute_path(&requested_path),
&PathUri::from_path(&requested_path)?,
CreateDirectoryOptions { recursive: false },
Some(&sandbox),
)
@@ -94,7 +94,7 @@ impl ExecutorFileSystem for SyntheticFileSystem {
async fn create_directory(
&self,
_path: &AbsolutePathBuf,
_path: &PathUri,
_options: CreateDirectoryOptions,
_sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
+1 -1
View File
@@ -166,7 +166,7 @@ pub trait ExecutorFileSystem: Send + Sync {
async fn create_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
create_directory_options: CreateDirectoryOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()>;