Skip to content

Commit 3a1380c

Browse files
westgatewestgate
authored andcommitted
S203e: deep debt — network centralization + 5-file refactoring
Centralize 8 hardcoded network constants (RFC1918 scan ranges, gateway fallback, subnet defaults, scan suffixes, TEST-NET-3 prefix) to core/config/defaults/network.rs. Update ecosystem_network.rs, byob/config.rs, byob/network_manager.rs to use constants. Extract inline test modules from 5 production files >550 LOC: byob_types (585→280), cross_spring_provenance (581→420), gpu_job_queue (581→430), silicon (575→390), registry (581→375). Full deep audit confirms: zero TODO/FIXME/HACK/dbg!/unwrap/set_var in production, all unsafe in hw-safe containment, all mocks test-gated, all hardcoding centralized, all C deps optional-feature-gated. Made-with: Cursor
1 parent ced705f commit 3a1380c

16 files changed

Lines changed: 1130 additions & 1033 deletions

File tree

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased] - April 12, 2026 (Sessions 43-203)
99

10+
### Session S203e (Apr 12, 2026) — Deep Debt: Network Centralization + File Refactoring
11+
12+
#### Hardcoded Network Centralization
13+
- CENTRALIZED: 8 network constants to `core/config/defaults/network.rs`
14+
- `DEFAULT_NETWORK_SUBNET`, `GATEWAY_FALLBACK_IP`, `INTERNAL_IP_BASE`, `INTERNAL_IP_OFFSET`
15+
- `RFC1918_SCAN_RANGES`, `PROBE_DEFAULT_PORT`, `COMMON_SCAN_SUFFIXES`
16+
- `TEST_NET_3_PREFIX` / `DOCUMENTATION_PREFIX` (RFC 5737)
17+
- UPDATED: `auto_config/ecosystem_network.rs` — scan ranges/suffixes from constants
18+
- UPDATED: `byob/config.rs` — subnet from constant
19+
- UPDATED: `byob/network_manager.rs` — gateway, IP base, TEST-NET from constants
20+
21+
#### Smart File Refactoring (5 production files)
22+
- EXTRACTED: `byob/byob_types.rs` tests → `byob_types_tests.rs` (585→~280)
23+
- EXTRACTED: `cross_spring_provenance.rs` tests → `cross_spring_provenance_tests.rs` (581→~420)
24+
- EXTRACTED: `gpu_job_queue.rs` tests → `gpu_job_queue_tests.rs` (581→~430)
25+
- EXTRACTED: `handler/silicon.rs` tests → `silicon_tests.rs` (575→~390)
26+
- EXTRACTED: `primal_capabilities/registry.rs` tests → `registry_tests.rs` (581→~375)
27+
28+
#### Deep Audit Results
29+
- Zero TODO/FIXME/HACK/dbg!/Box<dyn Error>/.unwrap()/std::env::set_var in production
30+
- All unsafe in hw-safe/VFIO/DRM/V4L2/GPU containment zones with SAFETY docs
31+
- All mocks properly #[cfg(test)] or feature-gated
32+
- All hardcoded values now centralized to config/defaults constants
33+
- All external C deps behind optional features (blake3 pure-Rust confirmed)
34+
1035
### Session S203d (Apr 12, 2026) — LD-04 Resolution: BTSP Auto-Detect + Env-Safe Tests
1136

1237
#### BTSP Plain-Text Auto-Detect (LD-04 Completion)

DEBT.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Active Technical Debt Register
22

3-
**Date**: April 12, 2026 — S203d
3+
**Date**: April 12, 2026 — S203e
44
**Philosophy**: Math is universal, precision is silicon. Workarounds are
55
short-term solutions that increase debt. We aim to solve deep debt over
66
iterations, evolving toward vendor-agnostic, capability-based solutions.
@@ -64,6 +64,22 @@ dependency is pure Rust (proc-macro) and zero-overhead at runtime for non-dyn pa
6464

