fix(tui): mount subagent panel independently of active cell

This commit is contained in:
Friel
2026-03-28 18:24:50 -07:00
parent 0af3f1f66e
commit 90d339cf75
5 changed files with 1112 additions and 11 deletions
@@ -0,0 +1,18 @@
---
source: tui/src/chatwidget/tests.rs
expression: terminal.backend().vt100().screen().contents()
---
╭──────────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.0.0) │
│ │
│ model: loading /model to change │
│ directory: ~/code/codex-split/…/codex-rs/tui │
╰──────────────────────────────────────────────╯
• Subagents (0s • no subagents running • esc to interrupt)
• [#1] [watchdog] watchdog-agent idle — watchdog idle
› show current subagent state
100% context left
+59 -3
View File
@@ -2166,6 +2166,7 @@ async fn make_chatwidget_manual(
codex_op_target: super::CodexOpTarget::Direct(op_tx),
bottom_pane: bottom,
active_cell: None,
subagent_panel: None,
active_cell_revision: 0,
config: cfg,
current_collaboration_mode,
@@ -2451,7 +2452,7 @@ async fn subagent_panel_is_not_flushed_into_transcript_history() {
latest_update_at: Instant::now(),
}],
}));
chat.on_subagent_panel_updated(Arc::new(SubagentStatusCell::new(state, true)));
chat.on_subagent_panel_updated(Arc::new(SubagentStatusCell::new(Arc::clone(&state), true)));
chat.add_to_history(history_cell::new_error_event("follow-up cell".to_string()));
@@ -2464,11 +2465,66 @@ async fn subagent_panel_is_not_flushed_into_transcript_history() {
let rendered = lines_to_single_string(&inserted[0]);
assert!(rendered.contains("follow-up cell"));
assert!(!rendered.contains("Subagents"));
assert!(
chat.subagent_panel
.as_ref()
.is_some_and(|panel| panel.matches_state(&state)),
"subagent panel should stay mounted after other history cells are inserted"
);
}
#[tokio::test]
async fn subagent_panel_mounts_while_placeholder_active_cell_exists_snapshot() {
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(None).await;
chat.active_cell = Some(ChatWidget::placeholder_session_header_cell(
chat.config_ref(),
));
chat.bottom_pane.set_composer_text(
"show current subagent state".to_string(),
Vec::new(),
Vec::new(),
);
let state = Arc::new(StdMutex::new(SubagentPanelState {
started_at: Instant::now(),
total_agents: 1,
running_count: 0,
running_agents: vec![SubagentPanelAgent {
ordinal: 1,
name: "watchdog-agent".to_string(),
status: AgentStatus::PendingInit,
is_watchdog: true,
preview: "watchdog idle".to_string(),
latest_update_at: Instant::now(),
}],
}));
chat.on_subagent_panel_updated(Arc::new(SubagentStatusCell::new(Arc::clone(&state), false)));
assert!(
chat.active_cell
.as_ref()
.is_some_and(|cell| cell.as_any().is::<SubagentStatusCell>()),
"subagent panel should stay mounted after other history cells are inserted"
.is_some_and(|cell| cell.as_any().is::<history_cell::SessionHeaderHistoryCell>()),
"placeholder session header should remain the active cell"
);
assert!(
chat.subagent_panel
.as_ref()
.is_some_and(|panel| panel.matches_state(&state)),
"subagent panel should mount even when another active cell already exists"
);
let width = 80;
let height = chat.desired_height(width);
let mut terminal =
ratatui::Terminal::new(VT100Backend::new(width, height)).expect("create terminal");
terminal.set_viewport_area(Rect::new(0, 0, width, height));
terminal
.draw(|f| chat.render(f.area(), f.buffer_mut()))
.expect("render chat with placeholder header and subagent panel");
assert_snapshot!(
"subagent_panel_mounts_while_placeholder_active_cell_exists",
terminal.backend().vt100().screen().contents()
);
}
fn make_token_info(total_tokens: i64, context_window: i64) -> TokenUsageInfo {