返回 CodeWhale
work_bar_keys_pty.rs
根目录 / crates / tui / tests / cucumber / work_bar_keys_pty.rs
1 //! Press the advertised work-bar chord through a real terminal decoder,
2 //! including the fresh-session screen where the hint first appears.
3
4 use std::time::Duration;
5
6 use super::qa_harness::{
7 harness::{Harness, make_sealed_workspace},
8 keys,
9 };
10
11 #[test]
12 fn work_bar_opens_from_launch_with_legacy_and_enhanced_keys() {
13 for (rows, cols) in [(12, 40), (16, 60), (24, 80), (32, 100), (40, 140)] {
14 let workspace = make_sealed_workspace().expect("sealed workspace");
15 std::fs::write(workspace.home().join(".codewhale/.onboarded"), "").unwrap();
16 workspace.trust_workspace().unwrap();
17 let mut tui = Harness::builder(Harness::codewhale_binary())
18 .cwd(workspace.workspace())
19 .clear_env()
20 .seal_home(workspace.home())
21 .env("CODEWHALE_DISABLE_MODELS_DEV_FETCH", "1")
22 .env("CODEWHALE_NO_UPDATE_CHECK", "1")
23 .env("NO_ANIMATIONS", "1")
24 .env("RUST_LOG", "warn")
25 .args([
26 "--workspace",
27 workspace.workspace().to_str().unwrap(),
28 "--no-project-config",
29 "--mouse-capture",
30 ])
31 .size(rows, cols)
32 .spawn()
33 .expect("start TUI");
34 tui.wait_for_text("New session", Duration::from_secs(15))
35 .unwrap();
36 tui.wait_for_idle(Duration::from_millis(250), Duration::from_secs(5))
37 .unwrap();
38
39 super::launch_card_pty::capture(&mut tui, "workbar-closed");
40
41 // Legacy Ctrl+] is one byte, decoded by crossterm as Ctrl+5.
42 tui.send([0x1d]).unwrap();
43 tui.wait_for_text("no agents have run this session", Duration::from_secs(5))
44 .unwrap_or_else(|error| panic!("{cols}x{rows}: legacy Ctrl+] failed: {error}"));
45
46 super::launch_card_pty::capture(&mut tui, "workbar-fleet");
47
48 // The enhanced backward chord must work on the same launch screen.
49 tui.send(b"\x1b[9;6u").unwrap();
50 tui.wait_for_text("no to-dos yet", Duration::from_secs(5))
51 .unwrap();
52 super::launch_card_pty::capture(&mut tui, "workbar-tasks");
53 // The visible close control and keyboard Escape share the close action.
54 let (row, col) = tui.frame().find_text("×").expect("visible close control");
55 tui.send(keys::mouse::click(row, col)).unwrap();
56 tui.wait_for(
57 |frame| !frame.contains("no to-dos yet"),
58 Duration::from_secs(5),
59 )
60 .unwrap();
61
62 tui.send(b"\x1b[93;5u").unwrap();
63 tui.wait_for_text("no agents have run this session", Duration::from_secs(5))
64 .unwrap_or_else(|error| panic!("{cols}x{rows}: enhanced Ctrl+] failed: {error}"));
65
66 // Ordinary bracket/digit text still reaches the composer; the legacy
67 // chord also works after typing has dismissed the launch card.
68 tui.send("draft ]5").unwrap();
69 tui.wait_for_text("draft ]5", Duration::from_secs(5))
70 .unwrap();
71 tui.wait_for_idle(Duration::from_millis(250), Duration::from_secs(5))
72 .unwrap();
73 tui.send([0x1d]).unwrap();
74 tui.wait_for_text("nothing running in the background", Duration::from_secs(5))
75 .unwrap();
76 tui.shutdown();
77 }
78 }
79
79 lines RUST