pretender 0.6.0

Multi-language structural code-quality checks — complexity, duplication, mutation testing, and CI integration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
//! Pretender configuration.
//!
//! The `Config` struct is the domain model for `pretender.toml`. All file
//! I/O (read, parse, validate) delegates to `genesis::config::ConfigFile`;
//! this module only owns the struct shape and the domain validation rules.

use genesis::config::{ConfigFile, ConfigRegistry, ConfigValidation, ValidationSeverity};
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};

// ── Config struct ─────────────────────────────────────────────────────

#[derive(Debug, Clone, Default, PartialEq, Deserialize)]
#[serde(default)]
pub struct Config {
    pub pretender: PretenderSection,
    pub thresholds: Thresholds,
    pub bands: Bands,
    pub scope: Scope,
    pub execute: Execute,
    pub plugins: Plugins,
    pub output: Output,
    pub roles: Roles,
    pub patterns: Patterns,
}

impl Config {
    /// Parse a config from a TOML source string without touching the
    /// filesystem. Test convenience; runtime loading goes through
    /// [`genesis::config::ConfigFile::read_from`] via the `ConfigStore`.
    #[cfg(test)]
    pub fn parse_str(source: &str) -> Result<Self, toml::de::Error> {
        toml::from_str(source)
    }
}

impl ConfigFile for Config {
    fn path(repo_root: &Path) -> PathBuf {
        repo_root.join("pretender.toml")
    }

    fn validate(&self) -> Result<Vec<ConfigValidation>, genesis::config::ConfigError> {
        let mut results = Vec::new();
        self.bands.collect_validations(&mut results);
        self.thresholds.collect_validations(&mut results);
        if self.output.formats.is_empty() {
            results.push(ConfigValidation::error(
                "output.formats",
                "expected at least one output format",
            ));
        }
        Ok(results)
    }
}

/// Build a [`ConfigRegistry`] with pretender's config registered.
///
/// Tools register their config struct at startup so the shared
/// `ConfigStore` can discover and validate it alongside other suite tools.
pub fn build_registry() -> ConfigRegistry {
    let mut registry = ConfigRegistry::new();
    registry.register::<Config>("pretender", "pretender.toml");
    registry
}

/// Return `true` if `validations` contains any error-severity entry.
pub fn has_errors(validations: &[ConfigValidation]) -> bool {
    validations
        .iter()
        .any(|v| v.severity == ValidationSeverity::Error)
}

// ── Sections ──────────────────────────────────────────────────────────

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct PretenderSection {
    pub mode: Mode,
    pub languages: Vec<String>,
    pub exclude: Vec<String>,
}

