mirror of
https://github.com/openai/codex.git
synced 2026-09-16 12:13:30 +00:00
fix(core): preserve absolute workdir paths
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -924,9 +924,12 @@ impl TurnContext {
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_path(&self, path: Option<String>) -> PathBuf {
|
||||
path.as_ref()
|
||||
.map(PathBuf::from)
|
||||
.map_or_else(|| self.cwd.clone(), |p| self.cwd.join(p))
|
||||
path.as_ref().map(PathBuf::from).map_or_else(
|
||||
|| self.cwd.clone(),
|
||||
|p| {
|
||||
if p.is_absolute() { p } else { self.cwd.join(p) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn compact_prompt(&self) -> &str {
|
||||
|
||||
@@ -112,6 +112,39 @@ async fn shell_command_handler_to_exec_params_uses_session_shell_and_turn_contex
|
||||
assert_eq!(exec_params.arg0, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn shell_command_handler_to_exec_params_preserves_absolute_workdir() {
|
||||
let (session, turn_context) = make_session_and_context().await;
|
||||
let absolute_workdir = turn_context.cwd.join("absolute-subdir");
|
||||
let expected_env = create_env(
|
||||
&turn_context.shell_environment_policy,
|
||||
Some(session.conversation_id),
|
||||
);
|
||||
|
||||
let params = ShellCommandToolCallParams {
|
||||
command: "echo hello".to_string(),
|
||||
workdir: Some(absolute_workdir.to_string_lossy().to_string()),
|
||||
login: None,
|
||||
timeout_ms: Some(250),
|
||||
sandbox_permissions: Some(SandboxPermissions::UseDefault),
|
||||
additional_permissions: None,
|
||||
prefix_rule: None,
|
||||
justification: None,
|
||||
};
|
||||
|
||||
let exec_params = ShellCommandHandler::to_exec_params(
|
||||
¶ms,
|
||||
&session,
|
||||
&turn_context,
|
||||
session.conversation_id,
|
||||
true,
|
||||
)
|
||||
.expect("absolute workdir should be accepted");
|
||||
|
||||
assert_eq!(exec_params.cwd, absolute_workdir);
|
||||
assert_eq!(exec_params.env, expected_env);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_command_handler_respects_explicit_login_flag() {
|
||||
let (_tx, shell_snapshot) = watch::channel(Some(Arc::new(ShellSnapshot {
|
||||
|
||||
Reference in New Issue
Block a user