Files
foxhunt/scripts/fix_services_unwrap3.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

62 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
echo "=== Fixing additional unwrap_used violations in services (Agent W17 Phase 3) ==="
# 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 13: File/Path operations
echo "Fixing Pattern 13: Path/File operations → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.to_str()\.unwrap()/\.to_str().expect("INVARIANT: Path should be valid UTF-8")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/\.to_string_lossy()\.unwrap()/\.to_string_lossy().expect("INVARIANT: Path conversion should succeed")/g' {} +
# Pattern 14: Iterator operations
echo "Fixing Pattern 14: Iterator operations → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.next()\.unwrap()/\.next().expect("INVARIANT: Iterator should have next element")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/\.nth(\([^)]*\))\.unwrap()/\.nth(\1).expect("INVARIANT: Iterator should have nth element")/g' {} +
# Pattern 15: Map/HashMap/BTreeMap operations
echo "Fixing Pattern 15: Map get operations → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.get(\([^)]*\))\.unwrap()/\.get(\1).expect("INVARIANT: Key should exist in map")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/\.get_mut(\([^)]*\))\.unwrap()/\.get_mut(\1).expect("INVARIANT: Key should exist in map")/g' {} +
# Pattern 16: String/byte conversion
echo "Fixing Pattern 16: String/byte conversion → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/String::from_utf8(\([^)]*\))\.unwrap()/String::from_utf8(\1).expect("INVARIANT: Valid UTF-8 bytes")/g' {} +
find services/ -name "*.rs" -type f -exec sed -i \
's/std::str::from_utf8(\([^)]*\))\.unwrap()/std::str::from_utf8(\1).expect("INVARIANT: Valid UTF-8 bytes")/g' {} +
# Pattern 17: OnceLock/OnceCell operations
echo "Fixing Pattern 17: OnceLock/OnceCell operations → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.set(\([^)]*\))\.unwrap()/\.set(\1).expect("INVARIANT: OnceLock should not be already set")/g' {} +
# Pattern 18: TryInto/TryFrom operations
echo "Fixing Pattern 18: TryInto/TryFrom operations → expect()"
find services/ -name "*.rs" -type f -exec sed -i \
's/\.try_into()\.unwrap()/\.try_into().expect("INVARIANT: Valid conversion")/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"