Files
foxhunt/scripts/testing/test_dqn_replay_pipeline.sh
jgrusewski 49ad0050aa chore: Major documentation cleanup - remove 2,060 obsolete files
BREAKING: Removes 746,569 lines of outdated documentation from root folder

## Summary
- Deleted 2,060 report/documentation files from root folder
- Kept only essential files: README.md, CLAUDE.md
- Updated .gitignore and config/tarpaulin.toml
- Reorganized config files into config/ directory

## Removed Content Categories
- Agent reports (AGENT_*.md, AGENT*.txt)
- Wave reports (WAVE_*.md, DQN_*.md)
- Implementation summaries
- Quick references and summaries
- Test reports and validation docs
- Deployment scripts (obsolete .sh files)
- Legacy config files and logs

## Preserved
- README.md - Main project documentation
- CLAUDE.md - Claude Code configuration
- docs/archive/ - Historical files for reference
- docs/ folder - Current documentation
- All source code unchanged

🐝 Hive Mind Collective Intelligence Cleanup

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 10:29:45 +01:00

439 lines
15 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
#
# DQN Replay Pipeline Integration Test Script
#
# Purpose: Run comprehensive end-to-end tests for DQN evaluation pipeline
# Usage:
# ./test_dqn_replay_pipeline.sh # Run all tests (default)
# ./test_dqn_replay_pipeline.sh --quick # Run quick validation only
# ./test_dqn_replay_pipeline.sh --verbose # Enable verbose logging
# ./test_dqn_replay_pipeline.sh --ci # CI/CD mode (no ANSI colors)
#
# Exit codes:
# 0 - All tests passed
# 1 - Tests failed
# 2 - Setup error (missing dependencies, data files, etc.)
#
# Requirements:
# - Rust toolchain (cargo)
# - Test data: test_data/ES_FUT_unseen.parquet
# - Optional: CUDA for GPU testing
#
# Architecture:
# 1. Pre-flight checks (dependencies, test data)
# 2. Run integration tests (5 test suites)
# 3. Generate test report (summary, timing, failures)
# 4. Cleanup (optional)
set -euo pipefail
# ============================================================================
# Configuration
# ============================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="${SCRIPT_DIR}"
TEST_DATA_DIR="${PROJECT_ROOT}/test_data"
REQUIRED_TEST_FILE="ES_FUT_unseen.parquet"
# Default options
RUN_MODE="full"
VERBOSE=false
CI_MODE=false
CLEANUP=true
# ANSI color codes (disabled in CI mode)
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# ============================================================================
# Functions
# ============================================================================
print_banner() {
if [[ "${CI_MODE}" == "false" ]]; then
echo -e "${CYAN}╔══════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║ DQN Replay Pipeline Integration Test Suite ║${NC}"
echo -e "${CYAN}║ Version: 1.0.0 ║${NC}"
echo -e "${CYAN}╚══════════════════════════════════════════════════════════════════════╝${NC}"
else
echo "==================================================================="
echo " DQN Replay Pipeline Integration Test Suite"
echo " Version: 1.0.0"
echo "==================================================================="
fi
echo ""
}
log_info() {
if [[ "${CI_MODE}" == "false" ]]; then
echo -e "${BLUE}${NC} $1"
else
echo "[INFO] $1"
fi
}
log_success() {
if [[ "${CI_MODE}" == "false" ]]; then
echo -e "${GREEN}${NC} $1"
else
echo "[PASS] $1"
fi
}
log_error() {
if [[ "${CI_MODE}" == "false" ]]; then
echo -e "${RED}${NC} $1" >&2
else
echo "[FAIL] $1" >&2
fi
}
log_warn() {
if [[ "${CI_MODE}" == "false" ]]; then
echo -e "${YELLOW}⚠️${NC} $1"
else
echo "[WARN] $1"
fi
}
log_step() {
if [[ "${CI_MODE}" == "false" ]]; then
echo -e "\n${BOLD}${CYAN}═══ $1 ═══${NC}\n"
else
echo ""
echo "=== $1 ==="
echo ""
fi
}
# ============================================================================
# Pre-flight Checks
# ============================================================================
check_dependencies() {
log_step "Pre-flight Checks"
# Check cargo
if ! command -v cargo &> /dev/null; then
log_error "cargo not found. Please install Rust toolchain."
exit 2
fi
log_success "cargo found: $(cargo --version)"
# Check CUDA availability (optional)
if command -v nvidia-smi &> /dev/null; then
log_success "CUDA available: $(nvidia-smi --query-gpu=name --format=csv,noheader | head -n1)"
else
log_warn "CUDA not available, tests will run on CPU"
fi
# Check test data directory
if [[ ! -d "${TEST_DATA_DIR}" ]]; then
log_error "Test data directory not found: ${TEST_DATA_DIR}"
exit 2
fi
log_success "Test data directory found: ${TEST_DATA_DIR}"
# Check for required test file
local test_file="${TEST_DATA_DIR}/${REQUIRED_TEST_FILE}"
if [[ ! -f "${test_file}" ]]; then
log_warn "Required test file not found: ${test_file}"
log_warn "Some tests may be skipped"
log_warn "Suggestion: Run data export script to generate test_data/ES_FUT_unseen.parquet"
else
local file_size=$(stat -f%z "${test_file}" 2>/dev/null || stat -c%s "${test_file}" 2>/dev/null || echo "unknown")
log_success "Test file found: ${test_file} (${file_size} bytes)"
fi
# Check disk space (need at least 500MB for temp files)
local available_space=$(df -m "${PROJECT_ROOT}" | tail -1 | awk '{print $4}')
if [[ "${available_space}" -lt 500 ]]; then
log_warn "Low disk space: ${available_space} MB available (recommended: 500 MB)"
else
log_success "Disk space: ${available_space} MB available"
fi
}
# ============================================================================
# Test Execution
# ============================================================================
run_integration_tests() {
log_step "Running Integration Tests"
local test_args=""
if [[ "${VERBOSE}" == "true" ]]; then
test_args="-- --nocapture --test-threads=1"
fi
local start_time=$(date +%s)
local test_results=()
local test_count=0
local pass_count=0
# Test 1: Full Pipeline
log_info "Test 1/5: Full Pipeline (export → load → backtest → validate)..."
if cargo test -p ml --test dqn_replay_full_pipeline_test test_full_replay_pipeline --release ${test_args}; then
log_success "Test 1: Full Pipeline PASSED"
test_results+=("PASS")
((pass_count++))
else
log_error "Test 1: Full Pipeline FAILED"
test_results+=("FAIL")
fi
((test_count++))
# Test 2: Timestamp Alignment
log_info "Test 2/5: Timestamp Alignment (>90% match rate)..."
if cargo test -p ml --test dqn_replay_full_pipeline_test test_timestamp_alignment --release ${test_args}; then
log_success "Test 2: Timestamp Alignment PASSED"
test_results+=("PASS")
((pass_count++))
else
log_error "Test 2: Timestamp Alignment FAILED"
test_results+=("FAIL")
fi
((test_count++))
# Test 3: Performance
log_info "Test 3/5: Performance (<30s constraint)..."
if cargo test -p ml --test dqn_replay_full_pipeline_test test_replay_performance --release ${test_args}; then
log_success "Test 3: Performance PASSED"
test_results+=("PASS")
((pass_count++))
else
log_error "Test 3: Performance FAILED"
test_results+=("FAIL")
fi
((test_count++))
# Test 4: Edge Cases
log_info "Test 4/5: Edge Cases (empty data, corrupt checkpoints, NaN/Inf)..."
if cargo test -p ml --test dqn_replay_full_pipeline_test test_replay_edge_cases --release ${test_args}; then
log_success "Test 4: Edge Cases PASSED"
test_results+=("PASS")
((pass_count++))
else
log_error "Test 4: Edge Cases FAILED"
test_results+=("FAIL")
fi
((test_count++))
# Test 5: Memory Efficiency
log_info "Test 5/5: Memory Efficiency (10,000+ bars without OOM)..."
if cargo test -p ml --test dqn_replay_full_pipeline_test test_memory_efficiency --release ${test_args}; then
log_success "Test 5: Memory Efficiency PASSED"
test_results+=("PASS")
((pass_count++))
else
log_error "Test 5: Memory Efficiency FAILED"
test_results+=("FAIL")
fi
((test_count++))
local end_time=$(date +%s)
local elapsed=$((end_time - start_time))
# Generate summary report
log_step "Test Summary"
echo "Test Results:"
echo " • Test 1 (Full Pipeline): ${test_results[0]}"
echo " • Test 2 (Timestamp Alignment): ${test_results[1]}"
echo " • Test 3 (Performance): ${test_results[2]}"
echo " • Test 4 (Edge Cases): ${test_results[3]}"
echo " • Test 5 (Memory Efficiency): ${test_results[4]}"
echo ""
echo "Summary:"
echo " • Total tests: ${test_count}"
echo " • Passed: ${pass_count}"
echo " • Failed: $((test_count - pass_count))"
echo " • Pass rate: $((pass_count * 100 / test_count))%"
echo " • Total time: ${elapsed}s"
echo ""
if [[ "${pass_count}" -eq "${test_count}" ]]; then
log_success "ALL TESTS PASSED ✅"
return 0
else
log_error "SOME TESTS FAILED ❌"
return 1
fi
}
run_quick_validation() {
log_step "Running Quick Validation"
log_info "Quick validation mode: Running only essential tests..."
# Run only Test 1 (Full Pipeline) and Test 3 (Performance)
local test_args=""
if [[ "${VERBOSE}" == "true" ]]; then
test_args="-- --nocapture --test-threads=1"
fi
local pass_count=0
if cargo test -p ml --test dqn_replay_full_pipeline_test test_full_replay_pipeline --release ${test_args}; then
log_success "Full Pipeline test PASSED"
((pass_count++))
else
log_error "Full Pipeline test FAILED"
fi
if cargo test -p ml --test dqn_replay_full_pipeline_test test_replay_performance --release ${test_args}; then
log_success "Performance test PASSED"
((pass_count++))
else
log_error "Performance test FAILED"
fi
if [[ "${pass_count}" -eq 2 ]]; then
log_success "Quick validation PASSED ✅"
return 0
else
log_error "Quick validation FAILED ❌"
return 1
fi
}
# ============================================================================
# Cleanup
# ============================================================================
cleanup_temp_files() {
if [[ "${CLEANUP}" == "true" ]]; then
log_step "Cleanup"
log_info "Removing temporary test artifacts..."
# Clean up any temporary checkpoints in /tmp
if ls /tmp/dqn_*.safetensors 1> /dev/null 2>&1; then
rm -f /tmp/dqn_*.safetensors
log_success "Removed temporary checkpoints"
fi
# Clean up cargo test artifacts
cargo clean --release -p ml 2>/dev/null || true
log_success "Cleaned cargo artifacts"
fi
}
# ============================================================================
# Main
# ============================================================================
main() {
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--quick)
RUN_MODE="quick"
shift
;;
--verbose|-v)
VERBOSE=true
shift
;;
--ci)
CI_MODE=true
# Disable colors in CI mode
GREEN=""
RED=""
YELLOW=""
BLUE=""
CYAN=""
BOLD=""
NC=""
shift
;;
--no-cleanup)
CLEANUP=false
shift
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --quick Run quick validation only (2 tests)"
echo " --verbose, -v Enable verbose logging"
echo " --ci CI/CD mode (no ANSI colors)"
echo " --no-cleanup Skip cleanup of temporary files"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run all tests"
echo " $0 --quick # Quick validation"
echo " $0 --verbose # Verbose output"
echo " $0 --ci # CI/CD mode"
exit 0
;;
*)
log_error "Unknown option: $1"
echo "Use --help for usage information"
exit 2
;;
esac
done
# Print banner
print_banner
# Log configuration
log_info "Run mode: ${RUN_MODE}"
log_info "Verbose: ${VERBOSE}"
log_info "CI mode: ${CI_MODE}"
echo ""
# Run pre-flight checks
check_dependencies
# Run tests based on mode
local test_result=0
if [[ "${RUN_MODE}" == "quick" ]]; then
run_quick_validation || test_result=$?
else
run_integration_tests || test_result=$?
fi
# Cleanup
cleanup_temp_files
# Final summary
if [[ "${test_result}" -eq 0 ]]; then
if [[ "${CI_MODE}" == "false" ]]; then
echo ""
echo -e "${GREEN}${BOLD}╔══════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}${BOLD}║ ALL TESTS PASSED ✅ ║${NC}"
echo -e "${GREEN}${BOLD}╚══════════════════════════════════════════════════════════════════════╝${NC}"
else
echo ""
echo "==================================================================="
echo " ALL TESTS PASSED"
echo "==================================================================="
fi
exit 0
else
if [[ "${CI_MODE}" == "false" ]]; then
echo ""
echo -e "${RED}${BOLD}╔══════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}${BOLD}║ TESTS FAILED ❌ ║${NC}"
echo -e "${RED}${BOLD}╚══════════════════════════════════════════════════════════════════════╝${NC}"
else
echo ""
echo "==================================================================="
echo " TESTS FAILED"
echo "==================================================================="
fi
exit 1
fi
}
# Run main function
main "$@"