tauri-plugin-hotswap 0.0.4

Open-source OTA plugin for Tauri v2 — push frontend updates to users without rebuilding the binary. Self-hosted, signed bundles, auto-rollback.
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
//! Configurable policy traits for OTA update lifecycle decisions.
//!
//! Four traits govern how the plugin handles cached bundles at startup,
//! on rollback, and during cleanup. Each has built-in enum implementations
//! configurable via `tauri.conf.json`. Custom implementations can be
//! injected via [`HotswapBuilder`](crate::HotswapBuilder) using the
//! `binary_cache_policy()`, `confirmation_policy()`, `rollback_policy()`,
//! and `retention_policy()` setters, which accept any `impl Policy` type.
//!
//! # Safety invariants (not trait-pluggable)
//!
//! - Signature verification is always mandatory
//! - Archive path validation remains strict
//! - Atomic extraction/activation behavior is fixed
//! - The "binary too old" safety check (`binary < min_binary_version`) is
//!   hardcoded outside `BinaryCachePolicy` — no policy can override it

use crate::manifest::HotswapMeta;
use semver::Version;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;

// ─── 1) BinaryCachePolicy ─────────────────────────────────────────────

/// Decides whether a cached OTA bundle should be discarded at startup
/// based on binary version changes.
///
/// The safety check (`current_binary < min_binary_version` → always discard)
/// is enforced **outside** this trait. This trait only governs the policy
/// decision for compatible binaries.
pub trait BinaryCachePolicy: Send + Sync + 'static {
    /// Return `true` to discard the cached bundle and fall back to embedded assets.
    ///
    /// `previous_binary` is `None` until a future release adds persistence
    /// of the previous binary version.
    fn should_discard(
        &self,
        current_binary: &Version,
        cached_meta: &HotswapMeta,
        previous_binary: Option<&Version>,
    ) -> bool;
}

/// Built-in binary cache policy variants, selectable via config.
///
/// # Config examples
///
/// ```json
/// { "binary_cache_policy": "keep_compatible" }
/// { "binary_cache_policy": "discard_on_upgrade" }
/// { "binary_cache_policy": "never_discard" }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum BinaryCachePolicyKind {
    /// Keep the cache as long as the current binary satisfies `min_binary_version`.
    /// Recommended for most apps — opt in via `"binary_cache_policy": "keep_compatible"`.
    KeepCompatible,
    /// Discard when `current_binary > min_binary_version`.
    /// This is the default, preserving pre-0.0.2 semantics.
    ///
    /// Note: this detects "binary newer than min", not actual binary *changes*
    /// (e.g., rebuild at same version, downgrade). True change detection
    /// would require persisting the previous binary version (deferred).
    #[default]
    DiscardOnUpgrade,
    /// Never discard based on binary version. Only the safety check
    /// (`binary < min`) still applies.
    NeverDiscard,
}

impl BinaryCachePolicy for BinaryCachePolicyKind {
    fn should_discard(
        &self,
        current_binary: &Version,
        cached_meta: &HotswapMeta,
        _previous_binary: Option<&Version>,
    ) -> bool {
        match self {
            BinaryCachePolicyKind::KeepCompatible => false,
            BinaryCachePolicyKind::DiscardOnUpgrade => {
                if let Ok(required) = Version::parse(&cached_meta.min_binary_version) {
                    current_binary > &required
                } else {
                    false
                }
            }
            BinaryCachePolicyKind::NeverDiscard => false,
        }
    }
}

// ─── 2) ConfirmationPolicy ────────────────────────────────────────────

/// Decides what to do on startup if the current OTA version has not
/// been confirmed via `notifyReady()`.
///
/// The trait takes immutable `&HotswapMeta`. The caller handles counter
/// mutation (incrementing `unconfirmed_launch_count`, writing to disk).
pub trait ConfirmationPolicy: Send + Sync + 'static {
    /// Decide what to do with an unconfirmed OTA version at startup.
    fn on_startup_unconfirmed(&self, meta: &HotswapMeta) -> ConfirmationDecision;
}

/// Decision returned by [`ConfirmationPolicy::on_startup_unconfirmed`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ConfirmationDecision {
    /// Keep the version for now. Caller increments `unconfirmed_launch_count`.
    KeepForNow,
    /// Trigger rollback immediately.
    RollbackNow,
}

