Skip to main content

koi_common/
capability.rs

1use serde::Serialize;
2use utoipa::ToSchema;
3
4/// Summary of a capability's current state for the unified dashboard.
5#[derive(Debug, Clone, Serialize, ToSchema)]
6pub struct CapabilityStatus {
7    pub name: String,
8    pub summary: String,
9    pub healthy: bool,
10}
11
12/// Trait implemented by each domain to participate in `koi status`.
13pub trait Capability: Send + Sync {
14    fn name(&self) -> &str;
15    fn status(&self) -> CapabilityStatus;
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn capability_status_serializes_expected_fields() {
24        let cs = CapabilityStatus {
25            name: "mdns".to_string(),
26            summary: "3 registered".to_string(),
27            healthy: true,
28        };
29        let json = serde_json::to_value(&cs).unwrap();
30        assert_eq!(json.get("name").unwrap(), "mdns");
31        assert_eq!(json.get("summary").unwrap(), "3 registered");
32        assert_eq!(json.get("healthy").unwrap(), true);
33    }
34
35    #[test]
36    fn capability_status_is_send_sync() {
37        fn assert_send_sync<T: Send + Sync>() {}
38        assert_send_sync::<CapabilityStatus>();
39    }
40}