From b1ee4b5898b30e4198decaddbb0289514c044c96 Mon Sep 17 00:00:00 2001 From: andrussal Date: Wed, 10 Dec 2025 13:13:19 +0100 Subject: [PATCH] Scaffold shared node modules and deduplicate binary resolution --- .../core/src/nodes/common/api/client.rs | 4 ++ .../core/src/nodes/common/api/mod.rs | 2 + .../core/src/nodes/common/api/proxy.rs | 4 ++ .../core/src/nodes/common/binary.rs | 35 +++++++++++++++++ .../core/src/nodes/common/config/injection.rs | 4 ++ .../core/src/nodes/common/config/mod.rs | 3 ++ .../core/src/nodes/common/config/paths.rs | 4 ++ .../src/nodes/common/config/validation.rs | 4 ++ .../src/nodes/common/lifecycle/cleanup.rs | 4 ++ .../core/src/nodes/common/lifecycle/mod.rs | 3 ++ .../src/nodes/common/lifecycle/monitor.rs | 4 ++ .../core/src/nodes/common/lifecycle/spawn.rs | 4 ++ .../core/src/nodes/common/mod.rs | 4 ++ testing-framework/core/src/nodes/executor.rs | 38 +++++++------------ testing-framework/core/src/nodes/mod.rs | 1 + testing-framework/core/src/nodes/validator.rs | 38 +++++++------------ 16 files changed, 108 insertions(+), 48 deletions(-) create mode 100644 testing-framework/core/src/nodes/common/api/client.rs create mode 100644 testing-framework/core/src/nodes/common/api/mod.rs create mode 100644 testing-framework/core/src/nodes/common/api/proxy.rs create mode 100644 testing-framework/core/src/nodes/common/binary.rs create mode 100644 testing-framework/core/src/nodes/common/config/injection.rs create mode 100644 testing-framework/core/src/nodes/common/config/mod.rs create mode 100644 testing-framework/core/src/nodes/common/config/paths.rs create mode 100644 testing-framework/core/src/nodes/common/config/validation.rs create mode 100644 testing-framework/core/src/nodes/common/lifecycle/cleanup.rs create mode 100644 testing-framework/core/src/nodes/common/lifecycle/mod.rs create mode 100644 testing-framework/core/src/nodes/common/lifecycle/monitor.rs create mode 100644 testing-framework/core/src/nodes/common/lifecycle/spawn.rs create mode 100644 testing-framework/core/src/nodes/common/mod.rs diff --git a/testing-framework/core/src/nodes/common/api/client.rs b/testing-framework/core/src/nodes/common/api/client.rs new file mode 100644 index 0000000..18a94b0 --- /dev/null +++ b/testing-framework/core/src/nodes/common/api/client.rs @@ -0,0 +1,4 @@ +#![allow(dead_code)] + +/// Shared API client wrappers (placeholder). +pub struct SharedApiClient; diff --git a/testing-framework/core/src/nodes/common/api/mod.rs b/testing-framework/core/src/nodes/common/api/mod.rs new file mode 100644 index 0000000..a37a212 --- /dev/null +++ b/testing-framework/core/src/nodes/common/api/mod.rs @@ -0,0 +1,2 @@ +pub mod client; +pub mod proxy; diff --git a/testing-framework/core/src/nodes/common/api/proxy.rs b/testing-framework/core/src/nodes/common/api/proxy.rs new file mode 100644 index 0000000..84ede92 --- /dev/null +++ b/testing-framework/core/src/nodes/common/api/proxy.rs @@ -0,0 +1,4 @@ +#![allow(dead_code)] + +/// Shared API proxy helpers (placeholder). +pub struct ApiProxy; diff --git a/testing-framework/core/src/nodes/common/binary.rs b/testing-framework/core/src/nodes/common/binary.rs new file mode 100644 index 0000000..3313a6b --- /dev/null +++ b/testing-framework/core/src/nodes/common/binary.rs @@ -0,0 +1,35 @@ +use std::{env, path::PathBuf}; + +pub struct BinaryConfig { + pub env_var: &'static str, + pub binary_name: &'static str, + pub fallback_path: &'static str, + pub shared_bin_subpath: &'static str, +} + +pub struct BinaryResolver; + +impl BinaryResolver { + pub fn resolve_path(config: &BinaryConfig) -> PathBuf { + if let Some(path) = env::var_os(config.env_var) { + return PathBuf::from(path); + } + if let Some(path) = Self::which_on_path(config.binary_name) { + return path; + } + let shared_bin = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(config.shared_bin_subpath); + if shared_bin.exists() { + return shared_bin; + } + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../../") + .join(config.fallback_path) + } + + fn which_on_path(bin: &str) -> Option { + let path_env = env::var_os("PATH")?; + env::split_paths(&path_env) + .map(|p| p.join(bin)) + .find(|candidate| candidate.is_file()) + } +} diff --git a/testing-framework/core/src/nodes/common/config/injection.rs b/testing-framework/core/src/nodes/common/config/injection.rs new file mode 100644 index 0000000..bf76abb --- /dev/null +++ b/testing-framework/core/src/nodes/common/config/injection.rs @@ -0,0 +1,4 @@ +#![allow(dead_code)] + +/// Shared cryptarchia/IBD config injection utilities (placeholder). +pub struct CryptarchiaConfigInjector; diff --git a/testing-framework/core/src/nodes/common/config/mod.rs b/testing-framework/core/src/nodes/common/config/mod.rs new file mode 100644 index 0000000..ed302f3 --- /dev/null +++ b/testing-framework/core/src/nodes/common/config/mod.rs @@ -0,0 +1,3 @@ +pub mod injection; +pub mod paths; +pub mod validation; diff --git a/testing-framework/core/src/nodes/common/config/paths.rs b/testing-framework/core/src/nodes/common/config/paths.rs new file mode 100644 index 0000000..66fdf66 --- /dev/null +++ b/testing-framework/core/src/nodes/common/config/paths.rs @@ -0,0 +1,4 @@ +#![allow(dead_code)] + +/// Shared config path helpers (placeholder). +pub struct RecoveryPathsSetup; diff --git a/testing-framework/core/src/nodes/common/config/validation.rs b/testing-framework/core/src/nodes/common/config/validation.rs new file mode 100644 index 0000000..3d058f5 --- /dev/null +++ b/testing-framework/core/src/nodes/common/config/validation.rs @@ -0,0 +1,4 @@ +#![allow(dead_code)] + +/// Shared config validation helpers (placeholder). +pub struct ConfigValidator; diff --git a/testing-framework/core/src/nodes/common/lifecycle/cleanup.rs b/testing-framework/core/src/nodes/common/lifecycle/cleanup.rs new file mode 100644 index 0000000..e730c3a --- /dev/null +++ b/testing-framework/core/src/nodes/common/lifecycle/cleanup.rs @@ -0,0 +1,4 @@ +#![allow(dead_code)] + +/// Shared cleanup helpers (placeholder). +pub struct CleanupManager; diff --git a/testing-framework/core/src/nodes/common/lifecycle/mod.rs b/testing-framework/core/src/nodes/common/lifecycle/mod.rs new file mode 100644 index 0000000..3f06df7 --- /dev/null +++ b/testing-framework/core/src/nodes/common/lifecycle/mod.rs @@ -0,0 +1,3 @@ +pub mod cleanup; +pub mod monitor; +pub mod spawn; diff --git a/testing-framework/core/src/nodes/common/lifecycle/monitor.rs b/testing-framework/core/src/nodes/common/lifecycle/monitor.rs new file mode 100644 index 0000000..4e03638 --- /dev/null +++ b/testing-framework/core/src/nodes/common/lifecycle/monitor.rs @@ -0,0 +1,4 @@ +#![allow(dead_code)] + +/// Shared monitoring helpers (placeholder). +pub struct Monitor; diff --git a/testing-framework/core/src/nodes/common/lifecycle/spawn.rs b/testing-framework/core/src/nodes/common/lifecycle/spawn.rs new file mode 100644 index 0000000..518ab8b --- /dev/null +++ b/testing-framework/core/src/nodes/common/lifecycle/spawn.rs @@ -0,0 +1,4 @@ +#![allow(dead_code)] + +/// Shared spawn helpers (placeholder). +pub struct SpawnManager; diff --git a/testing-framework/core/src/nodes/common/mod.rs b/testing-framework/core/src/nodes/common/mod.rs new file mode 100644 index 0000000..94fae70 --- /dev/null +++ b/testing-framework/core/src/nodes/common/mod.rs @@ -0,0 +1,4 @@ +pub mod api; +pub mod binary; +pub mod config; +pub mod lifecycle; diff --git a/testing-framework/core/src/nodes/executor.rs b/testing-framework/core/src/nodes/executor.rs index 5db8e3d..75fe312 100644 --- a/testing-framework/core/src/nodes/executor.rs +++ b/testing-framework/core/src/nodes/executor.rs @@ -1,6 +1,5 @@ use std::{ collections::HashSet, - env, path::PathBuf, process::{Child, Command, Stdio}, time::Duration, @@ -26,33 +25,24 @@ use serde_yaml::{Mapping, Number as YamlNumber, Value}; pub use testing_framework_config::nodes::executor::create_executor_config; use super::{ApiClient, create_tempdir, persist_tempdir, should_persist_tempdir}; -use crate::{IS_DEBUG_TRACING, adjust_timeout, nodes::LOGS_PREFIX}; +use crate::{ + IS_DEBUG_TRACING, adjust_timeout, + nodes::{ + LOGS_PREFIX, + common::binary::{BinaryConfig, BinaryResolver}, + }, +}; const BIN_PATH: &str = "target/debug/nomos-executor"; fn binary_path() -> PathBuf { - if let Some(path) = env::var_os("NOMOS_EXECUTOR_BIN") { - return PathBuf::from(path); - } - if let Some(path) = which_on_path("nomos-executor") { - return path; - } - // Default to the shared bin staging area; fall back to workspace target. - let shared_bin = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../testing-framework/assets/stack/bin/nomos-executor"); - if shared_bin.exists() { - return shared_bin; - } - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../") - .join(BIN_PATH) -} - -fn which_on_path(bin: &str) -> Option { - let path_env = env::var_os("PATH")?; - env::split_paths(&path_env) - .map(|p| p.join(bin)) - .find(|candidate| candidate.is_file()) + let cfg = BinaryConfig { + env_var: "NOMOS_EXECUTOR_BIN", + binary_name: "nomos-executor", + fallback_path: BIN_PATH, + shared_bin_subpath: "testing-framework/assets/stack/bin/nomos-executor", + }; + BinaryResolver::resolve_path(&cfg) } pub struct Executor { diff --git a/testing-framework/core/src/nodes/mod.rs b/testing-framework/core/src/nodes/mod.rs index ee1534a..8de1696 100644 --- a/testing-framework/core/src/nodes/mod.rs +++ b/testing-framework/core/src/nodes/mod.rs @@ -1,4 +1,5 @@ mod api_client; +pub mod common; pub mod executor; pub mod validator; diff --git a/testing-framework/core/src/nodes/validator.rs b/testing-framework/core/src/nodes/validator.rs index 8941ce7..42b07aa 100644 --- a/testing-framework/core/src/nodes/validator.rs +++ b/testing-framework/core/src/nodes/validator.rs @@ -1,6 +1,5 @@ use std::{ collections::HashSet, - env, path::PathBuf, process::{Child, Command, Stdio}, time::Duration, @@ -25,33 +24,24 @@ use tokio::time::error::Elapsed; use tx_service::MempoolMetrics; use super::{ApiClient, create_tempdir, persist_tempdir, should_persist_tempdir}; -use crate::{IS_DEBUG_TRACING, adjust_timeout, nodes::LOGS_PREFIX}; +use crate::{ + IS_DEBUG_TRACING, adjust_timeout, + nodes::{ + LOGS_PREFIX, + common::binary::{BinaryConfig, BinaryResolver}, + }, +}; const BIN_PATH: &str = "target/debug/nomos-node"; fn binary_path() -> PathBuf { - if let Some(path) = env::var_os("NOMOS_NODE_BIN") { - return PathBuf::from(path); - } - if let Some(path) = which_on_path("nomos-node") { - return path; - } - // Default to the shared bin staging area; fall back to workspace target. - let shared_bin = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../testing-framework/assets/stack/bin/nomos-node"); - if shared_bin.exists() { - return shared_bin; - } - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../") - .join(BIN_PATH) -} - -fn which_on_path(bin: &str) -> Option { - let path_env = env::var_os("PATH")?; - env::split_paths(&path_env) - .map(|p| p.join(bin)) - .find(|candidate| candidate.is_file()) + let cfg = BinaryConfig { + env_var: "NOMOS_NODE_BIN", + binary_name: "nomos-node", + fallback_path: BIN_PATH, + shared_bin_subpath: "testing-framework/assets/stack/bin/nomos-node", + }; + BinaryResolver::resolve_path(&cfg) } pub enum Pool {