oxirs-fuseki 0.2.4

SPARQL 1.1/1.2 HTTP protocol server with Fuseki-compatible configuration
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
//! Endpoint health check with configurable probes.
//!
//! Provides a composable health-check system for SPARQL endpoints.
//! Each [`HealthProbe`] implementation can report [`ProbeStatus::Healthy`],
//! [`ProbeStatus::Degraded`], or [`ProbeStatus::Unhealthy`].  A
//! [`HealthChecker`] aggregates multiple probes into a [`HealthReport`].

use std::time::{SystemTime, UNIX_EPOCH};

// ── Status types ──────────────────────────────────────────────────────────────

/// Per-probe health status.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ProbeStatus {
    /// The probe reports no issues.
    Healthy,
    /// The probe detected a degraded condition (detail in message).
    Degraded(String),
    /// The probe detected an unhealthy condition (detail in message).
    Unhealthy(String),
}

/// Result of a single probe invocation.
#[derive(Debug, Clone)]
pub struct ProbeResult {
    /// Name of the probe that produced this result.
    pub name: String,
    /// Status reported by the probe.
    pub status: ProbeStatus,
    /// How long the probe took (milliseconds, simulated / measured).
    pub latency_ms: u64,
    /// Unix timestamp (milliseconds) when the probe was executed.
    pub timestamp: u64,
}

impl ProbeResult {
    /// Convenience constructor.
    pub fn new(name: impl Into<String>, status: ProbeStatus, latency_ms: u64) -> Self {
        Self {
            name: name.into(),
            status,
            latency_ms,
            timestamp: current_time_ms(),
        }
    }

    /// Returns `true` if the status is [`ProbeStatus::Healthy`].
    pub fn is_healthy(&self) -> bool {
        matches!(self.status, ProbeStatus::Healthy)
    }

    /// Returns `true` if the status is [`ProbeStatus::Unhealthy`].
    pub fn is_unhealthy(&self) -> bool {
        matches!(self.status, ProbeStatus::Unhealthy(_))
    }
}

// ── Probe trait ───────────────────────────────────────────────────────────────

/// A health probe that can be registered with a [`HealthChecker`].
pub trait HealthProbe: Send + Sync {
    /// Unique name identifying this probe.
    fn name(&self) -> &str;
    /// Execute the probe and return a result.
    fn check(&self) -> ProbeResult;
}

// ── Built-in probes ───────────────────────────────────────────────────────────

/// A probe that checks available system memory against a threshold.
pub struct MemoryProbe {
    /// Minimum available memory in MB before the probe degrades.
    pub threshold_mb: usize,
}

impl MemoryProbe {
    /// Create a new memory probe with the given threshold in MB.
    pub fn new(threshold_mb: usize) -> Self {
        Self { threshold_mb }
    }
}

impl HealthProbe for MemoryProbe {
    fn name(&self) -> &str {
        "memory"
    }

    fn check(&self) -> ProbeResult {
        let start = current_time_ms();
        // In a real implementation this would query OS memory stats.
        // For now we use a fixed heuristic: we simulate 512 MB available.
        let simulated_available_mb: usize = 512;
        let latency = current_time_ms().saturating_sub(start);

        if simulated_available_mb >= self.threshold_mb {
            ProbeResult::new("memory", ProbeStatus::Healthy, latency)
        } else {
            ProbeResult::new(
                "memory",
                ProbeStatus::Degraded(format!(
                    "available {}MB < threshold {}MB",
                    simulated_available_mb, self.threshold_mb
                )),
                latency,
            )
        }
    }
}

/// A probe that reports how long the process has been running.
pub struct UptimeProbe {
    /// Unix timestamp (milliseconds) when the service was started.
    pub start_time: u64,
}

impl UptimeProbe {
    /// Create a new uptime probe recording the start time as now.
    pub fn new() -> Self {
        Self {
            start_time: current_time_ms(),
        }
    }

    /// Create a probe with a specific start time.
    pub fn with_start(start_time: u64) -> Self {
        Self { start_time }
    }

    /// Return uptime in milliseconds at query time.
    pub fn uptime_ms(&self) -> u64 {
        current_time_ms().saturating_sub(self.start_time)
    }
}

impl Default for UptimeProbe {
    fn default() -> Self {
        Self::new()
    }
}

impl HealthProbe for UptimeProbe {
    fn name(&self) -> &str {
        "uptime"
    }

