mirror of
https://github.com/openai/codex.git
synced 2026-05-16 01:02:48 +00:00
codex: fix apply_patch self-review follow-ups
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -322,7 +322,8 @@ pub(crate) fn guardian_approval_request_to_json(
|
||||
"files": files,
|
||||
"patch": patch,
|
||||
});
|
||||
if environment_id != codex_exec_server::LOCAL_ENVIRONMENT_ID
|
||||
if !environment_id.is_empty()
|
||||
&& environment_id != codex_exec_server::LOCAL_ENVIRONMENT_ID
|
||||
&& let Value::Object(object) = &mut value
|
||||
{
|
||||
object.insert(
|
||||
|
||||
@@ -719,6 +719,24 @@ fn format_guardian_action_pretty_reports_no_truncation_for_small_payload() -> se
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_guardian_action_pretty_omits_empty_apply_patch_environment_id() -> serde_json::Result<()>
|
||||
{
|
||||
let action = GuardianApprovalRequest::ApplyPatch {
|
||||
id: "patch-1".to_string(),
|
||||
environment_id: String::new(),
|
||||
cwd: test_path_buf("/tmp").abs(),
|
||||
files: Vec::new(),
|
||||
patch: "line\n".to_string(),
|
||||
};
|
||||
|
||||
let rendered = format_guardian_action_pretty(&action)?;
|
||||
|
||||
assert!(rendered.text.contains("\"tool\": \"apply_patch\""));
|
||||
assert!(!rendered.text.contains("environment_id"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_approval_request_to_json_renders_mcp_tool_call_shape() -> serde_json::Result<()> {
|
||||
let action = GuardianApprovalRequest::McpToolCall {
|
||||
|
||||
@@ -329,10 +329,10 @@ fn apply_patch_hook_tool_input(
|
||||
Ok(None) => return Some((tool_input, None)),
|
||||
Err(_) => return None,
|
||||
};
|
||||
if selected_environment.environment_id == codex_exec_server::LOCAL_ENVIRONMENT_ID {
|
||||
return Some((tool_input, None));
|
||||
}
|
||||
let cwd = Some(selected_environment.cwd.clone());
|
||||
if selected_environment.environment_id == codex_exec_server::LOCAL_ENVIRONMENT_ID {
|
||||
return Some((tool_input, cwd));
|
||||
}
|
||||
|
||||
if let Some(object) = tool_input.as_object_mut() {
|
||||
object.insert(
|
||||
|
||||
@@ -122,7 +122,7 @@ async fn pre_tool_use_payload_omits_local_environment_context_for_multi_environm
|
||||
handler.pre_tool_use_payload(&invocation),
|
||||
Some(PreToolUsePayload {
|
||||
tool_name: HookToolName::apply_patch(),
|
||||
cwd: None,
|
||||
cwd: Some(invocation.turn.cwd.clone()),
|
||||
tool_input: json!({ "command": patch }),
|
||||
})
|
||||
);
|
||||
@@ -182,7 +182,7 @@ async fn pre_tool_use_payload_uses_freeform_remote_environment_header() {
|
||||
tool_name: HookToolName::apply_patch(),
|
||||
cwd: Some(environment.cwd.clone()),
|
||||
tool_input: json!({
|
||||
"command": patch,
|
||||
"command": sample_patch(),
|
||||
"environment_id": &environment.environment_id,
|
||||
"cwd": &environment.cwd,
|
||||
}),
|
||||
|
||||
@@ -447,6 +447,7 @@ mod tests {
|
||||
fn apply_patch_approval_request_deserializes_legacy_shape_without_cwd() {
|
||||
let event: ApplyPatchApprovalRequestEvent = serde_json::from_value(serde_json::json!({
|
||||
"call_id": "call-1",
|
||||
"started_at_ms": 0,
|
||||
"changes": {},
|
||||
}))
|
||||
.expect("legacy apply patch approval request should deserialize");
|
||||
|
||||
@@ -1122,6 +1122,10 @@ mod tests {
|
||||
[
|
||||
(absolute_path("/tmp/readme.txt"), "/tmp/readme.txt"),
|
||||
(absolute_path("/tmp/out.txt"), "/tmp/out.txt"),
|
||||
(
|
||||
absolute_path("/tmp/remote-worktree"),
|
||||
"/tmp/remote-worktree",
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.fold(rendered, |rendered, (path, normalized)| {
|
||||
@@ -2043,7 +2047,7 @@ mod tests {
|
||||
keymap.approval,
|
||||
keymap.list,
|
||||
);
|
||||
let rendered = render_overlay_lines(&view, /*width*/ 120);
|
||||
let rendered = normalize_snapshot_paths(render_overlay_lines(&view, /*width*/ 120));
|
||||
assert_snapshot!(
|
||||
"approval_overlay_apply_patch_remote_prompt",
|
||||
rendered.as_str()
|
||||
|
||||
Reference in New Issue
Block a user