mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Preserve executor path URIs in permission profile workspace roots (#45863)
## Why Executor profile roots can use path conventions that are not native to the current host. Converting them to host paths during configuration or turn reconstruction can reject or drop those roots, while case-insensitive comparison can hide Windows path spelling changes. ## What changed - Store profile roots as URI-backed `ProfileWorkspaceRoot` values throughout permission snapshots and thread settings, preserving spelling in equality and deduplication. - Keep effective workspace roots as `PathUri` values for permission materialization and status summaries. Convert Windows sandbox root hints to native paths only at native Windows sandbox boundaries, rejecting incompatible roots. - Omit the legacy rollout `workspace_roots` field when profile roots cannot be represented as host paths, retaining the compiled permission profile. ## Testing Add regression coverage for Windows and UNC root spelling changes, settings restoration and turn recording with foreign roots, executor-root status display, and backend-specific Windows root conversion. GitOrigin-RevId: 903c068fd74959bdd10e7cb1141aa42b953a59a4
This commit is contained in:
@@ -1195,39 +1195,72 @@ fn process_exec_tool_call_uses_platform_sandbox_for_network_only_restrictions()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_exec_request_preserves_windows_workspace_roots() -> Result<()> {
|
||||
fn build_exec_request_projects_workspace_roots_only_for_windows_sandbox() -> Result<()> {
|
||||
let temp_dir = tempfile::TempDir::new()?;
|
||||
let cwd = temp_dir.path().abs();
|
||||
let additional_root = temp_dir.path().join("additional").abs();
|
||||
let workspace_roots = vec![cwd.clone(), additional_root];
|
||||
|
||||
let exec_request = build_exec_request(
|
||||
ExecParams {
|
||||
command: vec!["echo".to_string(), "ok".to_string()],
|
||||
cwd: cwd.clone(),
|
||||
expiration: ExecExpiration::DefaultTimeout,
|
||||
capture_policy: ExecCapturePolicy::ShellTool,
|
||||
env: HashMap::new(),
|
||||
network: None,
|
||||
network_environment_id: None,
|
||||
sandbox_permissions: SandboxPermissions::UseDefault,
|
||||
windows_sandbox_level: WindowsSandboxLevel::Disabled,
|
||||
windows_sandbox_private_desktop: false,
|
||||
justification: None,
|
||||
arg0: None,
|
||||
},
|
||||
&PermissionProfile::Disabled,
|
||||
&cwd,
|
||||
workspace_roots.as_slice(),
|
||||
&None,
|
||||
/*codex_self_exe*/ &None,
|
||||
/*use_legacy_landlock*/ false,
|
||||
let build_request = |profile: &PermissionProfile, roots: &[PathUri]| {
|
||||
build_exec_request(
|
||||
ExecParams {
|
||||
command: vec!["echo".to_string(), "ok".to_string()],
|
||||
cwd: cwd.clone(),
|
||||
expiration: ExecExpiration::DefaultTimeout,
|
||||
capture_policy: ExecCapturePolicy::ShellTool,
|
||||
env: HashMap::new(),
|
||||
network: None,
|
||||
network_environment_id: None,
|
||||
sandbox_permissions: SandboxPermissions::UseDefault,
|
||||
windows_sandbox_level: WindowsSandboxLevel::RestrictedToken,
|
||||
windows_sandbox_private_desktop: false,
|
||||
justification: None,
|
||||
arg0: None,
|
||||
},
|
||||
profile,
|
||||
&cwd,
|
||||
roots,
|
||||
&Some(temp_dir.path().join("codex-linux-sandbox")),
|
||||
/*codex_self_exe*/ &None,
|
||||
/*use_legacy_landlock*/ false,
|
||||
)
|
||||
};
|
||||
let native_roots = vec![cwd.clone(), temp_dir.path().join("additional").abs()];
|
||||
let request = build_request(
|
||||
&PermissionProfile::read_only(),
|
||||
&native_roots
|
||||
.iter()
|
||||
.map(PathUri::from_abs_path)
|
||||
.collect::<Vec<_>>(),
|
||||
)?;
|
||||
|
||||
assert_eq!(
|
||||
exec_request.windows_sandbox_workspace_roots,
|
||||
workspace_roots
|
||||
request.windows_sandbox_workspace_roots,
|
||||
if cfg!(windows) {
|
||||
native_roots
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
);
|
||||
|
||||
let foreign_root = PathUri::parse(if cfg!(windows) {
|
||||
"file:///workspace"
|
||||
} else {
|
||||
"file:///C:/workspace"
|
||||
})
|
||||
.expect("foreign workspace URI");
|
||||
let roots = [PathUri::from_abs_path(&cwd), foreign_root];
|
||||
assert_eq!(
|
||||
build_request(&PermissionProfile::Disabled, &roots)?.windows_sandbox_workspace_roots,
|
||||
Vec::new(),
|
||||
);
|
||||
let request = build_request(&PermissionProfile::read_only(), &roots);
|
||||
if cfg!(windows) {
|
||||
let error = request.expect_err("native Windows sandbox must reject foreign roots");
|
||||
assert!(matches!(
|
||||
error.details(),
|
||||
codex_protocol::error::CodexErrorDetails::InvalidRequest(message)
|
||||
if message.starts_with("invalid Windows sandbox workspace roots:")
|
||||
));
|
||||
} else {
|
||||
assert_eq!(request?.windows_sandbox_workspace_roots, Vec::new());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user