oximedia-archive 0.1.2

Media archive verification and long-term preservation system
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
//! Configurable quarantine policies.
//!
//! Provides rules for:
//! - Maximum quarantine size (auto-evict oldest entries when limit exceeded)
//! - Auto-cleanup after N days
//! - Size-based eviction strategies
//! - Policy evaluation against a set of quarantine records

use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};

// ---------------------------------------------------------------------------
// QuarantinePolicy
// ---------------------------------------------------------------------------

/// Configurable policy governing how quarantined files are managed.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuarantinePolicy {
    /// Maximum total size of quarantine directory in bytes.
    /// `None` means unlimited.
    pub max_total_bytes: Option<u64>,
    /// Maximum number of quarantined files.
    /// `None` means unlimited.
    pub max_file_count: Option<usize>,
    /// Auto-delete quarantined files older than this many days.
    /// `None` means never auto-delete.
    pub auto_cleanup_after_days: Option<u32>,
    /// Maximum size of a single file that may be quarantined in bytes.
    /// Files larger than this are rejected from quarantine.
    pub max_single_file_bytes: Option<u64>,
    /// Strategy for evicting entries when the quota is exceeded.
    pub eviction_strategy: EvictionStrategy,
    /// Whether to allow restoring quarantined files.
    pub allow_restore: bool,
    /// Whether quarantined files should be zero-filled instead of moved.
    /// Useful for secure erasure workflows.
    pub secure_delete: bool,
}

impl Default for QuarantinePolicy {
    fn default() -> Self {
        Self {
            max_total_bytes: Some(10 * 1024 * 1024 * 1024), // 10 GiB
            max_file_count: Some(10_000),
            auto_cleanup_after_days: Some(90),
            max_single_file_bytes: None,
            eviction_strategy: EvictionStrategy::OldestFirst,
            allow_restore: true,
            secure_delete: false,
        }
    }
}

impl QuarantinePolicy {
    /// Create an unrestricted policy (no limits).
    #[must_use]
    pub fn unlimited() -> Self {
        Self {
            max_total_bytes: None,
            max_file_count: None,
            auto_cleanup_after_days: None,
            max_single_file_bytes: None,
            eviction_strategy: EvictionStrategy::OldestFirst,
            allow_restore: true,
            secure_delete: false,
        }
    }

    /// Create a strict policy suitable for high-security environments.
    #[must_use]
    pub fn strict() -> Self {
        Self {
            max_total_bytes: Some(1024 * 1024 * 1024), // 1 GiB
            max_file_count: Some(100),
            auto_cleanup_after_days: Some(30),
            max_single_file_bytes: Some(512 * 1024 * 1024), // 512 MiB
            eviction_strategy: EvictionStrategy::OldestFirst,
            allow_restore: false,
            secure_delete: true,
        }
    }

    /// Check whether a file of `size_bytes` may be quarantined given the
    /// current state of the quarantine directory.
    pub fn check_admission(
        &self,
        file_size_bytes: u64,
        current_total_bytes: u64,
        current_file_count: usize,
    ) -> AdmissionDecision {
        // Single-file size check
        if let Some(max_single) = self.max_single_file_bytes {
            if file_size_bytes > max_single {
                return AdmissionDecision::Rejected(format!(
                    "file size {} bytes exceeds per-file limit {} bytes",
                    file_size_bytes, max_single
                ));
            }
        }

        // File count check
        if let Some(max_count) = self.max_file_count {
            if current_file_count >= max_count {
                return match self.eviction_strategy {
                    EvictionStrategy::OldestFirst => {
                        AdmissionDecision::AdmitAfterEviction(EvictionRequest {
                            reason: format!(
                                "file count {current_file_count} at limit {max_count}"
                            ),
                            strategy: self.eviction_strategy,
                            bytes_to_free: 0,
                            files_to_evict: 1,
                        })
                    }
                    EvictionStrategy::LargestFirst => {
                        AdmissionDecision::AdmitAfterEviction(EvictionRequest {
                            reason: format!(
                                "file count {current_file_count} at limit {max_count}"
                            ),
                            strategy: self.eviction_strategy,
                            bytes_to_free: 0,
                            files_to_evict: 1,
                        })
                    }
                    EvictionStrategy::None => {
                        AdmissionDecision::Rejected(format!(
                            "file count {current_file_count} at limit {max_count} and eviction is disabled"
                        ))
                    }
                };
            }
        }

        // Total size check
        if let Some(max_bytes) = self.max_total_bytes {
            let after = current_total_bytes.saturating_add(file_size_bytes);
            if after > max_bytes {
                let bytes_to_free = after - max_bytes;
                return match self.eviction_strategy {
                    EvictionStrategy::OldestFirst | EvictionStrategy::LargestFirst => {
                        AdmissionDecision::AdmitAfterEviction(EvictionRequest {
                            reason: format!(
                                "total size {after} bytes would exceed limit {max_bytes}"
                            ),
                            strategy: self.eviction_strategy,
                            bytes_to_free,
                            files_to_evict: 0,
                        })
                    }
                    EvictionStrategy::None => {
                        AdmissionDecision::Rejected(format!(
                            "total size {after} bytes would exceed limit {max_bytes} and eviction is disabled"
                        ))
                    }
                };
            }
        }

        AdmissionDecision::Admitted
    }

