mecha10-behavior-runtime 0.1.25

Behavior tree runtime for Mecha10 - unified AI and logic composition system
Documentation
// Tests for mecha10_behavior_runtime::behavior

use async_trait::async_trait;
use mecha10_behavior_runtime::{BehaviorNode, BehaviorNodeExt, Context, NodeStatus};

#[derive(Debug)]
struct TestBehavior {
    tick_count: usize,
    max_ticks: usize,
}

#[async_trait]
impl BehaviorNode for TestBehavior {
    async fn tick(&mut self, _ctx: &Context) -> anyhow::Result<NodeStatus> {
        self.tick_count += 1;
        if self.tick_count >= self.max_ticks {
            Ok(NodeStatus::Success)
        } else {
            Ok(NodeStatus::Running)
        }
    }

    fn name(&self) -> &str {
        "test_behavior"
    }
}

#[tokio::test]
#[ignore = "Requires Redis infrastructure"]
async fn test_behavior_runs_until_complete() {
    let ctx = Context::new("test_node").await.unwrap();
    let mut behavior = TestBehavior {
        tick_count: 0,
        max_ticks: 3,
    };

    let status = behavior.run_until_complete(&ctx).await.unwrap();
    assert_eq!(status, NodeStatus::Success);
    assert_eq!(behavior.tick_count, 3);
}

#[tokio::test]
#[ignore = "Requires Redis infrastructure"]
async fn test_behavior_with_limit() {
    let ctx = Context::new("test_node").await.unwrap();
    let mut behavior = TestBehavior {
        tick_count: 0,
        max_ticks: 100,
    };

    // Should fail because max_ticks is 100 but limit is 10
    let result = behavior.run_with_limit(&ctx, 10).await;
    assert!(result.is_err());
}