mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
codex: address PR review feedback (#27337)
This commit is contained in:
@@ -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::<Vec<_>>();
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user