    fn check(&self) -> ProbeResult {
        let start = current_time_ms();
        let uptime = current_time_ms().saturating_sub(self.start_time);
        let latency = current_time_ms().saturating_sub(start);
        ProbeResult::new("uptime", ProbeStatus::Healthy, latency).with_metadata_uptime(uptime)
    }
}

// Helper extension to attach uptime metadata in the name field for observability.
impl ProbeResult {
    fn with_metadata_uptime(mut self, uptime_ms: u64) -> Self {
        self.name = format!("uptime({}ms)", uptime_ms);
        self
    }
}

/// A composite probe that runs child probes and rolls up the worst status.
pub struct CompositeProbe {
    name: String,
    probes: Vec<Box<dyn HealthProbe>>,
}

impl CompositeProbe {
    /// Create a new composite probe with the given name.
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            probes: Vec::new(),
        }
    }

    /// Add a child probe.
    pub fn add_probe(&mut self, probe: Box<dyn HealthProbe>) {
        self.probes.push(probe);
    }

    /// Number of child probes.
    pub fn probe_count(&self) -> usize {
        self.probes.len()
    }
}

impl HealthProbe for CompositeProbe {
    fn name(&self) -> &str {
        &self.name
    }

    fn check(&self) -> ProbeResult {
        let start = current_time_ms();
        let results: Vec<ProbeResult> = self.probes.iter().map(|p| p.check()).collect();
        let latency = current_time_ms().saturating_sub(start);

        // Worst wins: Unhealthy > Degraded > Healthy.
        let mut worst = ProbeStatus::Healthy;
        for r in &results {
            match &r.status {
                ProbeStatus::Unhealthy(msg) => {
                    worst = ProbeStatus::Unhealthy(msg.clone());
                    break;
                }
                ProbeStatus::Degraded(msg) => {
                    if !matches!(worst, ProbeStatus::Unhealthy(_)) {
                        worst = ProbeStatus::Degraded(msg.clone());
                    }
                }
                ProbeStatus::Healthy => {}
            }
        }

        ProbeResult::new(&self.name, worst, latency)
    }
}

// ── Overall health ────────────────────────────────────────────────────────────

/// The rolled-up health of all probes.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OverallHealth {
    /// All probes are healthy.
    Healthy,
    /// At least one probe is degraded but none is unhealthy.
    Degraded,
    /// At least one probe is unhealthy.
    Unhealthy,
}

/// Aggregated health report produced by [`HealthChecker::check_all`].
#[derive(Debug, Clone)]
pub struct HealthReport {
    /// Rolled-up overall health status.
    pub overall: OverallHealth,
    /// Individual probe results.
    pub results: Vec<ProbeResult>,
    /// Unix timestamp (milliseconds) when the report was produced.
    pub timestamp: u64,
}

impl HealthReport {
    /// Returns `true` when `overall` is [`OverallHealth::Healthy`].
    pub fn is_healthy(&self) -> bool {
        self.overall == OverallHealth::Healthy
    }

    /// Returns the number of probes that reported healthy.
    pub fn healthy_count(&self) -> usize {
        self.results
            .iter()
            .filter(|r| matches!(r.status, ProbeStatus::Healthy))
            .count()
    }

    /// Returns the number of probes that reported unhealthy.
    pub fn unhealthy_count(&self) -> usize {
        self.results
            .iter()
            .filter(|r| matches!(r.status, ProbeStatus::Unhealthy(_)))
            .count()
    }
}

// ── Health checker ────────────────────────────────────────────────────────────

/// Aggregates multiple [`HealthProbe`] implementations and produces a
/// [`HealthReport`] on demand.
pub struct HealthChecker {
    probes: Vec<Box<dyn HealthProbe>>,
}

impl HealthChecker {
    /// Create an empty checker with no probes.
    pub fn new() -> Self {
        Self { probes: Vec::new() }
    }

    /// Register a probe.
    pub fn add_probe(&mut self, probe: Box<dyn HealthProbe>) {
        self.probes.push(probe);
    }

    /// Run all probes and return an aggregated report.
    pub fn check_all(&self) -> HealthReport {
        let results: Vec<ProbeResult> = self.probes.iter().map(|p| p.check()).collect();
        let overall = Self::overall_status(&results);
        HealthReport {
            overall,
            results,
            timestamp: current_time_ms(),
        }
    }

    /// Total number of registered probes.
    pub fn probe_count(&self) -> usize {
        self.probes.len()
    }

