use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
pub type AgentId = uuid::Uuid;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AgentStatus {
Starting,
Running,
Idle,
Stopped,
Failed,
}
impl std::fmt::Display for AgentStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AgentStatus::Starting => write!(f, "starting"),
AgentStatus::Running => write!(f, "running"),
AgentStatus::Idle => write!(f, "idle"),
AgentStatus::Stopped => write!(f, "stopped"),
AgentStatus::Failed => write!(f, "failed"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentInfo {
pub id: AgentId,
pub name: String,
pub status: AgentStatus,
pub created_at: DateTime<Utc>,
pub seed_id: Option<uuid::Uuid>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_agent_status_display_all_variants() {
assert_eq!(AgentStatus::Starting.to_string(), "starting");
assert_eq!(AgentStatus::Running.to_string(), "running");
assert_eq!(AgentStatus::Idle.to_string(), "idle");
assert_eq!(AgentStatus::Stopped.to_string(), "stopped");
assert_eq!(AgentStatus::Failed.to_string(), "failed");
}
#[test]
fn test_agent_status_equality() {
assert_eq!(AgentStatus::Running, AgentStatus::Running);
assert_ne!(AgentStatus::Running, AgentStatus::Idle);
}
#[test]
fn test_agent_status_serialization_roundtrip() {
for status in [
AgentStatus::Starting,
AgentStatus::Running,
AgentStatus::Idle,
AgentStatus::Stopped,
AgentStatus::Failed,
] {
let json = serde_json::to_string(&status).unwrap();
let restored: AgentStatus = serde_json::from_str(&json).unwrap();
assert_eq!(status, restored);
}
}
#[test]
fn test_agent_info_construction() {
let id = AgentId::new_v4();
let seed_id = uuid::Uuid::new_v4();
let now = Utc::now();
let info = AgentInfo {
id,
name: "test-agent".to_string(),
status: AgentStatus::Running,
created_at: now,
seed_id: Some(seed_id),
};
assert_eq!(info.id, id);
assert_eq!(info.name, "test-agent");
assert_eq!(info.status, AgentStatus::Running);
assert_eq!(info.created_at, now);
assert_eq!(info.seed_id, Some(seed_id));
}
#[test]
fn test_agent_info_serialization_roundtrip() {
let info = AgentInfo {
id: AgentId::new_v4(),
name: "serializer".to_string(),
status: AgentStatus::Idle,
created_at: Utc::now(),
seed_id: None,
};
let json = serde_json::to_string(&info).unwrap();
let restored: AgentInfo = serde_json::from_str(&json).unwrap();
assert_eq!(restored.id, info.id);
assert_eq!(restored.name, info.name);
assert_eq!(restored.status, info.status);
assert_eq!(restored.seed_id, None);
}
#[test]
fn test_agent_status_copy() {
let status = AgentStatus::Running;
let copied = status; assert_eq!(status, copied); }
}