    /// Determine which quarantine records should be cleaned up based on age.
    ///
    /// `records` is a slice of `(record_id, quarantine_date_epoch_secs, size_bytes)`.
    /// Returns the IDs of records eligible for cleanup.
    #[must_use]
    pub fn eligible_for_cleanup(
        &self,
        records: &[(u64, u64, u64)],
        now_epoch_secs: u64,
    ) -> Vec<u64> {
        let Some(max_days) = self.auto_cleanup_after_days else {
            return Vec::new();
        };
        let threshold_secs = u64::from(max_days) * 86_400;

        records
            .iter()
            .filter_map(|(id, quarantine_secs, _size)| {
                let age = now_epoch_secs.saturating_sub(*quarantine_secs);
                if age >= threshold_secs {
                    Some(*id)
                } else {
                    None
                }
            })
            .collect()
    }

    /// Determine which records to evict to satisfy the given eviction request.
    ///
    /// `records` is sorted from oldest (index 0) to newest.
    /// Each record: `(record_id, quarantine_date_epoch_secs, size_bytes)`.
    /// Returns the IDs of records that should be evicted.
    #[must_use]
    pub fn select_for_eviction(
        &self,
        records: &[(u64, u64, u64)],
        request: &EvictionRequest,
    ) -> Vec<u64> {
        let mut sorted = records.to_vec();
        match request.strategy {
            EvictionStrategy::OldestFirst => {
                // Already sorted oldest-first
                sorted.sort_by_key(|(_, ts, _)| *ts);
            }
            EvictionStrategy::LargestFirst => {
                sorted.sort_by(|a, b| b.2.cmp(&a.2));
            }
            EvictionStrategy::None => return Vec::new(),
        }

        let mut evicted = Vec::new();
        let mut freed_bytes = 0u64;
        let mut freed_files = 0usize;

        for (id, _ts, size) in &sorted {
            if freed_files >= request.files_to_evict.max(1) && freed_bytes >= request.bytes_to_free
            {
                break;
            }
            evicted.push(*id);
            freed_bytes = freed_bytes.saturating_add(*size);
            freed_files += 1;
        }

        evicted
    }
}

// ---------------------------------------------------------------------------
// Supporting types
// ---------------------------------------------------------------------------

/// Strategy for selecting which quarantined files to evict when space is low.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum EvictionStrategy {
    /// Evict the oldest quarantined files first.
    OldestFirst,
    /// Evict the largest files first to reclaim the most space quickly.
    LargestFirst,
    /// Do not automatically evict anything; reject new quarantine requests.
    None,
}

/// Decision returned by `QuarantinePolicy::check_admission`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AdmissionDecision {
    /// The file may be quarantined immediately.
    Admitted,
    /// The file may be quarantined after evicting the specified records.
    AdmitAfterEviction(EvictionRequest),
    /// The file cannot be quarantined under current policy.
    Rejected(String),
}

impl AdmissionDecision {
    /// Returns `true` if admission was granted (immediately or after eviction).
    #[must_use]
    pub fn is_admitted(&self) -> bool {
        !matches!(self, Self::Rejected(_))
    }

    /// Returns `true` if the file was outright rejected.
    #[must_use]
    pub fn is_rejected(&self) -> bool {
        matches!(self, Self::Rejected(_))
    }
}

/// Specification for an eviction operation.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EvictionRequest {
    /// Human-readable reason for the eviction.
    pub reason: String,
    /// Strategy to use when selecting candidates.
    pub strategy: EvictionStrategy,
    /// Minimum bytes that must be freed.
    pub bytes_to_free: u64,
    /// Minimum number of files to evict.
    pub files_to_evict: usize,
}

