use codewhale_execpolicy::ExecPolicyEngine;
use codewhale_protocol::ids::{SessionId, ThreadId};
#[derive(Debug)]
pub struct TurnExecutor {
pub thread_id: ThreadId,
pub session_id: SessionId,
pub exec_policy: ExecPolicyEngine,
pub max_steps: u32,
}
impl TurnExecutor {
#[must_use]
pub fn new(
thread_id: ThreadId,
session_id: SessionId,
exec_policy: ExecPolicyEngine,
max_steps: u32,
) -> Self {
Self {
thread_id,
session_id,
exec_policy,
max_steps,
}
}
#[must_use]
pub fn can_execute(&self, step: u32) -> bool {
step < self.max_steps
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn executor_respects_max_steps() {
let ex = TurnExecutor::new(
ThreadId::new(),
SessionId::new(),
ExecPolicyEngine::new(vec![], vec![]),
2,
);
assert!(ex.can_execute(0));
assert!(ex.can_execute(1));
assert!(!ex.can_execute(2));
}
}