6565
## S203 Resolved Debt (Deep Audit & Evolution Execution)
6666

67+
### D-NETWORK-HARDCODING-CENTRALIZATION — RESOLVED S203e
68+
**Scope**: `auto_config`, `core/toadstool/byob`, `core/config`
69+
Hardcoded network ranges (RFC1918 scan ranges, gateway fallback, subnet
70+
defaults, host scan suffixes, TEST-NET-3 prefix) centralized to 8 named
71+
constants in `core/config/defaults/network.rs`. Three call sites updated.
72+
Files: `ecosystem_network.rs`, `byob/config.rs`, `byob/network_manager.rs`.
73+
74+
### D-LARGE-FILE-REFACTOR-S203E — RESOLVED S203e
75+
**Scope**: 5 files across 4 crates
76+
Smart test extraction from production files >550 LOC:
77+
- `byob/byob_types.rs` (585→~280)
78+
- `cross_spring_provenance.rs` (581→~420)
79+
- `gpu_job_queue.rs` (581→~430)
80+
- `handler/silicon.rs` (575→~390)
81+
- `primal_capabilities/registry.rs` (581→~375)
82+
6783
### D-LD04-BTSP-AUTODETECT — RESOLVED S203d
6884
**Crate**: `server` | **Audit**: LD-04 (primalSpring downstream — partial blocker)
6985
BTSP-enabled sockets rejected plain JSON-RPC: primalSpring's `CompositionContext`

crates/auto_config/src/ecosystem_network.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use tracing::debug;
1212

1313
use crate::ecosystem_types::{ServiceInfo, ServicePattern, ServiceStatus};
1414
use crate::{ToadStoolError, ToadStoolResult};
15+
use toadstool_config::defaults::network::{
16+
COMMON_SCAN_SUFFIXES, PROBE_DEFAULT_PORT, RFC1918_SCAN_RANGES,
17+
};
1518
use toadstool_config::env_config::EnvironmentConfig;
1619