// ---------------------------------------------------------------------------
// QuarantineInventory — in-memory snapshot for policy evaluation
// ---------------------------------------------------------------------------

/// Lightweight snapshot of the quarantine directory for policy evaluation.
#[derive(Debug, Clone, Default)]
pub struct QuarantineInventory {
    /// Records: `(record_id, quarantine_date_epoch_secs, size_bytes, path)`.
    records: Vec<(u64, u64, u64, PathBuf)>,
}

impl QuarantineInventory {
    /// Create an empty inventory.
    #[must_use]
    pub fn new() -> Self {
        Self::default()
    }

    /// Add a record to the inventory.
    pub fn add(&mut self, id: u64, quarantine_epoch_secs: u64, size_bytes: u64, path: PathBuf) {
        self.records.push((id, quarantine_epoch_secs, size_bytes, path));
    }

    /// Total number of records.
    #[must_use]
    pub fn count(&self) -> usize {
        self.records.len()
    }

    /// Total bytes of all quarantined files.
    #[must_use]
    pub fn total_bytes(&self) -> u64 {
        self.records.iter().map(|(_, _, s, _)| s).sum()
    }

    /// Records as `(id, timestamp, size)` tuples for policy evaluation.
    #[must_use]
    pub fn as_tuples(&self) -> Vec<(u64, u64, u64)> {
        self.records
            .iter()
            .map(|(id, ts, size, _)| (*id, *ts, *size))
            .collect()
    }

    /// Get the path for a given record ID.
    #[must_use]
    pub fn path_for(&self, id: u64) -> Option<&Path> {
        self.records
            .iter()
            .find(|(rid, _, _, _)| *rid == id)
            .map(|(_, _, _, p)| p.as_path())
    }

