nextest-runner 0.114.0

Core runner logic for cargo nextest.
Documentation
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
// Copyright (c) The nextest Contributors
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Record-related user configuration.

use crate::user_config::helpers::resolve_record_setting;
use bytesize::ByteSize;
use serde::Deserialize;
use std::time::Duration;
use target_spec::{Platform, TargetSpec};

/// Minimum allowed value for `max_output_size`.
///
/// This ensures there's enough space for the truncation marker plus some
/// actual content. The truncation marker is approximately 40 bytes, so 1000
/// bytes provides reasonable headroom.
pub const MIN_MAX_OUTPUT_SIZE: ByteSize = ByteSize::b(1000);

/// Maximum allowed value for `max_output_size`.
///
/// This caps how much output can be stored per test, bounding memory usage
/// when reading archives. Values above this are clamped with a warning.
///
/// This constant is also used as the maximum size for reading any file from
/// a recorded archive, preventing malicious archives from causing OOM.
pub const MAX_MAX_OUTPUT_SIZE: ByteSize = ByteSize::mib(256);

/// Record configuration in user config.
///
/// This section controls retention policies for recorded test runs.
/// All fields are optional; unspecified fields will use defaults.
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DeserializedRecordConfig {
    /// Whether recording is enabled.
    ///
    /// This allows users to have recording configured but temporarily disabled.
    /// When false, no recording occurs even if the `record` experimental feature
    /// is enabled.
    #[serde(default)]
    pub enabled: Option<bool>,

    /// Maximum number of records to keep.
    #[serde(default)]
    pub max_records: Option<usize>,

    /// Maximum total size of all records.
    #[serde(default)]
    pub max_total_size: Option<ByteSize>,

    /// Maximum age of records.
    #[serde(default, with = "humantime_serde")]
    pub max_age: Option<Duration>,

    /// Maximum size of a single output (stdout/stderr) before truncation.
    #[serde(default)]
    pub max_output_size: Option<ByteSize>,
}

/// Default record configuration with all values required.
///
/// This is parsed from the embedded default user config TOML. All fields are
/// required - if the TOML is missing any field, parsing fails.
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DefaultRecordConfig {
    /// Whether recording is enabled by default.
    pub enabled: bool,

    /// Maximum number of records to keep.
    pub max_records: usize,

    /// Maximum total size of all records.
    pub max_total_size: ByteSize,

    /// Maximum age of records.
    #[serde(with = "humantime_serde")]
    pub max_age: Duration,

    /// Maximum size of a single output (stdout/stderr) before truncation.
    pub max_output_size: ByteSize,
}

/// Deserialized form of record override settings.
///
/// Each field is optional; only the fields that are specified will override the
/// base configuration.
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub(in crate::user_config) struct DeserializedRecordOverrideData {
    /// Whether recording is enabled.
    pub(in crate::user_config) enabled: Option<bool>,

    /// Maximum number of records to keep.
    pub(in crate::user_config) max_records: Option<usize>,

    /// Maximum total size of all records.
    pub(in crate::user_config) max_total_size: Option<ByteSize>,

    /// Maximum age of records.
    #[serde(default, with = "humantime_serde")]
    pub(in crate::user_config) max_age: Option<Duration>,

    /// Maximum size of a single output (stdout/stderr) before truncation.
    pub(in crate::user_config) max_output_size: Option<ByteSize>,
}

/// A compiled record override with parsed platform spec.
///
/// This is created after parsing the platform expression from a
/// `[[overrides]]` entry.
#[derive(Clone, Debug)]
pub(in crate::user_config) struct CompiledRecordOverride {
    platform_spec: TargetSpec,
    data: RecordOverrideData,
}

impl CompiledRecordOverride {
    /// Creates a new compiled override from a platform spec and record data.
    pub(in crate::user_config) fn new(
        platform_spec: TargetSpec,
        data: DeserializedRecordOverrideData,
    ) -> Self {
        Self {
            platform_spec,
            data: RecordOverrideData {
                enabled: data.enabled,
                max_records: data.max_records,
                max_total_size: data.max_total_size,
                max_age: data.max_age,
                max_output_size: data.max_output_size,
            },
        }
    }