    /// Compute the overall status from a slice of probe results.
    pub fn overall_status(results: &[ProbeResult]) -> OverallHealth {
        let mut has_degraded = false;
        for r in results {
            match &r.status {
                ProbeStatus::Unhealthy(_) => return OverallHealth::Unhealthy,
                ProbeStatus::Degraded(_) => has_degraded = true,
                ProbeStatus::Healthy => {}
            }
        }
        if has_degraded {
            OverallHealth::Degraded
        } else {
            OverallHealth::Healthy
        }
    }
}

impl Default for HealthChecker {
    fn default() -> Self {
        Self::new()
    }
}

// ── Utility ───────────────────────────────────────────────────────────────────

/// Return current Unix time in milliseconds.
fn current_time_ms() -> u64 {
    SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .map(|d| d.as_millis() as u64)
        .unwrap_or(0)
}

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

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

    // ── ProbeResult ───────────────────────────────────────────────────────────

    #[test]
    fn test_probe_result_healthy() {
        let r = ProbeResult::new("test", ProbeStatus::Healthy, 5);
        assert!(r.is_healthy());
        assert!(!r.is_unhealthy());
    }

    #[test]
    fn test_probe_result_unhealthy() {
        let r = ProbeResult::new("test", ProbeStatus::Unhealthy("oops".into()), 5);
        assert!(!r.is_healthy());
        assert!(r.is_unhealthy());
    }

    #[test]
    fn test_probe_result_degraded() {
        let r = ProbeResult::new("test", ProbeStatus::Degraded("slow".into()), 10);
        assert!(!r.is_healthy());
        assert!(!r.is_unhealthy());
    }

    #[test]
    fn test_probe_result_has_timestamp() {
        let r = ProbeResult::new("test", ProbeStatus::Healthy, 0);
        assert!(r.timestamp > 0);
    }

    // ── MemoryProbe ───────────────────────────────────────────────────────────

    #[test]
    fn test_memory_probe_low_threshold_healthy() {
        let probe = MemoryProbe::new(128); // 128 MB — simulated 512 available → healthy
        let result = probe.check();
        assert!(result.is_healthy());
    }

    #[test]
    fn test_memory_probe_high_threshold_degraded() {
        let probe = MemoryProbe::new(1024); // 1024 MB — simulated 512 → degraded
        let result = probe.check();
        assert!(matches!(result.status, ProbeStatus::Degraded(_)));
    }

    #[test]
    fn test_memory_probe_name() {
        let probe = MemoryProbe::new(256);
        assert_eq!(probe.name(), "memory");
    }

    #[test]
    fn test_memory_probe_exact_threshold_healthy() {
        let probe = MemoryProbe::new(512); // exactly at simulated available
        let result = probe.check();
        assert!(result.is_healthy());
    }

    // ── UptimeProbe ───────────────────────────────────────────────────────────

    #[test]
    fn test_uptime_probe_name() {
        let probe = UptimeProbe::new();
        assert_eq!(probe.name(), "uptime");
    }

    #[test]
    fn test_uptime_probe_result_is_healthy() {
        let probe = UptimeProbe::new();
        let result = probe.check();
        assert!(result.is_healthy());
    }

    #[test]
    fn test_uptime_probe_uptime_nonnegative() {
        let probe = UptimeProbe::new();
        assert!(probe.uptime_ms() < u64::MAX);
    }

    #[test]
    fn test_uptime_probe_with_start_in_past() {
        let now = current_time_ms();
        let probe = UptimeProbe::with_start(now.saturating_sub(1000));
        assert!(probe.uptime_ms() >= 1000 || probe.uptime_ms() < 2000);
    }

    #[test]
    fn test_uptime_probe_default() {
        let probe = UptimeProbe::default();
        let result = probe.check();
        assert!(result.is_healthy());
    }

    // ── CompositeProbe ────────────────────────────────────────────────────────

    #[test]
    fn test_composite_probe_empty_healthy() {
        let probe = CompositeProbe::new("composite");
        let result = probe.check();
        assert!(result.is_healthy());
    }

    #[test]
    fn test_composite_probe_all_healthy() {
        let mut composite = CompositeProbe::new("all_healthy");
        composite.add_probe(Box::new(MemoryProbe::new(128)));
        composite.add_probe(Box::new(UptimeProbe::new()));
        let result = composite.check();
        assert!(result.is_healthy());
    }

    #[test]
    fn test_composite_probe_one_degraded() {
        let mut composite = CompositeProbe::new("comp");
        composite.add_probe(Box::new(MemoryProbe::new(128))); // healthy
        composite.add_probe(Box::new(MemoryProbe::new(1024))); // degraded
        let result = composite.check();
        assert!(matches!(result.status, ProbeStatus::Degraded(_)));
    }

    #[test]
    fn test_composite_probe_count() {
        let mut composite = CompositeProbe::new("c");
        composite.add_probe(Box::new(MemoryProbe::new(128)));
        composite.add_probe(Box::new(UptimeProbe::new()));
        assert_eq!(composite.probe_count(), 2);
    }

    #[test]
    fn test_composite_probe_name() {
        let probe = CompositeProbe::new("my-composite");
        assert_eq!(probe.name(), "my-composite");
    }

    // ── HealthChecker ─────────────────────────────────────────────────────────

    #[test]
    fn test_checker_empty_produces_healthy_report() {
        let checker = HealthChecker::new();
        let report = checker.check_all();
        assert_eq!(report.overall, OverallHealth::Healthy);
    }

    #[test]
    fn test_checker_probe_count_zero() {
        let checker = HealthChecker::new();
        assert_eq!(checker.probe_count(), 0);
    }

    #[test]
    fn test_checker_add_probe_increments_count() {
        let mut checker = HealthChecker::new();
        checker.add_probe(Box::new(MemoryProbe::new(128)));
        assert_eq!(checker.probe_count(), 1);
    }

    #[test]
    fn test_checker_all_healthy_report() {
        let mut checker = HealthChecker::new();
        checker.add_probe(Box::new(MemoryProbe::new(128)));
        checker.add_probe(Box::new(UptimeProbe::new()));
        let report = checker.check_all();
        assert_eq!(report.overall, OverallHealth::Healthy);
        assert_eq!(report.healthy_count(), 2);
    }

    #[test]
    fn test_checker_degraded_report() {
        let mut checker = HealthChecker::new();
        checker.add_probe(Box::new(MemoryProbe::new(1024))); // degraded
        let report = checker.check_all();
        assert_eq!(report.overall, OverallHealth::Degraded);
    }

    #[test]
    fn test_checker_results_len() {
        let mut checker = HealthChecker::new();
        checker.add_probe(Box::new(MemoryProbe::new(128)));
        checker.add_probe(Box::new(UptimeProbe::new()));
        let report = checker.check_all();
        assert_eq!(report.results.len(), 2);
    }

    #[test]
    fn test_checker_report_timestamp() {
        let checker = HealthChecker::new();
        let report = checker.check_all();
        assert!(report.timestamp > 0);
    }

    // ── overall_status ────────────────────────────────────────────────────────

    #[test]
    fn test_overall_status_empty_is_healthy() {
        assert_eq!(HealthChecker::overall_status(&[]), OverallHealth::Healthy);
    }

    #[test]
    fn test_overall_status_all_healthy() {
        let results = vec![
            ProbeResult::new("a", ProbeStatus::Healthy, 0),
            ProbeResult::new("b", ProbeStatus::Healthy, 0),
        ];
        assert_eq!(
            HealthChecker::overall_status(&results),
            OverallHealth::Healthy
        );
    }

    #[test]
    fn test_overall_status_one_degraded() {
        let results = vec![
            ProbeResult::new("a", ProbeStatus::Healthy, 0),
            ProbeResult::new("b", ProbeStatus::Degraded("slow".into()), 0),
        ];
        assert_eq!(
            HealthChecker::overall_status(&results),
            OverallHealth::Degraded
        );
    }

    #[test]
    fn test_overall_status_one_unhealthy() {
        let results = vec![
            ProbeResult::new("a", ProbeStatus::Healthy, 0),
            ProbeResult::new("b", ProbeStatus::Unhealthy("down".into()), 0),
        ];
        assert_eq!(
            HealthChecker::overall_status(&results),
            OverallHealth::Unhealthy
        );
    }

    #[test]
    fn test_overall_status_unhealthy_dominates_degraded() {
        let results = vec![
            ProbeResult::new("a", ProbeStatus::Degraded("slow".into()), 0),
            ProbeResult::new("b", ProbeStatus::Unhealthy("down".into()), 0),
        ];
        assert_eq!(
            HealthChecker::overall_status(&results),
            OverallHealth::Unhealthy
        );
    }

    // ── HealthReport helpers ──────────────────────────────────────────────────

    #[test]
    fn test_report_is_healthy_true() {
        let report = HealthReport {
            overall: OverallHealth::Healthy,
            results: vec![],
            timestamp: 0,
        };
        assert!(report.is_healthy());
    }

    #[test]
    fn test_report_is_healthy_false_for_degraded() {
        let report = HealthReport {
            overall: OverallHealth::Degraded,
            results: vec![],
            timestamp: 0,
        };
        assert!(!report.is_healthy());
    }

    #[test]
    fn test_report_healthy_count() {
        let results = vec![
            ProbeResult::new("a", ProbeStatus::Healthy, 0),
            ProbeResult::new("b", ProbeStatus::Degraded("x".into()), 0),
            ProbeResult::new("c", ProbeStatus::Healthy, 0),
        ];
        let report = HealthReport {
            overall: OverallHealth::Degraded,
            results,
            timestamp: 0,
        };
        assert_eq!(report.healthy_count(), 2);
    }

    #[test]
    fn test_report_unhealthy_count() {
        let results = vec![
            ProbeResult::new("a", ProbeStatus::Unhealthy("x".into()), 0),
            ProbeResult::new("b", ProbeStatus::Healthy, 0),
            ProbeResult::new("c", ProbeStatus::Unhealthy("y".into()), 0),
        ];
        let report = HealthReport {
            overall: OverallHealth::Unhealthy,
            results,
            timestamp: 0,
        };
        assert_eq!(report.unhealthy_count(), 2);
    }

    // ── default ───────────────────────────────────────────────────────────────

    #[test]
    fn test_checker_default() {
        let checker = HealthChecker::default();
        assert_eq!(checker.probe_count(), 0);
    }

    #[test]
    fn test_uptime_default_check() {
        let probe = UptimeProbe::default();
        assert_eq!(probe.name(), "uptime");
    }

    // ── Additional coverage ───────────────────────────────────────────────────

    #[test]
    fn test_probe_status_healthy_eq() {
        assert_eq!(ProbeStatus::Healthy, ProbeStatus::Healthy);
    }

    #[test]
    fn test_probe_status_degraded_clone() {
        let s = ProbeStatus::Degraded("x".into());
        let s2 = s.clone();
        assert_eq!(s, s2);
    }

    #[test]
    fn test_probe_result_name_preserved() {
        let r = ProbeResult::new("my_probe", ProbeStatus::Healthy, 3);
        assert_eq!(r.name, "my_probe");
    }

    #[test]
    fn test_probe_result_latency_preserved() {
        let r = ProbeResult::new("p", ProbeStatus::Healthy, 42);
        assert_eq!(r.latency_ms, 42);
    }

    #[test]
    fn test_composite_with_one_unhealthy() {
        let mut c = CompositeProbe::new("c");
        // Unhealthy via high threshold — but MemoryProbe only returns Degraded, not Unhealthy.
        // So we use overall_status directly instead.
        c.add_probe(Box::new(MemoryProbe::new(1024)));
        let results = vec![ProbeResult::new(
            "x",
            ProbeStatus::Unhealthy("fail".into()),
            0,
        )];
        assert_eq!(
            HealthChecker::overall_status(&results),
            OverallHealth::Unhealthy
        );
    }

    #[test]
    fn test_health_checker_three_probes() {
        let mut checker = HealthChecker::new();
        checker.add_probe(Box::new(MemoryProbe::new(128)));
        checker.add_probe(Box::new(UptimeProbe::new()));
        checker.add_probe(Box::new(MemoryProbe::new(64)));
        assert_eq!(checker.probe_count(), 3);
    }

    #[test]
    fn test_overall_health_unhealthy_is_not_healthy() {
        let report = HealthReport {
            overall: OverallHealth::Unhealthy,
            results: vec![],
            timestamp: 0,
        };
        assert!(!report.is_healthy());
    }

    #[test]
    fn test_uptime_probe_start_in_future() {
        // start_time in the future → uptime saturates to 0
        let probe = UptimeProbe::with_start(u64::MAX);
        assert_eq!(probe.uptime_ms(), 0);
    }

    #[test]
    fn test_memory_probe_zero_threshold_healthy() {
        let probe = MemoryProbe::new(0); // 0 MB threshold → always healthy
        let result = probe.check();
        assert!(result.is_healthy());
    }
}