| 1 | //! Launch actions must work through the real input loop, including Enter |
| 2 | //! after a mouse click. All state is sealed; provider fixtures use loopback. |
| 3 | |
| 4 | use std::time::Duration; |
| 5 | |
| 6 | use super::qa_harness; |
| 7 | use qa_harness::harness::{Harness, SealedWorkspace, make_sealed_workspace}; |
| 8 | use qa_harness::keys; |
| 9 | |
| 10 | const WAIT: Duration = Duration::from_secs(15); |
| 11 | const SIZES: [(u16, u16); 5] = [(12, 40), (16, 60), (24, 80), (32, 100), (40, 140)]; |
| 12 | const TITLE: &str = "Recent proof"; |
| 13 | const SAVED_TEXT: &str = "Restored conversation proof"; |
| 14 | |
| 15 | fn start(rows: u16, cols: u16, with_mcp: bool) -> (SealedWorkspace, Harness) { |
| 16 | start_titled(rows, cols, with_mcp, TITLE) |
| 17 | } |
| 18 | |
| 19 | fn start_titled(rows: u16, cols: u16, with_mcp: bool, title: &str) -> (SealedWorkspace, Harness) { |
| 20 | start_with_titles(rows, cols, with_mcp, &[title]) |
| 21 | } |
| 22 | |
| 23 | fn start_with_titles( |
| 24 | rows: u16, |
| 25 | cols: u16, |
| 26 | with_mcp: bool, |
| 27 | titles: &[&str], |
| 28 | ) -> (SealedWorkspace, Harness) { |
| 29 | start_with_theme(rows, cols, with_mcp, titles, None) |
| 30 | } |
| 31 | |
| 32 | fn start_with_theme( |
| 33 | rows: u16, |
| 34 | cols: u16, |
| 35 | with_mcp: bool, |
| 36 | titles: &[&str], |
| 37 | theme: Option<&str>, |
| 38 | ) -> (SealedWorkspace, Harness) { |
| 39 | start_with_options(rows, cols, with_mcp, titles, theme, false, false) |
| 40 | } |
| 41 | |
| 42 | fn start_with_options( |
| 43 | rows: u16, |
| 44 | cols: u16, |
| 45 | with_mcp: bool, |
| 46 | titles: &[&str], |
| 47 | theme: Option<&str>, |
| 48 | animated: bool, |
| 49 | no_color: bool, |
| 50 | ) -> (SealedWorkspace, Harness) { |
| 51 | start_in( |
| 52 | make_sealed_workspace().unwrap(), |
| 53 | Launch { |
| 54 | rows, |
| 55 | cols, |
| 56 | with_mcp, |
| 57 | titles, |
| 58 | theme, |
| 59 | animated, |
| 60 | no_color, |
| 61 | keep_composer: false, |
| 62 | }, |
| 63 | ) |
| 64 | } |
| 65 | |
| 66 | #[derive(Default)] |
| 67 | struct Launch<'a> { |
| 68 | rows: u16, |
| 69 | cols: u16, |
| 70 | with_mcp: bool, |
| 71 | titles: &'a [&'a str], |
| 72 | theme: Option<&'a str>, |
| 73 | animated: bool, |
| 74 | no_color: bool, |
| 75 | /// Skip the post-launch Ctrl+U that empties the composer. |
| 76 | keep_composer: bool, |
| 77 | } |
| 78 | |
| 79 | /// Launch into `workspace`; the composer-first launch card is home. |
| 80 | fn start_in(workspace: SealedWorkspace, launch: Launch<'_>) -> (SealedWorkspace, Harness) { |
| 81 | let Launch { |
| 82 | rows, |
| 83 | cols, |
| 84 | with_mcp, |
| 85 | titles, |
| 86 | theme, |
| 87 | animated, |
| 88 | no_color, |
| 89 | keep_composer, |
| 90 | } = launch; |
| 91 | let sessions = workspace.home().join(".codewhale/sessions"); |
| 92 | std::fs::create_dir_all(&sessions).unwrap(); |
| 93 | workspace.trust_workspace().unwrap(); |
| 94 | let mut fixtures = vec![(workspace.home().join(".codewhale/.onboarded"), Vec::new())]; |
| 95 | if let Some(theme) = theme { |
| 96 | fixtures.push(( |
| 97 | workspace.home().join(".codewhale/settings.toml"), |
| 98 | format!("theme = {theme:?}\n").into_bytes(), |
| 99 | )); |
| 100 | } |
| 101 | for (index, title) in titles.iter().enumerate() { |
| 102 | let id = format!( |
| 103 | "11111111-2222-4333-8444-{:012}", |
| 104 | 555555555555u64 + index as u64 |
| 105 | ); |
| 106 | let session = serde_json::json!({ |
| 107 | "schema_version": 1, |
| 108 | "metadata": { |
| 109 | "id": id, |
| 110 | "title": title, |
| 111 | "created_at": "2026-09-19T00:00:00Z", |
| 112 | "updated_at": format!("2026-09-19T00:00:{:02}Z", 59usize.saturating_sub(index)), |
| 113 | "message_count": 1, |
| 114 | "total_tokens": 0, |
| 115 | "model": "deepseek-flash", |
| 116 | "model_provider": "deepseek", |
| 117 | "workspace": workspace.workspace() |
| 118 | }, |
| 119 | "messages": [{"role": "user", "content": [{"type": "text", "text": SAVED_TEXT}]}], |
| 120 | "system_prompt": null |
| 121 | }); |
| 122 | fixtures.push(( |
| 123 | sessions.join(format!("{id}.json")), |
| 124 | serde_json::to_vec(&session).unwrap(), |
| 125 | )); |
| 126 | } |
| 127 | if with_mcp { |
| 128 | // A local failing server gives the summary a real row without any network. |
| 129 | let mcp = serde_json::json!({"mcpServers": {"launch-proof": { |
| 130 | "command": "/usr/bin/false", "required": true |
| 131 | }}}); |
| 132 | fixtures.push(( |
| 133 | workspace.home().join(".codewhale/mcp.json"), |
| 134 | serde_json::to_vec(&mcp).unwrap(), |
| 135 | )); |
| 136 | } |
| 137 | for (path, contents) in fixtures { |
| 138 | std::fs::write(path, contents).unwrap(); |
| 139 | } |
| 140 | |
| 141 | let mut tui = Harness::builder(Harness::codewhale_binary()) |
| 142 | .cwd(workspace.workspace()) |
| 143 | .clear_env() |
| 144 | .seal_home(workspace.home()) |
| 145 | .env("CODEWHALE_DISABLE_MODELS_DEV_FETCH", "1") |
| 146 | .env("CODEWHALE_NO_UPDATE_CHECK", "1") |
| 147 | .env("CODEWHALE_DISABLE_LOCAL_OLLAMA_PROBE", "1") |
| 148 | .env("NO_ANIMATIONS", if animated { "0" } else { "1" }) |
| 149 | .env("COLORTERM", "truecolor") |
| 150 | .env("NO_COLOR", if no_color { "1" } else { "" }) |
| 151 | .args([ |
| 152 | "--workspace", |
| 153 | workspace.workspace().to_str().unwrap(), |
| 154 | "--no-project-config", |
| 155 | "--fresh", |
| 156 | "--mouse-capture", |
| 157 | ]) |
| 158 | .size(rows, cols) |
| 159 | .spawn() |
| 160 | .unwrap(); |
| 161 | wait(&mut tui, "New session"); |
| 162 | if animated || keep_composer { |
| 163 | return (workspace, tui); |
| 164 | } |
| 165 | tui.wait_for_idle(Duration::from_millis(300), WAIT).unwrap(); |
| 166 | tui.send(keys::key::ctrl('u')).unwrap(); |
| 167 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 168 | (workspace, tui) |
| 169 | } |
| 170 | |
| 171 | pub(crate) fn explore_offline_from_composer(tui: &mut Harness) { |
| 172 | wait(tui, "Describe a task"); |
| 173 | tui.type_line("seed").expect("send a first message"); |
| 174 | wait(tui, "Choose your model provider"); |
| 175 | tui.send(keys::key::ctrl('o')).unwrap(); |
| 176 | wait(tui, "You're ready."); |
| 177 | tui.send(keys::key::enter()).unwrap(); |
| 178 | tui.wait_for_idle(Duration::from_millis(300), WAIT).unwrap(); |
| 179 | tui.send(keys::key::ctrl('u')).unwrap(); |
| 180 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 181 | } |
| 182 | |
| 183 | fn wait(tui: &mut Harness, text: &str) { |
| 184 | if let Err(error) = tui.wait_for(|frame| frame.contains(text), WAIT) { |
| 185 | let transcript = tui.transcript(); |
| 186 | let tail = &transcript[transcript.len().saturating_sub(4096)..]; |
| 187 | panic!( |
| 188 | "waiting for {text:?}: {error}\n{}\nPTY tail: {:?}", |
| 189 | tui.diagnostics(), |
| 190 | String::from_utf8_lossy(tail) |
| 191 | ); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | fn wait_for_plugins_screen(tui: &mut Harness) { |
| 196 | if let Err(error) = tui.wait_for( |
| 197 | |frame| frame.contains("Plugins") && frame.contains("Connectors"), |
| 198 | WAIT, |
| 199 | ) { |
| 200 | panic!( |
| 201 | "waiting for the Plugins screen: {error}\n{}", |
| 202 | tui.diagnostics() |
| 203 | ); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | fn click_text(tui: &mut Harness, text: &str) { |
| 208 | tui.pump(); |
| 209 | let (row, col) = tui |
| 210 | .frame() |
| 211 | .find_text(text) |
| 212 | .unwrap_or_else(|| panic!("missing click target {text:?}\n{}", tui.diagnostics())); |
| 213 | tui.send(keys::mouse::click(row, col)).unwrap(); |
| 214 | } |
| 215 | |
| 216 | #[test] |
| 217 | fn local_slash_navigation_does_not_create_rewindable_user_turns() { |
| 218 | let (_workspace, mut tui) = start_with_titles(24, 80, false, &[]); |
| 219 | // The first command leaves home; the others use the active-session path. |
| 220 | for (command, title) in [("/settings", "Settings"), ("/skills", ""), ("/mcp", "")] { |
| 221 | tui.type_line(command).unwrap(); |
| 222 | if title.is_empty() { |
| 223 | wait_for_plugins_screen(&mut tui); |
| 224 | } else { |
| 225 | wait(&mut tui, title); |
| 226 | } |
| 227 | tui.send(keys::key::esc()).unwrap(); |
| 228 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 229 | assert!( |
| 230 | !tui.frame() |
| 231 | .text() |
| 232 | .lines() |
| 233 | .take(18) |
| 234 | .any(|line| line.contains(command)), |
| 235 | "navigation leaked into transcript above the composer: {}", |
| 236 | tui.diagnostics() |
| 237 | ); |
| 238 | } |
| 239 | tui.send(keys::key::esc()).unwrap(); |
| 240 | tui.send(keys::key::esc()).unwrap(); |
| 241 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 242 | assert!( |
| 243 | !tui.frame().contains("Backtrack preview"), |
| 244 | "view navigation became a rewindable turn: {}", |
| 245 | tui.diagnostics() |
| 246 | ); |
| 247 | tui.shutdown(); |
| 248 | } |
| 249 | |
| 250 | #[test] |
| 251 | fn raw_slash_input_keeps_a_steady_submit_cue_and_runs_on_enter_without_another_key() { |
| 252 | // #6397: the `[↵]` chip follows the draft, not the paste-burst window, so |
| 253 | // it is already lit while a raw (non-bracketed) burst's Enter-suppression |
| 254 | // window is still open. It is therefore not a signal that Enter will |
| 255 | // submit; wait out the window (120ms) with a quiet PTY before pressing |
| 256 | // Enter, which must then run the command with no other key. |
| 257 | let (_workspace, mut tui) = start_with_titles(24, 80, false, &[]); |
| 258 | tui.send("/mcp").unwrap(); |
| 259 | wait(&mut tui, "enter:run"); |
| 260 | wait(&mut tui, "[↵]"); |
| 261 | tui.wait_for_idle(Duration::from_millis(300), WAIT).unwrap(); |
| 262 | assert!( |
| 263 | tui.frame().contains("[↵]") && !tui.frame().contains("[·]"), |
| 264 | "submit cue did not stay steady: {}", |
| 265 | tui.diagnostics() |
| 266 | ); |
| 267 | tui.send(keys::key::enter()).unwrap(); |
| 268 | wait_for_plugins_screen(&mut tui); |
| 269 | tui.shutdown(); |
| 270 | } |
| 271 | |
| 272 | #[test] |
| 273 | fn clicking_send_on_fresh_home_opens_the_command_in_a_new_session() { |
| 274 | let (_workspace, mut tui) = start_with_titles(24, 80, false, &[]); |
| 275 | tui.paste("/mcp").unwrap(); |
| 276 | wait(&mut tui, "[↵]"); |
| 277 | click_text(&mut tui, "[↵]"); |
| 278 | wait_for_plugins_screen(&mut tui); |
| 279 | tui.send(keys::key::esc()).unwrap(); |
| 280 | wait(&mut tui, "What do you want to accomplish?"); |
| 281 | tui.shutdown(); |
| 282 | } |
| 283 | |
| 284 | #[test] |
| 285 | fn launch_recent_click_then_enter_resumes_without_another_mouse_event() { |
| 286 | for (rows, cols) in SIZES { |
| 287 | let (_workspace, mut tui) = start(rows, cols, false); |
| 288 | assert!(!tui.frame().contains(TITLE)); |
| 289 | capture(&mut tui, "home"); |
| 290 | click_text(&mut tui, "Recent"); |
| 291 | wait(&mut tui, TITLE); |
| 292 | capture(&mut tui, "recent-expanded"); |
| 293 | click_text(&mut tui, TITLE); |
| 294 | wait(&mut tui, "Resume"); |
| 295 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 296 | capture(&mut tui, "confirm"); |
| 297 | tui.send(keys::key::enter()).unwrap(); |
| 298 | // No pointer motion follows Enter: the accepted action must run now. |
| 299 | wait(&mut tui, SAVED_TEXT); |
| 300 | if cols >= 80 { |
| 301 | wait(&mut tui, "Resumed:"); |
| 302 | } |
| 303 | assert!( |
| 304 | !tui.frame().contains("Session loaded from"), |
| 305 | "resume should not add a technical path receipt to the conversation" |
| 306 | ); |
| 307 | capture(&mut tui, "conversation"); |
| 308 | tui.shutdown(); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | #[test] |
| 313 | fn launch_mcp_summary_opens_manager_by_click_and_keyboard() { |
| 314 | for (rows, cols) in SIZES { |
| 315 | let (_workspace, mut tui) = start(rows, cols, true); |
| 316 | wait(&mut tui, "Connectors"); |
| 317 | assert!(!tui.frame().contains("launch-proof")); |
| 318 | capture(&mut tui, "home-mcp"); |
| 319 | click_text(&mut tui, "Connectors"); |
| 320 | wait_for_plugins_screen(&mut tui); |
| 321 | wait(&mut tui, "launch-proof"); |
| 322 | capture(&mut tui, "mcp"); |
| 323 | tui.send(keys::key::esc()).unwrap(); |
| 324 | wait(&mut tui, "New session"); |
| 325 | assert!(!tui.frame().contains("launch-proof")); |
| 326 | for _ in 0..4 { |
| 327 | tui.send(keys::key::down()).unwrap(); |
| 328 | } |
| 329 | tui.send(keys::key::enter()).unwrap(); |
| 330 | wait_for_plugins_screen(&mut tui); |
| 331 | wait(&mut tui, "launch-proof"); |
| 332 | tui.shutdown(); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | #[test] |
| 337 | fn launch_resume_buttons_support_mouse_cancel_and_keyboard_choice() { |
| 338 | for (rows, cols) in SIZES { |
| 339 | let (_workspace, mut tui) = start(rows, cols, false); |
| 340 | tui.send(keys::key::up()).unwrap(); |
| 341 | wait(&mut tui, TITLE); |
| 342 | click_text(&mut tui, TITLE); |
| 343 | wait(&mut tui, "cancel"); |
| 344 | click_text(&mut tui, "cancel"); |
| 345 | tui.wait_for( |
| 346 | |frame| frame.find_text(TITLE).is_some() && !frame.contains("resume Enter"), |
| 347 | WAIT, |
| 348 | ) |
| 349 | .unwrap(); |
| 350 | wait(&mut tui, "New session"); |
| 351 | assert!(!tui.frame().contains(SAVED_TEXT)); |
| 352 | click_text(&mut tui, TITLE); |
| 353 | wait(&mut tui, "cancel"); |
| 354 | tui.send(keys::key::tab()).unwrap(); |
| 355 | tui.send(keys::key::enter()).unwrap(); |
| 356 | tui.wait_for( |
| 357 | |frame| frame.find_text(TITLE).is_some() && !frame.contains("resume Enter"), |
| 358 | WAIT, |
| 359 | ) |
| 360 | .unwrap(); |
| 361 | wait(&mut tui, "New session"); |
| 362 | assert!(!tui.frame().contains(SAVED_TEXT)); |
| 363 | click_text(&mut tui, TITLE); |
| 364 | wait(&mut tui, "resume Enter"); |
| 365 | click_text(&mut tui, "resume Enter"); |
| 366 | wait(&mut tui, SAVED_TEXT); |
| 367 | tui.shutdown(); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /// Optional review evidence from the real PTY, keeping cell colors rather |
| 372 | /// than relying on symbol-only goldens. The viewer supplies terminal fonts. |
| 373 | pub(super) fn capture(tui: &mut Harness, name: &str) { |
| 374 | let Some(directory) = std::env::var_os("QA_LAUNCH_CAPTURE_DIR") else { |
| 375 | return; |
| 376 | }; |
| 377 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 378 | let frame = tui.frame(); |
| 379 | let directory = std::path::PathBuf::from(directory); |
| 380 | std::fs::create_dir_all(&directory).unwrap(); |
| 381 | let path = directory.join(format!("{name}-{}x{}.json", frame.cols(), frame.rows())); |
| 382 | std::fs::write( |
| 383 | path, |
| 384 | serde_json::to_vec_pretty(&frame.capture_cells()).unwrap(), |
| 385 | ) |
| 386 | .unwrap(); |
| 387 | } |
| 388 | |
| 389 | #[test] |
| 390 | fn plugin_command_opens_plugins_screen_with_kind_filters() { |
| 391 | for (rows, cols) in [(24, 80), (32, 120)] { |
| 392 | let (_workspace, mut tui) = start(rows, cols, true); |
| 393 | tui.paste("/plugin").unwrap(); |
| 394 | tui.wait_for_idle(Duration::from_millis(300), WAIT).unwrap(); |
| 395 | tui.send(keys::key::enter()).unwrap(); |
| 396 | wait_for_plugins_screen(&mut tui); |
| 397 | tui.wait_for_idle(Duration::from_millis(300), WAIT).unwrap(); |
| 398 | let frame = tui.frame(); |
| 399 | println!("--- /plugin at {cols}x{rows} ---\n{}", frame.text()); |
| 400 | for label in ["Hooks", "Installed", "Skills", "Connectors", "Command"] { |
| 401 | assert!( |
| 402 | frame.contains(label), |
| 403 | "missing filter {label:?} at {cols}x{rows}\n{}", |
| 404 | frame.text() |
| 405 | ); |
| 406 | } |
| 407 | assert!( |
| 408 | !frame.contains("Extensions"), |
| 409 | "the screen still says Extensions at {cols}x{rows}\n{}", |
| 410 | frame.text() |
| 411 | ); |
| 412 | tui.shutdown(); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | #[test] |
| 417 | #[ignore = "opt-in visual evidence; writes only with QA_LAUNCH_CAPTURE_DIR"] |
| 418 | fn workbench_settings_visual_evidence() { |
| 419 | assert!(std::env::var_os("QA_LAUNCH_CAPTURE_DIR").is_some()); |
| 420 | for (command, title, name) in [ |
| 421 | ("/model", "route ·", "models"), |
| 422 | ("/provider", "Provider", "providers"), |
| 423 | ("/fleet members", "Coordinator", "fleet"), |
| 424 | ("/plugin", "Installed", "plugins"), |
| 425 | ("/config", "Settings", "settings"), |
| 426 | ("/statusline", "Status", "statusline"), |
| 427 | ] { |
| 428 | for (rows, cols) in SIZES { |
| 429 | let (_workspace, mut tui) = start(rows, cols, true); |
| 430 | tui.paste(command).unwrap(); |
| 431 | tui.wait_for_idle(Duration::from_millis(300), WAIT).unwrap(); |
| 432 | tui.send(keys::key::enter()).unwrap(); |
| 433 | wait(&mut tui, title); |
| 434 | capture(&mut tui, name); |
| 435 | if name == "providers" { |
| 436 | tui.send(keys::key::alt('v')).unwrap(); |
| 437 | wait(&mut tui, "DeepSeek · Open details"); |
| 438 | capture(&mut tui, "provider-details"); |
| 439 | tui.send(keys::key::esc()).unwrap(); |
| 440 | wait(&mut tui, "Provider"); |
| 441 | } |
| 442 | tui.shutdown(); |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | #[test] |
| 448 | #[ignore = "opt-in populated launch evidence; fixture sessions, no provider calls"] |
| 449 | fn workbench_populated_home_visual_evidence() { |
| 450 | assert!(std::env::var_os("QA_LAUNCH_CAPTURE_DIR").is_some()); |
| 451 | for (rows, cols) in SIZES { |
| 452 | let (_workspace, mut tui) = start_with_titles( |
| 453 | rows, |
| 454 | cols, |
| 455 | true, |
| 456 | &[ |
| 457 | "Polish the release notes", |
| 458 | "Investigate a provider timeout", |
| 459 | "Review the plugin setup flow", |
| 460 | ], |
| 461 | ); |
| 462 | capture(&mut tui, "home-populated"); |
| 463 | tui.send(keys::key::down()).unwrap(); |
| 464 | tui.send(keys::key::down()).unwrap(); |
| 465 | capture(&mut tui, "home-populated-selected"); |
| 466 | tui.shutdown(); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | #[test] |
| 471 | fn launch_long_resume_title_preserves_warning_and_truthful_enter_hint() { |
| 472 | let title = "Investigate provider timeouts and connection failures across multiple accounts, preserve the original credentials, and verify every saved session can still be restored after the upgrade"; |
| 473 | for (rows, cols) in SIZES { |
| 474 | let (_workspace, mut tui) = start_titled(rows, cols, false, title); |
| 475 | tui.send(keys::key::up()).unwrap(); |
| 476 | wait(&mut tui, "Investigate provider"); |
| 477 | click_text(&mut tui, "Investigate provider"); |
| 478 | wait(&mut tui, "resume"); |
| 479 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 480 | capture(&mut tui, "confirm-long"); |
| 481 | let frame = tui.frame(); |
| 482 | let (warning_row, _) = frame.find_text("This replaces").expect("resume warning"); |
| 483 | let panel = (warning_row..frame.rows()) |
| 484 | .map(|y| frame.row(y)) |
| 485 | .map_while(|row| { |
| 486 | let (_, body) = row.split_once(['│', '|'])?; |
| 487 | let (body, _) = body.rsplit_once(['│', '|'])?; |
| 488 | Some(body.trim().to_owned()) |
| 489 | }) |
| 490 | .collect::<Vec<_>>() |
| 491 | .join(" "); |
| 492 | assert!( |
| 493 | panel.starts_with("This replaces the current context with that session's history."), |
| 494 | "{}", |
| 495 | frame.text() |
| 496 | ); |
| 497 | tui.send(keys::key::tab()).unwrap(); |
| 498 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 499 | let text = tui.frame().text(); |
| 500 | assert!(text.contains("cancel Enter"), "{text}"); |
| 501 | assert!(!text.contains("resume Enter"), "{text}"); |
| 502 | capture(&mut tui, "confirm-cancel"); |
| 503 | tui.send(keys::key::enter()).unwrap(); |
| 504 | wait(&mut tui, "New session"); |
| 505 | assert!(!tui.frame().contains(SAVED_TEXT)); |
| 506 | tui.shutdown(); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | #[test] |
| 511 | #[ignore = "opt-in all-theme evidence; fixture sessions, no provider calls"] |
| 512 | fn workbench_every_theme_visual_evidence() { |
| 513 | assert!(std::env::var_os("QA_LAUNCH_CAPTURE_DIR").is_some()); |
| 514 | for theme in codewhale_palette::SELECTABLE_THEMES { |
| 515 | let (_workspace, mut tui) = start_with_theme(24, 80, true, &[TITLE], Some(theme.name())); |
| 516 | capture(&mut tui, &format!("theme-{}-home", theme.name())); |
| 517 | tui.paste("/statusline").unwrap(); |
| 518 | tui.wait_for_idle(Duration::from_millis(300), WAIT).unwrap(); |
| 519 | tui.send(keys::key::enter()).unwrap(); |
| 520 | wait(&mut tui, "Status"); |
| 521 | capture(&mut tui, &format!("theme-{}-statusline", theme.name())); |
| 522 | tui.shutdown(); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | #[test] |
| 527 | #[ignore = "opt-in real launch animation capture; fixture state, no provider calls"] |
| 528 | fn workbench_whale_reveal_visual_evidence() { |
| 529 | let directory = std::path::PathBuf::from(std::env::var_os("QA_LAUNCH_CAPTURE_DIR").unwrap()); |
| 530 | std::fs::create_dir_all(&directory).unwrap(); |
| 531 | let (_workspace, mut tui) = |
| 532 | start_with_options(32, 100, false, &[TITLE], Some("shoreline"), true, false); |
| 533 | let start = std::time::Instant::now(); |
| 534 | for index in 0..16 { |
| 535 | let frame = tui.frame(); |
| 536 | assert!( |
| 537 | frame.text().contains("New session"), |
| 538 | "controls must remain usable during reveal" |
| 539 | ); |
| 540 | std::fs::write( |
| 541 | directory.join(format!("reveal-{index:02}-100x32.json")), |
| 542 | serde_json::to_vec_pretty(&frame.capture_cells()).unwrap(), |
| 543 | ) |
| 544 | .unwrap(); |
| 545 | std::thread::sleep(Duration::from_millis(50)); |
| 546 | } |
| 547 | eprintln!("Captured launch reveal over {:?}", start.elapsed()); |
| 548 | tui.shutdown(); |
| 549 | } |
| 550 | |
| 551 | /// Record temporal evidence from the real terminal, including its idle settle. |
| 552 | #[test] |
| 553 | #[ignore = "opt-in Underwater motion capture; isolated fixture, no provider calls"] |
| 554 | fn underwater_motion_visual_evidence() { |
| 555 | use std::io::Write; |
| 556 | let directory = std::path::PathBuf::from(std::env::var_os("QA_LAUNCH_CAPTURE_DIR").unwrap()); |
| 557 | std::fs::create_dir_all(&directory).unwrap(); |
| 558 | for (rows, cols) in [(24, 80), (36, 120)] { |
| 559 | let (_workspace, mut tui) = |
| 560 | start_with_options(rows, cols, false, &[TITLE], Some("underwater"), true, false); |
| 561 | // Home intentionally gives its brief whale reveal the stage. Sea life |
| 562 | // lives in the conversation field, so enter a fresh offline session. |
| 563 | tui.send(keys::key::ctrl('u')).unwrap(); |
| 564 | click_text(&mut tui, "New session"); |
| 565 | wait(&mut tui, "What do you want to accomplish?"); |
| 566 | let file = |
| 567 | std::fs::File::create(directory.join(format!("ocean-{cols}x{rows}.jsonl.gz"))).unwrap(); |
| 568 | let mut output = flate2::write::GzEncoder::new(file, flate2::Compression::fast()); |
| 569 | let start = std::time::Instant::now(); |
| 570 | for index in 0..360u64 { |
| 571 | let frame = tui.frame(); |
| 572 | assert!( |
| 573 | frame.contains("Describe a task") |
| 574 | && frame.contains("What do you want to accomplish?"), |
| 575 | "motion cannot displace the conversation or composer" |
| 576 | ); |
| 577 | serde_json::to_writer( |
| 578 | &mut output, |
| 579 | &serde_json::json!({ |
| 580 | "elapsed_ms": start.elapsed().as_millis(), |
| 581 | "frame": frame.capture_cells() |
| 582 | }), |
| 583 | ) |
| 584 | .unwrap(); |
| 585 | output.write_all(b"\n").unwrap(); |
| 586 | let target = Duration::from_millis((index + 1) * 33); |
| 587 | if let Some(remaining) = target.checked_sub(start.elapsed()) { |
| 588 | std::thread::sleep(remaining); |
| 589 | } |
| 590 | } |
| 591 | output.finish().unwrap(); |
| 592 | tui.shutdown(); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | /// Exercise the visible catalog controls and provider search through the |
| 597 | /// input decoder. This only browses fixture state; it never applies a route. |
| 598 | #[test] |
| 599 | fn settings_catalog_controls_and_provider_search_work_with_mouse_and_keyboard() { |
| 600 | for (rows, cols) in SIZES { |
| 601 | let (_workspace, mut tui) = start(rows, cols, false); |
| 602 | tui.paste("/provider").unwrap(); |
| 603 | tui.send(keys::key::enter()).unwrap(); |
| 604 | wait(&mut tui, "Provider"); |
| 605 | click_text(&mut tui, "browse all"); |
| 606 | wait(&mut tui, "configured"); |
| 607 | tui.send("/Anthropic").unwrap(); |
| 608 | wait(&mut tui, "search: Anthropic"); |
| 609 | capture(&mut tui, "providers-search"); |
| 610 | tui.send(keys::key::esc()).unwrap(); |
| 611 | wait(&mut tui, "Provider"); |
| 612 | capture(&mut tui, "providers-catalog"); |
| 613 | tui.send(keys::key::esc()).unwrap(); |
| 614 | // Let the standalone Escape decode before starting a bracketed paste. |
| 615 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 616 | tui.paste("/model").unwrap(); |
| 617 | tui.send(keys::key::enter()).unwrap(); |
| 618 | wait(&mut tui, "route ·"); |
| 619 | click_text(&mut tui, "browse catalog"); |
| 620 | wait(&mut tui, "catalog"); |
| 621 | capture(&mut tui, "models-catalog"); |
| 622 | tui.send(keys::key::esc()).unwrap(); |
| 623 | tui.shutdown(); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | #[test] |
| 628 | fn fleet_roles_open_the_shared_model_picker_and_escape_returns_to_the_same_role() { |
| 629 | for (rows, cols) in SIZES { |
| 630 | let (_workspace, mut tui) = start(rows, cols, false); |
| 631 | tui.paste("/fleet members").unwrap(); |
| 632 | tui.send(keys::key::enter()).unwrap(); |
| 633 | wait(&mut tui, "Coordinator"); |
| 634 | capture(&mut tui, "fleet-assignments"); |
| 635 | tui.send(keys::key::enter()).unwrap(); |
| 636 | wait(&mut tui, "Model · Coordinator"); |
| 637 | wait(&mut tui, "Current session"); |
| 638 | capture(&mut tui, "fleet-coordinator-model"); |
| 639 | // The roster footer ("saved teams") can stay visible behind the |
| 640 | // picker at wide sizes, so it does not prove Esc landed. Wait for the |
| 641 | // picker itself to close and the screen to settle before the next |
| 642 | // key: a key sent inside the Esc disambiguation window is read as |
| 643 | // Alt+key and the role never changes. |
| 644 | close_picker(&mut tui, "Model · Coordinator"); |
| 645 | tui.send(keys::key::down()).unwrap(); |
| 646 | tui.send(keys::key::enter()).unwrap(); |
| 647 | wait(&mut tui, "Model · manager"); |
| 648 | capture(&mut tui, "fleet-role-model"); |
| 649 | tui.send("search-proof").unwrap(); |
| 650 | wait(&mut tui, "search-proof"); |
| 651 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 652 | tui.send(keys::key::esc()).unwrap(); |
| 653 | tui.wait_for(|frame| !frame.contains("search-proof"), WAIT) |
| 654 | .unwrap(); |
| 655 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 656 | close_picker(&mut tui, "Model · manager"); |
| 657 | tui.send(keys::key::enter()).unwrap(); |
| 658 | wait(&mut tui, "Model · manager"); |
| 659 | // Following Coordinator is a selectable local choice even without credentials. |
| 660 | tui.send(keys::key::enter()).unwrap(); |
| 661 | wait(&mut tui, "Personal"); |
| 662 | capture(&mut tui, "fleet-role-destination"); |
| 663 | tui.shutdown(); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /// Esc out of a Fleet model picker and wait until the roster is back and |
| 668 | /// quiet, so the next key is never folded into the Esc sequence. |
| 669 | fn close_picker(tui: &mut Harness, title: &str) { |
| 670 | tui.send(keys::key::esc()).unwrap(); |
| 671 | if let Err(error) = tui.wait_for(|frame| !frame.contains(title), WAIT) { |
| 672 | panic!( |
| 673 | "waiting for {title:?} to close: {error}\n{}", |
| 674 | tui.diagnostics() |
| 675 | ); |
| 676 | } |
| 677 | wait(tui, "saved teams"); |
| 678 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 679 | } |
| 680 | |
| 681 | #[test] |
| 682 | fn no_color_keeps_home_navigation_and_submit_cues_without_color() { |
| 683 | let sgr = regex::Regex::new(r"\x1b\[([0-9;:]*)m").unwrap(); |
| 684 | for (rows, cols) in SIZES { |
| 685 | let (_workspace, mut tui) = |
| 686 | start_with_options(rows, cols, false, &[TITLE], Some("shoreline"), false, true); |
| 687 | wait(&mut tui, "Describe a task"); |
| 688 | assert!(!tui.frame().contains("[·]")); |
| 689 | tui.send(keys::key::up()).unwrap(); |
| 690 | wait(&mut tui, TITLE); |
| 691 | tui.send(keys::key::up()).unwrap(); |
| 692 | capture(&mut tui, "no-color-selected"); |
| 693 | tui.send(keys::key::enter()).unwrap(); |
| 694 | wait(&mut tui, "Resume"); |
| 695 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 696 | tui.send(keys::key::enter()).unwrap(); |
| 697 | wait(&mut tui, SAVED_TEXT); |
| 698 | tui.send("monochrome draft").unwrap(); |
| 699 | wait(&mut tui, "[↵]"); |
| 700 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 701 | capture(&mut tui, "no-color-draft"); |
| 702 | |
| 703 | for row in 0..rows { |
| 704 | for col in 0..cols { |
| 705 | assert_eq!( |
| 706 | tui.frame().colors_at(row, col), |
| 707 | Some(( |
| 708 | qa_harness::frame::Color::Default, |
| 709 | qa_harness::frame::Color::Default |
| 710 | )), |
| 711 | "{cols}x{rows} cell ({row}, {col}) added a color" |
| 712 | ); |
| 713 | } |
| 714 | } |
| 715 | // Inspect the whole emitted stream, not just its last rendered frame. |
| 716 | let transcript = tui.transcript(); |
| 717 | let output = String::from_utf8_lossy(&transcript); |
| 718 | for codes in sgr.captures_iter(&output) { |
| 719 | for code in codes[1] |
| 720 | .split([';', ':']) |
| 721 | .filter_map(|code| code.parse::<u16>().ok()) |
| 722 | { |
| 723 | assert!( |
| 724 | !matches!(code, 30..=38 | 40..=48 | 58 | 90..=97 | 100..=107), |
| 725 | "{cols}x{rows} emitted color SGR {:?}", |
| 726 | &codes[0] |
| 727 | ); |
| 728 | } |
| 729 | } |
| 730 | tui.shutdown(); |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | #[test] |
| 735 | fn home_returns_to_the_same_conversation_by_escape_click_and_typing() { |
| 736 | for (rows, cols) in SIZES { |
| 737 | let (_workspace, mut tui) = start(rows, cols, false); |
| 738 | tui.send(keys::key::up()).unwrap(); |
| 739 | wait(&mut tui, TITLE); |
| 740 | click_text(&mut tui, TITLE); |
| 741 | wait(&mut tui, "Resume"); |
| 742 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 743 | tui.send(keys::key::enter()).unwrap(); |
| 744 | wait(&mut tui, SAVED_TEXT); |
| 745 | for return_path in ["escape", "click", "type"] { |
| 746 | tui.paste("/home").unwrap(); |
| 747 | tui.send(keys::key::enter()).unwrap(); |
| 748 | wait(&mut tui, "Back to conversation"); |
| 749 | capture(&mut tui, "home-return"); |
| 750 | match return_path { |
| 751 | "escape" => tui.send(keys::key::esc()).unwrap(), |
| 752 | "click" => click_text(&mut tui, "Back to conversation"), |
| 753 | _ => tui.send("draft stays here").unwrap(), |
| 754 | } |
| 755 | tui.wait_for(|frame| !frame.contains("Back to conversation"), WAIT) |
| 756 | .unwrap(); |
| 757 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 758 | if return_path == "type" { |
| 759 | wait(&mut tui, "draft stays here"); |
| 760 | capture(&mut tui, "home-return-draft"); |
| 761 | tui.send(keys::key::ctrl('u')).unwrap(); |
| 762 | } |
| 763 | // Slash commands add transcript rows. At 40x12 the original |
| 764 | // message is now above the viewport, so inspect scrollback. |
| 765 | tui.send(keys::key::page_up()).unwrap(); |
| 766 | wait(&mut tui, SAVED_TEXT); |
| 767 | tui.send(keys::key::alt('G')).unwrap(); |
| 768 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 769 | } |
| 770 | tui.paste("/overview").unwrap(); |
| 771 | tui.send(keys::key::enter()).unwrap(); |
| 772 | tui.wait_for_idle(Duration::from_millis(300), WAIT).unwrap(); |
| 773 | // The dashboard is longer than a short transcript viewport. |
| 774 | for _ in 0..20 { |
| 775 | if tui.frame().contains("Quick Actions") { |
| 776 | break; |
| 777 | } |
| 778 | tui.send(keys::key::page_up()).unwrap(); |
| 779 | tui.wait_for_idle(Duration::from_millis(200), WAIT).unwrap(); |
| 780 | } |
| 781 | wait(&mut tui, "Quick Actions"); |
| 782 | tui.shutdown(); |
| 783 | } |
| 784 | } |
| 785 |