    /// Checks if this override matches the host platform.
    ///
    /// Unknown results (e.g., unrecognized target features) are treated as
    /// non-matching to be conservative.
    pub(in crate::user_config) fn matches(&self, host_platform: &Platform) -> bool {
        self.platform_spec
            .eval(host_platform)
            .unwrap_or(/* unknown results are mapped to false */ false)
    }

    /// Returns a reference to the override data.
    pub(in crate::user_config) fn data(&self) -> &RecordOverrideData {
        &self.data
    }
}

/// Override data for record settings.
#[derive(Clone, Debug, Default)]
pub(in crate::user_config) struct RecordOverrideData {
    enabled: Option<bool>,
    max_records: Option<usize>,
    max_total_size: Option<ByteSize>,
    max_age: Option<Duration>,
    max_output_size: Option<ByteSize>,
}

impl RecordOverrideData {
    /// Returns the enabled setting, if specified.
    pub(in crate::user_config) fn enabled(&self) -> Option<&bool> {
        self.enabled.as_ref()
    }

    /// Returns the max_records setting, if specified.
    pub(in crate::user_config) fn max_records(&self) -> Option<&usize> {
        self.max_records.as_ref()
    }

    /// Returns the max_total_size setting, if specified.
    pub(in crate::user_config) fn max_total_size(&self) -> Option<&ByteSize> {
        self.max_total_size.as_ref()
    }

    /// Returns the max_age setting, if specified.
    pub(in crate::user_config) fn max_age(&self) -> Option<&Duration> {
        self.max_age.as_ref()
    }

    /// Returns the max_output_size setting, if specified.
    pub(in crate::user_config) fn max_output_size(&self) -> Option<&ByteSize> {
        self.max_output_size.as_ref()
    }
}

/// Resolved record configuration after applying defaults.
#[derive(Clone, Debug)]
pub struct RecordConfig {
    /// Whether recording is enabled.
    ///
    /// Recording only occurs when both this is true and the `record`
    /// experimental feature is enabled.
    pub enabled: bool,

    /// Maximum number of records to keep.
    pub max_records: usize,

    /// Maximum total size of all records.
    pub max_total_size: ByteSize,

    /// Maximum age of records.
    pub max_age: Duration,

    /// Maximum size of a single output (stdout/stderr) before truncation.
    pub max_output_size: ByteSize,
}

