返回 CodeWhale
conversation_mode_pty.rs
根目录 / crates / tui / tests / cucumber / conversation_mode_pty.rs
1 use std::time::Duration;
2
3 use super::qa_harness::{
4 harness::{Harness, make_sealed_workspace},
5 keys,
6 };
7
8 const WAIT: Duration = Duration::from_secs(15);
9
10 fn print_frame(label: &str, tui: &mut Harness) {
11 tui.pump();
12 let text = tui.frame().text();
13 println!("--- {label}");
14 for line in text.lines().filter(|line| !line.trim().is_empty()) {
15 println!("{}", line.trim_end());
16 }
17 }
18
19 #[test]
20 fn shipped_binary_lists_creator_disabled_and_refuses_new_creator_with_the_reason() {
21 let workspace = make_sealed_workspace().expect("sealed workspace");
22 std::fs::write(workspace.home().join(".codewhale/.onboarded"), "").unwrap();
23 std::fs::write(
24 workspace.home().join(".codewhale/config.toml"),
25 "[notifications]\nmethod = \"off\"\ncompletion_sound = \"off\"\n\n[extension_host]\nruntime = \"node\"\nnode = \"/nonexistent/codewhale-no-node\"\n",
26 )
27 .unwrap();
28 workspace.trust_workspace().unwrap();
29 let mut tui = Harness::builder(Harness::codewhale_binary())
30 .cwd(workspace.workspace())
31 .clear_env()
32 .seal_home(workspace.home())
33 .env("PATH", "/usr/bin:/bin:/usr/sbin:/sbin")
34 .env("CODEWHALE_DISABLE_MODELS_DEV_FETCH", "1")
35 .env("CODEWHALE_NO_UPDATE_CHECK", "1")
36 .env("CODEWHALE_DISABLE_LOCAL_OLLAMA_PROBE", "1")
37 .env("NO_ANIMATIONS", "1")
38 .env("RUST_LOG", "warn")
39 .args([
40 "--workspace",
41 workspace.workspace().to_str().unwrap(),
42 "--no-project-config",
43 "--skip-onboarding",
44 "--fresh",
45 ])
46 .size(32, 100)
47 .spawn()
48 .expect("start TUI");
49 tui.wait_for_text("New session", WAIT).unwrap();
50 tui.wait_for_idle(Duration::from_millis(250), Duration::from_secs(5))
51 .unwrap();
52
53 tui.type_line("/new creator").unwrap();
54 tui.wait_for_text("Creator mode needs a plugin runtime", WAIT)
55 .unwrap();
56 print_frame("/new creator in the shipped binary", &mut tui);
57 let after_refusal = tui.frame().text();
58 let normalized = after_refusal
59 .split_whitespace()
60 .collect::<Vec<_>>()
61 .join(" ");
62 assert!(
63 normalized.contains("Creator mode needs a plugin runtime (Node.js or Bun)"),
64 "{after_refusal}"
65 );
66 assert!(
67 after_refusal
68 .lines()
69 .filter(|line| !line.contains("Creator mode is not available:"))
70 .all(|line| !line.contains("Creator mode")),
71 "the conversation stays Standard: {}",
72 tui.diagnostics()
73 );
74
75 tui.type_line("/mode").unwrap();
76 tui.wait_for_text("Conversation mode", WAIT).unwrap();
77 tui.wait_for_text("Permissions", WAIT).unwrap();
78 print_frame("/mode picker in the shipped binary", &mut tui);
79 let frame = tui.frame().text();
80 let creator_row = frame
81 .lines()
82 .find(|line| line.contains("Creator mode"))
83 .expect("Creator is listed");
84 assert!(
85 creator_row.contains("Creator mode needs a plugin runtime"),
86 "{creator_row}"
87 );
88 let first_group = frame.find("Conversation mode").unwrap();
89 let second_group = frame.find("Permissions").unwrap();
90 assert!(first_group < frame.find("Standard mode").unwrap());
91 assert!(frame.find("Creator mode").unwrap() < second_group);
92 tui.send(keys::key::esc()).unwrap();
93 tui.shutdown();
94 }
95
95 lines RUST