mirror of
https://github.com/openai/codex.git
synced 2026-11-18 15:01:48 +00:00
Refine hook activity rendering in the TUI (#42118)
## What changed - Show revealed running hooks in the bottom activity area instead of the conversation viewport or transcript overlay. Fold the hook message into the active status row when space permits and reflow it below the row without displacing background-process controls or status details. - Keep fast hooks hidden, collapse concurrent hooks to a shared summary when needed, and support hook activity outside an active agent turn. - Simplify durable hook output into user-facing messages and actionable failure, block, and stop states. Suppress model-facing context and quiet successful completions from all TUI history surfaces. ## Testing - Add lifecycle, layout, narrow-width, multi-width Unicode, transcript, restart, and completion-output coverage for hook status and history rendering. GitOrigin-RevId: 4c52b7a736e9e466e109107eb3c04a39d089597f
This commit is contained in:
1 parent
ea7e0714da
commit
bc39b0ed59
35 files changed
+903
-945
No files matched your search
@@ -1127,14 +1127,6 @@ pub(super) fn active_blob(chat: &ChatWidget) -> String {
|
||||
lines_to_single_string(&lines)
|
||||
}
|
||||
|
||||
pub(super) fn active_hook_blob(chat: &ChatWidget) -> String {
|
||||
let Some(cell) = chat.active_hook_cell.as_ref() else {
|
||||
return "<empty>\n".to_string();
|
||||
};
|
||||
let lines = cell.display_lines(/*width*/ 80);
|
||||
lines_to_single_string(&lines)
|
||||
}
|
||||
|
||||
pub(super) fn expire_quiet_hook_linger(chat: &mut ChatWidget) {
|
||||
if let Some(cell) = chat.active_hook_cell.as_mut() {
|
||||
cell.expire_quiet_runs_now_for_test();
|
||||
@@ -1649,6 +1641,7 @@ pub(super) async fn assert_hook_events_snapshot(
|
||||
snapshot_name: &str,
|
||||
) {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.on_task_started();
|
||||
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
@@ -1665,12 +1658,19 @@ pub(super) async fn assert_hook_events_snapshot(
|
||||
"hook start should update the live hook cell instead of writing history"
|
||||
);
|
||||
reveal_running_hooks(&mut chat);
|
||||
let width = 100;
|
||||
let height = chat.desired_height(width);
|
||||
let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(width, height))
|
||||
.expect("create terminal");
|
||||
terminal
|
||||
.draw(|frame| chat.render(frame.area(), frame.buffer_mut()))
|
||||
.expect("render hook activity status");
|
||||
let running = normalized_backend_snapshot(terminal.backend());
|
||||
assert!(
|
||||
active_hook_blob(&chat).contains(&format!(
|
||||
"Running {} hook: {status_message}",
|
||||
hook_event_label(event_name)
|
||||
)),
|
||||
"hook start should render in the live hook cell"
|
||||
running
|
||||
.lines()
|
||||
.any(|line| line.contains("Working") && line.contains(status_message)),
|
||||
"hook start should render its status in the activity row: {running}"
|
||||
);
|
||||
|
||||
let mut entries = vec![codex_app_server_protocol::HookOutputEntry {
|
||||
@@ -1701,20 +1701,3 @@ pub(super) async fn assert_hook_events_snapshot(
|
||||
.collect::<String>();
|
||||
assert_chatwidget_snapshot!(snapshot_name, combined);
|
||||
}
|
||||
|
||||
fn hook_event_label(event_name: codex_app_server_protocol::HookEventName) -> &'static str {
|
||||
match event_name {
|
||||
codex_app_server_protocol::HookEventName::PreToolUse => "PreToolUse",
|
||||
codex_app_server_protocol::HookEventName::PermissionRequest => "PermissionRequest",
|
||||
codex_app_server_protocol::HookEventName::PostToolUse => "PostToolUse",
|
||||
codex_app_server_protocol::HookEventName::PreCompact => "PreCompact",
|
||||
codex_app_server_protocol::HookEventName::PostCompact => "PostCompact",
|
||||
codex_app_server_protocol::HookEventName::SessionStart => "SessionStart",
|
||||
codex_app_server_protocol::HookEventName::SessionEnd => "SessionEnd",
|
||||
codex_app_server_protocol::HookEventName::UserPromptSubmit => "UserPromptSubmit",
|
||||
codex_app_server_protocol::HookEventName::SubagentStart => "SubagentStart",
|
||||
codex_app_server_protocol::HookEventName::SubagentStop => "SubagentStop",
|
||||
codex_app_server_protocol::HookEventName::Stop => "Stop",
|
||||
codex_app_server_protocol::HookEventName::Interrupt => "Interrupt",
|
||||
}
|
||||
}
|
||||
@@ -1648,7 +1648,6 @@ async fn completed_token_activity_refresh_waits_for_active_hook() {
|
||||
),
|
||||
);
|
||||
|
||||
assert_matches!(rx.try_recv(), Ok(AppEvent::InsertHistoryCell(_)));
|
||||
assert_matches!(rx.try_recv(), Ok(AppEvent::CommitPendingUsageOutput));
|
||||
}
|
||||
|
||||
|
||||
@@ -3786,6 +3786,7 @@ impl crate::workspace_command::WorkspaceCommandExecutor for NoopWorkspaceCommand
|
||||
#[tokio::test]
|
||||
async fn interrupted_turn_clears_visible_running_hook() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.on_task_started();
|
||||
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
@@ -3796,15 +3797,15 @@ async fn interrupted_turn_clears_visible_running_hook() {
|
||||
),
|
||||
);
|
||||
reveal_running_hooks(&mut chat);
|
||||
let before_interrupt = active_hook_blob(&chat);
|
||||
let before_interrupt = hook_status_frame(&chat, /*width*/ 80);
|
||||
|
||||
handle_turn_interrupted(&mut chat, "turn-1");
|
||||
|
||||
assert_chatwidget_snapshot!(
|
||||
"interrupted_turn_clears_visible_running_hook",
|
||||
format!(
|
||||
"before interrupt:\n{before_interrupt}after interrupt:\n{}",
|
||||
active_hook_blob(&chat)
|
||||
"before interrupt:\n{before_interrupt}\nafter interrupt:\n{}",
|
||||
hook_status_frame(&chat, /*width*/ 80)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -3812,6 +3813,7 @@ async fn interrupted_turn_clears_visible_running_hook() {
|
||||
#[tokio::test]
|
||||
async fn completed_turn_clears_visible_running_hook() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.on_task_started();
|
||||
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
@@ -3822,15 +3824,15 @@ async fn completed_turn_clears_visible_running_hook() {
|
||||
),
|
||||
);
|
||||
reveal_running_hooks(&mut chat);
|
||||
let before_completion = active_hook_blob(&chat);
|
||||
let before_completion = hook_status_frame(&chat, /*width*/ 80);
|
||||
|
||||
handle_turn_completed(&mut chat, "turn-1", /*duration_ms*/ None);
|
||||
|
||||
assert_chatwidget_snapshot!(
|
||||
"completed_turn_clears_visible_running_hook",
|
||||
format!(
|
||||
"before completion:\n{before_completion}after completion:\n{}",
|
||||
active_hook_blob(&chat)
|
||||
"before completion:\n{before_completion}\nafter completion:\n{}",
|
||||
hook_status_frame(&chat, /*width*/ 80)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -4857,74 +4859,43 @@ async fn post_tool_use_hook_events_render_snapshot() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn completed_hook_with_no_entries_stays_out_of_history() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
async fn quiet_hook_cleanup_starts_when_the_hook_is_revealed() {
|
||||
for delayed_redraw in [false, true] {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
hook_started_run(
|
||||
"post-tool-use:0:/tmp/hooks.json",
|
||||
codex_app_server_protocol::HookEventName::PostToolUse,
|
||||
Some("checking output policy"),
|
||||
),
|
||||
);
|
||||
if delayed_redraw {
|
||||
reveal_running_hooks_after_delayed_redraw(&mut chat);
|
||||
} else {
|
||||
reveal_running_hooks(&mut chat);
|
||||
}
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
hook_completed_run(
|
||||
"post-tool-use:0:/tmp/hooks.json",
|
||||
codex_app_server_protocol::HookEventName::PostToolUse,
|
||||
codex_app_server_protocol::HookRunStatus::Completed,
|
||||
Vec::new(),
|
||||
),
|
||||
);
|
||||
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
hook_started_run(
|
||||
"post-tool-use:0:/tmp/hooks.json",
|
||||
codex_app_server_protocol::HookEventName::PostToolUse,
|
||||
/*status_message*/ None,
|
||||
),
|
||||
);
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
reveal_running_hooks(&mut chat);
|
||||
let running_snapshot = hook_live_and_history_snapshot(&chat, "running", "");
|
||||
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
hook_completed_run(
|
||||
"post-tool-use:0:/tmp/hooks.json",
|
||||
codex_app_server_protocol::HookEventName::PostToolUse,
|
||||
codex_app_server_protocol::HookRunStatus::Completed,
|
||||
Vec::new(),
|
||||
),
|
||||
);
|
||||
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
let completed_lingering_snapshot =
|
||||
hook_live_and_history_snapshot(&chat, "completed lingering", "");
|
||||
expire_quiet_hook_linger(&mut chat);
|
||||
let completed_snapshot = hook_live_and_history_snapshot(&chat, "completed after linger", "");
|
||||
assert_chatwidget_snapshot!(
|
||||
"hook_live_running_then_quiet_completed_snapshot",
|
||||
format!("{running_snapshot}\n\n{completed_lingering_snapshot}\n\n{completed_snapshot}")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn quiet_hook_linger_starts_when_delayed_redraw_reveals_hook() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
hook_started_run(
|
||||
"post-tool-use:0:/tmp/hooks.json",
|
||||
codex_app_server_protocol::HookEventName::PostToolUse,
|
||||
Some("checking output policy"),
|
||||
),
|
||||
);
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
|
||||
reveal_running_hooks_after_delayed_redraw(&mut chat);
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
hook_completed_run(
|
||||
"post-tool-use:0:/tmp/hooks.json",
|
||||
codex_app_server_protocol::HookEventName::PostToolUse,
|
||||
codex_app_server_protocol::HookRunStatus::Completed,
|
||||
Vec::new(),
|
||||
),
|
||||
);
|
||||
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
assert!(
|
||||
active_hook_blob(&chat).contains("Running PostToolUse hook"),
|
||||
"quiet hook should linger after the row becomes visible"
|
||||
);
|
||||
expire_quiet_hook_linger(&mut chat);
|
||||
assert_eq!(active_hook_blob(&chat), "<empty>\n");
|
||||
let cell = chat
|
||||
.active_hook_cell
|
||||
.as_ref()
|
||||
.expect("quiet cleanup should linger");
|
||||
assert!(cell.is_active());
|
||||
assert!(cell.next_timer_deadline().is_some());
|
||||
assert_eq!(cell.running_status_summary(), None);
|
||||
expire_quiet_hook_linger(&mut chat);
|
||||
assert!(chat.active_hook_cell.is_none());
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -4962,13 +4933,11 @@ async fn blocked_and_failed_hooks_render_feedback_and_errors() {
|
||||
.collect::<String>();
|
||||
assert_chatwidget_snapshot!("hook_blocked_failed_feedback_history_snapshot", rendered);
|
||||
assert!(
|
||||
rendered.contains(
|
||||
"PreToolUse hook (blocked)\n feedback: run tests before touching the fixture"
|
||||
),
|
||||
rendered.contains("Blocked by hook\n └ run tests before touching the fixture"),
|
||||
"expected blocked hook feedback: {rendered:?}"
|
||||
);
|
||||
assert!(
|
||||
rendered.contains("PostToolUse hook (failed)\n error: hook exited with code 7"),
|
||||
rendered.contains("Hook failed\n └ hook exited with code 7"),
|
||||
"expected failed hook error: {rendered:?}"
|
||||
);
|
||||
}
|
||||
@@ -4986,7 +4955,7 @@ async fn completed_hook_with_output_flushes_immediately() {
|
||||
),
|
||||
);
|
||||
reveal_running_hooks(&mut chat);
|
||||
let running_snapshot = hook_live_and_history_snapshot(&chat, "running", "");
|
||||
let running_snapshot = hook_status_and_history_snapshot(&chat, "running", "");
|
||||
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
@@ -5004,7 +4973,7 @@ async fn completed_hook_with_output_flushes_immediately() {
|
||||
.iter()
|
||||
.map(|lines| lines_to_single_string(lines))
|
||||
.collect::<String>();
|
||||
let completed_snapshot = hook_live_and_history_snapshot(&chat, "completed", &history);
|
||||
let completed_snapshot = hook_status_and_history_snapshot(&chat, "completed", &history);
|
||||
|
||||
assert_chatwidget_snapshot!(
|
||||
"completed_hook_with_output_flushes_immediately_snapshot",
|
||||
@@ -5052,13 +5021,10 @@ async fn completed_hook_output_precedes_following_assistant_message() {
|
||||
.collect::<String>();
|
||||
assert_chatwidget_snapshot!(
|
||||
"completed_hook_output_precedes_following_assistant_message_snapshot",
|
||||
format!(
|
||||
"active hooks:\n{}history:\n{history}",
|
||||
active_hook_blob(&chat)
|
||||
)
|
||||
history
|
||||
);
|
||||
let hook_index = history
|
||||
.find("PreToolUse hook (blocked)")
|
||||
.find("Blocked by hook")
|
||||
.expect("hook feedback should be in history");
|
||||
let assistant_index = history
|
||||
.find("The hook feedback was applied.")
|
||||
@@ -5111,45 +5077,125 @@ async fn completed_same_id_hook_output_survives_restart() {
|
||||
.collect::<String>();
|
||||
assert_chatwidget_snapshot!(
|
||||
"completed_same_id_hook_output_survives_restart_snapshot",
|
||||
format!(
|
||||
"active hooks:\n{}history:\n{history}",
|
||||
active_hook_blob(&chat)
|
||||
)
|
||||
hook_status_and_history_snapshot(&chat, "restarted", &history)
|
||||
);
|
||||
assert!(
|
||||
history.contains("Stop hook (stopped)\n stop: continue with more context"),
|
||||
history.contains("Hook stopped\n └ continue with more context"),
|
||||
"first hook output should not be overwritten: {history:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn identical_parallel_running_hooks_collapse_to_count() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
async fn running_hooks_fit_around_background_activity_and_finish_without_history_snapshot() {
|
||||
for (messages, snapshot) in [
|
||||
(
|
||||
vec!["checking command policy"; 3],
|
||||
"running_hooks_share_background_activity_row",
|
||||
),
|
||||
(
|
||||
vec![
|
||||
"checking command policy",
|
||||
"scanning for secrets",
|
||||
"loading project context",
|
||||
],
|
||||
"mixed_running_hooks_share_background_activity_row",
|
||||
),
|
||||
(
|
||||
vec![
|
||||
"checking command policy for deployment commands, production credentials, and paths containing 日本語 before continuing",
|
||||
],
|
||||
"long_running_hook_below_background_activity_row",
|
||||
),
|
||||
] {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.on_task_started();
|
||||
begin_unified_exec_startup(&mut chat, "call-1", "proc-1", "sleep 2");
|
||||
chat.bottom_pane.hide_status_indicator();
|
||||
|
||||
for tool_call_id in ["tool-call-1", "tool-call-2", "tool-call-3"] {
|
||||
for (index, message) in messages.iter().enumerate() {
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
hook_started_run(
|
||||
&format!("hook-{index}"),
|
||||
codex_app_server_protocol::HookEventName::PreToolUse,
|
||||
Some(message),
|
||||
),
|
||||
);
|
||||
}
|
||||
reveal_running_hooks(&mut chat);
|
||||
assert_chatwidget_snapshot!(
|
||||
snapshot,
|
||||
format!(
|
||||
"80 columns:\n{}\n120 columns:\n{}",
|
||||
hook_status_frame(&chat, /*width*/ 80),
|
||||
hook_status_frame(&chat, /*width*/ 120),
|
||||
)
|
||||
);
|
||||
|
||||
// Match production delivery: finish the batch before drawing another frame.
|
||||
for index in 0..messages.len() {
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
hook_completed_run(
|
||||
&format!("hook-{index}"),
|
||||
codex_app_server_protocol::HookEventName::PreToolUse,
|
||||
codex_app_server_protocol::HookRunStatus::Completed,
|
||||
Vec::new(),
|
||||
),
|
||||
);
|
||||
}
|
||||
let rendered = hook_status_frame(&chat, /*width*/ 120);
|
||||
assert!(rendered.contains("1 background terminal running"));
|
||||
assert!(!rendered.contains("Running hooks"));
|
||||
assert!(!rendered.contains("checking command policy"));
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_end_hook_has_standalone_activity_row() {
|
||||
for (message, snapshot) in [
|
||||
(Some("saving session summary"), "session_end_hook_activity"),
|
||||
(None, "session_end_hook_activity_without_message"),
|
||||
] {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
hook_started_run(
|
||||
&format!("pre-tool-use:0:/tmp/hooks.json:{tool_call_id}"),
|
||||
codex_app_server_protocol::HookEventName::PreToolUse,
|
||||
Some("checking command policy"),
|
||||
"session-end",
|
||||
codex_app_server_protocol::HookEventName::SessionEnd,
|
||||
message,
|
||||
),
|
||||
);
|
||||
let hidden = hook_status_frame(&chat, /*width*/ 80);
|
||||
reveal_running_hooks(&mut chat);
|
||||
let running = hook_status_frame(&chat, /*width*/ 80);
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
hook_completed_run(
|
||||
"session-end",
|
||||
codex_app_server_protocol::HookEventName::SessionEnd,
|
||||
codex_app_server_protocol::HookRunStatus::Completed,
|
||||
Vec::new(),
|
||||
),
|
||||
);
|
||||
assert_chatwidget_snapshot!(
|
||||
snapshot,
|
||||
format!(
|
||||
"before reveal:\n{hidden}\nrunning:\n{running}\ncompleted:\n{}",
|
||||
hook_status_frame(&chat, /*width*/ 80),
|
||||
)
|
||||
);
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
}
|
||||
reveal_running_hooks(&mut chat);
|
||||
|
||||
assert_chatwidget_snapshot!(
|
||||
"identical_parallel_running_hooks_collapse_to_count_snapshot",
|
||||
hook_live_and_history_snapshot(&chat, "running", "")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn overlapping_hook_live_cell_tracks_parallel_quiet_hooks() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
chat.on_task_started();
|
||||
chat.set_status_header("Thinking".to_string());
|
||||
chat.bottom_pane.ensure_status_indicator();
|
||||
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
@@ -5161,7 +5207,7 @@ async fn overlapping_hook_live_cell_tracks_parallel_quiet_hooks() {
|
||||
);
|
||||
assert_eq!(chat.status_state.current_status.header, "Thinking");
|
||||
reveal_running_hooks(&mut chat);
|
||||
let first_running_snapshot = hook_live_and_history_snapshot(&chat, "pre running", "");
|
||||
let first_running_snapshot = hook_status_and_history_snapshot(&chat, "pre running", "");
|
||||
|
||||
handle_hook_started(
|
||||
&mut chat,
|
||||
@@ -5173,7 +5219,7 @@ async fn overlapping_hook_live_cell_tracks_parallel_quiet_hooks() {
|
||||
);
|
||||
assert_eq!(chat.status_state.current_status.header, "Thinking");
|
||||
reveal_running_hooks(&mut chat);
|
||||
let second_running_snapshot = hook_live_and_history_snapshot(&chat, "post running", "");
|
||||
let second_running_snapshot = hook_status_and_history_snapshot(&chat, "post running", "");
|
||||
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
@@ -5185,11 +5231,15 @@ async fn overlapping_hook_live_cell_tracks_parallel_quiet_hooks() {
|
||||
),
|
||||
);
|
||||
assert_eq!(chat.status_state.current_status.header, "Thinking");
|
||||
let older_completed_snapshot =
|
||||
hook_live_and_history_snapshot(&chat, "pre completed lingering", "");
|
||||
let older_completed_snapshot = hook_status_and_history_snapshot(&chat, "pre completed", "");
|
||||
expire_quiet_hook_linger(&mut chat);
|
||||
let older_completed_expired_snapshot =
|
||||
hook_live_and_history_snapshot(&chat, "pre completed after linger", "");
|
||||
assert_eq!(
|
||||
chat.active_hook_cell
|
||||
.as_ref()
|
||||
.and_then(HookCell::running_status_summary)
|
||||
.as_deref(),
|
||||
Some("checking output policy"),
|
||||
);
|
||||
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
@@ -5203,14 +5253,13 @@ async fn overlapping_hook_live_cell_tracks_parallel_quiet_hooks() {
|
||||
assert_eq!(chat.status_state.current_status.header, "Thinking");
|
||||
assert!(chat.bottom_pane.status_indicator_visible());
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
let all_completed_lingering_snapshot =
|
||||
hook_live_and_history_snapshot(&chat, "all completed lingering", "");
|
||||
let all_completed_snapshot = hook_status_and_history_snapshot(&chat, "all completed", "");
|
||||
expire_quiet_hook_linger(&mut chat);
|
||||
let all_completed_snapshot = hook_live_and_history_snapshot(&chat, "all completed", "");
|
||||
assert!(chat.active_hook_cell.is_none());
|
||||
assert_chatwidget_snapshot!(
|
||||
"overlapping_hook_live_cell_snapshot",
|
||||
format!(
|
||||
"{first_running_snapshot}\n\n{second_running_snapshot}\n\n{older_completed_snapshot}\n\n{older_completed_expired_snapshot}\n\n{all_completed_lingering_snapshot}\n\n{all_completed_snapshot}"
|
||||
"{first_running_snapshot}\n\n{second_running_snapshot}\n\n{older_completed_snapshot}\n\n{all_completed_snapshot}"
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -5231,18 +5280,14 @@ async fn running_hook_does_not_displace_active_exec_cell() {
|
||||
),
|
||||
);
|
||||
reveal_running_hooks(&mut chat);
|
||||
let exec_and_hook_running = format!(
|
||||
"active exec:\n{}active hooks:\n{}",
|
||||
active_blob(&chat),
|
||||
active_hook_blob(&chat)
|
||||
);
|
||||
let exec_and_hook_running = hook_status_frame(&chat, /*width*/ 80);
|
||||
|
||||
end_exec(&mut chat, begin, "done", "", /*exit_code*/ 0);
|
||||
let history_after_exec = drain_insert_history(&mut rx)
|
||||
.iter()
|
||||
.map(|lines| lines_to_single_string(lines))
|
||||
.collect::<String>();
|
||||
let hook_running_after_exec = active_hook_blob(&chat);
|
||||
let hook_running_after_exec = hook_status_frame(&chat, /*width*/ 80);
|
||||
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
@@ -5254,20 +5299,20 @@ async fn running_hook_does_not_displace_active_exec_cell() {
|
||||
),
|
||||
);
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
let quiet_hook_completed_lingering = active_hook_blob(&chat);
|
||||
let quiet_hook_completed = hook_status_frame(&chat, /*width*/ 80);
|
||||
expire_quiet_hook_linger(&mut chat);
|
||||
let quiet_hook_completed = active_hook_blob(&chat);
|
||||
assert!(chat.active_hook_cell.is_none());
|
||||
|
||||
assert_chatwidget_snapshot!(
|
||||
"hook_runs_while_exec_active_snapshot",
|
||||
format!(
|
||||
"exec running:\n{exec_running}\nexec and hook running:\n{exec_and_hook_running}\nhistory after exec:\n{history_after_exec}\nhook running after exec:\n{hook_running_after_exec}\nquiet hook completed lingering:\n{quiet_hook_completed_lingering}\nquiet hook completed:\n{quiet_hook_completed}"
|
||||
"exec running:\n{exec_running}\nexec and hook running:\n{exec_and_hook_running}\nhistory after exec:\n{history_after_exec}\nhook running after exec:\n{hook_running_after_exec}\nquiet hook completed:\n{quiet_hook_completed}"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn hidden_active_hook_does_not_add_transcript_separator() {
|
||||
async fn running_hook_never_adds_active_transcript_lines() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
begin_exec(&mut chat, "call-1", "echo done");
|
||||
@@ -5290,28 +5335,14 @@ async fn hidden_active_hook_does_not_add_transcript_separator() {
|
||||
assert_eq!(hidden_hook_transcript.len(), exec_only_line_count);
|
||||
|
||||
reveal_running_hooks(&mut chat);
|
||||
let visible_hook_lines = chat
|
||||
.active_hook_cell
|
||||
.as_ref()
|
||||
.expect("active hook cell")
|
||||
.transcript_lines(/*width*/ 80);
|
||||
let visible_hook_transcript = chat
|
||||
.active_cell_transcript_lines(/*width*/ 80)
|
||||
.expect("active exec and hook transcript lines");
|
||||
assert_eq!(
|
||||
visible_hook_transcript.len(),
|
||||
exec_only_line_count + 1 + visible_hook_lines.len()
|
||||
);
|
||||
assert_eq!(
|
||||
lines_to_single_string(
|
||||
&visible_hook_transcript[exec_only_line_count..exec_only_line_count + 1],
|
||||
),
|
||||
"\n"
|
||||
);
|
||||
.expect("active exec transcript lines");
|
||||
assert_eq!(visible_hook_transcript.len(), exec_only_line_count);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn hook_completed_before_reveal_renders_completed_without_running_flash() {
|
||||
async fn context_only_hook_completed_before_reveal_stays_out_of_history() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
handle_hook_started(
|
||||
@@ -5322,7 +5353,6 @@ async fn hook_completed_before_reveal_renders_completed_without_running_flash()
|
||||
Some("warming the shell"),
|
||||
),
|
||||
);
|
||||
let started_hidden_snapshot = active_hook_blob(&chat);
|
||||
|
||||
handle_hook_completed(
|
||||
&mut chat,
|
||||
@@ -5337,18 +5367,12 @@ async fn hook_completed_before_reveal_renders_completed_without_running_flash()
|
||||
),
|
||||
);
|
||||
|
||||
let history = drain_insert_history(&mut rx)
|
||||
.iter()
|
||||
.map(|lines| lines_to_single_string(lines))
|
||||
.collect::<String>();
|
||||
assert_chatwidget_snapshot!(
|
||||
"hook_completed_before_reveal_renders_completed_without_running_flash_snapshot",
|
||||
format!("started hidden:\n{started_hidden_snapshot}\nhistory:\n{history}")
|
||||
);
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
assert!(chat.active_hook_cell.is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn long_hook_context_is_truncated_with_transcript_hint_snapshot() {
|
||||
async fn stopped_hook_hides_model_context_and_preserves_stop_reason_snapshot() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
handle_hook_completed(
|
||||
@@ -5377,7 +5401,7 @@ async fn long_hook_context_is_truncated_with_transcript_hint_snapshot() {
|
||||
.map(|lines| lines_to_single_string(lines))
|
||||
.collect::<String>();
|
||||
assert_chatwidget_snapshot!(
|
||||
"long_hook_context_is_truncated_with_transcript_hint",
|
||||
"stopped_hook_hides_model_context_and_preserves_stop_reason",
|
||||
history
|
||||
);
|
||||
}
|
||||
@@ -5443,18 +5467,32 @@ fn hook_run_summary(
|
||||
}
|
||||
}
|
||||
|
||||
fn hook_live_and_history_snapshot(chat: &ChatWidget, phase: &str, history: &str) -> String {
|
||||
fn hook_status_and_history_snapshot(chat: &ChatWidget, phase: &str, history: &str) -> String {
|
||||
let history = if history.is_empty() {
|
||||
"<empty>"
|
||||
} else {
|
||||
history
|
||||
};
|
||||
format!(
|
||||
"{phase}\nlive hooks:\n{}history:\n{history}",
|
||||
active_hook_blob(chat),
|
||||
"{phase}\nactivity:\n{}\nhistory:\n{history}",
|
||||
hook_status_frame(chat, /*width*/ 80),
|
||||
)
|
||||
}
|
||||
|
||||
fn hook_status_frame(chat: &ChatWidget, width: u16) -> String {
|
||||
let height = chat.desired_height(width);
|
||||
let mut terminal = ratatui::Terminal::new(TestBackend::new(width, height))
|
||||
.expect("create terminal for hook activity");
|
||||
terminal
|
||||
.draw(|frame| chat.render(frame.area(), frame.buffer_mut()))
|
||||
.expect("render hook activity frame");
|
||||
// Windows path normalization drops Display's final newline; make composed
|
||||
// frames independent of that platform difference.
|
||||
normalized_backend_snapshot(terminal.backend())
|
||||
.trim_end()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
// Combined visual snapshot using vt100 for history + direct buffer overlay for UI.
|
||||
// This renders the final visual as seen in a terminal: history above, then a blank line,
|
||||
// then the exec block, another blank line, the status line, a blank line, and the composer.
|
||||
|
||||
Reference in new issue
Block a user