Skip to content

Commit 524a7e1

Browse files
westgatewestgate
authored andcommitted
S203i: extract tests from 52 production files + evolve hardcoding
Massive test extraction sprint: ~10K lines of inline #[cfg(test)] mod tests moved to companion *_tests.rs files across 22 crates. Production files >500L reduced from 38 to 25 (remaining are pure production code without extractable test blocks). Hardcoding evolution: - discovery_defaults: literal "localhost" → DEFAULT_HOSTNAME constant - dispatch submit/shader_dispatch: CORALREEF_URL refs → capability-neutral guidance Made-with: Cursor
1 parent 8009148 commit 524a7e1

110 files changed

Lines changed: 12279 additions & 12135 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

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

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

10+
### Session S203i (Apr 14, 2026) — Deep Debt: Massive Test Extraction + Hardcoding Evolution
11+
12+
#### Smart File Refactoring (52 production files — test extraction)
13+
- EXTRACTED: inline `#[cfg(test)] mod tests { ... }` blocks from 52 production files into companion `*_tests.rs` files
14+
- Pattern: `#[cfg(test)] #[path = "{name}_tests.rs"] mod tests;` — consistent with repo convention
15+
- Affected crates: `core/config`, `core/common`, `core/toadstool`, `core/nvpmu`, `core/sysmon`, `toadstool-core`, `server`, `cli`, `auto_config`, `distributed`, `integration/protocols`, `integration/security`, `management/performance`, `runtime/container`, `runtime/orchestration`, `runtime/specialty`, `runtime/display`, `runtime/secure_enclave`, `runtime/gpu`, `security/sandbox`, `neuromorphic/akida-driver`, `ml/burn-inference`
16+
- Total test lines extracted: ~10,000+ lines moved from production files to dedicated test files
17+
- 25 production files remain >500 lines (pure production code — hardware drivers, type definitions, crypto managers — no extractable test blocks)
18+
19+
#### Hardcoding Evolution
20+
- EVOLVED: `FallbackEndpoints::fallback_endpoint()` — replaced literal `"localhost"` with `DEFAULT_HOSTNAME` constant
21+
- EVOLVED: `dispatch_submit` note — removed hardcoded `CORALREEF_URL` reference, replaced with capability-neutral guidance
22+
- EVOLVED: `shader_dispatch` note — removed hardcoded `CORALREEF_URL / CORALREEF_SOCKET` reference, replaced with capability-neutral guidance
23+
1024
### Session S203h (Apr 14, 2026) — benchScale: TCP Idle Timeout (primalSpring exp082)
1125

1226
#### TCP Idle Timeout (benchScale finding)

DEBT.md

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

3-
**Date**: April 14, 2026 — S203h
3+
**Date**: April 14, 2026 — S203i
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,19 @@ 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-LARGE-FILE-REFACTOR-S203I — RESOLVED S203i
68+
**Scope**: 52 production files across 22 crates
69+
Massive test extraction sprint: inline `#[cfg(test)] mod tests { ... }` blocks extracted to
70+
companion `*_tests.rs` files. ~10,000+ lines of test code moved out of production modules.
71+
Production file count over 500 lines reduced from 38 to 25 (remaining files are pure production
72+
code — hardware drivers, type definitions, crypto managers — with no extractable test blocks).
73+
74+
### D-HARDCODING-CORALREEF-NOTES-S203I — RESOLVED S203i
75+
**Scope**: `server/dispatch/submit.rs`, `server/dispatch/shader_dispatch.rs`
76+
Dispatch error metadata replaced hardcoded `CORALREEF_URL` / `CORALREEF_SOCKET` env var names
77+
with capability-neutral guidance. Also: `discovery_defaults.rs` literal `"localhost"` replaced
78+
with `DEFAULT_HOSTNAME` constant.
79+
6780
### D-LARGE-FILE-REFACTOR-S203G — RESOLVED S203g
6881
**Scope**: 12 files across 8 crates
6982
Smart test extraction from production files >540 LOC. Same pattern as S203c/S203e.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Nest = Tower + Storage <- storage
5858
| Hardcoded ports/localhost | 0 inline literals -- config constants + capability-based discovery |
5959
| Hardware transport | Implemented | DRM display, V4L2 capture, serial — frame protocol + router |
6060
| License | AGPL-3.0-or-later -- root LICENSE file + SPDX headers on all files |
61-
| File size limit | All production files **< 500 lines** (S203g: 26 large modules refactored via test extraction across S203c/e/g; all production files target <500 lines) |
61+
| File size limit | All production files target **< 500 lines** (S203i: 52 production files refactored via test extraction across S203c/e/g/i; 25 files remain >500 lines — pure production code with no extractable test blocks, all <700 lines) |
6262
| Test concurrency | Unlimited parallelism (removed global throttle); zero `#[serial]`; test-time mDNS/TCP timeouts via `cfg!(test)`; zero fixed sleeps in non-chaos tests |
6363
| Environment safety | All env-var tests use `temp_env` (thread-safe), zero `std::env::set_var` in tests |
6464

