story-kit: merge 105_story_test_coverage_io_shell_rs_to_95

This commit is contained in:
Dave
2026-02-23 22:16:33 +00:00
parent 0e098cea67
commit c139e03bfd

View File

@@ -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"));
}
}