    /// Apply cleanup: return IDs of records that should be deleted based on policy.
    #[must_use]
    pub fn cleanup_candidates(&self, policy: &QuarantinePolicy, now_epoch_secs: u64) -> Vec<u64> {
        policy.eligible_for_cleanup(&self.as_tuples(), now_epoch_secs)
    }
}

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

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

    fn now_secs() -> u64 {
        std::time::SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .map(|d| d.as_secs())
            .unwrap_or(0)
    }

    // --- QuarantinePolicy::check_admission ---

    #[test]
    fn test_admission_no_limits_always_admitted() {
        let policy = QuarantinePolicy::unlimited();
        let decision = policy.check_admission(999_999_999, 0, 0);
        assert_eq!(decision, AdmissionDecision::Admitted);
    }

    #[test]
    fn test_admission_within_limits() {
        let policy = QuarantinePolicy {
            max_total_bytes: Some(1_000_000),
            max_file_count: Some(100),
            max_single_file_bytes: Some(500_000),
            ..QuarantinePolicy::default()
        };
        let decision = policy.check_admission(1000, 100_000, 5);
        assert_eq!(decision, AdmissionDecision::Admitted);
    }

    #[test]
    fn test_admission_single_file_too_large() {
        let policy = QuarantinePolicy {
            max_single_file_bytes: Some(1024),
            ..QuarantinePolicy::unlimited()
        };
        let decision = policy.check_admission(2048, 0, 0);
        assert!(decision.is_rejected());
    }

    #[test]
    fn test_admission_file_count_exceeded_triggers_eviction() {
        let policy = QuarantinePolicy {
            max_file_count: Some(5),
            eviction_strategy: EvictionStrategy::OldestFirst,
            ..QuarantinePolicy::unlimited()
        };
        let decision = policy.check_admission(100, 0, 5);
        assert!(decision.is_admitted());
        assert!(matches!(decision, AdmissionDecision::AdmitAfterEviction(_)));
    }

    #[test]
    fn test_admission_file_count_exceeded_no_eviction_rejected() {
        let policy = QuarantinePolicy {
            max_file_count: Some(5),
            eviction_strategy: EvictionStrategy::None,
            ..QuarantinePolicy::unlimited()
        };
        let decision = policy.check_admission(100, 0, 5);
        assert!(decision.is_rejected());
    }

    #[test]
    fn test_admission_total_bytes_exceeded_triggers_eviction() {
        let policy = QuarantinePolicy {
            max_total_bytes: Some(1000),
            eviction_strategy: EvictionStrategy::OldestFirst,
            ..QuarantinePolicy::unlimited()
        };
        let decision = policy.check_admission(500, 800, 0);
        assert!(decision.is_admitted());
        assert!(matches!(decision, AdmissionDecision::AdmitAfterEviction(_)));
    }

    #[test]
    fn test_admission_total_bytes_exceeded_no_eviction_rejected() {
        let policy = QuarantinePolicy {
            max_total_bytes: Some(1000),
            eviction_strategy: EvictionStrategy::None,
            ..QuarantinePolicy::unlimited()
        };
        let decision = policy.check_admission(500, 800, 0);
        assert!(decision.is_rejected());
    }

    // --- QuarantinePolicy::eligible_for_cleanup ---

    #[test]
    fn test_cleanup_no_policy_none() {
        let policy = QuarantinePolicy {
            auto_cleanup_after_days: None,
            ..QuarantinePolicy::default()
        };
        let now = now_secs();
        let old_ts = now - 200 * 86400;
        let records = vec![(1, old_ts, 100)];
        let eligible = policy.eligible_for_cleanup(&records, now);
        assert!(eligible.is_empty());
    }

    #[test]
    fn test_cleanup_old_record_eligible() {
        let policy = QuarantinePolicy {
            auto_cleanup_after_days: Some(30),
            ..QuarantinePolicy::default()
        };
        let now = now_secs();
        let old_ts = now - 31 * 86400; // 31 days ago
        let records = vec![(42, old_ts, 500)];
        let eligible = policy.eligible_for_cleanup(&records, now);
        assert_eq!(eligible, vec![42]);
    }

    #[test]
    fn test_cleanup_recent_record_not_eligible() {
        let policy = QuarantinePolicy {
            auto_cleanup_after_days: Some(30),
            ..QuarantinePolicy::default()
        };
        let now = now_secs();
        let recent_ts = now - 5 * 86400; // 5 days ago
        let records = vec![(99, recent_ts, 100)];
        let eligible = policy.eligible_for_cleanup(&records, now);
        assert!(eligible.is_empty());
    }

    #[test]
    fn test_cleanup_mixed_records() {
        let policy = QuarantinePolicy {
            auto_cleanup_after_days: Some(30),
            ..QuarantinePolicy::default()
        };
        let now = now_secs();
        let records = vec![
            (1, now - 60 * 86400, 100), // 60 days old → eligible
            (2, now - 10 * 86400, 200), // 10 days old → not eligible
            (3, now - 31 * 86400, 300), // 31 days old → eligible
        ];
        let mut eligible = policy.eligible_for_cleanup(&records, now);
        eligible.sort();
        assert_eq!(eligible, vec![1, 3]);
    }

    // --- QuarantinePolicy::select_for_eviction ---

    #[test]
    fn test_eviction_oldest_first() {
        let policy = QuarantinePolicy {
            eviction_strategy: EvictionStrategy::OldestFirst,
            ..QuarantinePolicy::default()
        };
        let now = now_secs();
        let records = vec![
            (1, now - 10, 100),
            (2, now - 100, 200), // oldest
            (3, now - 5, 300),
        ];
        let req = EvictionRequest {
            reason: "test".into(),
            strategy: EvictionStrategy::OldestFirst,
            bytes_to_free: 0,
            files_to_evict: 1,
        };
        let evicted = policy.select_for_eviction(&records, &req);
        assert_eq!(evicted, vec![2]); // oldest evicted first
    }

    #[test]
    fn test_eviction_largest_first() {
        let policy = QuarantinePolicy {
            eviction_strategy: EvictionStrategy::LargestFirst,
            ..QuarantinePolicy::default()
        };
        let now = now_secs();
        let records = vec![
            (1, now - 10, 100),
            (2, now - 20, 500), // largest
            (3, now - 30, 200),
        ];
        let req = EvictionRequest {
            reason: "test".into(),
            strategy: EvictionStrategy::LargestFirst,
            bytes_to_free: 0,
            files_to_evict: 1,
        };
        let evicted = policy.select_for_eviction(&records, &req);
        assert_eq!(evicted, vec![2]); // largest evicted first
    }

    #[test]
    fn test_eviction_none_strategy() {
        let policy = QuarantinePolicy {
            eviction_strategy: EvictionStrategy::None,
            ..QuarantinePolicy::default()
        };
        let records = vec![(1, 1000, 100), (2, 2000, 200)];
        let req = EvictionRequest {
            reason: "test".into(),
            strategy: EvictionStrategy::None,
            bytes_to_free: 100,
            files_to_evict: 1,
        };
        let evicted = policy.select_for_eviction(&records, &req);
        assert!(evicted.is_empty());
    }

    #[test]
    fn test_eviction_frees_enough_bytes() {
        let policy = QuarantinePolicy::default();
        let now = now_secs();
        let records = vec![
            (1, now - 300, 100),
            (2, now - 200, 200),
            (3, now - 100, 500),
        ];
        let req = EvictionRequest {
            reason: "test".into(),
            strategy: EvictionStrategy::OldestFirst,
            bytes_to_free: 250,
            files_to_evict: 0,
        };
        let evicted = policy.select_for_eviction(&records, &req);
        let freed: u64 = evicted
            .iter()
            .map(|id| records.iter().find(|(r, _, _)| r == id).map(|(_, _, s)| *s).unwrap_or(0))
            .sum();
        assert!(
            freed >= 250,
            "freed {freed} bytes, expected at least 250"
        );
    }

    // --- QuarantineInventory ---

    #[test]
    fn test_inventory_empty() {
        let inv = QuarantineInventory::new();
        assert_eq!(inv.count(), 0);
        assert_eq!(inv.total_bytes(), 0);
    }

    #[test]
    fn test_inventory_add_and_query() {
        let mut inv = QuarantineInventory::new();
        inv.add(1, 1000, 500, PathBuf::from("/q/file1.bin"));
        inv.add(2, 2000, 1500, PathBuf::from("/q/file2.bin"));
        assert_eq!(inv.count(), 2);
        assert_eq!(inv.total_bytes(), 2000);
    }

    #[test]
    fn test_inventory_path_for() {
        let mut inv = QuarantineInventory::new();
        inv.add(42, 1000, 100, PathBuf::from("/q/answer.bin"));
        let path = inv.path_for(42);
        assert_eq!(path, Some(Path::new("/q/answer.bin")));
        assert!(inv.path_for(999).is_none());
    }

    #[test]
    fn test_inventory_cleanup_candidates() {
        let mut inv = QuarantineInventory::new();
        let now = now_secs();
        inv.add(1, now - 100 * 86400, 100, PathBuf::from("/q/old.bin"));
        inv.add(2, now - 5 * 86400, 200, PathBuf::from("/q/recent.bin"));

        let policy = QuarantinePolicy {
            auto_cleanup_after_days: Some(30),
            ..QuarantinePolicy::default()
        };
        let candidates = inv.cleanup_candidates(&policy, now);
        assert_eq!(candidates, vec![1]);
    }

    // --- Policy presets ---

    #[test]
    fn test_default_policy_has_limits() {
        let p = QuarantinePolicy::default();
        assert!(p.max_total_bytes.is_some());
        assert!(p.max_file_count.is_some());
        assert!(p.auto_cleanup_after_days.is_some());
        assert!(p.allow_restore);
    }

    #[test]
    fn test_strict_policy() {
        let p = QuarantinePolicy::strict();
        assert_eq!(p.allow_restore, false);
        assert_eq!(p.secure_delete, true);
        assert!(p.max_single_file_bytes.is_some());
        assert!(p.auto_cleanup_after_days.expect("strict policy should have auto_cleanup_after_days") <= 30);
    }

    #[test]
    fn test_unlimited_policy_admits_any_size() {
        let p = QuarantinePolicy::unlimited();
        let decision = p.check_admission(u64::MAX, u64::MAX / 2, usize::MAX / 2);
        // unlimited should always admit (no limits)
        assert_eq!(decision, AdmissionDecision::Admitted);
    }

    // --- AdmissionDecision helpers ---

    #[test]
    fn test_admission_decision_is_admitted_true_for_admitted() {
        assert!(AdmissionDecision::Admitted.is_admitted());
    }

    #[test]
    fn test_admission_decision_is_rejected_true() {
        let d = AdmissionDecision::Rejected("too big".into());
        assert!(d.is_rejected());
        assert!(!d.is_admitted());
    }

    #[test]
    fn test_admission_decision_eviction_is_admitted() {
        let d = AdmissionDecision::AdmitAfterEviction(EvictionRequest {
            reason: "r".into(),
            strategy: EvictionStrategy::OldestFirst,
            bytes_to_free: 0,
            files_to_evict: 1,
        });
        assert!(d.is_admitted());
        assert!(!d.is_rejected());
    }
}