fukurow_engine/
lib.rs

1//! # Fukurow Engine
2//!
3//! Reasoning engine orchestration
4//! Integrates reasoners and rules for knowledge processing
5
6pub mod engine;
7pub mod orchestration;
8pub mod pipeline;
9pub mod scaling;
10
11pub use engine::*;
12pub use orchestration::*;
13pub use pipeline::*;
14pub use scaling::*;
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19    use fukurow_core::model::{CyberEvent, SecurityAction, Triple};
20    use fukurow_store::store::RdfStore;
21
22    #[tokio::test]
23    async fn test_reasoner_engine_creation() {
24        let reasoner = ReasonerEngine::new();
25
26        // Engine should be created without errors
27        let store = reasoner.get_graph_store().await;
28        // If we reach here, creation succeeded
29        assert!(true);
30    }
31
32    #[tokio::test]
33    async fn test_add_event() {
34        let reasoner = ReasonerEngine::new();
35
36        let event = CyberEvent::NetworkConnection {
37            source_ip: "192.168.1.10".to_string(),
38            dest_ip: "10.0.0.50".to_string(),
39            port: 443,
40            protocol: "tcp".to_string(),
41            timestamp: 1640995200,
42        };
43
44        let result = reasoner.add_event(event).await;
45        assert!(result.is_ok());
46
47        // Check that the event was added to the graph
48        let store = reasoner.get_graph_store().await;
49        let store_read = store.read().await;
50        let triples = store_read.find_triples(None, None, None);
51        assert!(!triples.is_empty());
52    }
53
54    #[tokio::test]
55    async fn test_reasoning_engine_creation() {
56        let engine = ReasoningEngine::new();
57        assert!(true); // Engine should be created without errors
58    }
59
60    #[tokio::test]
61    async fn test_reasoning_engine_default_options() {
62        let options = ProcessingOptions::default();
63        assert_eq!(options.max_iterations, 10);
64        assert!(options.enable_validation);
65        assert!(options.enable_inference);
66        assert!(options.enable_rdfs_inference);
67        assert_eq!(options.timeout_ms, Some(5000));
68    }
69
70    #[tokio::test]
71    async fn test_empty_reasoning() {
72        let engine = ReasoningEngine::new();
73        let store = RdfStore::new();
74
75        let result = engine.process(&store).await;
76        assert!(result.is_ok());
77
78        let engine_result = result.unwrap();
79        assert_eq!(engine_result.inferred_triples.len(), 0);
80        assert_eq!(engine_result.actions.len(), 0);
81        assert_eq!(engine_result.violations.len(), 0);
82    }
83
84    #[tokio::test]
85    async fn test_engine_result_creation() {
86        let result = EngineResult {
87            inferred_triples: vec![
88                Triple {
89                    subject: "test".to_string(),
90                    predicate: "type".to_string(),
91                    object: "Test".to_string(),
92                }
93            ],
94            actions: vec![
95                SecurityAction::Alert {
96                    severity: "high".to_string(),
97                    message: "Test alert".to_string(),
98                    details: serde_json::json!({"test": true}),
99                }
100            ],
101            violations: vec![],
102            stats: ProcessingStats {
103                rules_applied: 1,
104                triples_processed: 10,
105                execution_time_ms: 150,
106                memory_used_kb: Some(1024),
107            },
108        };
109
110        assert_eq!(result.inferred_triples.len(), 1);
111        assert_eq!(result.actions.len(), 1);
112        assert_eq!(result.violations.len(), 0);
113        assert_eq!(result.stats.rules_applied, 1);
114        assert_eq!(result.stats.triples_processed, 10);
115        assert_eq!(result.stats.execution_time_ms, 150);
116        assert_eq!(result.stats.memory_used_kb, Some(1024));
117    }
118
119    #[tokio::test]
120    async fn test_processing_stats_creation() {
121        let stats = ProcessingStats {
122            rules_applied: 5,
123            triples_processed: 100,
124            execution_time_ms: 200,
125            memory_used_kb: None,
126        };
127
128        assert_eq!(stats.rules_applied, 5);
129        assert_eq!(stats.triples_processed, 100);
130        assert_eq!(stats.execution_time_ms, 200);
131        assert_eq!(stats.memory_used_kb, None);
132    }
133
134    #[test]
135    fn test_engine_error_variants() {
136        let rule_err = EngineError::RuleError(fukurow_rules::RuleError::ConfigurationError { message: "test".to_string() });
137        assert!(rule_err.to_string().contains("Invalid rule configuration"));
138
139        let rdfs_err = EngineError::RdfsError(fukurow_rdfs::RdfsError::Timeout(5000));
140        assert!(rdfs_err.to_string().contains("Inference timeout after 5000ms"));
141
142        let timeout_err = EngineError::TimeoutError(5000);
143        assert!(timeout_err.to_string().contains("5000ms"));
144
145        let iteration_err = EngineError::IterationLimitError(10);
146        assert!(iteration_err.to_string().contains("10"));
147
148        let internal_err = EngineError::InternalError("test error".to_string());
149        assert!(internal_err.to_string().contains("test error"));
150    }
151}