| 1 | use crate::commands::CommandResult; |
| 2 | use crate::tui::app::{App, AppAction}; |
| 3 | use codewhale_command_contract::workflow::*; |
| 4 | use codewhale_execpolicy::ApprovalMode; |
| 5 | use codewhale_models::ContentBlock; |
| 6 | use codewhale_models::Role; |
| 7 | use std::path::PathBuf; |
| 8 | |
| 9 | use crate::tui::app::TuiOptions; |
| 10 | |
| 11 | fn test_app() -> App { |
| 12 | let options = TuiOptions { |
| 13 | ..crate::tui::test_support::test_tui_options(PathBuf::from(".")) |
| 14 | }; |
| 15 | App::new(options, &codewhale_runtime::config::Config::default()) |
| 16 | } |
| 17 | |
| 18 | #[test] |
| 19 | fn auto_sets_auto_review_and_explains_the_trio() { |
| 20 | let mut app = test_app(); |
| 21 | app.ui_locale = codewhale_localization::Locale::En; |
| 22 | app.set_agent_approval_posture(ApprovalMode::Suggest); |
| 23 | |
| 24 | let result = auto(&mut app, None); |
| 25 | assert!(!result.is_error, "{:?}", result.message); |
| 26 | assert_eq!(app.approval_mode, ApprovalMode::Auto); |
| 27 | let text = result.message.as_deref().unwrap(); |
| 28 | assert!(text.contains("Auto-Review")); |
| 29 | assert!(text.contains("/goal")); |
| 30 | assert!(text.contains("/workflow")); |
| 31 | assert!(result.action.is_none()); |
| 32 | } |
| 33 | |
| 34 | #[test] |
| 35 | fn auto_rejects_arguments() { |
| 36 | let mut app = test_app(); |
| 37 | let result = auto(&mut app, Some("now")); |
| 38 | assert!(result.is_error); |
| 39 | assert!(result.message.as_deref().unwrap().contains("Usage: /auto")); |
| 40 | } |
| 41 | |
| 42 | #[test] |
| 43 | fn auto_errors_when_managed_auto_review_is_disabled() { |
| 44 | let mut app = test_app(); |
| 45 | app.auto_review_disabled = true; |
| 46 | app.set_agent_approval_posture(ApprovalMode::Suggest); |
| 47 | |
| 48 | let result = auto(&mut app, None); |
| 49 | assert!(result.is_error); |
| 50 | assert!( |
| 51 | result |
| 52 | .message |
| 53 | .as_deref() |
| 54 | .unwrap_or_default() |
| 55 | .contains("auto_review.disabled = true") |
| 56 | ); |
| 57 | assert_eq!(app.approval_mode, ApprovalMode::Suggest); |
| 58 | } |
| 59 | |
| 60 | #[test] |
| 61 | fn auto_emits_broad_allow_pause_note_only_when_broad_rules_are_suspended() { |
| 62 | let mut plain_app = test_app(); |
| 63 | plain_app.ui_locale = codewhale_localization::Locale::En; |
| 64 | plain_app.set_agent_approval_posture(ApprovalMode::Suggest); |
| 65 | let plain_result = auto(&mut plain_app, None); |
| 66 | assert!(!plain_result.is_error); |
| 67 | assert!( |
| 68 | !plain_result |
| 69 | .message |
| 70 | .as_deref() |
| 71 | .unwrap_or_default() |
| 72 | .contains("Broad allow rules are paused"), |
| 73 | "{:?}", |
| 74 | plain_result.message |
| 75 | ); |
| 76 | |
| 77 | let mut broad_app = test_app(); |
| 78 | broad_app.ui_locale = codewhale_localization::Locale::En; |
| 79 | broad_app.set_agent_approval_posture(ApprovalMode::Suggest); |
| 80 | broad_app.exec_policy_engine.set_ruleset( |
| 81 | codewhale_execpolicy::Ruleset::user(vec![], vec![]).with_ask_rules(vec![ |
| 82 | codewhale_execpolicy::ToolAskRule { |
| 83 | tool: "exec_shell".to_string(), |
| 84 | command: Some("*".to_string()), |
| 85 | action: codewhale_execpolicy::PermissionAction::Allow, |
| 86 | ..codewhale_execpolicy::ToolAskRule::new("") |
| 87 | }, |
| 88 | ]), |
| 89 | ); |
| 90 | let broad_result = auto(&mut broad_app, None); |
| 91 | assert!(!broad_result.is_error); |
| 92 | let broad_msg = broad_result.message.as_deref().unwrap_or_default(); |
| 93 | assert!( |
| 94 | broad_msg.contains("Broad allow rules are paused while Auto-Review is on"), |
| 95 | "{broad_msg}" |
| 96 | ); |
| 97 | } |
| 98 | |
| 99 | #[test] |
| 100 | fn ordinary_workflow_is_a_toolless_review_turn() { |
| 101 | let mut app = test_app(); |
| 102 | let result = workflow(&mut app, Some("audit provider error handling")); |
| 103 | assert!(!result.is_error); |
| 104 | let Some(AppAction::WorkflowInstruction { |
| 105 | display, |
| 106 | instruction, |
| 107 | }) = result.action |
| 108 | else { |
| 109 | panic!("expected WorkflowInstruction action"); |
| 110 | }; |
| 111 | assert!(display.contains("audit provider error handling")); |
| 112 | assert!(!display.contains("workflow` tool")); |
| 113 | assert!( |
| 114 | display.len() < 80, |
| 115 | "visible transcript line must stay compact" |
| 116 | ); |
| 117 | assert!(instruction.starts_with(WORKFLOW_DRAFT_INSTRUCTION_PREFIX)); |
| 118 | assert!( |
| 119 | instruction.len() < 700, |
| 120 | "draft instruction grew into a manual" |
| 121 | ); |
| 122 | assert!(!instruction.contains("parallel()")); |
| 123 | assert!(!instruction.contains("responseSchema")); |
| 124 | |
| 125 | let queued = crate::tui::app::QueuedMessage::new(display, Some(instruction)); |
| 126 | assert_eq!( |
| 127 | crate::tui::ui::allowed_tools_for_message(None, &queued), |
| 128 | Some(Vec::new()), |
| 129 | "the host, not model compliance, must prevent same-turn execution" |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | #[test] |
| 134 | fn oversized_multibyte_objective_is_bounded_once_and_confirmed_exactly() { |
| 135 | let mut app = test_app(); |
| 136 | let original = "鲸".repeat(WORKFLOW_OBJECTIVE_MAX_CHARS + 50); |
| 137 | let drafted = workflow(&mut app, Some(&original)); |
| 138 | let Some(AppAction::WorkflowInstruction { |
| 139 | display, |
| 140 | instruction, |
| 141 | }) = drafted.action |
| 142 | else { |
| 143 | panic!("expected WorkflowInstruction action"); |
| 144 | }; |
| 145 | |
| 146 | assert!(display.chars().count() <= WORKFLOW_DISPLAY_MAX_CHARS); |
| 147 | assert!(!display.contains('\n')); |
| 148 | let draft = envelope_from_instruction(WORKFLOW_DRAFT_INSTRUCTION_PREFIX, &instruction) |
| 149 | .expect("typed workflow draft envelope"); |
| 150 | let objective = draft.objective.as_deref().expect("bounded objective"); |
| 151 | assert_eq!(objective.chars().count(), WORKFLOW_OBJECTIVE_MAX_CHARS); |
| 152 | assert!(objective.ends_with('…')); |
| 153 | |
| 154 | app.api_messages_mut().push(codewhale_models::Message { |
| 155 | role: Role::User, |
| 156 | content: vec![ContentBlock::Text { |
| 157 | text: instruction, |
| 158 | cache_control: None, |
| 159 | }], |
| 160 | }); |
| 161 | app.api_messages_mut().push(codewhale_models::Message { |
| 162 | role: Role::Assistant, |
| 163 | content: vec![ContentBlock::Text { |
| 164 | text: "Reviewed bounded objective and proposed phases.".to_string(), |
| 165 | cache_control: None, |
| 166 | }], |
| 167 | }); |
| 168 | |
| 169 | let confirmed = workflow(&mut app, Some("confirm")); |
| 170 | let Some(AppAction::WorkflowInstruction { |
| 171 | display, |
| 172 | instruction, |
| 173 | }) = confirmed.action |
| 174 | else { |
| 175 | panic!("expected confirmed WorkflowInstruction action"); |
| 176 | }; |
| 177 | assert!(display.chars().count() <= WORKFLOW_DISPLAY_MAX_CHARS); |
| 178 | let confirmed = envelope_from_instruction(WORKFLOW_CONFIRM_INSTRUCTION_PREFIX, &instruction) |
| 179 | .expect("typed workflow confirmation envelope"); |
| 180 | assert_eq!(confirmed.objective.as_deref(), Some(objective)); |
| 181 | } |
| 182 | |
| 183 | #[test] |
| 184 | fn confirm_survives_ordinary_messages_between_draft_and_confirm() { |
| 185 | let mut app = test_app(); |
| 186 | let drafted = workflow(&mut app, Some("audit provider error handling")); |
| 187 | let Some(AppAction::WorkflowInstruction { |
| 188 | display, |
| 189 | instruction, |
| 190 | }) = drafted.action |
| 191 | else { |
| 192 | panic!("expected WorkflowInstruction action"); |
| 193 | }; |
| 194 | app.api_messages_mut().push(codewhale_models::Message { |
| 195 | role: Role::User, |
| 196 | content: vec![ContentBlock::Text { |
| 197 | text: format!("{instruction}\n\n---\n\nUser request: {display}"), |
| 198 | cache_control: None, |
| 199 | }], |
| 200 | }); |
| 201 | app.api_messages_mut().push(codewhale_models::Message { |
| 202 | role: Role::Assistant, |
| 203 | content: vec![ContentBlock::Text { |
| 204 | text: "Objective, phases, workers, and risks. Run /workflow confirm to start." |
| 205 | .to_string(), |
| 206 | cache_control: None, |
| 207 | }], |
| 208 | }); |
| 209 | |
| 210 | // The user types or the model replies again before confirming — the |
| 211 | // explicit confirm must still find the reviewed draft (regression: the |
| 212 | // old supersede rule cancelled the draft on any ordinary message and |
| 213 | // made repeated confirm attempts impossible). |
| 214 | app.api_messages_mut().push(codewhale_models::Message { |
| 215 | role: Role::User, |
| 216 | content: vec![ContentBlock::Text { |
| 217 | text: "hmm it won't let me confirm it lol".to_string(), |
| 218 | cache_control: None, |
| 219 | }], |
| 220 | }); |
| 221 | let confirmed = workflow(&mut app, Some("confirm")); |
| 222 | assert!(!confirmed.is_error, "{:?}", confirmed.message); |
| 223 | let Some(AppAction::WorkflowInstruction { instruction, .. }) = confirmed.action else { |
| 224 | panic!("expected confirmed WorkflowInstruction action"); |
| 225 | }; |
| 226 | assert!(instruction.starts_with(WORKFLOW_CONFIRM_INSTRUCTION_PREFIX)); |
| 227 | |
| 228 | // A newer DRAFT still supersedes the older one. |
| 229 | let redrafted = workflow(&mut app, Some("fix the confirm flow")); |
| 230 | let Some(AppAction::WorkflowInstruction { |
| 231 | instruction: redraft_instruction, |
| 232 | display: redraft_display, |
| 233 | }) = redrafted.action |
| 234 | else { |
| 235 | panic!("expected WorkflowInstruction action"); |
| 236 | }; |
| 237 | app.api_messages_mut().push(codewhale_models::Message { |
| 238 | role: Role::User, |
| 239 | content: vec![ContentBlock::Text { |
| 240 | text: format!("{redraft_instruction}\n\n---\n\nUser request: {redraft_display}"), |
| 241 | cache_control: None, |
| 242 | }], |
| 243 | }); |
| 244 | let still_unreviewed = workflow(&mut app, Some("confirm")); |
| 245 | assert!( |
| 246 | still_unreviewed.is_error |
| 247 | && still_unreviewed |
| 248 | .message |
| 249 | .as_deref() |
| 250 | .unwrap_or_default() |
| 251 | .contains("not been reviewed"), |
| 252 | "a newer, unreviewed draft must be confirmed only after its review: {:?}", |
| 253 | still_unreviewed.message |
| 254 | ); |
| 255 | } |
| 256 | |
| 257 | #[test] |
| 258 | fn workflow_confirmation_is_a_separate_tool_enabled_turn() { |
| 259 | let mut app = test_app(); |
| 260 | let drafted = workflow(&mut app, Some("audit provider error handling")); |
| 261 | let Some(AppAction::WorkflowInstruction { |
| 262 | display, |
| 263 | instruction, |
| 264 | }) = drafted.action |
| 265 | else { |
| 266 | panic!("expected WorkflowInstruction action"); |
| 267 | }; |
| 268 | app.api_messages_mut().push(codewhale_models::Message { |
| 269 | role: Role::User, |
| 270 | content: vec![ContentBlock::Text { |
| 271 | text: format!("{instruction}\n\n---\n\nUser request: {display}"), |
| 272 | cache_control: None, |
| 273 | }], |
| 274 | }); |
| 275 | assert!( |
| 276 | workflow(&mut app, Some("confirm")).is_error, |
| 277 | "a failed or unfinished draft turn is not a reviewed plan" |
| 278 | ); |
| 279 | app.api_messages_mut().push(codewhale_models::Message { |
| 280 | role: Role::Assistant, |
| 281 | content: vec![ContentBlock::Text { |
| 282 | text: "Objective, phases, workers, and risks. Run /workflow confirm to start." |
| 283 | .to_string(), |
| 284 | cache_control: None, |
| 285 | }], |
| 286 | }); |
| 287 | |
| 288 | let confirmed = workflow(&mut app, Some("confirm")); |
| 289 | assert!(!confirmed.is_error); |
| 290 | let Some(AppAction::WorkflowInstruction { |
| 291 | display, |
| 292 | instruction, |
| 293 | }) = confirmed.action |
| 294 | else { |
| 295 | panic!("expected confirmed WorkflowInstruction action"); |
| 296 | }; |
| 297 | assert!(instruction.starts_with(WORKFLOW_CONFIRM_INSTRUCTION_PREFIX)); |
| 298 | let queued = crate::tui::app::QueuedMessage::new(display, Some(instruction.clone())); |
| 299 | assert_eq!( |
| 300 | crate::tui::ui::allowed_tools_for_message(None, &queued), |
| 301 | None, |
| 302 | "only the later explicit confirmation restores the normal catalog" |
| 303 | ); |
| 304 | |
| 305 | app.api_messages_mut().push(codewhale_models::Message { |
| 306 | role: Role::User, |
| 307 | content: vec![ContentBlock::Text { |
| 308 | text: instruction, |
| 309 | cache_control: None, |
| 310 | }], |
| 311 | }); |
| 312 | let replay = workflow(&mut app, Some("confirm")); |
| 313 | assert!(replay.is_error, "one draft may not be confirmed twice"); |
| 314 | } |
| 315 | |
| 316 | #[test] |
| 317 | fn workflow_status_and_cancel_answer_from_the_host_without_a_model_turn() { |
| 318 | let dir = tempfile::tempdir().expect("tempdir"); |
| 319 | let mut app = test_app(); |
| 320 | app.workspace = dir.path().to_path_buf(); |
| 321 | app.current_session_id = Some("workflow-host-test-session".to_string()); |
| 322 | |
| 323 | // Nothing has run in this workspace: status is a plain answer, and it |
| 324 | // must not create the run journal just to say so. |
| 325 | let result = workflow(&mut app, Some("status")); |
| 326 | assert!(!result.is_error); |
| 327 | assert!( |
| 328 | result.action.is_none(), |
| 329 | "status must not send a model message" |
| 330 | ); |
| 331 | assert!( |
| 332 | result |
| 333 | .message |
| 334 | .as_deref() |
| 335 | .unwrap() |
| 336 | .contains("No workflow runs") |
| 337 | ); |
| 338 | assert!(!dir.path().join(".codewhale/workflow-runs.jsonl").exists()); |
| 339 | |
| 340 | let result = workflow(&mut app, Some("status wf_missing")); |
| 341 | assert!(result.is_error); |
| 342 | assert!(result.action.is_none()); |
| 343 | |
| 344 | // A seeded run is listed and described from host state. |
| 345 | codewhale_engine::tools::workflow::structcopy_test_seed_run( |
| 346 | dir.path(), |
| 347 | "workflow_seed", |
| 348 | app.current_session_id |
| 349 | .as_deref() |
| 350 | .expect("test session identity"), |
| 351 | ); |
| 352 | let result = workflow(&mut app, Some("runs")); |
| 353 | let text = result.message.unwrap(); |
| 354 | assert!(text.contains("workflow_seed"), "{text}"); |
| 355 | assert!(text.contains("queued"), "{text}"); |
| 356 | assert!(result.action.is_none()); |
| 357 | |
| 358 | // Cancel with one active run needs no id and never asks the model. |
| 359 | // The seeded record has no live controller (no VM ran); cancel still |
| 360 | // marks the journal cancelled with an honest nothing-live receipt. |
| 361 | let result = workflow(&mut app, Some("cancel")); |
| 362 | assert!(result.action.is_none()); |
| 363 | assert!(!result.is_error, "{:?}", result.message); |
| 364 | let text = result.message.as_deref().unwrap(); |
| 365 | assert!(text.contains("workflow_seed"), "{text}"); |
| 366 | assert!(text.contains("cancelled"), "{text}"); |
| 367 | let after = codewhale_engine::tools::workflow::host_workflow_runs( |
| 368 | &app.workspace, |
| 369 | app.current_session_id.as_deref(), |
| 370 | ); |
| 371 | assert_eq!( |
| 372 | after |
| 373 | .iter() |
| 374 | .find(|line| line.run_id == "workflow_seed") |
| 375 | .map(|line| line.status), |
| 376 | Some("cancelled") |
| 377 | ); |
| 378 | |
| 379 | let result = workflow(&mut app, Some("cancel with spaces")); |
| 380 | assert!(result.is_error); |
| 381 | |
| 382 | let result = workflow(&mut app, Some("help")); |
| 383 | assert!(result.message.unwrap().contains("/workflow status")); |
| 384 | |
| 385 | // `/workflow run <path>` now drafts a tool-less review. Only a later |
| 386 | // explicit confirmation may launch the exact saved source. |
| 387 | let result = workflow(&mut app, Some("run workflows/tiny.workflow.js")); |
| 388 | let Some(AppAction::WorkflowInstruction { |
| 389 | display, |
| 390 | instruction, |
| 391 | }) = result.action |
| 392 | else { |
| 393 | panic!("expected WorkflowInstruction action"); |
| 394 | }; |
| 395 | assert!(display.contains("workflows/tiny.workflow.js"), "{display}"); |
| 396 | let draft = envelope_from_instruction(WORKFLOW_DRAFT_INSTRUCTION_PREFIX, &instruction) |
| 397 | .expect("typed saved-workflow draft"); |
| 398 | assert_eq!( |
| 399 | draft.source_path.as_deref(), |
| 400 | Some("workflows/tiny.workflow.js") |
| 401 | ); |
| 402 | let queued = crate::tui::app::QueuedMessage::new(display, Some(instruction.clone())); |
| 403 | assert_eq!( |
| 404 | crate::tui::ui::allowed_tools_for_message(None, &queued), |
| 405 | Some(Vec::new()) |
| 406 | ); |
| 407 | |
| 408 | app.api_messages_mut().push(codewhale_models::Message { |
| 409 | role: Role::User, |
| 410 | content: vec![ContentBlock::Text { |
| 411 | text: instruction, |
| 412 | cache_control: None, |
| 413 | }], |
| 414 | }); |
| 415 | app.api_messages_mut().push(codewhale_models::Message { |
| 416 | role: Role::Assistant, |
| 417 | content: vec![ContentBlock::Text { |
| 418 | text: "Saved Workflow path and risks reviewed.".to_string(), |
| 419 | cache_control: None, |
| 420 | }], |
| 421 | }); |
| 422 | let confirmed = workflow(&mut app, Some("confirm")); |
| 423 | let Some(AppAction::WorkflowInstruction { instruction, .. }) = confirmed.action else { |
| 424 | panic!("expected confirmed saved Workflow action"); |
| 425 | }; |
| 426 | assert!(instruction.contains("`source_path`"), "{instruction}"); |
| 427 | assert!( |
| 428 | instruction.contains("workflows/tiny.workflow.js"), |
| 429 | "{instruction}" |
| 430 | ); |
| 431 | |
| 432 | assert!(workflow(&mut app, Some("run ../outside.workflow.js")).is_error); |
| 433 | assert!(workflow(&mut app, Some("run /tmp/outside.workflow.js")).is_error); |
| 434 | } |
| 435 | |
| 436 | #[test] |
| 437 | fn workflows_opens_the_run_dashboard_and_keeps_host_verbs_free() { |
| 438 | let dir = tempfile::tempdir().expect("tempdir"); |
| 439 | let mut app = test_app(); |
| 440 | app.workspace = dir.path().to_path_buf(); |
| 441 | app.current_session_id = Some("workflow-host-test-session".to_string()); |
| 442 | |
| 443 | // Bare `/workflows` opens the dashboard: a host action, never a |
| 444 | // model turn — observation carries no orchestration authority. |
| 445 | let result = workflows(&mut app, None); |
| 446 | assert!(!result.is_error); |
| 447 | assert!(matches!( |
| 448 | result.action, |
| 449 | Some(AppAction::OpenWorkflowsManager) |
| 450 | )); |
| 451 | |
| 452 | // Host control verbs still answer inline (the old alias surface). |
| 453 | let result = workflows(&mut app, Some("status")); |
| 454 | assert!(!result.is_error); |
| 455 | assert!( |
| 456 | result.action.is_none(), |
| 457 | "status must not send a model message" |
| 458 | ); |
| 459 | assert!( |
| 460 | result |
| 461 | .message |
| 462 | .as_deref() |
| 463 | .unwrap() |
| 464 | .contains("No workflow runs") |
| 465 | ); |
| 466 | |
| 467 | // Orchestration attempts are redirected to /workflow, the only |
| 468 | // surface that carries launch authority. |
| 469 | let result = workflows(&mut app, Some("audit provider errors")); |
| 470 | assert!(result.is_error); |
| 471 | assert!(result.action.is_none()); |
| 472 | assert!(result.message.unwrap().contains("never launches")); |
| 473 | } |
| 474 | |
| 475 | #[test] |
| 476 | fn workflow_settings_explains_the_session_table() { |
| 477 | let mut app = test_app(); |
| 478 | app.workflow_config.automatic = false; |
| 479 | app.workflow_config.require_approval_for_writes = false; |
| 480 | app.goal_max_continuations = 25; |
| 481 | let result = workflow(&mut app, Some("settings")); |
| 482 | assert!(result.action.is_none()); |
| 483 | let text = result.message.unwrap(); |
| 484 | assert!(!text.contains("automatic ="), "{text}"); |
| 485 | assert!(text.contains("require_approval_for_writes = off"), "{text}"); |
| 486 | assert!(text.contains("max_continuations = 25"), "{text}"); |
| 487 | } |
| 488 | |
| 489 | #[test] |
| 490 | fn workflow_settings_and_tool_share_a_refreshed_session_table() { |
| 491 | use codewhale_engine::tools::spec::{ApprovalRequirement, ToolContext, ToolSpec}; |
| 492 | use codewhale_engine::tools::subagent::{SubAgentRuntime, new_shared_subagent_manager}; |
| 493 | use codewhale_engine::tools::workflow::WorkflowTool; |
| 494 | use serde_json::json; |
| 495 | |
| 496 | let dir = tempfile::tempdir().expect("tempdir"); |
| 497 | let mut app = test_app(); |
| 498 | app.workspace = dir.path().to_path_buf(); |
| 499 | |
| 500 | let mut table = app.workflow_config.clone(); |
| 501 | table.automatic = false; |
| 502 | table.require_approval_for_writes = false; |
| 503 | table.auto_start_read_only = false; |
| 504 | codewhale_engine::tools::workflow::set_session_workflow_config(&app.workspace, table.clone()); |
| 505 | app.workflow_config = table; |
| 506 | |
| 507 | let result = workflow(&mut app, Some("settings")); |
| 508 | assert!(result.action.is_none()); |
| 509 | let text = result.message.unwrap(); |
| 510 | assert!(!text.contains("automatic ="), "{text}"); |
| 511 | assert!(text.contains("require_approval_for_writes = off"), "{text}"); |
| 512 | assert!(text.contains("auto_start_read_only = off"), "{text}"); |
| 513 | |
| 514 | let ctx = ToolContext::new(dir.path().to_path_buf()); |
| 515 | let manager = new_shared_subagent_manager(dir.path().to_path_buf(), 2); |
| 516 | let _ = rustls::crypto::ring::default_provider().install_default(); |
| 517 | let client = codewhale_engine::client::CodewhaleClient::new( |
| 518 | &codewhale_runtime::config::Config::default() |
| 519 | .with_legacy_root(Some("test-key".to_string()), None), |
| 520 | ) |
| 521 | .expect("stub client"); |
| 522 | let mut runtime = SubAgentRuntime::new( |
| 523 | client, |
| 524 | "deepseek-v4-flash".to_string(), |
| 525 | ctx, |
| 526 | true, |
| 527 | None, |
| 528 | manager.clone(), |
| 529 | ); |
| 530 | // Stale snapshot: product defaults still require write approval. |
| 531 | runtime.api_config = Some(std::sync::Arc::new( |
| 532 | codewhale_runtime::config::Config::default(), |
| 533 | )); |
| 534 | let tool = WorkflowTool::new(manager, runtime); |
| 535 | |
| 536 | let write_plan = json!({ |
| 537 | "action": "start", |
| 538 | "plan": { |
| 539 | "goal": "write freely", |
| 540 | "risk": "writes", |
| 541 | "children": [{ "prompt": "edit", "type": "implementer" }] |
| 542 | } |
| 543 | }); |
| 544 | let read_only = json!({ |
| 545 | "action": "start", |
| 546 | "plan": { |
| 547 | "goal": "scout crates", |
| 548 | "risk": "read_only", |
| 549 | "children": [{ "prompt": "look", "type": "explore" }] |
| 550 | } |
| 551 | }); |
| 552 | assert_eq!( |
| 553 | tool.approval_requirement_for(&write_plan), |
| 554 | ApprovalRequirement::Auto, |
| 555 | "refreshed require_approval_for_writes = false must win over the stale runtime snapshot" |
| 556 | ); |
| 557 | assert_eq!( |
| 558 | tool.approval_requirement_for(&read_only), |
| 559 | ApprovalRequirement::Required, |
| 560 | "refreshed auto_start_read_only = false must still ask" |
| 561 | ); |
| 562 | } |
| 563 | |
| 564 | fn workflow(app: &mut App, arg: Option<&str>) -> CommandResult { |
| 565 | crate::commands::execute(&format!("/workflow {}", arg.unwrap_or_default()), app) |
| 566 | } |
| 567 | |
| 568 | fn workflows(app: &mut App, arg: Option<&str>) -> CommandResult { |
| 569 | crate::commands::execute(&format!("/workflows {}", arg.unwrap_or_default()), app) |
| 570 | } |
| 571 | |
| 572 | fn auto(app: &mut App, arg: Option<&str>) -> CommandResult { |
| 573 | crate::commands::execute(&format!("/auto {}", arg.unwrap_or_default()), app) |
| 574 | } |
| 575 |