@@ -271,6 +271,8 @@ toadStool/
271271
- **Sovereign compiler Phase 4+** -- register pressure estimation, loop software pipelining (barraCuda)
272272

273273
### Recently Completed
274+
- **S203i (Apr 14, 2026)**: Deep debt — 52 production files refactored via test extraction (~10K+ lines moved to companion files). Hardcoding evolution: `CORALREEF_URL`/`CORALREEF_SOCKET` references replaced with capability-neutral guidance; literal `localhost` in `FallbackEndpoints` replaced with `DEFAULT_HOSTNAME` constant. Production files >500L reduced from 38→25.
275+
- **S203h (Apr 14, 2026)**: TCP idle timeout — `TCP_IDLE_TIMEOUT_SECS` (300s configurable), `tokio::time::timeout` wraps on all TCP read loops (JSON-RPC + tarpc), `TCP_NODELAY` on all accepted streams. Resolves primalSpring benchScale exp082.
274276
- **S203g (Apr 13, 2026)**: Deep debt — 12 production files >540 LOC refactored via test extraction. 6 deprecated zero-caller items removed (`localhost_endpoint`, `METRICS_PORT`, `capability_typical_provider` module, `get_primal_default_port` wrappers, `TarpcClient::address()`). Blocking `thread::sleep` in async GPU discovery evolved to `tokio::oneshot` + `tokio::time::timeout`. Forward dispatch clone optimization.
275277
- **S203f (Apr 13, 2026)**: wetSpring V143 validation — `compute.execute` promoted to direct JSON-RPC route (PG-05 gap). Pipeline methods added to `capabilities.list`. plasmidBin metadata expanded to 46 callable methods.
276278
- **S203e (Apr 12, 2026)**: Deep debt — 8 hardcoded network constants centralized to `core/config/defaults/network.rs`. 5 production files refactored via test extraction. Full deep audit: zero TODO/FIXME/HACK/dbg/unwrap/set_var in production.

crates/auto_config/src/ai_mcp_interface/mod.rs

