Files
codex/codex-rs/tui/src/daemon_recovery_tests.rs
T
Eric Traut 8196bcdc18 Check daemon feature overrides and prompt for mismatch recovery (#55442)
## Why

A fixed feature allowlist excluded other boolean feature overrides from daemon use. Feature mismatches could also silently fall back to embedded mode, while automatic startup could persist enabled overrides without confirmation.

## What changed

- Allow boolean feature overrides without a fixed allowlist and compare explicit overrides with the daemon's reported settings. Ignore removed features, treat unreported features as disabled, and include only mismatches in restart settings.
- Preserve saved daemon settings during automatic startup. Prompt on feature mismatches even when embedded fallback is allowed, letting users run without the daemon, confirm a managed-daemon restart, or cancel.
- Detect managed daemons during recovery, mark available restarts as recommended, and limit the displayed feature list to three entries plus a remaining count.

## Testing

Update compatibility tests for mixed overrides, removed and unreported features, unreachable daemons, and required versus optional attachment. Update recovery snapshots and the TUI integration test to exercise explicit embedded-mode selection.

GitOrigin-RevId: 9204620f168ff80aaef312c88e681b754908a431
2026-10-20 03:11:07 +00:00

70 lines
2.5 KiB
Rust

use super::*;
use crossterm::event::KeyCode;
use crossterm::event::KeyEvent;
use crossterm::event::KeyModifiers;
use pretty_assertions::assert_eq;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use std::collections::BTreeMap;
#[test]
fn daemon_recovery_requires_explicit_restart_and_defaults_to_cancel() {
let issue = CompatibilityError {
reason: "This session requires api_key_model_discovery to be enabled".to_string(),
restart_features: Some(BTreeMap::from([
("api_key_model_discovery".to_string(), true),
("code_mode_host".to_string(), true),
("instant_interrupt".to_string(), true),
("mcp_oauth_refresh_coordination".to_string(), false),
])),
};
let non_restartable = CompatibilityError {
reason: "code-mode host fallback policy requires embedded mode".to_string(),
restart_features: None,
};
for (issue, managed, snapshot) in [
(&issue, true, "daemon_recovery_menu"),
(&issue, false, "unmanaged_daemon_recovery_menu"),
(
&non_restartable,
true,
"non_restartable_daemon_recovery_menu",
),
] {
let mut view = recovery_view(issue, managed, &RuntimeKeymap::defaults());
let area = Rect::new(
/*x*/ 0,
/*y*/ 0,
/*width*/ 90,
view.desired_height(/*width*/ 90),
);
let mut buffer = Buffer::empty(area);
view.render(area, &mut buffer);
let text = buffer
.content
.chunks(90)
.map(|row| {
row.iter()
.map(ratatui::buffer::Cell::symbol)
.collect::<String>()
.trim_end()
.to_string()
})
.collect::<Vec<_>>()
.join("\n");
insta::assert_snapshot!(snapshot, text);
view.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
assert_eq!(view.take_last_selected_index(), Some(2));
let mut view = recovery_view(issue, managed, &RuntimeKeymap::defaults());
view.handle_key_event(KeyEvent::new(KeyCode::Char('2'), KeyModifiers::NONE));
if managed && issue.restart_features.is_some() {
assert!(!view.is_complete());
view.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
assert_eq!(view.take_last_selected_index(), Some(1));
} else {
assert_eq!(view.take_last_selected_index(), Some(2));
}
}
}