mirror of
https://github.com/openai/codex.git
synced 2026-11-14 21:40:39 +00:00
app-server: preserve legacy cwd strings in exec events
This commit is contained in:
@@ -35,8 +35,8 @@ use codex_protocol::protocol::PatchApplyBeginEvent;
|
||||
use codex_protocol::protocol::PatchApplyEndEvent;
|
||||
use codex_shell_command::parse_command::parse_command;
|
||||
use codex_shell_command::parse_command::shlex_join;
|
||||
use codex_utils_path_uri::LegacyAppPathString;
|
||||
use codex_utils_path_uri::PathConvention;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use tracing::warn;
|
||||
@@ -90,11 +90,11 @@ pub fn build_command_execution_approval_request_item(
|
||||
}
|
||||
|
||||
pub fn build_command_execution_begin_item(payload: &ExecCommandBeginEvent) -> ThreadItem {
|
||||
let command_actions = command_actions_for_path_uri(&payload.parsed_cmd, &payload.cwd);
|
||||
let command_actions = command_actions_for_legacy_cwd(&payload.parsed_cmd, &payload.cwd);
|
||||
ThreadItem::CommandExecution {
|
||||
id: payload.call_id.clone(),
|
||||
command: shlex_join(&payload.command),
|
||||
cwd: payload.cwd.clone().into(),
|
||||
cwd: payload.cwd.clone(),
|
||||
process_id: payload.process_id.clone(),
|
||||
source: payload.source.into(),
|
||||
status: CommandExecutionStatus::InProgress,
|
||||
@@ -112,12 +112,12 @@ pub fn build_command_execution_end_item(payload: &ExecCommandEndEvent) -> Thread
|
||||
Some(payload.aggregated_output.clone())
|
||||
};
|
||||
let duration_ms = i64::try_from(payload.duration.as_millis()).unwrap_or(i64::MAX);
|
||||
let command_actions = command_actions_for_path_uri(&payload.parsed_cmd, &payload.cwd);
|
||||
let command_actions = command_actions_for_legacy_cwd(&payload.parsed_cmd, &payload.cwd);
|
||||
|
||||
ThreadItem::CommandExecution {
|
||||
id: payload.call_id.clone(),
|
||||
command: shlex_join(&payload.command),
|
||||
cwd: payload.cwd.clone().into(),
|
||||
cwd: payload.cwd.clone(),
|
||||
process_id: payload.process_id.clone(),
|
||||
source: payload.source.into(),
|
||||
status: (&payload.status).into(),
|
||||
@@ -128,14 +128,19 @@ pub fn build_command_execution_end_item(payload: &ExecCommandEndEvent) -> Thread
|
||||
}
|
||||
}
|
||||
|
||||
fn command_actions_for_path_uri(parsed_cmd: &[ParsedCommand], cwd: &PathUri) -> Vec<CommandAction> {
|
||||
fn command_actions_for_legacy_cwd(
|
||||
parsed_cmd: &[ParsedCommand],
|
||||
cwd: &LegacyAppPathString,
|
||||
) -> Vec<CommandAction> {
|
||||
// TODO(anp): Carry PathUri into CommandAction so foreign Read actions retain resolved paths.
|
||||
// Until then, omit those actions rather than project a foreign cwd onto the host.
|
||||
let native_cwd = if cwd.infer_path_convention() == Some(PathConvention::native()) {
|
||||
cwd.to_abs_path().ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let native_cwd = cwd.to_inferred_path_uri().and_then(|cwd| {
|
||||
if cwd.infer_path_convention() == Some(PathConvention::native()) {
|
||||
cwd.to_abs_path().ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
parsed_cmd
|
||||
.iter()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
@@ -25,7 +26,7 @@ fn foreign_read_is_omitted_without_dropping_other_command_actions() {
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
command_actions_for_path_uri(&parsed_cmd, &cwd),
|
||||
command_actions_for_legacy_cwd(&parsed_cmd, &cwd.into()),
|
||||
vec![
|
||||
CommandAction::ListFiles {
|
||||
command: "ls".to_string(),
|
||||
@@ -39,3 +40,32 @@ fn foreign_read_is_omitted_without_dropping_other_command_actions() {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_file_uri_cwd_is_converted_for_command_actions() {
|
||||
#[cfg(windows)]
|
||||
let raw_uri = "file:///C:/src";
|
||||
#[cfg(not(windows))]
|
||||
let raw_uri = "file:///usr/local/src";
|
||||
let expected_path = PathUri::parse(raw_uri)
|
||||
.expect("raw file URI should parse")
|
||||
.to_abs_path()
|
||||
.expect("raw file URI should be native")
|
||||
.join("file.txt");
|
||||
let cwd = serde_json::from_value::<LegacyAppPathString>(serde_json::json!(raw_uri))
|
||||
.expect("raw file URI should deserialize as a legacy API path");
|
||||
let parsed_cmd = vec![ParsedCommand::Read {
|
||||
cmd: "cat file.txt".to_string(),
|
||||
name: "file.txt".to_string(),
|
||||
path: PathBuf::from("file.txt"),
|
||||
}];
|
||||
|
||||
assert_eq!(
|
||||
command_actions_for_legacy_cwd(&parsed_cmd, &cwd),
|
||||
vec![CommandAction::Read {
|
||||
command: "cat file.txt".to_string(),
|
||||
name: "file.txt".to_string(),
|
||||
path: expected_path,
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user