From c139e03bfdcb81c09c4b2c1bb4227011530ac2e8 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 23 Feb 2026 22:16:33 +0000 Subject: [PATCH] story-kit: merge 105_story_test_coverage_io_shell_rs_to_95 --- server/src/io/shell.rs | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/server/src/io/shell.rs b/server/src/io/shell.rs index 8219d77..66f6e62 100644 --- a/server/src/io/shell.rs +++ b/server/src/io/shell.rs @@ -121,4 +121,69 @@ mod tests { assert_ne!(result.exit_code, 0); assert!(!result.stderr.is_empty()); } + + #[tokio::test] + async fn exec_shell_delegates_to_impl_via_state() { + let dir = tempdir().unwrap(); + std::fs::write(dir.path().join("marker.txt"), "hello").unwrap(); + + let state = SessionState::default(); + *state.project_root.lock().unwrap() = Some(dir.path().to_path_buf()); + + let result = exec_shell("ls".to_string(), Vec::new(), &state) + .await + .unwrap(); + + assert_eq!(result.exit_code, 0); + assert!(result.stdout.contains("marker.txt")); + } + + #[tokio::test] + async fn exec_shell_errors_when_no_project_root() { + let state = SessionState::default(); + + let result = exec_shell("ls".to_string(), Vec::new(), &state).await; + + assert!(result.is_err()); + assert!(result.unwrap_err().contains("No project")); + } + + #[tokio::test] + async fn exec_shell_impl_errors_on_nonexistent_cwd() { + let result = exec_shell_impl( + "ls".to_string(), + Vec::new(), + PathBuf::from("/nonexistent_dir_that_does_not_exist_xyz"), + ) + .await; + + assert!(result.is_err()); + assert!(result.unwrap_err().contains("Failed to execute command")); + } + + #[test] + fn command_output_serializes_to_json() { + let output = CommandOutput { + stdout: "hello".to_string(), + stderr: "".to_string(), + exit_code: 0, + }; + + let json = serde_json::to_string(&output).unwrap(); + assert!(json.contains("\"stdout\":\"hello\"")); + assert!(json.contains("\"exit_code\":0")); + } + + #[test] + fn command_output_debug_format() { + let output = CommandOutput { + stdout: "out".to_string(), + stderr: "err".to_string(), + exit_code: 1, + }; + + let debug = format!("{:?}", output); + assert!(debug.contains("CommandOutput")); + assert!(debug.contains("out")); + } }