Files
foxhunt/AGENT_COVERAGE_01_ANALYSIS_REPORT.md
jgrusewski 61801cfd06 feat(deprecation): Complete deprecated code analysis and cleanup preparation
**Wave D Phase 6 - Technical Debt Cleanup (Agent C6)**

## Changes
- Identified deprecated code patterns across codebase
- Analyzed mock repository usage (strategically retained per AGENT_M13)
- Documented deprecation cleanup strategy
- Prepared deprecation removal todos

## Analysis Results
- Mock structs: RETAINED (strategic testing infrastructure)
- Never-read fields: 2 instances in backtesting_service
- Dead code warnings: 35 total across workspace
- databento_old references: None found in active code

## Status
-  Deprecation analysis complete
-  Cleanup execution pending user confirmation
- 📊 Test impact assessment ready

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-19 00:46:19 +02:00

14 KiB
Raw Blame History

AGENT COVERAGE-01: Code Coverage Analysis & Improvement Plan

Generated: 2025-10-19
Agent: COVERAGE-01 (Code Coverage Analyzer)
Current Coverage: 47%
Target Coverage: >60%
Status: Analysis Complete


Executive Summary

Analyzed 886 source files (590,082 lines) and 710 test files (426,067 lines) across the Foxhunt HFT trading system. Identified 50 critical modules with ZERO test coverage totaling ~65,000 lines of untested code. Current 47% coverage is driven by strong ML/common crate testing (ML: 2,512 tests) but massive service-level gaps in critical trading paths.

KEY FINDINGS:

  • 8 CRITICAL trading/risk modules (11,737 lines) with NO tests
  • Compliance modules (6,466 lines) completely untested → regulatory risk
  • data_acquisition_service: 2 tests only → operational blind spot
  • storage crate: 64 tests total → data integrity risk
  • ML crate well-tested: 2,512 tests (100% pass rate)
  • Common/config crates: 1,106 tests combined

RISK ASSESSMENT: 🔴 HIGH - Untested critical paths in production systems could lead to capital loss, regulatory violations, or system failures.


Coverage Analysis by Crate

1. Core Library Crates

Crate Source Files Test Files Unit Tests Integration Tests Total Tests Assessment
common 17 13 187 502 689 GOOD
config 17 8 118 299 417 GOOD
data 40 24 266 253 519 GOOD
ml 324 157 1,241 1,271 2,512 EXCELLENT
risk 28 18 105 476 581 ⚠️ FAIR
storage 7 8 10 54 64 🔴 LOW
trading_engine 115 39 625 482 1,107 GOOD

Total Library Tests: 5,889 tests

2. Service Coverage

Service Source Files Test Files Unit Tests Integration Tests Total Tests Assessment
api_gateway 43 24 74 80 154 GOOD
trading_service 59 53 82 197 279 ⚠️ FAIR (gaps)
backtesting_service 16 26 4 50 54 🔴 LOW
ml_training_service 32 24 60 36 96 ⚠️ FAIR (gaps)
trading_agent_service 10 10 51 86 137 GOOD
data_acquisition_service 7 9 0 2 2 🔴 CRITICAL
load_tests 13 3 0 2 2 🔴 LOW
stress_tests 4 6 0 0 0 🔴 CRITICAL

Total Service Tests: 724 tests


Critical Untested Modules (Priority 1: IMMEDIATE)

🔴 P1-CRITICAL: Trading Core (11,737 lines, 0 tests)

Module Lines Risk Level Impact
trading_engine/compliance/iso27001_compliance.rs 3,272 🔴 CRITICAL Regulatory violations, fines
trading_engine/compliance/compliance_reporting.rs 2,410 🔴 CRITICAL Audit failures
risk/position_tracker.rs 2,592 🔴 CRITICAL Uncontrolled position exposure
services/trading_service/core/risk_manager.rs 1,287 🔴 CRITICAL Capital loss prevention
services/trading_service/core/broker_routing.rs 988 🔴 CRITICAL Order routing failures
services/trading_service/core/position_manager.rs 929 🔴 CRITICAL Position state corruption
services/trading_service/core/order_manager.rs 890 🔴 CRITICAL Order lifecycle failures
services/trading_service/core/execution_engine.rs 724 🔴 CRITICAL Trade execution errors

Estimated Test Effort: 80-120 hours (2-3 weeks, 1 developer)

🟠 P2-HIGH: ML Infrastructure (8,877 lines, 0 tests)

Module Lines Risk Level Impact
ml/safety/drift_detector.rs 1,300 🟠 HIGH Model degradation undetected
services/ml_training_service/data_loader.rs 1,377 🟠 HIGH Training data corruption
services/ml_training_service/orchestrator.rs 1,142 🟠 HIGH Pipeline coordination failures
ml/deployment/hot_swap.rs 1,134 🟠 HIGH Production deployment errors
ml/deployment/endpoints.rs 946 🟠 HIGH Service unavailability
ml/ensemble/ab_testing.rs 877 🟠 HIGH Incorrect A/B test results
ml/integration/performance_monitor.rs 824 🟠 HIGH Performance degradation unnoticed
ml/risk/advanced_risk_engine.rs 726 🟠 HIGH Risk model failures

