entrenar/storage/preflight/
types.rs1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5use thiserror::Error;
6
7#[derive(Debug, Error)]
9pub enum PreflightError {
10 #[error("Data integrity check failed: {0}")]
11 DataIntegrity(String),
12
13 #[error("Environment check failed: {0}")]
14 Environment(String),
15
16 #[error("Validation failed: {checks_failed} of {total_checks} checks failed")]
17 ValidationFailed { checks_failed: usize, total_checks: usize },
18
19 #[error("IO error: {0}")]
20 Io(#[from] std::io::Error),
21}
22
23#[derive(Debug, Clone)]
25pub struct CheckMetadata {
26 pub name: String,
28 pub check_type: CheckType,
30 pub description: String,
32 pub required: bool,
34}
35
36#[derive(Debug, Clone, Default)]
38pub struct PreflightContext {
39 pub min_samples: Option<usize>,
41 pub min_features: Option<usize>,
43 pub min_disk_space_mb: Option<u64>,
45 pub min_memory_mb: Option<u64>,
47 pub label_range: Option<(f64, f64)>,
49 pub params: HashMap<String, String>,
51}
52
53impl PreflightContext {
54 pub fn new() -> Self {
56 Self::default()
57 }
58
59 pub fn with_min_samples(mut self, min: usize) -> Self {
61 self.min_samples = Some(min);
62 self
63 }
64
65 pub fn with_min_features(mut self, min: usize) -> Self {
67 self.min_features = Some(min);
68 self
69 }
70
71 pub fn with_min_disk_space_mb(mut self, mb: u64) -> Self {
73 self.min_disk_space_mb = Some(mb);
74 self
75 }
76
77 pub fn with_min_memory_mb(mut self, mb: u64) -> Self {
79 self.min_memory_mb = Some(mb);
80 self
81 }
82
83 pub fn with_label_range(mut self, min: f64, max: f64) -> Self {
85 self.label_range = Some((min, max));
86 self
87 }
88}
89
90#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
92pub enum CheckType {
93 DataIntegrity,
95 Environment,
97 Resources,
99 Configuration,
101 Custom(String),
103}
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108
109 #[test]
114 fn test_context_default() {
115 let ctx = PreflightContext::new();
116 assert!(ctx.min_samples.is_none());
117 assert!(ctx.min_features.is_none());
118 }
119
120 #[test]
121 fn test_context_builder() {
122 let ctx = PreflightContext::new()
123 .with_min_samples(100)
124 .with_min_features(10)
125 .with_min_disk_space_mb(1024)
126 .with_min_memory_mb(512)
127 .with_label_range(0.0, 1.0);
128
129 assert_eq!(ctx.min_samples, Some(100));
130 assert_eq!(ctx.min_features, Some(10));
131 assert_eq!(ctx.min_disk_space_mb, Some(1024));
132 assert_eq!(ctx.min_memory_mb, Some(512));
133 assert_eq!(ctx.label_range, Some((0.0, 1.0)));
134 }
135}