feat: Improve service manager testing and error handling

- Add comprehensive testing instructions to README.
- Improve error handling in examples to prevent crashes.
- Enhance launchctl error handling for production safety.
- Improve zinit error handling for production safety.
- Remove obsolete plan_to_fix.md file.
- Update Rhai integration tests for improved robustness.
- Improve service manager creation on Linux with systemd fallback.
This commit is contained in:
Mahmoud-Emad
2025-07-02 12:05:03 +03:00
parent a63cbe2bd9
commit 95122dffee
12 changed files with 473 additions and 422 deletions

View File

@@ -4,13 +4,17 @@ use std::path::Path;
/// Helper function to create a Rhai engine for service manager testing
fn create_service_manager_engine() -> Result<Engine, Box<EvalAltResult>> {
let engine = Engine::new();
// Register any custom functions that would be needed for service manager integration
// For now, we'll keep it simple since the actual service manager integration
// would require more complex setup
Ok(engine)
#[cfg(feature = "rhai")]
{
let mut engine = Engine::new();
// Register the service manager module for real testing
sal_service_manager::rhai::register_service_manager_module(&mut engine)?;
Ok(engine)
}
#[cfg(not(feature = "rhai"))]
{
Ok(Engine::new())
}
}
/// Helper function to run a Rhai script file
@@ -65,7 +69,7 @@ fn test_rhai_service_manager_basic() {
}
Err(e) => {
println!("✗ Rhai basic test failed: {}", e);
panic!("Rhai script execution failed");
assert!(false, "Rhai script execution failed: {}", e);
}
}
}
@@ -112,7 +116,7 @@ fn test_rhai_service_lifecycle() {
}
Err(e) => {
println!("✗ Rhai lifecycle test failed: {}", e);
panic!("Rhai script execution failed");
assert!(false, "Rhai script execution failed: {}", e);
}
}
}
@@ -155,7 +159,7 @@ fn test_rhai_engine_functionality() {
println!("✓ All basic Rhai functionality tests passed");
} else {
println!("✗ Some basic Rhai functionality tests failed");
panic!("Basic Rhai tests failed");
assert!(false, "Basic Rhai tests failed");
}
}
}
@@ -181,7 +185,7 @@ fn test_rhai_engine_functionality() {
}
Err(e) => {
println!("✗ Basic Rhai functionality test failed: {}", e);
panic!("Basic Rhai test failed");
assert!(false, "Basic Rhai test failed: {}", e);
}
}
}
@@ -201,7 +205,10 @@ fn test_rhai_script_error_handling() {
match engine.eval::<rhai::Dynamic>(error_script) {
Ok(_) => {
println!("⚠ Expected error but script succeeded");
panic!("Error handling test failed - expected error but got success");
assert!(
false,
"Error handling test failed - expected error but got success"
);
}
Err(e) => {
println!("✓ Error correctly caught: {}", e);
@@ -228,16 +235,16 @@ fn test_rhai_script_files_exist() {
match fs::read_to_string(script_file) {
Ok(content) => {
if content.trim().is_empty() {
panic!("Script file {} is empty", script_file);
assert!(false, "Script file {} is empty", script_file);
}
println!(" Content length: {} characters", content.len());
}
Err(e) => {
panic!("Failed to read script file {}: {}", script_file, e);
assert!(false, "Failed to read script file {}: {}", script_file, e);
}
}
} else {
panic!("Required script file not found: {}", script_file);
assert!(false, "Required script file not found: {}", script_file);
}
}