exec-server: carry cwd as PathUri

This commit is contained in:
Adam Perry
2026-06-13 06:26:43 +00:00
parent f5dfe0cb26
commit fe560a0e13
12 changed files with 82 additions and 33 deletions
+2 -1
View File
@@ -887,7 +887,8 @@ mod tests {
.start(crate::ExecParams {
process_id: ProcessId::from("default-env-proc"),
argv: vec!["true".to_string()],
cwd: std::env::current_dir().expect("read current dir"),
cwd: PathUri::from_path(std::env::current_dir().expect("read current dir"))
.expect("cwd URI"),
env_policy: None,
env: Default::default(),
tty: false,
+13 -11
View File
@@ -156,6 +156,12 @@ impl LocalProcess {
.argv
.split_first()
.ok_or_else(|| invalid_params("argv must not be empty".to_string()))?;
let cwd = params.cwd.to_abs_path().map_err(|err| {
invalid_params(format!(
"cwd `{}` is not native to this exec-server host: {err}",
params.cwd
))
})?;
{
let mut process_map = self.inner.processes.lock().await;
@@ -172,26 +178,20 @@ impl LocalProcess {
codex_utils_pty::spawn_pty_process(
program,
args,
params.cwd.as_path(),
cwd.as_path(),
&env,
&params.arg0,
TerminalSize::default(),
)
.await
} else if params.pipe_stdin {
codex_utils_pty::spawn_pipe_process(
program,
args,
params.cwd.as_path(),
&env,
&params.arg0,
)
.await
codex_utils_pty::spawn_pipe_process(program, args, cwd.as_path(), &env, &params.arg0)
.await
} else {
codex_utils_pty::spawn_pipe_process_no_stdin(
program,
args,
params.cwd.as_path(),
cwd.as_path(),
&env,
&params.arg0,
)
@@ -783,16 +783,18 @@ fn notification_sender(inner: &Inner) -> Option<RpcNotificationSender> {
mod tests {
use super::*;
use codex_protocol::config_types::ShellEnvironmentPolicyInherit;
use codex_utils_path_uri::PathUri;
use codex_utils_pty::ProcessDriver;
use pretty_assertions::assert_eq;
use tokio::sync::oneshot;
use tokio::time::timeout;
fn test_exec_params(env: HashMap<String, String>) -> ExecParams {
let cwd = std::env::current_dir().expect("current directory");
ExecParams {
process_id: ProcessId::from("env-test"),
argv: vec!["true".to_string()],
cwd: std::path::PathBuf::from("/tmp"),
cwd: PathUri::from_path(cwd).expect("cwd URI"),
env_policy: None,
env,
tty: false,
+36 -2
View File
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::path::PathBuf;
use crate::FileSystemSandboxContext;
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
@@ -103,7 +102,8 @@ pub struct ExecParams {
/// This is a protocol key, not an OS pid.
pub process_id: ProcessId,
pub argv: Vec<String>,
pub cwd: PathBuf,
/// Absolute working directory, converted to a native path by the executing server.
pub cwd: PathUri,
#[serde(default)]
pub env_policy: Option<ExecEnvPolicy>,
pub env: HashMap<String, String>,
@@ -465,15 +465,49 @@ mod base64_bytes {
#[cfg(test)]
mod tests {
use super::EnvironmentInfo;
use super::ExecParams;
use super::FsReadFileParams;
use super::HttpRequestParams;
use super::ShellInfo;
use crate::FileSystemSandboxContext;
use crate::ProcessId;
use codex_protocol::models::PermissionProfile;
use codex_utils_path_uri::PathConvention;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
#[test]
fn exec_protocol_accepts_legacy_native_cwd_and_serializes_path_uri() {
let legacy_cwd = std::env::current_dir().expect("current directory");
let expected_cwd = PathUri::from_path(&legacy_cwd).expect("cwd URI");
let params: ExecParams = serde_json::from_value(serde_json::json!({
"processId": "legacy-cwd",
"argv": ["example"],
"cwd": legacy_cwd.to_string_lossy(),
"env": {},
"tty": false,
"pipeStdin": false,
"arg0": null,
}))
.expect("legacy native cwd should deserialize");
let expected = ExecParams {
process_id: ProcessId::from("legacy-cwd"),
argv: vec!["example".to_string()],
cwd: expected_cwd.clone(),
env_policy: None,
env: Default::default(),
tty: false,
pipe_stdin: false,
arg0: None,
};
assert_eq!(params, expected);
assert_eq!(
serde_json::to_value(params).expect("params should serialize")["cwd"],
expected_cwd.to_string()
);
}
#[test]
fn filesystem_protocol_accepts_legacy_absolute_paths_and_serializes_path_uris() {
let legacy_path = std::env::current_dir()
@@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
use tokio::sync::mpsc;
use uuid::Uuid;
@@ -26,7 +27,7 @@ fn exec_params_with_argv(process_id: &str, argv: Vec<String>) -> ExecParams {
ExecParams {
process_id: ProcessId::from(process_id),
argv,
cwd: std::env::current_dir().expect("cwd"),
cwd: PathUri::from_path(std::env::current_dir().expect("cwd")).expect("cwd URI"),
env_policy: None,
env: inherited_path_env(),
tty: false,
+2 -1
View File
@@ -195,6 +195,7 @@ mod tests {
use codex_app_server_protocol::JSONRPCRequest;
use codex_app_server_protocol::JSONRPCResponse;
use codex_app_server_protocol::RequestId;
use codex_utils_path_uri::PathUri;
use serde::Serialize;
use serde::de::DeserializeOwned;
use tokio::io::AsyncBufReadExt;
@@ -396,7 +397,7 @@ mod tests {
ExecParams {
process_id,
argv: sleep_then_print_argv(),
cwd: std::env::current_dir().expect("cwd"),
cwd: PathUri::from_path(std::env::current_dir().expect("cwd")).expect("cwd URI"),
env_policy: None,
env,
tty: false,