diff --git a/rust/src/cli/serve/dashboard/window.rs b/rust/src/cli/serve/dashboard/window.rs index 790a19cc11a..bb1f9c587ca 100644 --- a/rust/src/cli/serve/dashboard/window.rs +++ b/rust/src/cli/serve/dashboard/window.rs @@ -10,6 +10,9 @@ pub struct WindowPayload { pub used_percent: f64, pub remaining_percent: f64, pub reset_at: Option>, + /// Preserve the engine's measurement validity for provider and account clients. + #[serde(skip_serializing_if = "is_false")] + pub is_informational: bool, /// Display-only hint. Script clients can ignore this additive schema-v1 key. #[serde(skip_serializing_if = "is_false")] pub idle: bool, @@ -23,6 +26,36 @@ fn is_false(value: &bool) -> bool { !*value } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn informational_window_keeps_its_authoritative_flag() { + let payload = make_window_with_idle( + "session", + "Session", + &RateWindow::no_active_session(), + false, + ); + let json = serde_json::to_value(payload).unwrap(); + assert_eq!(json["isInformational"], true); + assert_eq!(json["usedPercent"], 0.0); + assert!(json["resetAt"].is_null()); + } + + #[test] + fn measured_zero_without_reset_is_not_informational() { + for kind in ["session", "weekly"] { + let payload = make_window_with_idle(kind, kind, &RateWindow::new(0.0), false); + let json = serde_json::to_value(payload).unwrap(); + assert!(json.get("isInformational").is_none()); + assert_eq!(json["usedPercent"], 0.0); + assert!(json["resetAt"].is_null()); + } + } +} + pub(super) fn make_window_with_idle( kind: &str, label: &str, @@ -36,6 +69,7 @@ pub(super) fn make_window_with_idle( used_percent: used, remaining_percent: (100.0 - used).clamp(0.0, 100.0), reset_at: window.resets_at, + is_informational: window.is_informational, idle, unavailable: window.is_informational, }