buildfix_core_runtime/
settings.rs1use camino::Utf8PathBuf;
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
11pub enum RunMode {
12 #[default]
13 Standalone,
14 Cockpit,
15}
16
17#[derive(Debug, Clone)]
19pub struct PlanSettings {
20 pub repo_root: Utf8PathBuf,
21 pub artifacts_dir: Utf8PathBuf,
22 pub out_dir: Utf8PathBuf,
23
24 pub allow: Vec<String>,
26 pub deny: Vec<String>,
27 pub allow_guarded: bool,
28 pub allow_unsafe: bool,
29 pub allow_dirty: bool,
30 pub max_ops: Option<u64>,
31 pub max_files: Option<u64>,
32 pub max_patch_bytes: Option<u64>,
33 pub params: HashMap<String, String>,
34
35 pub require_clean_hashes: bool,
37 pub git_head_precondition: bool,
38
39 pub backup_suffix: String,
41
42 pub mode: RunMode,
44}
45
46impl Default for PlanSettings {
47 fn default() -> Self {
48 Self {
49 repo_root: Utf8PathBuf::from("."),
50 artifacts_dir: Utf8PathBuf::from("artifacts"),
51 out_dir: Utf8PathBuf::from("artifacts/buildfix"),
52 allow: Vec::new(),
53 deny: Vec::new(),
54 allow_guarded: false,
55 allow_unsafe: false,
56 allow_dirty: false,
57 max_ops: None,
58 max_files: None,
59 max_patch_bytes: None,
60 params: HashMap::new(),
61 require_clean_hashes: true,
62 git_head_precondition: false,
63 backup_suffix: ".buildfix.bak".to_string(),
64 mode: RunMode::default(),
65 }
66 }
67}
68
69#[derive(Debug, Clone)]
71pub struct ApplySettings {
72 pub repo_root: Utf8PathBuf,
73 pub out_dir: Utf8PathBuf,
74
75 pub dry_run: bool,
77 pub allow_guarded: bool,
78 pub allow_unsafe: bool,
79 pub allow_dirty: bool,
80 pub params: HashMap<String, String>,
81 pub auto_commit: bool,
82 pub commit_message: Option<String>,
83
84 pub backup_enabled: bool,
86 pub backup_suffix: String,
87
88 pub mode: RunMode,
90}
91
92impl Default for ApplySettings {
93 fn default() -> Self {
94 Self {
95 repo_root: Utf8PathBuf::from("."),
96 out_dir: Utf8PathBuf::from("artifacts/buildfix"),
97 dry_run: true,
98 allow_guarded: false,
99 allow_unsafe: false,
100 allow_dirty: false,
101 params: HashMap::new(),
102 auto_commit: false,
103 commit_message: None,
104 backup_enabled: true,
105 backup_suffix: ".buildfix.bak".to_string(),
106 mode: RunMode::default(),
107 }
108 }
109}
110
111#[cfg(test)]
112mod tests {
113 use super::*;
114
115 #[test]
116 fn plan_settings_default_values() {
117 let settings = PlanSettings::default();
118 assert_eq!(settings.repo_root.as_str(), ".");
119 assert_eq!(settings.artifacts_dir.as_str(), "artifacts");
120 assert_eq!(settings.out_dir.as_str(), "artifacts/buildfix");
121 assert!(settings.allow.is_empty());
122 assert!(settings.deny.is_empty());
123 assert!(!settings.allow_guarded);
124 assert!(!settings.allow_unsafe);
125 assert!(!settings.allow_dirty);
126 assert!(settings.max_ops.is_none());
127 assert!(settings.max_files.is_none());
128 assert!(settings.max_patch_bytes.is_none());
129 assert!(settings.params.is_empty());
130 assert!(settings.require_clean_hashes);
131 assert!(!settings.git_head_precondition);
132 assert_eq!(settings.backup_suffix, ".buildfix.bak");
133 assert_eq!(settings.mode, RunMode::Standalone);
134 }
135
136 #[test]
137 fn apply_settings_default_values() {
138 let settings = ApplySettings::default();
139 assert_eq!(settings.repo_root.as_str(), ".");
140 assert_eq!(settings.out_dir.as_str(), "artifacts/buildfix");
141 assert!(settings.dry_run);
142 assert!(!settings.allow_guarded);
143 assert!(!settings.allow_unsafe);
144 assert!(!settings.allow_dirty);
145 assert!(settings.params.is_empty());
146 assert!(!settings.auto_commit);
147 assert!(settings.commit_message.is_none());
148 assert!(settings.backup_enabled);
149 assert_eq!(settings.backup_suffix, ".buildfix.bak");
150 assert_eq!(settings.mode, RunMode::Standalone);
151 }
152}