kanade_shared/wire/
result.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Clone)]
4pub struct ExecResult {
5 pub request_id: String,
6 pub pc_id: String,
7 pub exit_code: i32,
8 pub stdout: String,
9 pub stderr: String,
10 pub started_at: chrono::DateTime<chrono::Utc>,
11 pub finished_at: chrono::DateTime<chrono::Utc>,
12}
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17 use chrono::TimeZone;
18
19 #[test]
20 fn exec_result_round_trips_through_json() {
21 let t0 = chrono::Utc.with_ymd_and_hms(2026, 5, 16, 0, 0, 0).unwrap();
22 let t1 = chrono::Utc.with_ymd_and_hms(2026, 5, 16, 0, 0, 5).unwrap();
23 let r = ExecResult {
24 request_id: "req-1".into(),
25 pc_id: "minipc".into(),
26 exit_code: 0,
27 stdout: "hello\n".into(),
28 stderr: String::new(),
29 started_at: t0,
30 finished_at: t1,
31 };
32 let json = serde_json::to_string(&r).unwrap();
33 let back: ExecResult = serde_json::from_str(&json).unwrap();
34 assert_eq!(back.request_id, r.request_id);
35 assert_eq!(back.exit_code, r.exit_code);
36 assert_eq!(back.stdout, r.stdout);
37 assert_eq!(back.started_at, t0);
38 assert_eq!(back.finished_at, t1);
39 }
40}