diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rs index 318e4b933f..595b996be9 100644 --- a/codex-rs/tui/src/app/event_dispatch.rs +++ b/codex-rs/tui/src/app/event_dispatch.rs @@ -2335,8 +2335,10 @@ impl App { error = %err, "failed to persist approvals reviewer update" ); - self.chat_widget - .add_error_message(format!("Failed to save approvals reviewer: {err}")); + self.chat_widget.add_error_message(format!( + "Failed to save approvals reviewer: {}", + format_config_error(&err) + )); } } AppEvent::FetchExperimentalFeatures { thread_id, response_tx } => { diff --git a/codex-rs/tui/src/app/tests.rs b/codex-rs/tui/src/app/tests.rs index f82320005b..715ffbf4a9 100644 --- a/codex-rs/tui/src/app/tests.rs +++ b/codex-rs/tui/src/app/tests.rs @@ -9,6 +9,8 @@ mod math_interruption_tests; mod advanced_reasoning_tests; #[path = "tests/agents_navigation_tests.rs"] mod agents_navigation_tests; +#[path = "tests/approvals_reviewer_error_tests.rs"] +mod approvals_reviewer_error_tests; #[path = "tests/backend_banner_fallback_tests.rs"] mod backend_banner_fallback_tests; #[path = "tests/backend_banner_recovery_tests.rs"] diff --git a/codex-rs/tui/src/app/tests/approvals_reviewer_error_tests.rs b/codex-rs/tui/src/app/tests/approvals_reviewer_error_tests.rs new file mode 100644 index 0000000000..d0ca48d7f8 --- /dev/null +++ b/codex-rs/tui/src/app/tests/approvals_reviewer_error_tests.rs @@ -0,0 +1,38 @@ +//! Verify that approvals persistence failures retain the backend's actionable cause. + +use super::*; + +#[tokio::test] +async fn approvals_reviewer_error_retains_config_cause() -> Result<()> { + let (mut app, mut events, _op_rx) = make_test_app_with_channels().await; + let codex_home = tempdir()?; + app.config.codex_home = codex_home.path().to_path_buf().abs(); + let config_path = codex_home.path().join("config.toml"); + std::fs::write(&config_path, "")?; + let mut app_server = start_config_write_test_app_server(&app).await?; + let mut tui = crate::tui::test_support::make_test_tui()?; + while events.try_recv().is_ok() {} + + // Simulate an external config edit after startup so the real batch-write + // reload fails, rather than injecting an already-formatted UI error. + std::fs::write(&config_path, "approvals_reviewer = [\n")?; + Box::pin(app.handle_event( + &mut tui, + &mut app_server, + AppEvent::UpdateApprovalsReviewer(ApprovalsReviewer::User), + )) + .await?; + app_server.shutdown().await?; + + let cell = match events.try_recv() { + Ok(AppEvent::InsertHistoryCell(cell)) => cell, + other => panic!("expected the persistence error, got {other:?}"), + }; + let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 120)).replace( + &config_path.to_string_lossy().to_string(), + "/config.toml", + ); + assert!(rendered.contains("unclosed array"), "{rendered}"); + insta::assert_snapshot!("approvals_reviewer_config_error", rendered); + Ok(()) +} diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__approvals_reviewer_error_tests__approvals_reviewer_config_error.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__approvals_reviewer_error_tests__approvals_reviewer_config_error.snap new file mode 100644 index 0000000000..ed4e880e4d --- /dev/null +++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__approvals_reviewer_error_tests__approvals_reviewer_config_error.snap @@ -0,0 +1,6 @@ +--- +source: tui/src/app/tests/approvals_reviewer_error_tests.rs +assertion_line: 34 +expression: rendered +--- +■ Failed to save approvals reviewer: config/batchWrite failed in TUI: config/batchWrite failed: failed to load configuration: /config.toml:1:24: unclosed array, expected `]` (code -32603)