| 1 | use std::time::Duration; |
| 2 | |
| 3 | use super::qa_harness::harness::{Harness, make_sealed_workspace}; |
| 4 | |
| 5 | const WAIT: Duration = Duration::from_secs(15); |
| 6 | |
| 7 | fn print_frame(label: &str, tui: &mut Harness) { |
| 8 | tui.pump(); |
| 9 | let text = tui.frame().text(); |
| 10 | println!("--- {label}"); |
| 11 | for line in text.lines().filter(|line| !line.trim().is_empty()) { |
| 12 | println!("{}", line.trim_end()); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | #[test] |
| 17 | fn plugin_create_uses_engine_mode_availability_and_lists_help_in_real_terminal() { |
| 18 | let workspace = make_sealed_workspace().expect("sealed workspace"); |
| 19 | std::fs::write(workspace.home().join(".codewhale/.onboarded"), "").unwrap(); |
| 20 | std::fs::write( |
| 21 | workspace.home().join(".codewhale/config.toml"), |
| 22 | "[notifications]\nmethod = \"off\"\ncompletion_sound = \"off\"\n\n[extension_host]\nruntime = \"node\"\nnode = \"/nonexistent/codewhale-no-node\"\n", |
| 23 | ) |
| 24 | .unwrap(); |
| 25 | workspace.trust_workspace().unwrap(); |
| 26 | let mut tui = Harness::builder(Harness::codewhale_binary()) |
| 27 | .cwd(workspace.workspace()) |
| 28 | .clear_env() |
| 29 | .seal_home(workspace.home()) |
| 30 | .env("PATH", "/usr/bin:/bin:/usr/sbin:/sbin") |
| 31 | .env("CODEWHALE_DISABLE_MODELS_DEV_FETCH", "1") |
| 32 | .env("CODEWHALE_NO_UPDATE_CHECK", "1") |
| 33 | .env("CODEWHALE_DISABLE_LOCAL_OLLAMA_PROBE", "1") |
| 34 | .env("NO_ANIMATIONS", "1") |
| 35 | .env("RUST_LOG", "warn") |
| 36 | .args([ |
| 37 | "--workspace", |
| 38 | workspace.workspace().to_str().unwrap(), |
| 39 | "--no-project-config", |
| 40 | "--skip-onboarding", |
| 41 | "--fresh", |
| 42 | ]) |
| 43 | .size(32, 100) |
| 44 | .spawn() |
| 45 | .expect("start TUI"); |
| 46 | tui.wait_for_text("New session", WAIT).unwrap(); |
| 47 | tui.wait_for_idle(Duration::from_millis(250), Duration::from_secs(5)) |
| 48 | .unwrap(); |
| 49 | |
| 50 | tui.type_line("/plugin help").unwrap(); |
| 51 | tui.wait_for_text("/plugin create [idea]", WAIT).unwrap(); |
| 52 | print_frame("/plugin help in the shipped binary", &mut tui); |
| 53 | |
| 54 | tui.type_line("/plugin create a word counter").unwrap(); |
| 55 | tui.wait_for_text("Creator mode needs a plugin runtime", WAIT) |
| 56 | .unwrap(); |
| 57 | print_frame("/plugin create in the shipped binary", &mut tui); |
| 58 | let frame = tui.frame().text(); |
| 59 | let normalized = frame.split_whitespace().collect::<Vec<_>>().join(" "); |
| 60 | assert!( |
| 61 | normalized.contains( |
| 62 | "Creator mode is not available: Creator mode needs a plugin runtime (Node.js or Bun)" |
| 63 | ), |
| 64 | "{frame}" |
| 65 | ); |
| 66 | assert!( |
| 67 | !frame |
| 68 | .lines() |
| 69 | .any(|line| line.contains("Creator mode") && !line.contains("is not available")), |
| 70 | "{frame}" |
| 71 | ); |
| 72 | assert!(frame.contains("Describe a task"), "{frame}"); |
| 73 | tui.shutdown(); |
| 74 | } |
| 75 |