/// Built-in confirmation policy variants.
///
/// # Config examples
///
/// ```json
/// { "confirmation_policy": "single_launch" }
/// { "confirmation_policy": { "grace_period": { "max_unconfirmed_launches": 3 } } }
/// ```
///
/// # Threshold semantics
///
/// Rollback when `unconfirmed_launch_count >= max_unconfirmed_launches`.
/// With `max=1` (default `SingleLaunch`), the first unconfirmed startup
/// triggers rollback — matching the pre-0.0.2 behavior.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ConfirmationPolicyKind {
    /// Rollback on first unconfirmed launch (pre-0.0.2 behavior).
    #[default]
    SingleLaunch,
    /// Allow up to N unconfirmed launches before rollback.
    GracePeriod {
        /// Number of unconfirmed launches allowed before rollback.
        /// `0` is treated the same as `SingleLaunch` (immediate rollback).
        max_unconfirmed_launches: u32,
    },
}

impl ConfirmationPolicy for ConfirmationPolicyKind {
    fn on_startup_unconfirmed(&self, meta: &HotswapMeta) -> ConfirmationDecision {
        match self {
            ConfirmationPolicyKind::SingleLaunch => ConfirmationDecision::RollbackNow,
            ConfirmationPolicyKind::GracePeriod {
                max_unconfirmed_launches,
            } => {
                if *max_unconfirmed_launches == 0
                    || meta.unconfirmed_launch_count >= *max_unconfirmed_launches
                {
                    ConfirmationDecision::RollbackNow
                } else {
                    ConfirmationDecision::KeepForNow
                }
            }
        }
    }
}

// ─── 3) RollbackPolicy ───────────────────────────────────────────────

/// Selects a rollback target from available confirmed versions.
pub trait RollbackPolicy: Send + Sync + 'static {
    /// Select a rollback target from confirmed candidates sorted descending by sequence.
    /// Returns `None` to fall back to embedded assets.
    fn select_target(
        &self,
        current_sequence: Option<u64>,
        candidates_desc: &[HotswapMeta],
    ) -> Option<u64>;
}

/// Built-in rollback policy variants.
///
/// # Config examples
///
/// ```json
/// { "rollback_policy": "latest_confirmed" }
/// { "rollback_policy": "embedded_only" }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum RollbackPolicyKind {
    /// Roll back to the highest-sequence confirmed version (pre-0.0.2 behavior).
    #[default]
    LatestConfirmed,
    /// Roll back to the confirmed version immediately before current.
    ImmediatePreviousConfirmed,
    /// Always fall back to embedded assets.
    EmbeddedOnly,
}

impl RollbackPolicy for RollbackPolicyKind {
    fn select_target(
        &self,
        current_sequence: Option<u64>,
        candidates_desc: &[HotswapMeta],
    ) -> Option<u64> {
        match self {
            RollbackPolicyKind::LatestConfirmed => candidates_desc.first().map(|m| m.sequence),
            RollbackPolicyKind::ImmediatePreviousConfirmed => {
                let current = current_sequence?;
                candidates_desc
                    .iter()
                    .find(|m| m.sequence < current)
                    .map(|m| m.sequence)
            }
            RollbackPolicyKind::EmbeddedOnly => None,
        }
    }
}

// ─── 4) RetentionPolicy ──────────────────────────────────────────────

/// Determines which cached versions to keep during cleanup.
///
/// The orchestrator enforces a safety floor: current and rollback candidate
/// are always preserved, even if the trait returns fewer sequences.
pub trait RetentionPolicy: Send + Sync + 'static {
    /// Return the set of sequence numbers to keep.
    /// The orchestrator will additionally preserve current + rollback candidate.
    fn select_kept_sequences(
        &self,
        current_sequence: Option<u64>,
        rollback_candidate: Option<u64>,
        available_desc: &[HotswapMeta],
    ) -> HashSet<u64>;
}

/// Retention configuration.
///
/// `max_retained_versions` is the **total** number of versions kept on disk,
/// including current and rollback candidate.
///
/// | `max_retained_versions` | Versions on disk |
/// |--------------------------|------------------|
/// | 2 (default) | current + rollback candidate |
/// | 3 | current + rollback + 1 older |
/// | 5 | current + rollback + 3 older |
///
/// Values below 2 are clamped to 2.
///
/// # Config example
///
/// ```json
/// { "max_retained_versions": 3 }
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RetentionConfig {
    /// Total number of versions to keep. Default 2, min 2.
    #[serde(default = "default_max_retained")]
    pub max_retained_versions: u32,
}

