Skip to main content

stackless_core/
checkpoint.rs

1//! Checkpoint payload schemas shared across substrates and the daemon.
2
3use serde::{Deserialize, Serialize};
4
5use crate::types::{LogPath, Pid, ProcessStartTime, ProxyHost, TcpPort};
6
7/// What a `start:` checkpoint records.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9pub struct StartCheckpoint {
10    pub pid: Pid,
11    pub start_time: ProcessStartTime,
12    pub port: TcpPort,
13    pub hosts: Vec<ProxyHost>,
14    pub log: LogPath,
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[test]
22    fn start_checkpoint_roundtrip() {
23        let original = StartCheckpoint {
24            pid: Pid::from_os(12345),
25            start_time: ProcessStartTime::from_os(1_700_000_000),
26            port: TcpPort::try_new(8080).unwrap(),
27            hosts: vec![
28                ProxyHost::try_new("api.dev.localhost").unwrap(),
29                ProxyHost::try_new("dev.localhost").unwrap(),
30            ],
31            log: LogPath::try_new("/tmp/state/logs/dev/api.log").unwrap(),
32        };
33        let json = serde_json::to_string(&original).unwrap();
34        let restored: StartCheckpoint = serde_json::from_str(&json).unwrap();
35        assert_eq!(original, restored);
36        assert!(json.contains("\"pid\":12345"));
37        assert!(json.contains("\"port\":8080"));
38    }
39}