Files
foxhunt/scripts/fix_services_unwrap2.sh
jgrusewski eae3c31e53 fix(clippy): Fix 6 unwrap_used violations in risk/data
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)
2025-10-23 14:58:32 +02:00

60 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
echo "=== Fixing additional unwrap_used violations in services (Agent W17 Phase 2) ==="
# 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 8: .first().unwrap() and .last().unwrap() in production code
echo "Fixing Pattern 8: .first().unwrap() → .first().expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.first()\.unwrap()/\.first().expect("INVARIANT: Collection should be non-empty")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/\.last()\.unwrap()/\.last().expect("INVARIANT: Collection should be non-empty")/g' {} +
# Pattern 9: Uuid/String operations
echo "Fixing Pattern 9: UUID/String parse operations → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.parse()\.unwrap()/\.parse().expect("INVARIANT: Valid parse input")/g' {} +
# Pattern 10: Lock operations
echo "Fixing Pattern 10: Lock operations → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.lock()\.unwrap()/\.lock().expect("INVARIANT: Lock should not be poisoned")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/\.read()\.unwrap()/\.read().expect("INVARIANT: RwLock should not be poisoned")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/\.write()\.unwrap()/\.write().expect("INVARIANT: RwLock should not be poisoned")/g' {} +
# Pattern 11: Option unwrapping in function chains
echo "Fixing Pattern 11: as_ref().unwrap() → as_ref().expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.as_ref()\.unwrap()/\.as_ref().expect("INVARIANT: Option should be Some")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/\.as_mut()\.unwrap()/\.as_mut().expect("INVARIANT: Option should be Some")/g' {} +
# Pattern 12: Channel operations
echo "Fixing Pattern 12: Channel send/recv operations → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.send(\([^)]*\))\.unwrap()/\.send(\1).expect("INVARIANT: Channel should not be closed")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/\.recv()\.unwrap()/\.recv().expect("INVARIANT: Channel should not be closed")/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"