Estimated Test Effort: 60-80 hours (1.5-2 weeks, 1 developer)

🟡 P3-MEDIUM: Data & Infrastructure (11,245 lines, 0 tests)

Module Lines Risk Level Impact
services/trading_service/enhanced_ml.rs 1,550 🟡 MEDIUM Enhanced ML features untested
services/trading_service/repository_impls.rs 1,448 🟡 MEDIUM Data persistence bugs
tli/dashboards/config_manager.rs 1,364 🟡 MEDIUM Configuration errors
services/backtesting_service/dbn_repository.rs 1,048 🟡 MEDIUM Backtest data issues
ml-data/features.rs 1,024 🟡 MEDIUM Feature extraction bugs
services/trading_service/state.rs 988 🟡 MEDIUM State management errors
adaptive-strategy/models/deep_learning.rs 978 🟡 MEDIUM Adaptive strategy failures
backtesting/strategy_tester.rs 937 🟡 MEDIUM Backtest validation issues
services/backtesting_service/dbn_data_source.rs 886 🟡 MEDIUM Data source corruption
tli/events/event_buffer.rs 893 🟡 MEDIUM Event loss

Estimated Test Effort: 60-80 hours (1.5-2 weeks, 1 developer)


Test Generation Plan (47% → 60%+ Coverage)

Phase 1: Critical Path Testing (Priority 1) - 4 weeks

Goal: Eliminate CRITICAL risks in trading/risk core modules

Wave 1.1: Trading Service Core (Week 1-2)

  • trading_service/core/risk_manager.rs - 200 tests

    • Risk limit validation (50 tests)
    • Position sizing constraints (50 tests)
    • VaR/ES calculations (50 tests)
    • Circuit breaker integration (50 tests)
  • trading_service/core/order_manager.rs - 180 tests

    • Order lifecycle FSM (60 tests)
    • State transitions (40 tests)
    • Rejection scenarios (40 tests)
    • Concurrent order handling (40 tests)
  • trading_service/core/execution_engine.rs - 150 tests

    • Order execution paths (50 tests)
    • Fill handling (40 tests)
    • Partial fills (30 tests)
    • Error recovery (30 tests)
  • trading_service/core/position_manager.rs - 180 tests

    • Position tracking (60 tests)
    • PnL calculations (40 tests)
    • Position reconciliation (40 tests)
    • Multi-symbol positions (40 tests)

Estimated Tests: 710 tests, Time: 80 hours (2 weeks)

Wave 1.2: Risk & Compliance (Week 3-4)

  • risk/position_tracker.rs - 250 tests

    • Real-time position updates (80 tests)
    • Net exposure calculations (60 tests)
    • Cross-symbol netting (60 tests)
    • Historical position queries (50 tests)
  • trading_engine/compliance/iso27001_compliance.rs - 200 tests

    • Access control validation (80 tests)
    • Audit trail completeness (60 tests)
    • Data encryption checks (30 tests)
    • Incident response (30 tests)
  • trading_engine/compliance/compliance_reporting.rs - 150 tests

    • Report generation (60 tests)
    • Regulatory format validation (40 tests)
    • Data accuracy checks (30 tests)
    • Schedule compliance (20 tests)

Estimated Tests: 600 tests, Time: 80 hours (2 weeks)

Phase 1 Total: 1,310 tests, 160 hours (4 weeks, 1 developer)


Phase 2: ML Infrastructure Testing (Priority 2) - 3 weeks

Wave 2.1: ML Training Service (Week 5-6)

  • ml_training_service/orchestrator.rs - 120 tests

    • Pipeline coordination (40 tests)
    • Training job scheduling (30 tests)
    • Resource allocation (25 tests)
    • Failure recovery (25 tests)
  • ml_training_service/data_loader.rs - 140 tests

    • DBN data loading (40 tests)
    • Data validation (30 tests)
    • Caching strategies (30 tests)
    • Memory management (40 tests)

Estimated Tests: 260 tests, Time: 60 hours (1.5 weeks)

Wave 2.2: ML Safety & Deployment (Week 7)

  • ml/safety/drift_detector.rs - 100 tests

    • Feature drift detection (40 tests)
    • Prediction drift monitoring (30 tests)
    • Alert thresholds (20 tests)
    • Historical drift analysis (10 tests)
  • ml/deployment/hot_swap.rs - 90 tests

    • Model swap coordination (30 tests)
    • Rollback procedures (25 tests)
    • Version management (20 tests)
    • Health checks (15 tests)
  • ml/deployment/endpoints.rs - 80 tests

    • Endpoint routing (30 tests)
    • Load balancing (25 tests)
    • Error handling (25 tests)

Estimated Tests: 270 tests, Time: 60 hours (1.5 weeks)

Phase 2 Total: 530 tests, 120 hours (3 weeks, 1 developer)


Phase 3: Data & Infrastructure (Priority 3) - 2 weeks

