Skip to content

Commit 2242b3e

Browse files
charley-oaicodex
andcommitted
codex: fix CI failure on PR #14506
Bazel was failing the BTW app tests before they reached any BTW logic because the test helper tried to probe a real terminal on stdout. Add a test-only TUI constructor with synthetic terminal state and route the BTW app tests through it so they no longer depend on an interactive terminal. Co-authored-by: Codex <noreply@openai.com>
1 parent 6ae06d0 commit 2242b3e

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

codex-rs/tui/src/app.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7049,11 +7049,7 @@ smart_approvals = true
70497049
}
70507050

70517051
fn make_test_tui() -> crate::tui::Tui {
7052-
let terminal = crate::custom_terminal::Terminal::with_options(
7053-
ratatui::backend::CrosstermBackend::new(std::io::stdout()),
7054-
)
7055-
.expect("terminal");
7056-
crate::tui::Tui::new(terminal)
7052+
crate::tui::Tui::new_test()
70577053
}
70587054

70597055
fn app_enabled_in_effective_config(config: &Config, app_id: &str) -> Option<bool> {

codex-rs/tui/src/custom_terminal.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ where
201201
})
202202
}
203203

204+
#[cfg(test)]
205+
pub fn with_test_options(backend: B, screen_size: Size, cursor_pos: Position) -> Self {
206+
Self {
207+
backend,
208+
buffers: [Buffer::empty(Rect::ZERO), Buffer::empty(Rect::ZERO)],
209+
current: 0,
210+
hidden_cursor: false,
211+
viewport_area: Rect::ZERO,
212+
last_known_screen_size: screen_size,
213+
last_known_cursor_pos: cursor_pos,
214+
visible_history_rows: 0,
215+
}
216+
}
217+
204218
/// Get a Frame object which provides a consistent view into the terminal state for rendering.
205219
pub fn get_frame(&mut self) -> Frame<'_> {
206220
Frame {

codex-rs/tui/src/tui.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,36 @@ impl Tui {
286286
}
287287
}
288288

289+
#[cfg(test)]
290+
pub(crate) fn new_test() -> Self {
291+
let terminal = CustomTerminal::with_test_options(
292+
CrosstermBackend::new(stdout()),
293+
ratatui::layout::Size {
294+
width: 80,
295+
height: 24,
296+
},
297+
ratatui::layout::Position { x: 0, y: 0 },
298+
);
299+
let (draw_tx, _) = broadcast::channel(1);
300+
let frame_requester = FrameRequester::new(draw_tx.clone());
301+
302+
Self {
303+
frame_requester,
304+
draw_tx,
305+
event_broker: Arc::new(EventBroker::new()),
306+
terminal,
307+
pending_history_lines: vec![],
308+
alt_saved_viewport: None,
309+
#[cfg(unix)]
310+
suspend_context: SuspendContext::new(),
311+
alt_screen_active: Arc::new(AtomicBool::new(false)),
312+
terminal_focused: Arc::new(AtomicBool::new(true)),
313+
enhanced_keys_supported: false,
314+
notification_backend: None,
315+
alt_screen_enabled: true,
316+
}
317+
}
318+
289319
/// Set whether alternate screen is enabled. When false, enter_alt_screen() becomes a no-op.
290320
pub fn set_alt_screen_enabled(&mut self, enabled: bool) {
291321
self.alt_screen_enabled = enabled;

0 commit comments

Comments
 (0)