| 1 | #![cfg(all(unix, feature = "long-running-tests"))] |
| 2 | |
| 3 | use std::time::Duration; |
| 4 | |
| 5 | use super::qa_harness; |
| 6 | use qa_harness::harness::{Harness, make_sealed_workspace}; |
| 7 | use qa_harness::keys; |
| 8 | |
| 9 | const STARTUP_WAIT: Duration = Duration::from_secs(15); |
| 10 | const SETTLE_WAIT: Duration = Duration::from_secs(5); |
| 11 | |
| 12 | #[test] |
| 13 | fn offline_queue_late_unbracketed_submit_keeps_composer_and_commands_responsive() { |
| 14 | for (rows, cols) in [(24, 80), (32, 100)] { |
| 15 | for delay_ms in [150, 250, 400] { |
| 16 | let workspace = make_sealed_workspace().expect("sealed workspace"); |
| 17 | std::fs::write(workspace.home().join(".codewhale/.onboarded"), "") |
| 18 | .expect("onboarded marker"); |
| 19 | workspace.trust_workspace().expect("trust workspace"); |
| 20 | let mut tui = Harness::builder(Harness::codewhale_binary()) |
| 21 | .cwd(workspace.workspace()) |
| 22 | .clear_env() |
| 23 | .seal_home(workspace.home()) |
| 24 | .env("CODEWHALE_DISABLE_MODELS_DEV_FETCH", "1") |
| 25 | .env("CODEWHALE_NO_UPDATE_CHECK", "1") |
| 26 | .env("NO_ANIMATIONS", "1") |
| 27 | .args([ |
| 28 | "--workspace", |
| 29 | workspace.workspace().to_str().expect("workspace UTF-8"), |
| 30 | "--no-project-config", |
| 31 | "--fresh", |
| 32 | ]) |
| 33 | .size(rows, cols) |
| 34 | .spawn() |
| 35 | .expect("start offline TUI"); |
| 36 | |
| 37 | wait_or_panic(&mut tui, "New session", STARTUP_WAIT, "launch card"); |
| 38 | super::launch_card_pty::explore_offline_from_composer(&mut tui); |
| 39 | |
| 40 | tui.send(keys::key::text("late queue draft")) |
| 41 | .expect("raw prompt bytes"); |
| 42 | std::thread::sleep(Duration::from_millis(delay_ms)); |
| 43 | tui.send(keys::key::enter()).expect("late submit"); |
| 44 | wait_or_panic( |
| 45 | &mut tui, |
| 46 | "Queued #1", |
| 47 | STARTUP_WAIT, |
| 48 | &format!("offline queue receipt ({cols}x{rows}, {delay_ms}ms submit)"), |
| 49 | ); |
| 50 | |
| 51 | tui.send(keys::key::ctrl('u')).expect("clear queued draft"); |
| 52 | tui.send(keys::key::text("input is still live")) |
| 53 | .expect("type after queued submit"); |
| 54 | wait_or_panic( |
| 55 | &mut tui, |
| 56 | "input is still live", |
| 57 | SETTLE_WAIT, |
| 58 | "composer liveness", |
| 59 | ); |
| 60 | tui.send(keys::key::ctrl('u')) |
| 61 | .expect("clear liveness probe"); |
| 62 | tui.wait_for(|frame| !frame.contains("input is still live"), SETTLE_WAIT) |
| 63 | .expect("Ctrl+U still clears the composer"); |
| 64 | tui.send(keys::key::text("/queue drop 1")) |
| 65 | .expect("type queue command"); |
| 66 | tui.wait_for_idle(Duration::from_millis(300), SETTLE_WAIT) |
| 67 | .expect("queue command settles"); |
| 68 | tui.send(keys::key::enter()).expect("execute queue command"); |
| 69 | wait_or_panic( |
| 70 | &mut tui, |
| 71 | "Dropped queued message", |
| 72 | SETTLE_WAIT, |
| 73 | "command liveness", |
| 74 | ); |
| 75 | assert!( |
| 76 | !tui.frame().contains("engine session id diverged"), |
| 77 | "{cols}x{rows}, {delay_ms}ms submit: {}", |
| 78 | tui.diagnostics() |
| 79 | ); |
| 80 | tui.shutdown(); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | fn wait_or_panic(tui: &mut Harness, needle: &str, timeout: Duration, label: &str) { |
| 86 | if tui.wait_for_text(needle, timeout).is_err() { |
| 87 | panic!("{label}: {needle:?} not visible\n{}", tui.diagnostics()); |
| 88 | } |
| 89 | } |
| 90 |