Skip to main content

kanade_shared/wire/
heartbeat.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Clone)]
4pub struct Heartbeat {
5    pub pc_id: String,
6    pub at: chrono::DateTime<chrono::Utc>,
7    pub agent_version: String,
8}
9
10#[cfg(test)]
11mod tests {
12    use super::*;
13    use chrono::TimeZone;
14
15    #[test]
16    fn heartbeat_round_trips_through_json() {
17        let hb = Heartbeat {
18            pc_id: "minipc".into(),
19            at: chrono::Utc.with_ymd_and_hms(2026, 5, 16, 0, 0, 0).unwrap(),
20            agent_version: "0.1.4".into(),
21        };
22        let json = serde_json::to_string(&hb).unwrap();
23        let back: Heartbeat = serde_json::from_str(&json).unwrap();
24        assert_eq!(back.pc_id, hb.pc_id);
25        assert_eq!(back.at, hb.at);
26        assert_eq!(back.agent_version, hb.agent_version);
27    }
28}