1720
/// TCP connect timeout for `probe_service`. Production uses 2s; tests use a
@@ -27,12 +30,10 @@ const TCP_PROBE_CONNECT_TIMEOUT: Duration = if cfg!(test) {
2730
/// Returns a list of CIDR-style network ranges to scan for ecosystem services.
2831
#[must_use]
2932
pub fn get_local_network_ranges() -> Vec<String> {
30-
let ranges = vec![
31-
"192.168.1.0/24".to_string(),
32-
"192.168.0.0/24".to_string(),
33-
"10.0.0.0/24".to_string(),
34-
"172.16.0.0/24".to_string(),
35-
];
33+
let ranges: Vec<String> = RFC1918_SCAN_RANGES
34+
.iter()
35+
.map(|s| (*s).to_string())
36+
.collect();
3637

3738
debug!("Using default network ranges: {:?}", ranges);
3839
ranges
@@ -53,7 +54,7 @@ pub async fn probe_service(
5354

5455
let config = EnvironmentConfig::from_env();
5556
let host = url.host_str().unwrap_or(&config.network.bind_address);
56-
let port = url.port().unwrap_or(80);
57+
let port = url.port().unwrap_or(PROBE_DEFAULT_PORT);
5758
let socket_addr = format!("{host}:{port}");
5859

5960
if timeout(TCP_PROBE_CONNECT_TIMEOUT, TcpStream::connect(&socket_addr))
@@ -110,9 +111,7 @@ pub async fn scan_network_range(
110111

111112
let base = format!("{}.{}.{}", ip_parts[0], ip_parts[1], ip_parts[2]);
112113

113-
let scan_ips = vec![1, 2, 10, 20, 50, 100, 200, 254];
114-
115-
for ip_suffix in scan_ips {
114+
for &ip_suffix in COMMON_SCAN_SUFFIXES {
116115
let ip = format!("{base}.{ip_suffix}");
117116

118117
for (capability_key, pattern) in service_patterns {
@@ -160,13 +159,14 @@ pub async fn discover_network_services(
160159
#[cfg(test)]
161160
mod tests {
162161
use super::*;
162+
use toadstool_config::defaults::network::RFC1918_SCAN_RANGES;
163163

164164
#[tokio::test]
165165
async fn test_network_range_parsing() {
166166
let ranges = get_local_network_ranges();
167167

168168
assert!(!ranges.is_empty());
169-
assert!(ranges.contains(&"192.168.1.0/24".to_string()));
169+
assert!(ranges.contains(&RFC1918_SCAN_RANGES[0].to_string()));
170170
}
171171

172172
#[tokio::test]
@@ -227,9 +227,9 @@ mod tests {
227227
#[tokio::test]
228228
async fn test_get_local_network_ranges_has_four_defaults() {
229229
let ranges = get_local_network_ranges();
230-
assert_eq!(ranges.len(), 4);
231-
assert!(ranges.contains(&"192.168.1.0/24".to_string()));
232-
assert!(ranges.contains(&"10.0.0.0/24".to_string()));
230+
assert_eq!(ranges.len(), RFC1918_SCAN_RANGES.len());
231+
assert!(ranges.contains(&RFC1918_SCAN_RANGES[0].to_string()));
232+
assert!(ranges.contains(&RFC1918_SCAN_RANGES[2].to_string()));
233233
}
234234

235235
#[tokio::test]

crates/core/config/src/defaults/network.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,39 @@ pub const DISCOVERY_PORT: u16 = 0;
7676
/// Default federation port for cross-primal communication
7777
/// Port 0 = OS-assigned at bind time.
7878
pub const FEDERATION_PORT: u16 = 0;
79+
80+
// ═══════════════════════════════════════════════════════════════════════════
81+
// BYOB / ECOSYSTEM DISCOVERY SHARED LITERALS
82+
// ═══════════════════════════════════════════════════════════════════════════
83+
84+
/// Default CIDR for BYOB executor default network subnet.
85+
pub const DEFAULT_NETWORK_SUBNET: &str = "10.0.0.0/24";
86+
87+
/// Gateway IP when the subnet base cannot be parsed (last octet forced to `.1`).
88+
pub const GATEWAY_FALLBACK_IP: &str = "10.0.0.1";
89+
90+
/// First three octets for allocated internal service IPs in BYOB (`{base}.{offset+n}`).
91+
pub const INTERNAL_IP_BASE: &str = "10.0.0";
92+
93+
/// Host octet for the first service in BYOB internal IP allocation.
94+
pub const INTERNAL_IP_OFFSET: usize = 10;
95+
96+
/// Typical private-network `/24` ranges scanned for ecosystem discovery (RFC 1918-style defaults).
97+
pub const RFC1918_SCAN_RANGES: &[&str] = &[
98+
"192.168.1.0/24",
99+
"192.168.0.0/24",
100+
"10.0.0.0/24",
101+
"172.16.0.0/24",
102+
];
103+
104+
/// Default TCP port when a URL has no port (HTTP probe).
105+
pub const PROBE_DEFAULT_PORT: u16 = 80;
106+
107+
/// Host octets to probe when scanning a `/24` range for ecosystem services.
108+
pub const COMMON_SCAN_SUFFIXES: &[u8] = &[1, 2, 10, 20, 50, 100, 200, 254];
109+
110+
/// RFC 5737 TEST-NET-3 documentation prefix (non-globally routable; safe for examples).
111+
pub const TEST_NET_3_PREFIX: &str = "203.0.113";
112+
113+
/// Alias for documentation / example IP allocation (same as [`TEST_NET_3_PREFIX`]).
114+
pub const DOCUMENTATION_PREFIX: &str = TEST_NET_3_PREFIX;

0 commit comments

Comments
 (0)