impl Default for PretenderSection {
    fn default() -> Self {
        Self {
            mode: Mode::Tiered,
            languages: vec!["auto".to_string()],
            exclude: vec![
                "vendor/**".to_string(),
                "node_modules/**".to_string(),
                "**/*_generated.*".to_string(),
            ],
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Mode {
    Guidance,
    Tiered,
    Gate,
}

#[derive(Debug, Clone, Default, PartialEq, Deserialize)]
#[serde(default)]
pub struct Thresholds {
    #[serde(flatten)]
    pub app: AppThresholds,
    pub test: TestThresholds,
    pub library: LibraryThresholds,
    pub script: ScriptThresholds,
    pub coupling: CouplingThresholds,
    #[serde(rename = "unit-test")]
    pub unit_test: DurationThresholds,
    #[serde(rename = "integration-test")]
    pub integration_test: DurationThresholds,
}

impl Thresholds {
    fn collect_validations(&self, out: &mut Vec<ConfigValidation>) {
        validate_percent(
            out,
            "thresholds.duplication_pct_max",
            self.app.duplication_pct_max,
        );
        validate_percent(
            out,
            "thresholds.test.duplication_pct_max",
            self.test.duplication_pct_max,
        );
        self.coupling
            .collect_validations("thresholds.coupling", out);
        if self.app.mut_ratio_max > 0.0
            && (self.app.mut_ratio_max < 0.0 || self.app.mut_ratio_max > 1.0)
        {
            out.push(ConfigValidation::error(
                "thresholds.mut_ratio_max",
                "expected value between 0.0 and 1.0",
            ));
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
#[serde(default)]
pub struct DurationThresholds {
    pub duration_max_ms: u32,
}

fn validate_percent(out: &mut Vec<ConfigValidation>, field: &'static str, value: u32) {
    if value > 100 {
        out.push(ConfigValidation::error(
            field,
            "expected percentage value <= 100",
        ));
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Default)]
#[serde(rename_all = "kebab-case")]
pub enum TimeUnit {
    #[default]
    Seconds,
    Milliseconds,
}

#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(default)]
pub struct AppThresholds {
    pub cyclomatic_max: u32,
    pub cognitive_max: u32,
    pub function_lines_max: u32,
    pub file_lines_max: u32,
    pub nesting_max: u32,
    pub params_max: u32,
    pub abc_max: u32,
    pub duplication_pct_max: u32,
    pub void_mutators_max: u32,
    pub mut_ratio_max: f64,
    pub unwrap_max: u32,
    pub bool_cluster_max: u32,
    pub primitive_param_check: bool,
    pub inheritance_depth_max: u32,
}

impl Default for AppThresholds {
    fn default() -> Self {
        Self {
            cyclomatic_max: 10,
            cognitive_max: 15,
            function_lines_max: 40,
            file_lines_max: 400,
            nesting_max: 3,
            params_max: 4,
            abc_max: 30,
            duplication_pct_max: 5,
            void_mutators_max: 0,
            mut_ratio_max: 0.0,
            unwrap_max: 0,
            bool_cluster_max: 0,
            primitive_param_check: false,
            inheritance_depth_max: 0,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct TestThresholds {
    pub cyclomatic_max: u32,
    pub function_lines_max: u32,
    pub nesting_max: u32,
    pub params_max: u32,
    pub cognitive_max: u32,
    pub duplication_pct_max: u32,
    pub min_assertions: Option<u32>,
    pub mock_count_max: u32,
    pub void_mutators_max: u32,
    pub unwrap_max: u32,
    pub lazy_cluster_min: u32,
}

impl Default for TestThresholds {
    fn default() -> Self {
        Self {
            cyclomatic_max: 3,
            function_lines_max: 80,
            nesting_max: 2,
            params_max: 2,
            cognitive_max: 5,
            duplication_pct_max: 30,
            min_assertions: Some(1),
            mock_count_max: 0,
            void_mutators_max: 0,
            unwrap_max: 0,
            lazy_cluster_min: 0,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct LibraryThresholds {
    pub exported_params_max: u32,
    pub exported_cyclomatic_max: u32,
    pub exported_lines_max: u32,
    pub require_docstring: bool,
}

impl Default for LibraryThresholds {
    fn default() -> Self {
        Self {
            exported_params_max: 3,
            exported_cyclomatic_max: 8,
            exported_lines_max: 30,
            require_docstring: true,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct ScriptThresholds {
    pub function_lines_max: u32,
    pub file_lines_max: u32,
}

impl Default for ScriptThresholds {
    fn default() -> Self {
        Self {
            function_lines_max: 100,
            file_lines_max: 300,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
#[serde(default)]
pub struct CouplingThresholds {
    pub ce_max: u32,
    pub ca_max: u32,
    pub cbo_max: u32,
    pub lcom_hs_max: u32,
    pub cycle_detection: bool,
}

impl CouplingThresholds {
    fn collect_validations(&self, field: &'static str, out: &mut Vec<ConfigValidation>) {
        if self.lcom_hs_max > 100 {
            out.push(ConfigValidation::error(
                format!("{field}.lcom_hs_max"),
                "expected percentage value <= 100",
            ));
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
pub struct Band {
    pub green: u32,
    pub yellow: u32,
    pub red: u32,
}

impl Band {
    fn collect_validations(&self, field: &'static str, out: &mut Vec<ConfigValidation>) {
        if !(self.green <= self.yellow && self.yellow <= self.red) {
            out.push(ConfigValidation::error(
                field,
                "expected green <= yellow <= red",
            ));
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct Bands {
    pub cyclomatic: Option<Band>,
    pub cognitive: Option<Band>,
}

impl Bands {
    fn collect_validations(&self, out: &mut Vec<ConfigValidation>) {
        if let Some(band) = self.cyclomatic {
            band.collect_validations("bands.cyclomatic", out);
        }
        if let Some(band) = self.cognitive {
            band.collect_validations("bands.cognitive", out);
        }
    }
}

impl Default for Bands {
    fn default() -> Self {
        Self {
            cyclomatic: Some(Band {
                green: 10,
                yellow: 15,
                red: 20,
            }),
            cognitive: Some(Band {
                green: 15,
                yellow: 25,
                red: 40,
            }),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct Scope {
    pub diff_only: bool,
    pub diff_base: String,
}

impl Default for Scope {
    fn default() -> Self {
        Self {
            diff_only: true,
            diff_base: "origin/main".to_string(),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct Execute {
    pub enabled: bool,
    pub coverage_cmd: Option<String>,
    pub mutation_cmd: Option<String>,
    pub test_cmd: Option<String>,
    pub test_report_path: Option<String>,
    pub test_timeout_s: u32,
    pub test_time_unit: TimeUnit,
}

impl Default for Execute {
    fn default() -> Self {
        Self {
            enabled: false,
            coverage_cmd: None,
            mutation_cmd: None,
            test_cmd: None,
            test_report_path: None,
            test_timeout_s: 600,
            test_time_unit: TimeUnit::Seconds,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct Plugins {
    pub languages: Vec<String>,
    pub metrics: Vec<String>,
}

impl Default for Plugins {
    fn default() -> Self {
        Self {
            languages: vec![
                "python".to_string(),
                "javascript".to_string(),
                "typescript".to_string(),
                "go".to_string(),
                "rust".to_string(),
            ],
            metrics: vec![
                "eslint".to_string(),
                "ruff".to_string(),
                "clippy".to_string(),
            ],
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct Output {
    pub formats: Vec<OutputFormat>,
    pub sarif_path: String,
}

impl Default for Output {
    fn default() -> Self {
        Self {
            formats: vec![OutputFormat::Human, OutputFormat::Sarif],
            sarif_path: "pretender.sarif".to_string(),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
#[serde(default)]
pub struct Patterns {
    pub mock: MockPatterns,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
#[serde(default)]
pub struct MockPatterns {
    pub extra: Vec<String>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum OutputFormat {
    Human,
    Json,
    Sarif,
    Junit,
    Markdown,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct Roles {
    pub test: RoleMatcher,
    pub library: RoleMatcher,
    pub script: RoleMatcher,
    pub generated: RoleMatcher,
    pub vendor: RoleMatcher,
    #[serde(rename = "unit-test")]
    pub unit_test: RoleMatcher,
    #[serde(rename = "integration-test")]
    pub integration_test: RoleMatcher,
}

impl Default for Roles {
    fn default() -> Self {
        Self {
            test: RoleMatcher {
                paths: vec![
                    "tests/**".to_string(),
                    "**/*_test.*".to_string(),
                    "spec/**".to_string(),
                ],
                classname_root: "tests".to_string(),
            },
            library: RoleMatcher {
                paths: vec!["pkg/**".to_string(), "lib/**".to_string()],
                classname_root: String::new(),
            },
            script: RoleMatcher {
                paths: vec!["scripts/**".to_string(), "examples/**".to_string()],
                classname_root: String::new(),
            },
            generated: RoleMatcher {
                paths: vec!["**/*.pb.go".to_string(), "**/*_generated.*".to_string()],
                classname_root: String::new(),
            },
            vendor: RoleMatcher {
                paths: vec!["vendor/**".to_string(), "node_modules/**".to_string()],
                classname_root: String::new(),
            },
            unit_test: RoleMatcher {
                paths: vec!["tests/unit/**".to_string()],
                classname_root: String::new(),
            },
            integration_test: RoleMatcher {
                paths: vec!["tests/integration/**".to_string()],
                classname_root: String::new(),
            },
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
#[serde(default)]
pub struct RoleMatcher {
    pub paths: Vec<String>,
    pub classname_root: String,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn parses_full_config_schema_and_ignores_unknown_keys() {
        let config = Config::parse_str(
            r#"
            unknown_top_level = "ignored"

            [pretender]
            mode = "gate"
            languages = ["python", "rust"]
            exclude = ["vendor/**"]
            future_key = true

            [thresholds]
            cyclomatic_max = 9
            cognitive_max = 14
            function_lines_max = 39
            file_lines_max = 399
            nesting_max = 2
            params_max = 3
            duplication_pct_max = 4

            [thresholds.test]
            cyclomatic_max = 3
            function_lines_max = 80
            nesting_max = 2
            params_max = 2
            cognitive_max = 5
            duplication_pct_max = 30
            min_assertions = 1

            [thresholds.library]
            exported_params_max = 3
            exported_cyclomatic_max = 8
            exported_lines_max = 30
            require_docstring = true

            [thresholds.script]
            function_lines_max = 100
            file_lines_max = 300

            [bands]
            cyclomatic = { green = 10, yellow = 15, red = 20 }
            cognitive = { green = 15, yellow = 25, red = 40 }

            [scope]
            diff_only = true
            diff_base = "origin/main"

            [execute]
            enabled = true
            coverage_cmd = "pytest --cov --cov-report=xml"
            mutation_cmd = "mutmut run"
            test_cmd = "cargo test"
            test_report_path = "target/test-report.xml"
            test_timeout_s = 300
            test_time_unit = "seconds"

            [plugins]
            languages = ["python", "javascript"]
            metrics = ["ruff", "eslint"]

            [output]
            formats = ["human", "sarif"]
            sarif_path = "pretender.sarif"

            [roles]
            test = { paths = ["tests/**"], classname_root = "tests" }
            library = { paths = ["lib/**"] }
            script = { paths = ["scripts/**"] }
            generated = { paths = ["**/*_generated.*"] }
            vendor = { paths = ["vendor/**"] }
            unit-test = { paths = ["tests/unit/**"] }
            integration-test = { paths = ["tests/integration/**"] }
            "#,
        )
        .expect("config should parse");

        assert_eq!(config.pretender.mode, Mode::Gate);
        assert_eq!(config.pretender.languages, vec!["python", "rust"]);
        assert_eq!(config.thresholds.app.cyclomatic_max, 9);
        assert_eq!(config.thresholds.test.min_assertions, Some(1));
        assert!(config.thresholds.library.require_docstring);
        assert_eq!(config.bands.cyclomatic.unwrap().red, 20);
        assert!(config.scope.diff_only);
        assert!(config.execute.enabled);
        assert_eq!(config.execute.test_cmd, Some("cargo test".to_string()));
        assert_eq!(
            config.execute.test_report_path,
            Some("target/test-report.xml".to_string())
        );
        assert_eq!(config.execute.test_timeout_s, 300);
        assert_eq!(config.execute.test_time_unit, TimeUnit::Seconds);
        assert_eq!(config.plugins.metrics, vec!["ruff", "eslint"]);
        assert_eq!(
            config.output.formats,
            vec![OutputFormat::Human, OutputFormat::Sarif]
        );
        assert_eq!(config.roles.test.paths, vec!["tests/**"]);
        assert_eq!(config.roles.test.classname_root, "tests");
        assert_eq!(config.roles.unit_test.paths, vec!["tests/unit/**"]);
        assert_eq!(
            config.roles.integration_test.paths,
            vec!["tests/integration/**"]
        );

        let validations = config.validate().expect("validate");
        assert!(!has_errors(&validations), "valid config has no errors");
    }

    #[test]
    fn default_config_matches_documented_conventions() {
        let config = Config::default();

        assert_eq!(config.pretender.mode, Mode::Tiered);
        assert_eq!(config.pretender.languages, vec!["auto"]);
        assert_eq!(config.thresholds.app.cyclomatic_max, 10);
        assert_eq!(config.thresholds.app.cognitive_max, 15);
        assert_eq!(config.thresholds.app.function_lines_max, 40);
        assert_eq!(config.thresholds.app.file_lines_max, 400);
        assert_eq!(config.thresholds.app.nesting_max, 3);
        assert_eq!(config.thresholds.app.params_max, 4);
        assert_eq!(config.thresholds.app.duplication_pct_max, 5);
        assert_eq!(
            config.bands.cyclomatic.unwrap(),
            Band {
                green: 10,
                yellow: 15,
                red: 20
            }
        );
        assert_eq!(
            config.bands.cognitive.unwrap(),
            Band {
                green: 15,
                yellow: 25,
                red: 40
            }
        );
        assert_eq!(
            config.roles.vendor.paths,
            vec!["vendor/**", "node_modules/**"]
        );
        assert_eq!(config.roles.test.classname_root, "tests");
        assert_eq!(config.roles.library.classname_root, "");
        assert_eq!(config.roles.unit_test.classname_root, "");
        assert_eq!(config.roles.integration_test.classname_root, "");
        assert_eq!(config.execute.test_timeout_s, 600);
        assert_eq!(config.execute.test_time_unit, TimeUnit::Seconds);
        assert_eq!(config.execute.test_cmd, None);
        assert_eq!(config.execute.test_report_path, None);
        assert_eq!(config.thresholds.unit_test.duration_max_ms, 0);
        assert_eq!(config.thresholds.integration_test.duration_max_ms, 0);
    }

    #[test]
    fn validation_flags_inverted_bands() {
        let config = Config::parse_str(
            r#"
            [bands]
            cyclomatic = { green = 20, yellow = 10, red = 15 }
            "#,
        )
        .expect("config should parse");

        let validations = config.validate().expect("validate");
        let band_issue = validations
            .iter()
            .find(|v| v.field == "bands.cyclomatic")
            .expect("bands.cyclomatic should be flagged");
        assert_eq!(band_issue.severity, ValidationSeverity::Error);
        assert!(band_issue.message.contains("green <= yellow <= red"));
    }

    #[test]
    fn validation_flags_impossible_percentages() {
        let config = Config::parse_str(
            r#"
            [thresholds]
            duplication_pct_max = 101
            "#,
        )
        .expect("config should parse");

        let validations = config.validate().expect("validate");
        assert!(validations
            .iter()
            .any(|v| v.field == "thresholds.duplication_pct_max"
                && v.severity == ValidationSeverity::Error));
    }

    #[test]
    fn configfile_path_is_repo_root_pretender_toml() {
        let root = Path::new("/tmp/repo");
        assert_eq!(Config::path(root), root.join("pretender.toml"));
    }

    #[test]
    fn build_registry_registers_pretender() {
        let registry = build_registry();
        assert!(registry.is_registered("pretender"));
        assert_eq!(registry.marker("pretender"), Some("pretender.toml"));
    }

    #[test]
    fn validation_passes_for_duration_thresholds_zero() {
        let config = Config::parse_str(
            r#"
            [thresholds.unit-test]
            duration_max_ms = 0
            [thresholds.integration-test]
            duration_max_ms = 0
            "#,
        )
        .expect("config should parse");
        let validations = config.validate().expect("validate");
        assert!(!has_errors(&validations), "zero duration is valid");
    }

    #[test]
    fn execute_time_unit_defaults_to_seconds() {
        let config = Config::default();
        assert_eq!(config.execute.test_time_unit, TimeUnit::Seconds);
    }

    #[test]
    fn execute_parses_time_unit_kebab_case() {
        let config = Config::parse_str(
            r#"
            [execute]
            test_time_unit = "milliseconds"
            "#,
        )
        .expect("config should parse");
        assert_eq!(config.execute.test_time_unit, TimeUnit::Milliseconds);
    }

    #[test]
    fn role_matcher_classname_root_defaults_to_empty() {
        let config = Config::parse_str(
            r#"
            [roles.unit-test]
            paths = ["tests/unit/**"]
            "#,
        )
        .expect("config should parse");
        assert_eq!(config.roles.unit_test.classname_root, "");
    }

    #[test]
    fn role_matcher_classname_root_can_be_set() {
        let config = Config::parse_str(
            r#"
            [roles.test]
            paths = ["tests/**"]
            classname_root = "spec"
            "#,
        )
        .expect("config should parse");
        assert_eq!(config.roles.test.classname_root, "spec");
    }
}