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("download", crate::phases::run_download);
33        reg.register("upload", crate::phases::run_upload);
34        reg.register("result", crate::phases::run_result);
35        Self { registry: reg }
36    }
37
38    // Convenience wrapper used by legacy tests
39    pub async fn run_all(
40        &self,
41        orch: &crate::orchestrator::Orchestrator,
42    ) -> Result<(), crate::error::Error> {
43        crate::phase_registry::run_all_registered(orch, &self.registry).await
44    }
45}
46
47#[async_trait]
48impl PhaseRunner for DefaultPhaseRunner {
49    async fn run_all(&self, orch: &Orchestrator) -> Result<(), Error> {
50        crate::phase_registry::run_all_registered(orch, &self.registry).await
51    }
52}