| 1 | //! `/turn` command — inspect the current or latest completed turn. |
| 2 | |
| 3 | use crate::commands::traits::{CommandInfo, RegisterCommand}; |
| 4 | use crate::localization::MessageId; |
| 5 | use crate::tui::app::{App, AppAction}; |
| 6 | |
| 7 | use super::CommandResult; |
| 8 | |
| 9 | pub(in crate::commands) const COMMAND_INFO: CommandInfo = CommandInfo { |
| 10 | name: "turn", |
| 11 | aliases: &["turns"], |
| 12 | usage: "/turn inspect", |
| 13 | description_id: MessageId::CmdTurnInspectDescription, |
| 14 | }; |
| 15 | |
| 16 | pub(in crate::commands) struct TurnCmd; |
| 17 | |
| 18 | impl RegisterCommand for TurnCmd { |
| 19 | fn info() -> &'static CommandInfo { |
| 20 | &COMMAND_INFO |
| 21 | } |
| 22 | |
| 23 | fn execute(_app: &mut App, arg: Option<&str>) -> CommandResult { |
| 24 | let verb = arg.map(str::trim).unwrap_or(""); |
| 25 | if matches!(verb, "inspect" | "i" | "") { |
| 26 | return CommandResult::action(AppAction::OpenTurnInspector); |
| 27 | } |
| 28 | CommandResult::error(format!( |
| 29 | "Unknown /turn verb '{verb}'. Use /turn inspect to open the whole-turn inspector." |
| 30 | )) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | #[cfg(test)] |
| 35 | mod tests { |
| 36 | use super::*; |
| 37 | use crate::config::Config; |
| 38 | use crate::tui::app::{App, TuiOptions}; |
| 39 | use std::path::PathBuf; |
| 40 | |
| 41 | fn test_app() -> App { |
| 42 | let options = TuiOptions { |
| 43 | model: "deepseek-v4-flash".to_string(), |
| 44 | ..crate::test_support::test_tui_options(PathBuf::from(".")) |
| 45 | }; |
| 46 | App::new(options, &Config::default()) |
| 47 | } |
| 48 | |
| 49 | #[test] |
| 50 | fn bare_turn_inspect_opens_turn_inspector() { |
| 51 | let mut app = test_app(); |
| 52 | let result = TurnCmd::execute(&mut app, None); |
| 53 | assert!(!result.is_error); |
| 54 | assert_eq!(result.action, Some(AppAction::OpenTurnInspector)); |
| 55 | assert!(result.message.is_none()); |
| 56 | } |
| 57 | |
| 58 | #[test] |
| 59 | fn turn_inspect_verb_opens_turn_inspector() { |
| 60 | let mut app = test_app(); |
| 61 | let result = TurnCmd::execute(&mut app, Some("inspect")); |
| 62 | assert!(!result.is_error); |
| 63 | assert_eq!(result.action, Some(AppAction::OpenTurnInspector)); |
| 64 | } |
| 65 | |
| 66 | #[test] |
| 67 | fn unknown_turn_verb_returns_error() { |
| 68 | let mut app = test_app(); |
| 69 | let result = TurnCmd::execute(&mut app, Some("bad")); |
| 70 | assert!(result.is_error); |
| 71 | assert!( |
| 72 | result |
| 73 | .message |
| 74 | .as_deref() |
| 75 | .is_some_and(|m| m.contains("/turn inspect")) |
| 76 | ); |
| 77 | assert!(result.action.is_none()); |
| 78 | } |
| 79 | } |
| 80 |