repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

test(mutants): all first-party crates in scope; config boundary tests catch the missed mutants

395ad226cd039ecfb3ecb3223c050c91bc98e4cc

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

+98 / −0 text lines

Diff layout

smith/src/config.rs

Modified

+98 / −0 text lines

1//! Runtime configuration, validated once at load (`SMH-SPEC-SPEC0001`,
2//! Configuration): invalid values fail with their field path, never a
3//! generic error.
4
15use crate::error::{Result, SmithError};
26use serde::{Deserialize, Serialize};
105109 Self::default_valid()
106110 }
113#[cfg(test)]
114mod tests {
115 use super::*;
117 fn with_max_frame_bytes(value: usize) -> Config {
118 let mut config = Config::default_valid();
119 config.max_frame_bytes = value;
120 config
121 }
123 fn with_tool_timeout_ms(value: u64) -> Config {
124 let mut config = Config::default_valid();
125 config.tool_timeout_ms = value;
126 config
127 }
129 /// `max_frame_bytes < MIN_FRAME_BYTES` is the only rejection; the bound
130 /// itself, and one step above it, are both accepted.
131 #[test]
132 fn max_frame_bytes_lower_bound_is_inclusive() {
133 assert!(
134 with_max_frame_bytes(MIN_FRAME_BYTES - 1)
135 .validate()
136 .is_err()
137 );
138 assert!(with_max_frame_bytes(MIN_FRAME_BYTES).validate().is_ok());
139 assert!(with_max_frame_bytes(MIN_FRAME_BYTES + 1).validate().is_ok());
140 }
142 /// `max_frame_bytes > MAX_FRAME_BYTES` is the only rejection; the bound
143 /// itself, and one step below it, are both accepted.
144 #[test]
145 fn max_frame_bytes_upper_bound_is_inclusive() {
146 assert!(with_max_frame_bytes(MAX_FRAME_BYTES - 1).validate().is_ok());
147 assert!(with_max_frame_bytes(MAX_FRAME_BYTES).validate().is_ok());
148 assert!(
149 with_max_frame_bytes(MAX_FRAME_BYTES + 1)
150 .validate()
151 .is_err()
152 );
153 }
155 /// `tool_timeout_ms < MIN_TOOL_TIMEOUT_MS` is the only rejection; the
156 /// bound itself, and one step above it, are both accepted.
157 #[test]
158 fn tool_timeout_ms_lower_bound_is_inclusive() {
159 assert!(
160 with_tool_timeout_ms(MIN_TOOL_TIMEOUT_MS - 1)
161 .validate()
162 .is_err()
163 );
164 assert!(with_tool_timeout_ms(MIN_TOOL_TIMEOUT_MS).validate().is_ok());
165 assert!(
166 with_tool_timeout_ms(MIN_TOOL_TIMEOUT_MS + 1)
167 .validate()
168 .is_ok()
169 );
170 }
172 /// Pins the exact scale factor so a `*` mutated to `+` (or a swapped
173 /// operand) changes the default instead of surviving unnoticed.
174 #[test]
175 fn default_max_frame_bytes_is_the_lower_bound_scaled_by_1024() {
176 assert_eq!(
177 Config::default_valid().max_frame_bytes,
178 MIN_FRAME_BYTES * 1024
179 );
180 }
182 /// A literal, not an expression built from the same operators, so a
183 /// `*` mutated to `+` in the constant's own definition cannot cancel
184 /// out against an identically mutated expectation.
185 #[test]
186 fn max_frame_bytes_upper_bound_is_100_mebibytes() {
187 assert_eq!(MAX_FRAME_BYTES, 104_857_600);
188 }
190 /// `auth_dir` composes a directory, always ending in `auth` under a
191 /// `smith` (or, lacking a platform data directory, `.smith`) base; it
192 /// is never the empty default `PathBuf`.
193 #[test]
194 fn auth_dir_ends_with_smith_auth_segments() {
195 let dir = auth_dir();
196 assert_eq!(dir.file_name(), Some(std::ffi::OsStr::new("auth")));
197 let base = dir.parent().expect("auth_dir has a parent");
198 let base_name = base.file_name().expect("base has a name");
199 assert!(
200 base_name == "smith" || base_name == ".smith",
201 "unexpected auth dir base: {}",
202 base.display()
203 );
204 }
205}