Skip to main content

netspeed_cli/
phase_runner.rs

1//! Trait to run all test phases. Allows custom implementations for testing.
2use crate::{error::Error, orchestrator::Orchestrator};
3
4use async_trait::async_trait;
5
6#[async_trait]
7pub trait PhaseRunner: Send + Sync {
8    async fn run_all(&self, orch: &Orchestrator) -> Result<(), Error>;
9}
10
11/// Production runner that delegates to the existing `crate::phases` module.
12pub struct DefaultPhaseRunner {
13    registry: crate::phase_registry::PhaseRegistry,
14}
15
16impl Default for DefaultPhaseRunner {
17    fn default() -> Self {
18        Self::new()
19    }
20}
21
22impl DefaultPhaseRunner {
23    /// Build a runner with the default phase registry.
24    pub fn new() -> Self {
25        let mut reg = crate::phase_registry::PhaseRegistry::new();
26        // Register the core phases in the same order as before.
27        reg.register("early_exit", crate::phases::run_early_exit);
28        reg.register("header", crate::phases::run_header);
29        reg.register("server_discovery", crate::phases::run_server_discovery);
30        reg.register("ip_discovery", crate::phases::run_ip_discovery);
31        reg.register("ping", crate::phases::run_ping);
32        reg.register("result", crate::phases::run_result);
33        Self { registry: reg }
34    }
35
36    // Convenience wrapper used by legacy tests
37    pub async fn run_all(
38        &self,
39        orch: &crate::orchestrator::Orchestrator,
40    ) -> Result<(), crate::error::Error> {
41        crate::phase_registry::run_all_registered(orch, &self.registry).await
42    }
43}
44
45#[async_trait]
46impl PhaseRunner for DefaultPhaseRunner {
47    async fn run_all(&self, orch: &Orchestrator) -> Result<(), Error> {
48        crate::phase_registry::run_all_registered(orch, &self.registry).await
49    }
50}