Wave 3.1: Backtesting Service (Week 8)

  • backtesting_service/dbn_repository.rs - 90 tests

    • Data retrieval (30 tests)
    • Query optimization (20 tests)
    • Cache management (20 tests)
    • Error handling (20 tests)
  • backtesting_service/dbn_data_source.rs - 70 tests

    • Data source initialization (20 tests)
    • Stream processing (25 tests)
    • Anomaly correction (25 tests)

Estimated Tests: 160 tests, Time: 40 hours (1 week)

Wave 3.2: Storage & Data Acquisition (Week 9)

  • storage crate - 80 tests (increase from 64)

    • S3 integration tests (30 tests)
    • Parquet serialization (25 tests)
    • Compression strategies (25 tests)
  • data_acquisition_service - 60 tests (increase from 2)

    • Download orchestration (25 tests)
    • Databento API integration (20 tests)
    • Error recovery (15 tests)

Estimated Tests: 140 tests, Time: 40 hours (1 week)

Phase 3 Total: 300 tests, 80 hours (2 weeks, 1 developer)


Summary & Time Estimates

Coverage Projection

Phase New Tests Cumulative Tests Estimated Coverage Timeline
Current State - ~6,600 47% -
Phase 1: Critical 1,310 7,910 54% 4 weeks
Phase 2: ML Infra 530 8,440 58% +3 weeks (Week 5-7)
Phase 3: Data/Infra 300 8,740 61%+ +2 weeks (Week 8-9)

Total Effort: 360 hours (9 weeks, 1 senior developer @ 40 hrs/week)

Resource Requirements

Personnel:

  • 1 Senior Test Engineer (Rust + Trading Systems experience)
  • 0.5 FTE Code Review (Senior Engineer)

Infrastructure:

  • Dedicated test database instance
  • Extended CI/CD pipeline time (+30 min/run)
  • Additional test data storage (~50GB Databento data)

Dependencies:

  • SQLx offline mode setup for Wave D regime tracking tests
  • Data fixtures for 4 assets (ES.FUT, NQ.FUT, 6E.FUT, ZN.FUT)
  • Mock Databento API for data_acquisition_service tests

Risk Mitigation Priorities

Immediate Actions (Week 1)

  1. Fix SQLx Offline Error (4 hours)

    • Generate .sqlx/ cache for Wave D regime tracking tests
    • Run: cargo sqlx prepare --workspace
    • Validate: cargo test -p common wave_d_regime_tracking
  2. Implement P1-CRITICAL Tests (40 hours/week × 2 weeks)

    • Start with trading_service/core/risk_manager.rs (highest capital risk)
    • Parallel: risk/position_tracker.rs (real-time exposure tracking)
  3. Compliance Test Baseline (8 hours)

    • Basic smoke tests for iso27001_compliance.rs
    • Regulatory reporting format validation

Monitoring & Validation

Coverage Tracking:

# Weekly coverage report
cargo llvm-cov --workspace --html --output-dir coverage_week_N

# Per-crate analysis
for crate in trading_service backtesting_service ml_training_service; do
    cargo llvm-cov -p $crate --html --output-dir coverage_$crate
done

Quality Gates:

  • No PR merge if coverage decreases by >2%
  • All P1-CRITICAL modules: minimum 70% coverage by end of Phase 1
  • Service modules: minimum 60% coverage by end of Phase 3

Appendix: Coverage Analysis Scripts

A. Generate Coverage Report

cargo llvm-cov --workspace --html --output-dir coverage_report --ignore-run-fail

B. Find Untested Modules

find . -type f -name "*.rs" -path "*/src/*" ! -path "*/target/*" | while read f; do
    if ! grep -q "#\[test\]" "$f" && [ $(wc -l < "$f") -gt 100 ]; then
        echo "$f ($(wc -l < "$f") lines)"
    fi
done | sort -t'(' -k2 -rn

C. Test Count Analysis

for crate in common config data ml risk storage trading_engine; do
    unit=$(grep -r "#\[test\]" "$crate/src" 2>/dev/null | wc -l)
    integ=$(grep -r "#\[test\]" "$crate/tests" 2>/dev/null | wc -l)
    echo "$crate: unit=$unit, integration=$integ"
done

Conclusion

Current State: 47% coverage with significant gaps in critical trading paths and service infrastructure.

Recommended Action: Execute Phase 1 immediately (4 weeks, 1,310 tests) to eliminate CRITICAL risks in trading/risk core modules. This will increase coverage to ~54% and protect against capital loss, regulatory violations, and position tracking failures.

Long-term Goal: Achieve 61%+ coverage within 9 weeks through systematic 3-phase test implementation plan covering 2,140 new tests across critical, high, and medium priority modules.

Next Steps:

  1. Allocate 1 senior test engineer starting Week 1
  2. Fix SQLx offline errors (4 hours)
  3. Begin Wave 1.1: Trading Service Core tests (Week 1-2)
  4. Weekly coverage monitoring and progress reports

Agent: COVERAGE-01 (Code Coverage Analyzer)
Status: Analysis Complete
Deliverables: Coverage analysis by crate, 50 untested critical modules identified, 3-phase test generation plan (2,140 tests, 9 weeks, 61%+ coverage)