fn default_max_retained() -> u32 {
    2
}

impl Default for RetentionConfig {
    fn default() -> Self {
        Self {
            max_retained_versions: default_max_retained(),
        }
    }
}

impl RetentionConfig {
    /// Effective max, clamped to floor of 2.
    pub fn effective_max(&self) -> u32 {
        self.max_retained_versions.max(2)
    }
}

impl RetentionPolicy for RetentionConfig {
    fn select_kept_sequences(
        &self,
        current_sequence: Option<u64>,
        rollback_candidate: Option<u64>,
        available_desc: &[HotswapMeta],
    ) -> HashSet<u64> {
        let max = self.effective_max() as usize;
        let mut kept = HashSet::new();

        // Safety floor: always preserve current + rollback candidate
        if let Some(seq) = current_sequence {
            kept.insert(seq);
        }
        if let Some(seq) = rollback_candidate {
            kept.insert(seq);
        }

        // Fill up to max from highest-sequence versions
        for meta in available_desc {
            if kept.len() >= max {
                break;
            }
            kept.insert(meta.sequence);
        }

        kept
    }
}

// ─── Tests ───────────────────────────────────────────────────────────

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

    fn meta(min_bin: &str, seq: u64, confirmed: bool) -> HotswapMeta {
        HotswapMeta {
            version: format!("1.0.0-ota.{}", seq),
            sequence: seq,
            min_binary_version: min_bin.into(),
            confirmed,
            unconfirmed_launch_count: 0,
        }
    }

    fn v(s: &str) -> Version {
        Version::parse(s).unwrap()
    }

    // ── BinaryCachePolicy ─────────────────────────────────────────

    #[test]
    fn keep_compatible_keeps_when_binary_matches() {
        let p = BinaryCachePolicyKind::KeepCompatible;
        assert!(!p.should_discard(&v("1.0.0"), &meta("1.0.0", 1, true), None));
    }

    #[test]
    fn keep_compatible_keeps_when_binary_newer() {
        let p = BinaryCachePolicyKind::KeepCompatible;
        assert!(!p.should_discard(&v("2.0.0"), &meta("1.0.0", 1, true), None));
    }

    #[test]
    fn discard_on_upgrade_discards_when_binary_newer() {
        let p = BinaryCachePolicyKind::DiscardOnUpgrade;
        assert!(p.should_discard(&v("2.0.0"), &meta("1.0.0", 1, true), None));
    }

    #[test]
    fn discard_on_upgrade_keeps_when_binary_matches() {
        let p = BinaryCachePolicyKind::DiscardOnUpgrade;
        assert!(!p.should_discard(&v("1.0.0"), &meta("1.0.0", 1, true), None));
    }

    #[test]
    fn discard_on_upgrade_keeps_on_invalid_semver() {
        let p = BinaryCachePolicyKind::DiscardOnUpgrade;
        assert!(!p.should_discard(&v("2.0.0"), &meta("not-semver", 1, true), None));
    }

    #[test]
    fn never_discard_keeps_always() {
        let p = BinaryCachePolicyKind::NeverDiscard;
        assert!(!p.should_discard(&v("99.0.0"), &meta("1.0.0", 1, true), None));
    }

    #[test]
    fn binary_cache_policy_default_is_discard_on_upgrade() {
        assert_eq!(
            BinaryCachePolicyKind::default(),
            BinaryCachePolicyKind::DiscardOnUpgrade
        );
    }

    #[test]
    fn binary_cache_policy_serde_roundtrip() {
        for (json, expected) in [
            ("\"keep_compatible\"", BinaryCachePolicyKind::KeepCompatible),
            (
                "\"discard_on_upgrade\"",
                BinaryCachePolicyKind::DiscardOnUpgrade,
            ),
            ("\"never_discard\"", BinaryCachePolicyKind::NeverDiscard),
        ] {
            let parsed: BinaryCachePolicyKind = serde_json::from_str(json).unwrap();
            assert_eq!(parsed, expected);
            let serialized = serde_json::to_string(&expected).unwrap();
            let reparsed: BinaryCachePolicyKind = serde_json::from_str(&serialized).unwrap();
            assert_eq!(reparsed, expected);
        }
    }

    // ── ConfirmationPolicy ────────────────────────────────────────

    #[test]
    fn single_launch_always_rollbacks() {
        let p = ConfirmationPolicyKind::SingleLaunch;
        let m = meta("1.0.0", 1, false);
        assert_eq!(
            p.on_startup_unconfirmed(&m),
            ConfirmationDecision::RollbackNow
        );
    }

    #[test]
    fn grace_period_keeps_when_under_threshold() {
        let p = ConfirmationPolicyKind::GracePeriod {
            max_unconfirmed_launches: 3,
        };
        let mut m = meta("1.0.0", 1, false);
        m.unconfirmed_launch_count = 0;
        assert_eq!(
            p.on_startup_unconfirmed(&m),
            ConfirmationDecision::KeepForNow
        );

        m.unconfirmed_launch_count = 2;
        assert_eq!(
            p.on_startup_unconfirmed(&m),
            ConfirmationDecision::KeepForNow
        );
    }

    #[test]
    fn grace_period_rollbacks_at_threshold() {
        let p = ConfirmationPolicyKind::GracePeriod {
            max_unconfirmed_launches: 3,
        };
        let mut m = meta("1.0.0", 1, false);
        m.unconfirmed_launch_count = 3;
        assert_eq!(
            p.on_startup_unconfirmed(&m),
            ConfirmationDecision::RollbackNow
        );
    }

    #[test]
    fn grace_period_rollbacks_above_threshold() {
        let p = ConfirmationPolicyKind::GracePeriod {
            max_unconfirmed_launches: 3,
        };
        let mut m = meta("1.0.0", 1, false);
        m.unconfirmed_launch_count = 10;
        assert_eq!(
            p.on_startup_unconfirmed(&m),
            ConfirmationDecision::RollbackNow
        );
    }

    #[test]
    fn grace_period_zero_is_immediate_rollback() {
        let p = ConfirmationPolicyKind::GracePeriod {
            max_unconfirmed_launches: 0,
        };
        let m = meta("1.0.0", 1, false);
        assert_eq!(
            p.on_startup_unconfirmed(&m),
            ConfirmationDecision::RollbackNow
        );
    }

    #[test]
    fn confirmation_policy_default_is_single_launch() {
        assert_eq!(
            ConfirmationPolicyKind::default(),
            ConfirmationPolicyKind::SingleLaunch
        );
    }

    #[test]
    fn confirmation_policy_serde_roundtrip() {
        let single: ConfirmationPolicyKind = serde_json::from_str("\"single_launch\"").unwrap();
        assert_eq!(single, ConfirmationPolicyKind::SingleLaunch);

        let grace: ConfirmationPolicyKind =
            serde_json::from_str(r#"{"grace_period":{"max_unconfirmed_launches":5}}"#).unwrap();
        assert_eq!(
            grace,
            ConfirmationPolicyKind::GracePeriod {
                max_unconfirmed_launches: 5
            }
        );
    }

    // ── RollbackPolicy ────────────────────────────────────────────

    fn confirmed_candidates() -> Vec<HotswapMeta> {
        vec![
            meta("1.0.0", 10, true),
            meta("1.0.0", 7, true),
            meta("1.0.0", 3, true),
        ]
    }

    #[test]
    fn latest_confirmed_picks_highest() {
        let p = RollbackPolicyKind::LatestConfirmed;
        assert_eq!(p.select_target(Some(15), &confirmed_candidates()), Some(10));
    }

    #[test]
    fn latest_confirmed_with_empty_candidates() {
        let p = RollbackPolicyKind::LatestConfirmed;
        assert_eq!(p.select_target(Some(15), &[]), None);
    }

    #[test]
    fn immediate_previous_picks_just_below_current() {
        let p = RollbackPolicyKind::ImmediatePreviousConfirmed;
        assert_eq!(p.select_target(Some(10), &confirmed_candidates()), Some(7));
    }

    #[test]
    fn immediate_previous_skips_equal_sequence() {
        let p = RollbackPolicyKind::ImmediatePreviousConfirmed;
        // Current is 10, candidates include 10 — should skip to 7
        assert_eq!(p.select_target(Some(10), &confirmed_candidates()), Some(7));
    }

    #[test]
    fn immediate_previous_none_when_no_lower() {
        let p = RollbackPolicyKind::ImmediatePreviousConfirmed;
        let candidates = vec![meta("1.0.0", 10, true)];
        assert_eq!(p.select_target(Some(10), &candidates), None);
    }

    #[test]
    fn immediate_previous_none_when_no_current() {
        let p = RollbackPolicyKind::ImmediatePreviousConfirmed;
        assert_eq!(p.select_target(None, &confirmed_candidates()), None);
    }

    #[test]
    fn embedded_only_always_none() {
        let p = RollbackPolicyKind::EmbeddedOnly;
        assert_eq!(p.select_target(Some(10), &confirmed_candidates()), None);
    }

    #[test]
    fn rollback_policy_default_is_latest_confirmed() {
        assert_eq!(
            RollbackPolicyKind::default(),
            RollbackPolicyKind::LatestConfirmed
        );
    }

    #[test]
    fn rollback_policy_serde_roundtrip() {
        for (json, expected) in [
            ("\"latest_confirmed\"", RollbackPolicyKind::LatestConfirmed),
            (
                "\"immediate_previous_confirmed\"",
                RollbackPolicyKind::ImmediatePreviousConfirmed,
            ),
            ("\"embedded_only\"", RollbackPolicyKind::EmbeddedOnly),
        ] {
            let parsed: RollbackPolicyKind = serde_json::from_str(json).unwrap();
            assert_eq!(parsed, expected);
        }
    }

    // ── RetentionPolicy ───────────────────────────────────────────

    fn available_versions() -> Vec<HotswapMeta> {
        vec![
            meta("1.0.0", 10, true),
            meta("1.0.0", 7, true),
            meta("1.0.0", 5, true),
            meta("1.0.0", 3, true),
            meta("1.0.0", 1, true),
        ]
    }

    #[test]
    fn retention_default_keeps_two() {
        let r = RetentionConfig::default();
        let kept = r.select_kept_sequences(Some(10), Some(7), &available_versions());
        assert_eq!(kept.len(), 2);
        assert!(kept.contains(&10));
        assert!(kept.contains(&7));
    }

    #[test]
    fn retention_three_keeps_three() {
        let r = RetentionConfig {
            max_retained_versions: 3,
        };
        let kept = r.select_kept_sequences(Some(10), Some(7), &available_versions());
        assert_eq!(kept.len(), 3);
        assert!(kept.contains(&10));
        assert!(kept.contains(&7));
        // Third slot goes to next highest available
        assert!(kept.contains(&5));
    }

    #[test]
    fn retention_five_keeps_five() {
        let r = RetentionConfig {
            max_retained_versions: 5,
        };
        let kept = r.select_kept_sequences(Some(10), Some(7), &available_versions());
        assert_eq!(kept.len(), 5);
    }

    #[test]
    fn retention_preserves_current_and_rollback_even_if_not_in_available() {
        let r = RetentionConfig::default();
        // current=10, rollback=7, but available only has [5, 3, 1]
        let available = vec![
            meta("1.0.0", 5, true),
            meta("1.0.0", 3, true),
            meta("1.0.0", 1, true),
        ];
        let kept = r.select_kept_sequences(Some(10), Some(7), &available);
        assert!(kept.contains(&10));
        assert!(kept.contains(&7));
    }

    #[test]
    fn retention_clamps_below_two() {
        let r = RetentionConfig {
            max_retained_versions: 0,
        };
        assert_eq!(r.effective_max(), 2);

        let r = RetentionConfig {
            max_retained_versions: 1,
        };
        assert_eq!(r.effective_max(), 2);
    }

    #[test]
    fn retention_no_current_no_rollback() {
        let r = RetentionConfig::default();
        let kept = r.select_kept_sequences(None, None, &available_versions());
        // Should still keep up to max from available
        assert_eq!(kept.len(), 2);
        assert!(kept.contains(&10));
        assert!(kept.contains(&7));
    }

    #[test]
    fn retention_config_serde_roundtrip() {
        let json = r#"{"max_retained_versions":4}"#;
        let parsed: RetentionConfig = serde_json::from_str(json).unwrap();
        assert_eq!(parsed.max_retained_versions, 4);

        // Default when field omitted
        let empty: RetentionConfig = serde_json::from_str("{}").unwrap();
        assert_eq!(empty.max_retained_versions, 2);
    }

    #[test]
    fn retention_config_default() {
        let r = RetentionConfig::default();
        assert_eq!(r.max_retained_versions, 2);
    }
}