Skip to main content

meerkat_runtime/
input_scope.rs

1//! §11 InputScope — scoping for queue filtering and input targeting.
2
3use serde::{Deserialize, Serialize};
4
5use crate::identifiers::LogicalRuntimeId;
6use meerkat_core::lifecycle::InputId;
7use meerkat_core::ops::OperationId;
8
9/// Scope for filtering inputs in the queue.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11#[serde(tag = "scope_type", rename_all = "snake_case")]
12#[non_exhaustive]
13pub enum InputScope {
14    /// All inputs for a specific runtime.
15    Runtime { runtime_id: LogicalRuntimeId },
16    /// A specific input by ID.
17    Specific { input_id: InputId },
18    /// All lifecycle notices for one operation.
19    Operation { operation_id: OperationId },
20    /// All inputs (global scope).
21    All,
22}
23
24#[cfg(test)]
25#[allow(clippy::unwrap_used)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn input_scope_runtime_serde() {
31        let scope = InputScope::Runtime {
32            runtime_id: LogicalRuntimeId::new("agent-1"),
33        };
34        let json = serde_json::to_value(&scope).unwrap();
35        assert_eq!(json["scope_type"], "runtime");
36        let parsed: InputScope = serde_json::from_value(json).unwrap();
37        assert_eq!(scope, parsed);
38    }
39
40    #[test]
41    fn input_scope_specific_serde() {
42        let scope = InputScope::Specific {
43            input_id: InputId::new(),
44        };
45        let json = serde_json::to_value(&scope).unwrap();
46        assert_eq!(json["scope_type"], "specific");
47        let parsed: InputScope = serde_json::from_value(json).unwrap();
48        assert_eq!(scope, parsed);
49    }
50
51    #[test]
52    fn input_scope_all_serde() {
53        let scope = InputScope::All;
54        let json = serde_json::to_value(&scope).unwrap();
55        assert_eq!(json["scope_type"], "all");
56        let parsed: InputScope = serde_json::from_value(json).unwrap();
57        assert_eq!(scope, parsed);
58    }
59
60    #[test]
61    fn input_scope_operation_serde() {
62        let scope = InputScope::Operation {
63            operation_id: OperationId::new(),
64        };
65        let json = serde_json::to_value(&scope).unwrap();
66        assert_eq!(json["scope_type"], "operation");
67        let parsed: InputScope = serde_json::from_value(json).unwrap();
68        assert_eq!(scope, parsed);
69    }
70}