1use std::process::{Command, Stdio};
8
9use crate::error::{Autom8Error, Result};
10
11#[derive(Debug)]
13pub struct ImproveSessionResult {
14 pub success: bool,
16 pub exit_code: Option<i32>,
18}
19
20pub fn run_improve_session(prompt: &str) -> Result<ImproveSessionResult> {
33 let status = Command::new("claude")
34 .arg(prompt)
35 .stdin(Stdio::inherit())
36 .stdout(Stdio::inherit())
37 .stderr(Stdio::inherit())
38 .status()
39 .map_err(|e| {
40 if e.kind() == std::io::ErrorKind::NotFound {
41 Autom8Error::ClaudeNotFound
42 } else {
43 Autom8Error::ClaudeSpawnError(e.to_string())
44 }
45 })?;
46
47 Ok(ImproveSessionResult {
48 success: status.success(),
49 exit_code: status.code(),
50 })
51}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_improve_session_result_debug() {
59 let result = ImproveSessionResult {
60 success: true,
61 exit_code: Some(0),
62 };
63 let debug = format!("{:?}", result);
64 assert!(debug.contains("ImproveSessionResult"));
65 assert!(debug.contains("success: true"));
66 }
67
68 #[test]
69 fn test_improve_session_result_success_false() {
70 let result = ImproveSessionResult {
71 success: false,
72 exit_code: Some(1),
73 };
74 assert!(!result.success);
75 assert_eq!(result.exit_code, Some(1));
76 }
77
78 #[test]
79 fn test_improve_session_result_no_exit_code() {
80 let result = ImproveSessionResult {
82 success: false,
83 exit_code: None,
84 };
85 assert!(!result.success);
86 assert!(result.exit_code.is_none());
87 }
88}