use acton_reactive::prelude::*;
use acton_test::prelude::*;
use anyhow::Ok;
use std::fs;
use tempfile::TempDir;
#[acton_test]
async fn test_default_configuration_loading() -> Result<(), anyhow::Error> {
let temp_dir = TempDir::new().unwrap();
std::env::set_var("XDG_CONFIG_HOME", temp_dir.path());
let mut app = ActonApp::launch_async().await;
let actor_builder = app.new_actor::<TestActor>();
let _handle = actor_builder.start().await;
temp_dir.close().unwrap();
Ok(())
}
#[acton_test]
async fn test_custom_configuration_override() -> anyhow::Result<()> {
let temp_dir = TempDir::new().unwrap();
let config_dir = temp_dir.path().join("acton");
fs::create_dir_all(&config_dir).unwrap();
let config_content = r#"
[timeouts]
actor_shutdown = 5000
system_shutdown = 15000
[limits]
actor_inbox_capacity = 512
concurrent_handlers_high_water_mark = 50
[defaults]
actor_name = "custom_actor"
[tracing]
debug = "info"
"#;
fs::write(config_dir.join("config.toml"), config_content).unwrap();
std::env::set_var("XDG_CONFIG_HOME", temp_dir.path());
let mut app = ActonApp::launch_async().await;
let actor_builder = app.new_actor::<TestActor>();
let _handle = actor_builder.start().await;
temp_dir.close().unwrap();
Ok(())
}
#[acton_test]
async fn test_xdg_directory_resolution() -> Result<(), anyhow::Error> {
let temp_dir = TempDir::new().unwrap();
let config_dir = temp_dir.path().join("acton");
fs::create_dir_all(&config_dir).unwrap();
let config_content = r"
[timeouts]
actor_shutdown = 7500
";
fs::write(config_dir.join("config.toml"), config_content).unwrap();
std::env::set_var("XDG_CONFIG_HOME", temp_dir.path());
let mut app = ActonApp::launch_async().await;
let actor_builder = app.new_actor::<TestActor>();
let _handle = actor_builder.start().await;
temp_dir.close().unwrap();
Ok(())
}
#[acton_test]
async fn test_malformed_config_handling() -> Result<(), anyhow::Error> {
let temp_dir = TempDir::new().unwrap();
let config_dir = temp_dir.path().join("acton");
fs::create_dir_all(&config_dir).unwrap();
let malformed_content = r#"
[timeouts]
actor_shutdown = "not_a_number"
[limits]
actor_inbox_capacity = -1
"#;
fs::write(config_dir.join("config.toml"), malformed_content).unwrap();
std::env::set_var("XDG_CONFIG_HOME", temp_dir.path());
let mut app = ActonApp::launch_async().await;
let actor_builder = app.new_actor::<TestActor>();
let _handle = actor_builder.start().await;
temp_dir.close().unwrap();
Ok(())
}
#[acton_test]
async fn test_backward_compatibility() -> Result<(), anyhow::Error> {
let mut app = ActonApp::launch_async().await;
let mut actor_builder = app.new_actor::<CounterActor>();
actor_builder.mutate_on::<Increment>(|actor, _| {
actor.model.count += 1;
Reply::ready()
});
let handle = actor_builder.start().await;
handle.send(Increment).await;
Ok(())
}
#[acton_test]
async fn test_config_values_used_in_behavior() -> Result<(), anyhow::Error> {
let temp_dir = TempDir::new().unwrap();
let config_dir = temp_dir.path().join("acton");
fs::create_dir_all(&config_dir).unwrap();
let config_content = r"
[limits]
actor_inbox_capacity = 2
";
fs::write(config_dir.join("config.toml"), config_content).unwrap();
std::env::set_var("XDG_CONFIG_HOME", temp_dir.path());
let mut app = ActonApp::launch_async().await;
let mut actor_builder = app.new_actor::<CounterActor>();
actor_builder.mutate_on::<Increment>(|actor, _| {
actor.model.count += 1;
Reply::ready()
});
let handle = actor_builder.start().await;
for _ in 0..5 {
handle.send(Increment).await;
}
temp_dir.close().unwrap();
Ok(())
}
#[acton_test]
async fn test_consistent_config_across_actors() -> Result<(), anyhow::Error> {
let temp_dir = TempDir::new().unwrap();
let config_dir = temp_dir.path().join("acton");
fs::create_dir_all(&config_dir).unwrap();
let config_content = r#"
[defaults]
actor_name = "test_actor"
"#;
fs::write(config_dir.join("config.toml"), config_content).unwrap();
std::env::set_var("XDG_CONFIG_HOME", temp_dir.path());
let mut app = ActonApp::launch_async().await;
let builder1 = app.new_actor::<CounterActor>();
let _handle1 = builder1.start().await;
let builder2 = app.new_actor::<CounterActor>();
let _handle2 = builder2.start().await;
temp_dir.close().unwrap();
Ok(())
}
#[derive(Debug, Default)]
struct TestActor;
#[derive(Debug, Default)]
struct CounterActor {
count: i32,
}
#[acton_message]
struct Increment;