Lines changed: 2 additions & 318 deletions
Original file line numberDiff line numberDiff line change
@@ -209,321 +209,5 @@ impl AiMcpInterface {
209209
// =============================================================================
210210

211211
#[cfg(test)]
212-
mod tests {
213-
use super::*;
214-
use std::collections::HashMap;
215-
216-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
217-
async fn test_intelligence_mcp_interface_creation() {
218-
let interface = AiMcpInterface::new();
219-
assert!(interface.is_ok());
220-
}
221-
222-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
223-
#[cfg_attr(
224-
not(feature = "slow-tests"),
225-
ignore = "slow integration test - runs full NL processing and hardware detection"
226-
)]
227-
async fn test_natural_language_config_request() {
228-
let mut interface = AiMcpInterface::new().unwrap();
229-
230-
let request = McpRequest {
231-
request_id: "test-001".to_string(),
232-
session_id: None,
233-
agent_id: "test-agent".to_string(),
234-
request_type: McpRequestType::NaturalLanguageConfig {
235-
instruction: "Enable high performance mode".to_string(),
236-
},
237-
metadata: HashMap::new(),
238-
timestamp: SystemTime::now(),
239-
};
240-
241-
let response = interface.process_ai_request(request).await;
242-
243-
assert!(
244-
response.is_ok(),
245-
"AI request should succeed: {:?}",
246-
response.as_ref().err()
247-
);
248-
let result = response.unwrap();
249-
assert!(result.success, "Should return success response");
250-
assert!(
251-
!result.message.is_empty(),
252-
"Should return non-empty message"
253-
);
254-
}
255-
256-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
257-
async fn test_natural_language_config_request_fast() {
258-
// Fast test that checks interface state without full NL pipeline
259-
let interface = AiMcpInterface::new().unwrap();
260-
261-
// This should be fast as it only checks interface state
262-
let stats = interface.get_session_stats().await;
263-
assert!(!stats.is_empty(), "Should return stats");
264-
265-
// Verify expected keys exist
266-
assert!(stats.contains_key("active_sessions"));
267-
assert!(stats.contains_key("total_requests"));
268-
}
269-
270-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
271-
async fn test_intelligence_mcp_context_handling() {
272-
let interface = AiMcpInterface::new().unwrap();
273-
let stats = interface.get_session_stats().await;
274-
275-
// Check that stats are returned and active sessions is 0
276-
assert!(!stats.is_empty(), "Should return stats");
277-
if let Some(serde_json::Value::Number(n)) = stats.get("active_sessions") {
278-
assert_eq!(
279-
n.as_u64().unwrap(),
280-
0,
281-
"Should start with no active sessions"
282-
);
283-
} else {
284-
unreachable!("active_sessions key not found or wrong type");
285-
}
286-
}
287-
288-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
289-
async fn test_process_ai_request_create_session() {
290-
let mut interface = AiMcpInterface::new().unwrap();
291-
292-
let request = McpRequest {
293-
request_id: "create-session-001".to_string(),
294-
session_id: None,
295-
agent_id: "test-agent".to_string(),
296-
request_type: McpRequestType::CreateSession { preferences: None },
297-
metadata: HashMap::new(),
298-
timestamp: SystemTime::now(),
299-
};
300-
301-
let response = interface.process_ai_request(request).await.unwrap();
302-
assert!(response.success);
303-
assert!(response.message.contains("session created"));
304-
assert!(response.session_info.is_some());
305-
let session_info = response.session_info.unwrap();
306-
assert!(!session_info.session_id.is_empty());
307-
assert_eq!(session_info.status, "Active");
308-
}
309-
310-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
311-
async fn test_process_ai_request_create_session_with_preferences() {
312-
let mut interface = AiMcpInterface::new().unwrap();
313-
let prefs = AiPreferences::default();
314-
315-
let request = McpRequest {
316-
request_id: "create-002".to_string(),
317-
session_id: None,
318-
agent_id: "agent-2".to_string(),
319-
request_type: McpRequestType::CreateSession {
320-
preferences: Some(prefs),
321-
},
322-
metadata: HashMap::new(),
323-
timestamp: SystemTime::now(),
324-
};
325-
326-
let response = interface.process_ai_request(request).await.unwrap();
327-
assert!(response.success);
328-
assert!(response.session_info.is_some());
329-
}
330-
331-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
332-
async fn test_process_ai_request_update_preferences_session_not_found() {
333-
let mut interface = AiMcpInterface::new().unwrap();
334-
335-
let request = McpRequest {
336-
request_id: "update-001".to_string(),
337-
session_id: Some("nonexistent-session".to_string()),
338-
agent_id: "agent".to_string(),
339-
request_type: McpRequestType::UpdatePreferences {
340-
preferences: AiPreferences::default(),
341-
},
342-
metadata: HashMap::new(),
343-
timestamp: SystemTime::now(),
344-
};
345-
346-
let response = interface.process_ai_request(request).await.unwrap();
347-
assert!(!response.success);
348-
assert!(response.message.contains("Session not found"));
349-
}
350-
351-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
352-
async fn test_process_ai_request_update_preferences_success() {
353-
let mut interface = AiMcpInterface::new().unwrap();
354-
355-
// First create a session
356-
let create_req = McpRequest {
357-
request_id: "create".to_string(),
358-
session_id: None,
359-
agent_id: "agent".to_string(),
360-
request_type: McpRequestType::CreateSession { preferences: None },
361-
metadata: HashMap::new(),
362-
timestamp: SystemTime::now(),
363-
};
364-
let create_resp = interface.process_ai_request(create_req).await.unwrap();
365-
let session_id = create_resp
366-
.session_info
367-
.as_ref()
368-
.unwrap()
369-
.session_id
370-
.clone();
371-
372-
// Now update preferences
373-
let prefs = AiPreferences::default();
374-
let request = McpRequest {
375-
request_id: "update".to_string(),
376-
session_id: Some(session_id),
377-
agent_id: "agent".to_string(),
378-
request_type: McpRequestType::UpdatePreferences {
379-
preferences: prefs.clone(),
380-
},
381-
metadata: HashMap::new(),
382-
timestamp: SystemTime::now(),
383-
};
384-
385-
let response = interface.process_ai_request(request).await.unwrap();
386-
assert!(response.success);
387-
assert!(response.message.contains("Preferences updated"));
388-
}
389-
390-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
391-
async fn test_process_ai_request_get_system_status() {
392-
let mut interface = AiMcpInterface::new().unwrap();
393-
394-
let request = McpRequest {
395-
request_id: "status-001".to_string(),
396-
session_id: None,
397-
agent_id: "agent".to_string(),
398-
request_type: McpRequestType::GetSystemStatus,
399-
metadata: HashMap::new(),
400-
timestamp: SystemTime::now(),
401-
};
402-
403-
let response = interface.process_ai_request(request).await.unwrap();
404-
assert!(response.success);
405-
assert!(response.data.is_some());
406-
let data = response.data.unwrap();
407-
assert!(data.get("hardware").is_some());
408-
assert!(data.get("ecosystem").is_some());
409-
}
410-
411-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
412-
async fn test_process_ai_request_optimize_for_task() {
413-
let mut interface = AiMcpInterface::new().unwrap();
414-
415-
let request = McpRequest {
416-
request_id: "optimize-001".to_string(),
417-
session_id: None,
418-
agent_id: "agent".to_string(),
419-
request_type: McpRequestType::OptimizeForTask {
420-
task_description: "run machine learning training".to_string(),
421-
},
422-
metadata: HashMap::new(),
423-
timestamp: SystemTime::now(),
424-
};
425-
426-
let response = interface.process_ai_request(request).await.unwrap();
427-
assert!(response.success);
428-
assert!(response.config_applied.is_some());
429-
}
430-
431-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
432-
async fn test_process_ai_request_execute_with_intent() {
433-
let mut interface = AiMcpInterface::new().unwrap();
434-
435-
let request = McpRequest {
436-
request_id: "execute-001".to_string(),
437-
session_id: None,
438-
agent_id: "agent".to_string(),
439-
request_type: McpRequestType::ExecuteWithIntent {
440-
code: "print('hello')".to_string(),
441-
intent: ExecutionIntent {
442-
purpose: "test execution".to_string(),
443-
security_requirements: vec![],
444-
performance_expectations: PerformanceExpectations {
445-
expected_duration: None,
446-
cpu_intensity: 0.5,
447-
memory_pattern: MemoryPattern::Normal,
448-
io_intensity: IoIntensity::Low,
449-
},
450-
resource_hints: ResourceHints {
451-
cpu_cores: None,
452-
memory_gb: None,
453-
gpu_required: false,
454-
storage_gb: None,
455-
},
456-
runtime_hint: None,
457-
},
458-
},
459-
metadata: HashMap::new(),
460-
timestamp: SystemTime::now(),
461-
};
462-
463-
let response = interface.process_ai_request(request).await.unwrap();
464-
assert!(response.success);
465-
assert!(response.config_applied.is_some());
466-
}
467-
468-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
469-
async fn test_process_ai_request_increments_counter() {
470-
let mut interface = AiMcpInterface::new().unwrap();
471-
472-
let request = McpRequest {
473-
request_id: "req-1".to_string(),
474-
session_id: None,
475-
agent_id: "agent".to_string(),
476-
request_type: McpRequestType::GetSystemStatus,
477-
metadata: HashMap::new(),
478-
timestamp: SystemTime::now(),
479-
};
480-
let _ = interface.process_ai_request(request).await.unwrap();
481-
482-
let stats = interface.get_session_stats().await;
483-
let total = stats
484-
.get("total_requests")
485-
.and_then(serde_json::Value::as_u64)
486-
.unwrap_or(0);
487-
assert!(total >= 1);
488-
}
489-
490-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
491-
async fn test_process_ai_request_updates_session_activity() {
492-
let mut interface = AiMcpInterface::new().unwrap();
493-
494-
let create_req = McpRequest {
495-
request_id: "c1".to_string(),
496-
session_id: None,
497-
agent_id: "a".to_string(),
498-
request_type: McpRequestType::CreateSession { preferences: None },
499-
metadata: HashMap::new(),
500-
timestamp: SystemTime::now(),
501-
};
502-
let create_resp = interface.process_ai_request(create_req).await.unwrap();
503-
let session_id = create_resp
504-
.session_info
505-
.as_ref()
506-
.unwrap()
507-
.session_id
508-
.clone();
509-
510-
let status_req = McpRequest {
511-
request_id: "s1".to_string(),
512-
session_id: Some(session_id.clone()),
513-
agent_id: "a".to_string(),
514-
request_type: McpRequestType::GetSystemStatus,
515-
metadata: HashMap::new(),
516-
timestamp: SystemTime::now(),
517-
};
518-
let _ = interface.process_ai_request(status_req).await.unwrap();
519-
520-
let stats = interface.get_session_stats().await;
521-
assert!(
522-
stats
523-
.get("active_sessions")
524-
.and_then(serde_json::Value::as_u64)
525-
.unwrap_or(0)
526-
>= 1
527-
);
528-
}
529-
}
212+
#[path = "mod_tests.rs"]
213+
mod tests;

0 commit comments

Comments
 (0)