use serde::{Deserialize, Serialize};
use crate::types::{CollectiveId, Timestamp};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Activity {
pub agent_id: String,
pub collective_id: CollectiveId,
pub current_task: Option<String>,
pub context_summary: Option<String>,
pub started_at: Timestamp,
pub last_heartbeat: Timestamp,
}
pub struct NewActivity {
pub agent_id: String,
pub collective_id: CollectiveId,
pub current_task: Option<String>,
pub context_summary: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_activity_postcard_roundtrip() {
let activity = Activity {
agent_id: "claude-opus".to_string(),
collective_id: CollectiveId::new(),
current_task: Some("Implementing feature X".to_string()),
context_summary: Some("Working on module Y".to_string()),
started_at: Timestamp::now(),
last_heartbeat: Timestamp::now(),
};
let bytes = postcard::to_stdvec(&activity).unwrap();
let restored: Activity = postcard::from_bytes(&bytes).unwrap();
assert_eq!(activity.agent_id, restored.agent_id);
assert_eq!(activity.collective_id, restored.collective_id);
assert_eq!(activity.current_task, restored.current_task);
assert_eq!(activity.context_summary, restored.context_summary);
assert_eq!(activity.started_at, restored.started_at);
assert_eq!(activity.last_heartbeat, restored.last_heartbeat);
}
#[test]
fn test_activity_with_optional_fields_roundtrip() {
let activity = Activity {
agent_id: "agent-minimal".to_string(),
collective_id: CollectiveId::new(),
current_task: None,
context_summary: None,
started_at: Timestamp::from_millis(1000),
last_heartbeat: Timestamp::from_millis(2000),
};
let bytes = postcard::to_stdvec(&activity).unwrap();
let restored: Activity = postcard::from_bytes(&bytes).unwrap();
assert_eq!(activity.agent_id, restored.agent_id);
assert!(restored.current_task.is_none());
assert!(restored.context_summary.is_none());
assert_eq!(activity.started_at, restored.started_at);
assert_eq!(activity.last_heartbeat, restored.last_heartbeat);
}
}