Files
codex/codex-rs/tui/src/app/tests/agents_navigation_tests.rs
T
Eric Traut 70e8fe1be3 Add opt-in automatic background server startup (#46117)
## What changed

- Add `features.daemon_auto_start`, disabled by default and available through `/experimental`, to start the shared local server for eligible new, resumed, and forked sessions. Changes take effect on the next launch, and disabling the feature persists an explicit `false`.
- Require successful daemon startup and connection when auto-start applies. On failure, show guidance to rerun the same command with `--no-daemon` instead of silently falling back to an embedded server.
- Preserve embedded mode for excluded launches, including Bedrock sign-in, and carry exclusion warnings through resume and fork pickers. Honor `--no-daemon` without an exclusion warning.
- Update `/import` guidance to recommend restarting with `codex --no-daemon`.

## Testing

Add CLI and TUI coverage for automatic daemon attachment, startup and connection failures, `--no-daemon`, picker warning persistence, and Bedrock onboarding with and without a running daemon. Add snapshots and configuration-write assertions for the experimental toggle.

GitOrigin-RevId: 2e8eb163bc7ddd268a86c7546c05a85356c1e9ee
2026-09-17 04:53:51 +00:00

102 lines
3.8 KiB
Rust

use super::*;
use pretty_assertions::assert_eq;
#[tokio::test]
async fn agents_navigation_requires_local_daemon() -> Result<()> {
let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;
let mut tui = crate::tui::test_support::make_test_tui()?;
let mut app_server = start_config_write_test_app_server(&app).await?;
let endpoint = crate::RemoteAppServerEndpoint::UnixSocket {
socket_path: AbsolutePathBuf::relative_to_current_dir("codex.sock")?,
};
for target in [
AppServerTarget::Embedded,
AppServerTarget::Remote {
endpoint: endpoint.clone(),
},
AppServerTarget::LocalDaemon {
endpoint,
allow_embedded_fallback: true,
},
] {
let enabled = matches!(target, AppServerTarget::LocalDaemon { .. });
app.app_server_target = target;
let init = app.chatwidget_init_for_forked_or_resumed_thread(
&mut tui,
app.config.clone(),
/*initial_user_message*/ None,
);
app.replace_chat_widget(ChatWidget::new_with_app_event(init));
while events.try_recv().is_ok() {}
app.handle_tui_event(
&mut tui,
&mut app_server,
TuiEvent::Key(KeyCode::Left.into()),
)
.await?;
if enabled {
let event = events.try_recv()?;
assert_matches!(event, AppEvent::OpenAgentsOverview);
app.handle_event(&mut tui, &mut app_server, event).await?;
assert!(!app.chat_widget.no_modal_or_popup_active());
} else {
assert!(events.try_recv().is_err());
assert!(app.chat_widget.no_modal_or_popup_active());
assert!(!render_bottom_popup(&app.chat_widget, /*width*/ 96).contains("for agents"));
}
}
app_server.shutdown().await?;
Ok(())
}
#[tokio::test]
async fn pending_windows_sandbox_setup_blocks_thread_replacement() -> Result<()> {
use crate::app_event::WindowsSandboxEnableMode;
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
app.chat_widget.windows_sandbox_local_server = true;
while events.try_recv().is_ok() {}
let mut app_server = start_config_write_test_app_server(&app).await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
let current = ThreadId::new();
let other = ThreadId::new();
app.active_thread_id = Some(current);
app.primary_thread_id = Some(current);
let preset = codex_utils_approval_presets::builtin_approval_presets()
.into_iter()
.find(|preset| preset.id == "auto")
.expect("auto preset");
app.windows_sandbox.pending_setup = Some((WindowsSandboxEnableMode::Elevated, preset, None));
let prompt = crate::chatwidget::create_initial_user_message(
Some("review this".to_string()),
Vec::new(),
Vec::new(),
);
app.chat_widget.initial_user_message = prompt.clone();
app.select_agent_thread(&mut tui, &mut app_server, other)
.await?;
assert_eq!(app.active_thread_id, Some(current));
assert_eq!(app.chat_widget.initial_user_message, prompt);
let cell = match events.try_recv() {
Ok(AppEvent::InsertHistoryCell(cell)) => cell,
other => panic!("expected setup navigation message, got {other:?}"),
};
let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 100));
insta::assert_snapshot!(rendered, @"• Finish Windows sandbox setup before switching threads.");
app.chat_widget.initial_user_message = None;
app.run_agents_overview_action(
&mut tui,
&mut app_server,
current,
crate::app_event::AgentsOverviewAction::Archive,
)
.await?;
assert_eq!(app.active_thread_id, Some(current));
assert!(events.try_recv().is_err());
app_server.shutdown().await?;
Ok(())
}