use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, schemars::JsonSchema, Debug, Clone, Default)]
pub struct PingParams {}
#[derive(Serialize, Deserialize, schemars::JsonSchema, Debug, Clone)]
pub struct PingResult {
pub agent_time: chrono::DateTime<chrono::Utc>,
}
#[derive(Serialize, Deserialize, schemars::JsonSchema, Debug, Clone, Default)]
pub struct VersionParams {}
#[derive(Serialize, Deserialize, schemars::JsonSchema, Debug, Clone)]
pub struct VersionResult {
pub agent_version: String,
pub target_agent_version: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub target_client_version: Option<String>,
}
#[derive(Serialize, Deserialize, schemars::JsonSchema, Debug, Clone)]
pub struct LogTailParams {
#[serde(default = "default_log_tail_lines")]
pub lines: u32,
}
impl Default for LogTailParams {
fn default() -> Self {
Self {
lines: default_log_tail_lines(),
}
}
}
fn default_log_tail_lines() -> u32 {
200
}
#[derive(Serialize, Deserialize, schemars::JsonSchema, Debug, Clone)]
pub struct LogTailResult {
pub lines: Vec<String>,
#[serde(default)]
pub truncated: bool,
}
#[cfg(test)]
mod tests {
use super::*;
use chrono::TimeZone;
#[test]
fn ping_params_decodes_from_empty_object() {
let _: PingParams = serde_json::from_str("{}").unwrap();
}
#[test]
fn ping_result_round_trips_through_json() {
let t = chrono::Utc.with_ymd_and_hms(2026, 5, 24, 0, 0, 0).unwrap();
let r = PingResult { agent_time: t };
let json = serde_json::to_string(&r).unwrap();
let back: PingResult = serde_json::from_str(&json).unwrap();
assert_eq!(back.agent_time, t);
}
#[test]
fn version_result_target_client_optional() {
let wire = r#"{"agent_version":"0.4.0","target_agent_version":"0.4.0"}"#;
let r: VersionResult = serde_json::from_str(wire).unwrap();
assert_eq!(r.agent_version, "0.4.0");
assert!(r.target_client_version.is_none());
let json = serde_json::to_string(&r).unwrap();
assert!(!json.contains("target_client_version"));
}
#[test]
fn log_tail_params_defaults_to_200_lines() {
let p = LogTailParams::default();
assert_eq!(p.lines, 200);
let p: LogTailParams = serde_json::from_str("{}").unwrap();
assert_eq!(p.lines, 200);
}
#[test]
fn log_tail_result_truncated_defaults_to_false() {
let wire = r#"{"lines":["a","b","c"]}"#;
let r: LogTailResult = serde_json::from_str(wire).unwrap();
assert_eq!(r.lines.len(), 3);
assert!(!r.truncated);
}
}