mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
## Stack 1. [1 of 3] Support long raw TUI goal objectives - #27508 2. **[2 of 3] Support long pasted text in TUI goals** - this PR 3. [3 of 3] Support images in TUI goals - #27510 ## Why Large text pasted into the TUI composer is represented as a paste placeholder plus pending paste metadata. For `/goal`, preserving only the visible placeholder is not enough: the agent would see a short placeholder string instead of the actual pasted text, and the long-text support from the first PR would never see the payload. The TUI also needs to avoid writing stale sidecar files when a user pastes a large block and then deletes its placeholder before submitting the goal. ## What Changed - Introduces a TUI `GoalDraft` for goal submissions so `/goal`, `/goal edit`, and queued goal commands can carry objective text plus text elements and pending paste payloads. - Materializes active pasted-text placeholders to `pasted-text-N.txt` files through the app-server filesystem path introduced in #27508. - Rewrites active paste placeholders in the persisted objective to file references, while leaving literal placeholder-looking text alone. - Filters out deleted paste placeholders so otherwise-small goals do not require `$CODEX_HOME` or remote filesystem writes. - Preserves pending paste metadata when a `/goal` command is queued before a thread exists. ## Verification - Added goal materialization tests for active paste placeholders, deleted paste placeholders, and whitespace-only paste payloads. - Added/updated TUI slash-command tests for large pasted text, queued `/goal` commands before thread start, and queued oversized goal behavior. ## Manual Testing - Used real terminal bracketed-paste sequences through a remote TUI session. A 1,228-byte multiline paste became `pasted-text-1.txt`; its first/last lines and byte count matched exactly, and the persisted objective referenced the server-host path. - Pasted a large block, deleted its placeholder, and submitted a small replacement objective. No new directory or sidecar file was created. - Added two same-length large pastes to one goal. The composer disambiguated their visible placeholders, and materialization preserved order and contents in `pasted-text-1.txt` and `pasted-text-2.txt`. - Submitted a whitespace-only large paste and verified the goal was rejected as empty without writing a file. - Submitted a pasted-text replacement while another goal was active, verified no file was written before confirmation, then canceled and confirmed the original goal remained unchanged. - Combined a large paste with enough raw text to exceed 4,000 characters after placeholder rewriting. The paste sidecar and `goal-objective.md` were created in the same remote attachment directory, and `/goal edit` restored the rewritten objective with its sidecar reference.
283 lines
8.6 KiB
Rust
283 lines
8.6 KiB
Rust
use super::*;
|
|
|
|
#[tokio::test]
|
|
async fn goal_menu_active_snapshot() {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_summary(test_goal(
|
|
thread_id,
|
|
AppThreadGoalStatus::Active,
|
|
/*token_budget*/ Some(80_000),
|
|
));
|
|
|
|
assert_chatwidget_snapshot!("goal_menu_active", rendered_goal_summary(&mut rx));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn goal_menu_paused_snapshot() {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_summary(test_goal(
|
|
thread_id,
|
|
AppThreadGoalStatus::Paused,
|
|
/*token_budget*/ None,
|
|
));
|
|
|
|
assert_chatwidget_snapshot!("goal_menu_paused", rendered_goal_summary(&mut rx));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn goal_menu_blocked_snapshot() {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_summary(test_goal(
|
|
thread_id,
|
|
AppThreadGoalStatus::Blocked,
|
|
/*token_budget*/ None,
|
|
));
|
|
|
|
assert_chatwidget_snapshot!("goal_menu_blocked", rendered_goal_summary(&mut rx));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn goal_menu_usage_limited_snapshot() {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_summary(test_goal(
|
|
thread_id,
|
|
AppThreadGoalStatus::UsageLimited,
|
|
/*token_budget*/ None,
|
|
));
|
|
|
|
assert_chatwidget_snapshot!("goal_menu_usage_limited", rendered_goal_summary(&mut rx));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn goal_menu_budget_limited_snapshot() {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_summary(test_goal(
|
|
thread_id,
|
|
AppThreadGoalStatus::BudgetLimited,
|
|
/*token_budget*/ Some(80_000),
|
|
));
|
|
|
|
assert_chatwidget_snapshot!("goal_menu_budget_limited", rendered_goal_summary(&mut rx));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn resume_paused_goal_prompt_snapshot() {
|
|
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_resume_paused_goal_prompt(
|
|
thread_id,
|
|
"Keep improving the bare goal command until it feels calm and useful.".to_string(),
|
|
);
|
|
|
|
assert_chatwidget_snapshot!(
|
|
"resume_paused_goal_prompt",
|
|
render_bottom_popup(&chat, /*width*/ 100)
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn goal_edit_prompt_snapshot() {
|
|
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_edit_prompt(
|
|
thread_id,
|
|
test_goal(
|
|
thread_id,
|
|
AppThreadGoalStatus::Active,
|
|
/*token_budget*/ Some(80_000),
|
|
),
|
|
);
|
|
|
|
assert_chatwidget_snapshot!(
|
|
"goal_edit_prompt",
|
|
render_bottom_popup(&chat, /*width*/ 100)
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn goal_edit_prompt_submits_preserved_status_and_budget() {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_edit_prompt(
|
|
thread_id,
|
|
test_goal(
|
|
thread_id,
|
|
AppThreadGoalStatus::Paused,
|
|
/*token_budget*/ Some(80_000),
|
|
),
|
|
);
|
|
chat.handle_paste(" with clearer wording".to_string());
|
|
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
|
|
|
match rx.try_recv() {
|
|
Ok(AppEvent::SetThreadGoalDraft {
|
|
thread_id: event_thread_id,
|
|
draft,
|
|
mode:
|
|
crate::app_event::ThreadGoalSetMode::UpdateExisting {
|
|
status,
|
|
token_budget,
|
|
},
|
|
}) => {
|
|
assert_eq!(event_thread_id, thread_id);
|
|
assert_eq!(
|
|
draft.objective,
|
|
"Keep improving the bare goal command until it feels calm and useful. with clearer wording"
|
|
);
|
|
assert_eq!(status, AppThreadGoalStatus::Paused);
|
|
assert_eq!(token_budget, Some(80_000));
|
|
}
|
|
other => panic!("expected SetThreadGoalDraft event, got {other:?}"),
|
|
}
|
|
assert!(chat.no_modal_or_popup_active());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn goal_edit_prompt_preserves_resumable_stopped_statuses() {
|
|
for stopped_status in [
|
|
AppThreadGoalStatus::Blocked,
|
|
AppThreadGoalStatus::UsageLimited,
|
|
] {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_edit_prompt(
|
|
thread_id,
|
|
test_goal(
|
|
thread_id,
|
|
stopped_status,
|
|
/*token_budget*/ Some(80_000),
|
|
),
|
|
);
|
|
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
|
|
|
match rx.try_recv() {
|
|
Ok(AppEvent::SetThreadGoalDraft {
|
|
mode:
|
|
crate::app_event::ThreadGoalSetMode::UpdateExisting {
|
|
status,
|
|
token_budget,
|
|
},
|
|
..
|
|
}) => {
|
|
assert_eq!(status, stopped_status);
|
|
assert_eq!(token_budget, Some(80_000));
|
|
}
|
|
other => panic!("expected SetThreadGoalDraft event, got {other:?}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn goal_edit_prompt_resets_terminal_status_to_active() {
|
|
let cases = [
|
|
AppThreadGoalStatus::BudgetLimited,
|
|
AppThreadGoalStatus::Complete,
|
|
];
|
|
|
|
for terminal_status in cases {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_goal_edit_prompt(
|
|
thread_id,
|
|
test_goal(
|
|
thread_id,
|
|
terminal_status,
|
|
/*token_budget*/ Some(80_000),
|
|
),
|
|
);
|
|
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
|
|
|
match rx.try_recv() {
|
|
Ok(AppEvent::SetThreadGoalDraft {
|
|
mode:
|
|
crate::app_event::ThreadGoalSetMode::UpdateExisting {
|
|
status,
|
|
token_budget,
|
|
},
|
|
..
|
|
}) => {
|
|
assert_eq!(status, AppThreadGoalStatus::Active);
|
|
assert_eq!(token_budget, Some(80_000));
|
|
}
|
|
other => panic!("expected SetThreadGoalDraft event, got {other:?}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn resume_paused_goal_prompt_default_resumes_goal() {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_resume_paused_goal_prompt(thread_id, "Finish the paused goal.".to_string());
|
|
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
|
|
|
match rx.try_recv() {
|
|
Ok(AppEvent::SetThreadGoalStatus {
|
|
thread_id: event_thread_id,
|
|
status,
|
|
}) => {
|
|
assert_eq!(event_thread_id, thread_id);
|
|
assert_eq!(status, AppThreadGoalStatus::Active);
|
|
}
|
|
other => panic!("expected SetThreadGoalStatus event, got {other:?}"),
|
|
}
|
|
assert!(chat.no_modal_or_popup_active());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn resume_paused_goal_prompt_can_leave_goal_paused() {
|
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
|
let thread_id = ThreadId::new();
|
|
|
|
chat.show_resume_paused_goal_prompt(thread_id, "Finish the paused goal.".to_string());
|
|
chat.handle_key_event(KeyEvent::from(KeyCode::Down));
|
|
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
|
|
|
assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty)));
|
|
assert!(chat.no_modal_or_popup_active());
|
|
}
|
|
|
|
fn test_goal(
|
|
thread_id: ThreadId,
|
|
status: AppThreadGoalStatus,
|
|
token_budget: Option<i64>,
|
|
) -> AppThreadGoal {
|
|
AppThreadGoal {
|
|
thread_id: thread_id.to_string(),
|
|
objective: "Keep improving the bare goal command until it feels calm and useful."
|
|
.to_string(),
|
|
status,
|
|
token_budget,
|
|
tokens_used: 12_500,
|
|
time_used_seconds: 90,
|
|
created_at: 1_776_272_400,
|
|
updated_at: 1_776_272_460,
|
|
}
|
|
}
|
|
|
|
fn rendered_goal_summary(
|
|
rx: &mut tokio::sync::mpsc::UnboundedReceiver<crate::app_event::AppEvent>,
|
|
) -> String {
|
|
drain_insert_history(rx)
|
|
.iter()
|
|
.map(|lines| lines_to_single_string(lines))
|
|
.collect::<Vec<_>>()
|
|
.join("\n")
|
|
}
|