impl RecordConfig {
    /// Resolves record configuration from user configs, defaults, and the host
    /// platform.
    ///
    /// Resolution order (highest to lowest priority):
    ///
    /// 1. User overrides (first matching override for each setting)
    /// 2. Default overrides (first matching override for each setting)
    /// 3. User base config
    /// 4. Default base config
    ///
    /// This matches the resolution order used by repo config.
    ///
    /// If `max_output_size` is below [`MIN_MAX_OUTPUT_SIZE`], it is clamped
    /// to the minimum and a warning is logged.
    pub(in crate::user_config) fn resolve(
        default_config: &DefaultRecordConfig,
        default_overrides: &[CompiledRecordOverride],
        user_config: Option<&DeserializedRecordConfig>,
        user_overrides: &[CompiledRecordOverride],
        host_platform: &Platform,
    ) -> Self {
        let mut max_output_size = resolve_record_setting(
            &default_config.max_output_size,
            default_overrides,
            user_config.and_then(|c| c.max_output_size.as_ref()),
            user_overrides,
            host_platform,
            |data| data.max_output_size(),
        );

        // Enforce minimum to ensure truncation marker fits.
        if max_output_size < MIN_MAX_OUTPUT_SIZE {
            tracing::warn!(
                "max-output-size ({}) is below minimum ({}), using minimum",
                max_output_size,
                MIN_MAX_OUTPUT_SIZE,
            );
            max_output_size = MIN_MAX_OUTPUT_SIZE;
        } else if max_output_size > MAX_MAX_OUTPUT_SIZE {
            tracing::warn!(
                "max-output-size ({}) exceeds maximum ({}), using maximum",
                max_output_size,
                MAX_MAX_OUTPUT_SIZE,
            );
            max_output_size = MAX_MAX_OUTPUT_SIZE;
        }

        Self {
            enabled: resolve_record_setting(
                &default_config.enabled,
                default_overrides,
                user_config.and_then(|c| c.enabled.as_ref()),
                user_overrides,
                host_platform,
                |data| data.enabled(),
            ),
            max_records: resolve_record_setting(
                &default_config.max_records,
                default_overrides,
                user_config.and_then(|c| c.max_records.as_ref()),
                user_overrides,
                host_platform,
                |data| data.max_records(),
            ),
            max_total_size: resolve_record_setting(
                &default_config.max_total_size,
                default_overrides,
                user_config.and_then(|c| c.max_total_size.as_ref()),
                user_overrides,
                host_platform,
                |data| data.max_total_size(),
            ),
            max_age: resolve_record_setting(
                &default_config.max_age,
                default_overrides,
                user_config.and_then(|c| c.max_age.as_ref()),
                user_overrides,
                host_platform,
                |data| data.max_age(),
            ),
            max_output_size,
        }
    }
}

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

    #[test]
    fn test_deserialized_record_config_parsing() {
        // Test full config.
        let config: DeserializedRecordConfig = toml::from_str(
            r#"
            enabled = true
            max-records = 50
            max-total-size = "2GB"
            max-age = "7d"
            max-output-size = "5MB"
            "#,
        )
        .unwrap();

        assert_eq!(config.enabled, Some(true));
        assert_eq!(config.max_records, Some(50));
        assert_eq!(config.max_total_size, Some(ByteSize::gb(2)));
        assert_eq!(config.max_age, Some(Duration::from_secs(7 * 24 * 60 * 60)));
        assert_eq!(config.max_output_size, Some(ByteSize::mb(5)));

        // Test partial config.
        let config: DeserializedRecordConfig = toml::from_str(
            r#"
            max-records = 100
            "#,
        )
        .unwrap();

        assert!(config.enabled.is_none());
        assert_eq!(config.max_records, Some(100));
        assert!(config.max_total_size.is_none());
        assert!(config.max_age.is_none());
        assert!(config.max_output_size.is_none());

        // Test empty config.
        let config: DeserializedRecordConfig = toml::from_str("").unwrap();
        assert!(config.enabled.is_none());
        assert!(config.max_records.is_none());
        assert!(config.max_total_size.is_none());
        assert!(config.max_age.is_none());
        assert!(config.max_output_size.is_none());
    }

    #[test]
    fn test_default_record_config_parsing() {
        let config: DefaultRecordConfig = toml::from_str(
            r#"
            enabled = true
            max-records = 100
            max-total-size = "1GB"
            max-age = "30d"
            max-output-size = "10MB"
            "#,
        )
        .unwrap();

        assert!(config.enabled);
        assert_eq!(config.max_records, 100);
        assert_eq!(config.max_total_size, ByteSize::gb(1));
        assert_eq!(config.max_age, Duration::from_secs(30 * 24 * 60 * 60));
        assert_eq!(config.max_output_size, ByteSize::mb(10));
    }

    #[test]
    fn test_resolve_uses_defaults() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], None, &[], &host);

        assert!(!resolved.enabled);
        assert_eq!(resolved.max_records, 100);
        assert_eq!(resolved.max_total_size, ByteSize::gb(1));
        assert_eq!(resolved.max_age, Duration::from_secs(30 * 24 * 60 * 60));
        assert_eq!(resolved.max_output_size, ByteSize::mb(10));
    }

    #[test]
    fn test_resolve_user_overrides_defaults() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        let user_config = DeserializedRecordConfig {
            enabled: Some(true),
            max_records: Some(50),
            max_total_size: None,
            max_age: Some(Duration::from_secs(7 * 24 * 60 * 60)),
            max_output_size: Some(ByteSize::mb(5)),
        };

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], Some(&user_config), &[], &host);

        assert!(resolved.enabled); // From user.
        assert_eq!(resolved.max_records, 50); // From user.
        assert_eq!(resolved.max_total_size, ByteSize::gb(1)); // From defaults.
        assert_eq!(resolved.max_age, Duration::from_secs(7 * 24 * 60 * 60)); // From user.
        assert_eq!(resolved.max_output_size, ByteSize::mb(5)); // From user.
    }

    #[test]
    fn test_resolve_clamps_small_max_output_size() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // User specifies a value below the minimum.
        let user_config = DeserializedRecordConfig {
            enabled: None,
            max_records: None,
            max_total_size: None,
            max_age: None,
            max_output_size: Some(ByteSize::b(100)), // Way below minimum.
        };

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], Some(&user_config), &[], &host);

        // Should be clamped to the minimum.
        assert_eq!(resolved.max_output_size, MIN_MAX_OUTPUT_SIZE);
    }

    #[test]
    fn test_resolve_accepts_value_at_minimum() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // User specifies exactly the minimum.
        let user_config = DeserializedRecordConfig {
            enabled: None,
            max_records: None,
            max_total_size: None,
            max_age: None,
            max_output_size: Some(MIN_MAX_OUTPUT_SIZE),
        };

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], Some(&user_config), &[], &host);

        // Should be accepted as-is.
        assert_eq!(resolved.max_output_size, MIN_MAX_OUTPUT_SIZE);
    }

    #[test]
    fn test_resolve_clamps_large_max_output_size() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // User specifies a value above the maximum.
        let user_config = DeserializedRecordConfig {
            enabled: None,
            max_records: None,
            max_total_size: None,
            max_age: None,
            max_output_size: Some(ByteSize::gib(1)), // Way above maximum.
        };

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], Some(&user_config), &[], &host);

        // Should be clamped to the maximum.
        assert_eq!(resolved.max_output_size, MAX_MAX_OUTPUT_SIZE);
    }

    #[test]
    fn test_resolve_accepts_value_at_maximum() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // User specifies exactly the maximum.
        let user_config = DeserializedRecordConfig {
            enabled: None,
            max_records: None,
            max_total_size: None,
            max_age: None,
            max_output_size: Some(MAX_MAX_OUTPUT_SIZE),
        };

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], Some(&user_config), &[], &host);

        // Should be accepted as-is.
        assert_eq!(resolved.max_output_size, MAX_MAX_OUTPUT_SIZE);
    }

    /// Helper to create a CompiledRecordOverride for tests.
    fn make_override(
        platform: &str,
        data: DeserializedRecordOverrideData,
    ) -> CompiledRecordOverride {
        let platform_spec =
            TargetSpec::new(platform.to_string()).expect("valid platform spec in test");
        CompiledRecordOverride::new(platform_spec, data)
    }

    #[test]
    fn test_resolve_user_override_applies() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // Create a user override that matches any platform.
        let override_ = make_override(
            "cfg(all())",
            DeserializedRecordOverrideData {
                enabled: Some(true),
                max_records: Some(50),
                ..Default::default()
            },
        );

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], None, &[override_], &host);

        assert!(resolved.enabled);
        assert_eq!(resolved.max_records, 50);
        assert_eq!(resolved.max_total_size, ByteSize::gb(1)); // From defaults.
        assert_eq!(resolved.max_age, Duration::from_secs(30 * 24 * 60 * 60)); // From defaults.
        assert_eq!(resolved.max_output_size, ByteSize::mb(10)); // From defaults.
    }

    #[test]
    fn test_resolve_default_override_applies() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // Create a default override that matches any platform.
        let override_ = make_override(
            "cfg(all())",
            DeserializedRecordOverrideData {
                enabled: Some(true),
                max_records: Some(50),
                ..Default::default()
            },
        );

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[override_], None, &[], &host);

        assert!(resolved.enabled);
        assert_eq!(resolved.max_records, 50);
        assert_eq!(resolved.max_total_size, ByteSize::gb(1)); // From defaults.
    }

    #[test]
    fn test_resolve_platform_override_no_match() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // Create an override that never matches (cfg(any()) with no arguments
        // is false).
        let override_ = make_override(
            "cfg(any())",
            DeserializedRecordOverrideData {
                enabled: Some(true),
                max_records: Some(50),
                max_total_size: Some(ByteSize::gb(2)),
                max_age: Some(Duration::from_secs(7 * 24 * 60 * 60)),
                max_output_size: Some(ByteSize::mb(5)),
            },
        );

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], None, &[override_], &host);

        // Nothing should be overridden - all values should match defaults.
        assert!(!resolved.enabled);
        assert_eq!(resolved.max_records, 100);
        assert_eq!(resolved.max_total_size, ByteSize::gb(1));
        assert_eq!(resolved.max_age, Duration::from_secs(30 * 24 * 60 * 60));
        assert_eq!(resolved.max_output_size, ByteSize::mb(10));
    }

    #[test]
    fn test_resolve_first_matching_user_override_wins() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // Create two user overrides that both match (cfg(all()) is always true).
        let override1 = make_override(
            "cfg(all())",
            DeserializedRecordOverrideData {
                enabled: Some(true),
                ..Default::default()
            },
        );

        let override2 = make_override(
            "cfg(all())",
            DeserializedRecordOverrideData {
                enabled: Some(false), // Should be ignored.
                max_records: Some(50),
                ..Default::default()
            },
        );

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], None, &[override1, override2], &host);

        // First override wins for enabled.
        assert!(resolved.enabled);
        // Second override's max_records applies (first didn't set it).
        assert_eq!(resolved.max_records, 50);
    }

    #[test]
    fn test_resolve_user_override_beats_default_override() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // User override sets enabled.
        let user_override = make_override(
            "cfg(all())",
            DeserializedRecordOverrideData {
                enabled: Some(true),
                ..Default::default()
            },
        );

        // Default override sets enabled and max_records.
        let default_override = make_override(
            "cfg(all())",
            DeserializedRecordOverrideData {
                enabled: Some(false), // Should be ignored.
                max_records: Some(50),
                ..Default::default()
            },
        );

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(
            &defaults,
            &[default_override],
            None,
            &[user_override],
            &host,
        );

        // User override wins for enabled.
        assert!(resolved.enabled);
        // Default override applies for max_records (user didn't set it).
        assert_eq!(resolved.max_records, 50);
    }

    #[test]
    fn test_resolve_override_beats_user_base() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // User base config sets enabled.
        let user_config = DeserializedRecordConfig {
            enabled: Some(false),
            max_records: Some(25),
            ..Default::default()
        };

        // Default override sets enabled (should beat user base).
        let default_override = make_override(
            "cfg(all())",
            DeserializedRecordOverrideData {
                enabled: Some(true),
                ..Default::default()
            },
        );

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(
            &defaults,
            &[default_override],
            Some(&user_config),
            &[],
            &host,
        );

        // Default override is chosen over user base for enabled.
        assert!(resolved.enabled);
        // User base applies for max_records (override didn't set it).
        assert_eq!(resolved.max_records, 25);
    }

    #[test]
    fn test_resolve_override_clamps_max_output_size() {
        let defaults = DefaultRecordConfig {
            enabled: false,
            max_records: 100,
            max_total_size: ByteSize::gb(1),
            max_age: Duration::from_secs(30 * 24 * 60 * 60),
            max_output_size: ByteSize::mb(10),
        };

        // Override specifies a value below the minimum.
        let override_ = make_override(
            "cfg(all())",
            DeserializedRecordOverrideData {
                max_output_size: Some(ByteSize::b(100)), // Way below minimum.
                ..Default::default()
            },
        );

        let host = detect_host_platform_for_tests();
        let resolved = RecordConfig::resolve(&defaults, &[], None, &[override_], &host);

        // Should be clamped to the minimum.
        assert_eq!(resolved.max_output_size, MIN_MAX_OUTPUT_SIZE);
    }
}