From d8ab30ea362e584d044622c914e9287a498a80f8 Mon Sep 17 00:00:00 2001 From: Simon Klee Date: Mon, 9 Nov 2026 02:20:49 +0100 Subject: [PATCH] rust: wait for any frame in the lifecycle tests The first Windows run of the Rust tests timed out waiting for "lifecycle frame 1" in --app mode, although the fixture drew it. App draws again when the terminal answers a startup query, and Windows' pseudoconsole answers DA1 and DECRQM itself, so frame 2 follows within milliseconds. The pseudoconsole sends its screen on its own tick, not each frame, and that run only ever showed frame 2. The tests now wait for any frame. They only need the fixture to be up; the frame numbers pty-smoke.py counts stay exact on Unix, where the pseudo-terminal forwards every byte and answers no query. Tests +3 lines: a named constant whose comment says why the number is left out, used by the six waits. Issue: 447 --- packages/rust/crates/opentui/tests/lifecycle.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/rust/crates/opentui/tests/lifecycle.rs b/packages/rust/crates/opentui/tests/lifecycle.rs index ab320c10bd..e131f3aa20 100644 --- a/packages/rust/crates/opentui/tests/lifecycle.rs +++ b/packages/rust/crates/opentui/tests/lifecycle.rs @@ -11,6 +11,9 @@ use std::time::Duration; const ENTER_ALT: &str = "\x1b[?1049h"; const LEAVE_ALT: &str = "\x1b[?1049l"; +/// Any frame. Windows' pseudoconsole sends its screen, not each frame: with `--app`, its replies to the startup +/// queries draw frame 2 at once, and frame 1 may never show. +const DRAWN: &str = "lifecycle frame "; /// The lifecycle example, which `cargo test` builds along with the tests. fn fixture() -> PathBuf { @@ -88,7 +91,7 @@ const MODES: [&[&str]; 2] = [&[], &["--app"]]; fn quitting_restores_the_terminal() { for arguments in MODES { let run = Run::fixture(arguments); - run.wait_for("lifecycle frame 1"); + run.wait_for(DRAWN); run.press("q"); assert_eq!(run.code(), Some(0), "{arguments:?}"); run.after_leaving(); @@ -99,7 +102,7 @@ fn quitting_restores_the_terminal() { fn resizes_are_drawn() { for arguments in MODES { let run = Run::fixture(arguments); - run.wait_for("lifecycle frame 1"); + run.wait_for(DRAWN); run.pty.resize(100, 30).unwrap(); run.wait_for("size 100x30"); run.press("q"); @@ -112,7 +115,7 @@ fn errors_and_panics_print_after_the_terminal_is_restored() { for arguments in MODES { for (key, code, message) in [("e", 1, "lifecycle fixture error"), ("p", 101, "lifecycle fixture panic")] { let run = Run::fixture(arguments); - run.wait_for("lifecycle frame 1"); + run.wait_for(DRAWN); run.press(key); assert_eq!(run.code(), Some(code), "{arguments:?} {key}"); assert!(run.after_leaving().contains(message), "{arguments:?} {key}: {:?}", run.text()); @@ -123,7 +126,7 @@ fn errors_and_panics_print_after_the_terminal_is_restored() { #[test] fn captured_stderr_stays_off_the_screen() { let run = Run::fixture(&["--app"]); - run.wait_for("lifecycle frame 1"); + run.wait_for(DRAWN); run.press("w"); run.app.wait_until(Duration::from_millis(300), || false); run.press("q"); @@ -139,7 +142,7 @@ fn captured_stderr_stays_off_the_screen() { #[test] fn releasing_hands_the_terminal_over_and_takes_it_back() { let run = Run::fixture(&["--app"]); - run.wait_for("lifecycle frame 1"); + run.wait_for(DRAWN); // As in Core, the release ends the batch it came in: the q after it never quits. run.press("rq"); run.wait_for("lifecycle released"); @@ -177,7 +180,7 @@ fn console_modes_are_restored() { let mut command = Command::new("cmd.exe"); command.args(["/d", "/s", "/c", &script]); let run = Run::start(command); - run.wait_for("lifecycle frame 1"); + run.wait_for(DRAWN); run.press(key); run.code(); let text = run.text();