Files
codex/codex-rs/tui/tests/suite/tui_mode_picker_tests.rs
Felipe Couryandcopyberry 2f34d236f5 Add /tui to choose the terminal UI mode for the next launch (#46883)
## What changed

Add a picker for Scrollback and Fullscreen modes that requires explicit
confirmation and saves `tui.fullscreen_transcript` to the selected user config
file. Keep the running renderer unchanged and explain that a restart is required
and launch overrides still apply. Report save failures without changing the
stored preference in memory.

## Testing

Add picker snapshots and tests for confirmation, cancellation, selected-config
persistence, and failed saves. Add a PTY test covering mode changes in both
directions across restarts while verifying that the current session stays in
its original mode.

GitOrigin-RevId: 7f231ab37c89e2168133fcfd6aaee54775aa7972
2026-09-20 20:38:26 +00:00

67 lines
2.5 KiB
Rust

//! The picker persists a preference, but only a new process adopts the renderer.
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn tui_mode_picker_applies_only_after_restart() -> Result<()> {
let root = codex_utils_cargo_bin::repo_root()?;
let mut home = tempfile::tempdir()?;
write_test_config(home.path(), &root)?;
let path = home.path().join("config.toml");
let config = std::fs::read_to_string(&path)?;
std::fs::write(
&path,
format!(
"tui.fullscreen_transcript = false\ntui.alternate_screen = \"always\"\ntui.disable_paste_burst = true\ntui.status_line = [\"thread-id\"]\n{config}"
),
)?;
for (launch, current) in [false, true, false].into_iter().enumerate() {
let mut terminal = PtyCodex::start(&root, home, &[])?;
terminal.wait_for_startup()?;
// The header precedes session setup; wait for the thread ID before sending commands.
let deadline = Instant::now() + STARTUP_TIMEOUT;
loop {
terminal.read_output(Duration::from_millis(/*millis*/ 50))?;
terminal.answer_startup_queries()?;
if terminal
.screen_contents()
.split_whitespace()
.any(|word| uuid::Uuid::parse_str(word).is_ok())
{
break;
}
ensure!(
Instant::now() < deadline,
"thread did not become ready: {}",
terminal.screen_contents()
);
terminal.ensure_running()?;
}
assert_eq!(terminal.parser.screen().alternate_screen(), current);
if launch == 2 {
break;
}
terminal.write_input(b"/tui")?;
terminal.wait_for_screen("/tui")?;
terminal.write_input(b"\r")?;
terminal.wait_for_screen("TUI mode for next launch")?;
terminal.write_input(if current { b"\x1b[A" } else { b"\x1b[B" })?;
terminal.write_input(b"\r")?;
terminal.wait_for_screen(if current {
"Saved TUI mode: Scrollback"
} else {
"Saved TUI mode: Fullscreen"
})?;
assert_eq!(terminal.parser.screen().alternate_screen(), current);
let saved: toml::Value = toml::from_str(&std::fs::read_to_string(&path)?)?;
assert_eq!(
saved["tui"]["fullscreen_transcript"].as_bool(),
Some(!current)
);
home = std::mem::replace(&mut terminal._codex_home, tempfile::tempdir()?);
drop(terminal);
}
Ok(())
}