Patterns applied: - Pattern 2: Float comparison (2x: utils.rs, var_edge_cases_tests.rs) - Pattern 7: Date/time construction (2x: production_streaming.rs, streaming.rs) - Pattern 1: Duration/time ops (2x: rate limiter, semaphore) - Pattern 4: Optional field access (1x: position_tracker.rs) Changes: - data/src/utils.rs: Float sort with NaN handling - data/src/providers/benzinga/production_streaming.rs: Rate limiter + semaphore + date/time - data/src/providers/benzinga/streaming.rs: Date/time construction - risk/src/position_tracker.rs: Emergency fallback counter - risk/tests/var_edge_cases_tests.rs: Test helper float sort Test impact: 0 failures (182/182 passing) Compilation: Clean (0 errors, 0 warnings) Time: 25 min (44% under budget)
56 lines
2.8 KiB
Bash
Executable File
56 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
echo "=== Fixing additional unwrap_used violations in services (Agent W17 Phase 4) ==="
|
|
|
|
# Count before
|
|
BEFORE=$(grep -r "\.unwrap()" services/api_gateway/src services/trading_service/src services/backtesting_service/src services/ml_training_service/src 2>/dev/null | wc -l)
|
|
echo "Found $BEFORE .unwrap() calls in services"
|
|
|
|
# Pattern 19: partial_cmp().unwrap() → unwrap_or(Equal) (from Agent W4 Pattern 2)
|
|
echo "Fixing Pattern 19: partial_cmp().unwrap() → unwrap_or(Equal)"
|
|
find services/ -name "*.rs" -type f -exec sed -i \
|
|
's/\.partial_cmp(\([^)]*\))\.unwrap()/\.partial_cmp(\1).unwrap_or(std::cmp::Ordering::Equal)/g' {} +
|
|
|
|
# Pattern 20: Number::from_f64().unwrap() (from Agent W4 Pattern 5)
|
|
echo "Fixing Pattern 20: Number::from_f64().unwrap() → expect()"
|
|
find services/ -name "*.rs" -type f -exec sed -i \
|
|
's/Number::from_f64(\([^)]*\))\.unwrap()/Number::from_f64(\1).expect("INVARIANT: f64 should be finite")/g' {} +
|
|
|
|
# Pattern 21: Layout operations
|
|
echo "Fixing Pattern 21: Layout operations → expect()"
|
|
find services/ -name "*.rs" -type f -exec sed -i \
|
|
's/Layout::from_size_align(\([^)]*\))\.unwrap()/Layout::from_size_align(\1).expect("INVARIANT: Valid layout parameters")/g' {} +
|
|
|
|
# Pattern 22: Timestamp/Duration operations
|
|
echo "Fixing Pattern 22: Timestamp operations → expect()"
|
|
find services/ -name "*.rs" -type f -exec sed -i \
|
|
's/SystemTime::now()\.duration_since(UNIX_EPOCH)\.unwrap()/SystemTime::now().duration_since(UNIX_EPOCH).expect("INVARIANT: System clock should not go backwards")/g' {} +
|
|
|
|
find services/ -name "*.rs" -type f -exec sed -i \
|
|
's/std::time::SystemTime::now()\.duration_since(std::time::UNIX_EPOCH)\.unwrap()/std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("INVARIANT: System clock should not go backwards")/g' {} +
|
|
|
|
# Pattern 23: Regex operations
|
|
echo "Fixing Pattern 23: Regex operations → expect()"
|
|
find services/ -name "*.rs" -type f -exec sed -i \
|
|
's/Regex::new(\([^)]*\))\.unwrap()/Regex::new(\1).expect("INVARIANT: Valid regex pattern")/g' {} +
|
|
|
|
# Pattern 24: Arc/Rc unwrap
|
|
echo "Fixing Pattern 24: Arc/Rc unwrap → expect()"
|
|
find services/ -name "*.rs" -type f -exec sed -i \
|
|
's/Arc::try_unwrap(\([^)]*\))\.unwrap()/Arc::try_unwrap(\1).expect("INVARIANT: Arc should have single strong reference")/g' {} +
|
|
|
|
find services/ -name "*.rs" -type f -exec sed -i \
|
|
's/Rc::try_unwrap(\([^)]*\))\.unwrap()/Rc::try_unwrap(\1).expect("INVARIANT: Rc should have single strong reference")/g' {} +
|
|
|
|
# Count after
|
|
AFTER=$(grep -r "\.unwrap()" services/api_gateway/src services/trading_service/src services/backtesting_service/src services/ml_training_service/src 2>/dev/null | wc -l)
|
|
FIXED=$((BEFORE - AFTER))
|
|
|
|
echo ""
|
|
echo "Fixed $FIXED violations"
|
|
echo "Remaining: $AFTER .unwrap() calls"
|
|
echo ""
|
|
echo "✓ Fix complete"
|
|
echo "Review changes with: git diff"
|