From 053302d4fede9f9876f60b1eccc79312d06bfc1e Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 10 Jun 2026 00:51:46 -0700 Subject: [PATCH] codex: address PR review feedback (#27337) --- .../src/chatwidget/tests/goal_validation.rs | 21 +++++++++++++++ .../src/chatwidget/tests/slash_commands.rs | 6 ++--- codex-rs/tui/src/goal_files.rs | 27 ++++++++++++++----- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/codex-rs/tui/src/chatwidget/tests/goal_validation.rs b/codex-rs/tui/src/chatwidget/tests/goal_validation.rs index 74300239ba..e706bff7c0 100644 --- a/codex-rs/tui/src/chatwidget/tests/goal_validation.rs +++ b/codex-rs/tui/src/chatwidget/tests/goal_validation.rs @@ -177,6 +177,27 @@ async fn goal_slash_command_materializes_large_paste() { assert_no_submit_op(&mut op_rx); } +#[tokio::test] +async fn goal_slash_command_rejects_whitespace_only_large_paste() { + let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.set_feature_enabled(Feature::Goals, /*enabled*/ true); + chat.thread_id = Some(ThreadId::new()); + chat.bottom_pane + .set_composer_text("/goal ".to_string(), Vec::new(), Vec::new()); + chat.handle_paste(" ".repeat(MAX_THREAD_GOAL_OBJECTIVE_CHARS + 1)); + + submit_current_composer(&mut chat); + + let events = std::iter::from_fn(|| rx.try_recv().ok()).collect::>(); + assert!( + events + .iter() + .all(|event| !matches!(event, AppEvent::SetThreadGoalObjective { .. })), + "expected no goal objective event, got {events:?}" + ); + assert_no_submit_op(&mut op_rx); +} + #[tokio::test] async fn queued_goal_materialization_error_drains_next_input() { let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await; diff --git a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs index caed65f2fc..b084f72b86 100644 --- a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs +++ b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs @@ -669,8 +669,8 @@ async fn goal_slash_command_materializes_attached_images() { let local_image = chat.config.codex_home.join("goal-local.png"); std::fs::write(&local_image, b"png bytes").expect("write local image"); let placeholder = "[Image #2]"; - let command = format!("/goal describe {placeholder}"); - let placeholder_start = command.find(placeholder).expect("placeholder in command"); + let command = format!("/goal literal {placeholder} describe {placeholder}"); + let placeholder_start = command.rfind(placeholder).expect("placeholder in command"); chat.set_remote_image_urls(vec![remote_url.clone()]); chat.bottom_pane.set_composer_text( command, @@ -693,7 +693,7 @@ async fn goal_slash_command_materializes_attached_images() { panic!("expected SetThreadGoalObjective, got {event:?}"); }; assert_eq!(actual_thread_id, thread_id); - assert!(objective.contains("describe image file: ")); + assert!(objective.contains(&format!("literal {placeholder} describe image file: "))); assert!(objective.contains("Referenced image URLs:")); assert!(objective.contains(&remote_url)); let copied_image = objective diff --git a/codex-rs/tui/src/goal_files.rs b/codex-rs/tui/src/goal_files.rs index 5571a45a43..8e01cdad63 100644 --- a/codex-rs/tui/src/goal_files.rs +++ b/codex-rs/tui/src/goal_files.rs @@ -35,6 +35,15 @@ pub(crate) fn materialize_goal_draft(codex_home: &Path, draft: GoalDraft) -> Res if objective.trim().is_empty() { bail!("Goal objective must not be empty."); } + let text_elements = draft.text_elements; + let (validation_objective, _) = ChatComposer::expand_pending_pastes( + &objective, + text_elements.clone(), + &draft.pending_pastes, + ); + if validation_objective.trim().is_empty() { + bail!("Goal objective must not be empty."); + } let mut output_dir = None; let mut materialized_pastes = Vec::new(); @@ -50,11 +59,12 @@ pub(crate) fn materialize_goal_draft(codex_home: &Path, draft: GoalDraft) -> Res )); } } - let (expanded_objective, _) = - ChatComposer::expand_pending_pastes(&objective, draft.text_elements, &materialized_pastes); - objective = expanded_objective.trim().to_string(); + let (expanded_objective, text_elements) = + ChatComposer::expand_pending_pastes(&objective, text_elements, &materialized_pastes); + objective = expanded_objective; let mut image_lines = Vec::new(); + let mut materialized_images = Vec::new(); for (idx, image) in draft.local_images.iter().enumerate() { let extension = image_extension(&image.path); let path = ensure_output_dir(codex_home, &mut output_dir)?.join(format!( @@ -72,12 +82,15 @@ pub(crate) fn materialize_goal_draft(codex_home: &Path, draft: GoalDraft) -> Res if image.placeholder.is_empty() { image_lines.push(format!("- [Image #{}]: {}", idx + 1, path.display())); } else { - objective = objective.replace( - &image.placeholder, - &format!("image file: {}", path.display()), - ); + materialized_images.push(( + image.placeholder.clone(), + format!("image file: {}", path.display()), + )); } } + let (expanded_objective, _) = + ChatComposer::expand_pending_pastes(&objective, text_elements, &materialized_images); + objective = expanded_objective.trim().to_string(); append_section(&mut objective, "Referenced image files:", image_lines); append_section(