cc_audit/runtime/
executor.rs1use super::context::ScanContext;
6use super::pipeline::Pipeline;
7use crate::error::Result;
8use crate::rules::ScanResult;
9
10pub struct ScanExecutor {
15 context: ScanContext,
16 pipeline: Pipeline,
17}
18
19impl ScanExecutor {
20 pub fn new(context: ScanContext) -> Self {
22 Self {
23 context,
24 pipeline: Pipeline::new(),
25 }
26 }
27
28 pub fn context(&self) -> &ScanContext {
30 &self.context
31 }
32
33 pub fn pipeline(&self) -> &Pipeline {
35 &self.pipeline
36 }
37
38 pub fn run(&mut self) -> Result<ScanResult> {
44 use crate::rules::Summary;
45
46 while self.pipeline.advance()? {}
48
49 Ok(ScanResult {
51 version: env!("CARGO_PKG_VERSION").to_string(),
52 scanned_at: chrono::Utc::now().to_rfc3339(),
53 target: self
54 .context
55 .paths
56 .first()
57 .map(|p| p.display().to_string())
58 .unwrap_or_default(),
59 summary: Summary {
60 critical: 0,
61 high: 0,
62 medium: 0,
63 low: 0,
64 passed: true,
65 errors: 0,
66 warnings: 0,
67 },
68 findings: Vec::new(),
69 risk_score: None,
70 })
71 }
72}
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77 use crate::config::Config;
78 use std::path::PathBuf;
79
80 #[test]
81 fn test_executor_creation() {
82 let ctx = ScanContext::new(vec![PathBuf::from(".")], Config::default());
83 let executor = ScanExecutor::new(ctx);
84
85 assert!(!executor.pipeline().is_complete());
86 }
87
88 #[test]
89 fn test_executor_run() {
90 let ctx = ScanContext::new(vec![PathBuf::from(".")], Config::default());
91 let mut executor = ScanExecutor::new(ctx);
92
93 let result = executor.run().unwrap();
94 assert!(executor.pipeline().is_complete());
95 assert!(result.findings.is_empty());
96 }
97}