OrbitalSimulator/test_interfaces.sh
2025-06-21 23:29:14 -04:00

201 lines
5.9 KiB
Bash
Executable File

#!/bin/bash
# Test script for Orbital Simulator Interfaces
# This script tests all available interfaces and functionality
echo "🧪 Testing Orbital Simulator Interfaces"
echo "======================================="
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Test results
TESTS_PASSED=0
TESTS_FAILED=0
# Function for test output
test_result() {
if [ $1 -eq 0 ]; then
echo -e "${GREEN}$2${NC}"
((TESTS_PASSED++))
else
echo -e "${RED}$2${NC}"
((TESTS_FAILED++))
fi
}
# Test 1: Check prerequisites
echo -e "${BLUE}Test 1: Prerequisites${NC}"
command -v cargo &> /dev/null
test_result $? "Rust/Cargo available"
command -v node &> /dev/null
test_result $? "Node.js available"
command -v npm &> /dev/null
test_result $? "npm available"
command -v python3 &> /dev/null
test_result $? "Python 3 available"
# Test 2: Build Rust project
echo -e "\n${BLUE}Test 2: Rust Project Build${NC}"
cargo check --bin api_server --no-default-features &> /dev/null
test_result $? "API server builds without GUI features"
cargo check --bin simulator &> /dev/null
test_result $? "CLI simulator builds"
# Test 3: Web dependencies
echo -e "\n${BLUE}Test 3: Web Frontend${NC}"
cd web
npm install &> /dev/null
test_result $? "Web dependencies install successfully"
npm run build &> /dev/null
test_result $? "Web frontend builds successfully"
cd ..
# Test 4: Start services for testing
echo -e "\n${BLUE}Test 4: Service Integration${NC}"
# Start API server
echo "Starting API server for testing..."
cargo run --bin api_server --no-default-features &> /dev/null &
API_PID=$!
sleep 5
# Test API endpoints
if curl -s http://localhost:3000/api/configs > /dev/null; then
test_result 0 "API server responds to requests"
# Test creating a simulation
RESPONSE=$(curl -s -X POST http://localhost:3000/api/simulations \
-H "Content-Type: application/json" \
-d '{
"config": {
"bodies": [
{
"name": "Sun",
"mass": 1.989e30,
"position": [0.0, 0.0, 0.0],
"velocity": [0.0, 0.0, 0.0]
},
{
"name": "Earth",
"mass": 5.972e24,
"position": [147095000000.0, 0.0, 0.0],
"velocity": [0.0, 30290.0, 0.0]
}
]
},
"step_size": 3600,
"total_steps": 100
}')
if echo "$RESPONSE" | grep -q '"id"'; then
test_result 0 "Simulation creation API works"
SIM_ID=$(echo "$RESPONSE" | grep -o '"id":"[^"]*"' | cut -d'"' -f4)
# Test simulation control
curl -s -X POST "http://localhost:3000/api/simulations/$SIM_ID/control?action=start" > /dev/null
test_result $? "Simulation control API works"
sleep 1
# Test getting simulation state
STATE_RESPONSE=$(curl -s "http://localhost:3000/api/simulations/$SIM_ID")
if echo "$STATE_RESPONSE" | grep -q '"step"'; then
test_result 0 "Simulation state retrieval works"
else
test_result 1 "Simulation state retrieval fails"
fi
# Test simulation list
LIST_RESPONSE=$(curl -s http://localhost:3000/api/simulations)
if echo "$LIST_RESPONSE" | grep -q "$SIM_ID"; then
test_result 0 "Simulation listing works"
else
test_result 1 "Simulation listing fails"
fi
else
test_result 1 "Simulation creation API fails"
fi
else
test_result 1 "API server not responding"
fi
# Clean up
kill $API_PID 2>/dev/null || true
wait $API_PID 2>/dev/null || true
# Test 5: CLI tools
echo -e "\n${BLUE}Test 5: CLI Tools${NC}"
# Test simulator with sample config
if [ -f "config/planets.toml" ]; then
timeout 5s cargo run --bin simulator -- --config config/planets.toml --time 1h --step-size 3600 --output-file test_output.bin &> /dev/null
test_result $? "CLI simulator runs with config file"
rm -f test_output.bin 2>/dev/null
else
test_result 1 "Sample config file not found"
fi
# Test 6: Python plotting tools
echo -e "\n${BLUE}Test 6: Python Tools${NC}"
if [ -f "requirements.txt" ]; then
# Create virtual environment if it doesn't exist
if [ ! -d ".venv" ]; then
python3 -m venv .venv
fi
source .venv/bin/activate
pip install -r requirements.txt &> /dev/null
test_result $? "Python dependencies install"
# Test if plotting script can be imported
if python3 -c "import plot_trajectories" &> /dev/null; then
test_result 0 "Python plotting tools available"
else
test_result 1 "Python plotting tools not working"
fi
else
test_result 1 "Python requirements file not found"
fi
# Test 7: GUI availability
echo -e "\n${BLUE}Test 7: GUI Availability${NC}"
if command -v cargo-tauri &> /dev/null; then
test_result 0 "Tauri CLI available for desktop GUI"
# Try to check Tauri build (don't actually build to save time)
if [ -f "src-tauri/Cargo.toml" ]; then
test_result 0 "Tauri project structure exists"
else
test_result 1 "Tauri project structure missing"
fi
else
echo -e "${YELLOW}⚠️ Tauri CLI not installed - desktop GUI not available${NC}"
echo " Install with: cargo install tauri-cli"
fi
# Final results
echo -e "\n${BLUE}Test Results Summary${NC}"
echo "==================="
echo -e "${GREEN}Tests Passed: $TESTS_PASSED${NC}"
echo -e "${RED}Tests Failed: $TESTS_FAILED${NC}"
if [ $TESTS_FAILED -eq 0 ]; then
echo -e "\n${GREEN}🎉 All tests passed! The orbital simulator is ready to use.${NC}"
echo -e "${BLUE}Run ./start_interfaces.sh to start all interfaces.${NC}"
exit 0
else
echo -e "\n${YELLOW}⚠️ Some tests failed. Check the output above for details.${NC}"
exit 1
fi