rts-commander / tests /README.md
Luigi's picture
Initial commit: Complete RTS project with MCP evaluation
551ad28
# ๐Ÿงช Test Scripts
This directory contains all test scripts for the RTS Web version.
---
## ๐Ÿ“‹ Available Tests
### 1. **test.sh** - Main Test Suite
```bash
./test.sh
```
**Purpose:** Complete test suite for all game features
**Coverage:**
- Server connection
- Game initialization
- Unit creation and control
- Building construction
- Resource management
- Combat system
- AI behavior
- UI rendering
**Usage:**
- Ensure server is running (`cd .. && python start.py`)
- Execute from web/ directory: `./tests/test.sh`
- Review output for any failures
---
### 2. **test_features.sh** - Feature-Specific Tests
```bash
./test_features.sh
```
**Purpose:** Test specific game features individually
**Coverage:**
- Fog of War
- Unit production
- Building placement
- Resource gathering
- Combat mechanics
- Superweapon system
**Usage:**
- Run after major feature additions
- Use for regression testing
- Verify specific functionality
---
### 3. **test_harvester_ai.py** - Harvester AI Tests
```bash
python test_harvester_ai.py
```
**Purpose:** Comprehensive harvester AI testing
**Coverage:**
- Pathfinding to Tiberium
- Resource collection
- Return to refinery
- Avoiding obstacles
- Manual control override
- State transitions
**Dependencies:**
```
requests
websocket-client
```
**Usage:**
- Detailed harvester behavior testing
- AI logic verification
- Performance benchmarking
**Output:**
- Step-by-step AI decisions
- State transition logs
- Performance metrics
---
### 4. **docker-test.sh** - Docker Testing
```bash
./docker-test.sh
```
**Purpose:** Test Docker deployment
**Coverage:**
- Docker build process
- Container startup
- Server accessibility
- WebSocket connections
- Production readiness
**Usage:**
- Pre-deployment testing
- Docker configuration validation
- CI/CD pipeline integration
**Requirements:**
- Docker installed
- Docker daemon running
- Port 8000 available
---
### 5. **test_mcp_server.py** - MCP Server Tests
```bash
python test_mcp_server.py
```
**Purpose:** Test MCP server functionality
**Coverage:**
- MCP server import
- Server instance creation
- Server initialization
**Usage:**
- Run to verify MCP server functionality
- Use for regression testing of MCP integration
**Output:**
- Import success/failure
- Instance creation success/failure
- Initialization success/failure
---
## ๐Ÿš€ Quick Start
### Basic Test Run
```bash
cd /home/luigi/rts/web
python start.py & # Start server
./tests/test.sh # Run tests
```
### Harvester AI Test
```bash
cd /home/luigi/rts/web
python start.py &
python tests/test_harvester_ai.py
```
### MCP Server Test
```bash
cd /home/luigi/rts/web
python tests/test_mcp_server.py
```
### Docker Test
```bash
cd /home/luigi/rts/web
./tests/docker-test.sh
```
---
## ๐Ÿ“Š Test Coverage
| Test Script | Features Tested | Execution Time | Automation |
|------------|----------------|----------------|------------|
| test.sh | All core features | ~2 min | โœ… Full |
| test_features.sh | Specific features | ~3 min | โœ… Full |
| test_harvester_ai.py | Harvester AI only | ~1 min | โœ… Full |
| docker-test.sh | Docker deployment | ~5 min | โœ… Full |
| test_mcp_server.py | MCP server functionality | ~10s | โœ… Full |
---
## ๐Ÿ”ง Test Configuration
### Environment Variables
```bash
# Server URL (default: http://localhost:8000)
export TEST_SERVER_URL="http://localhost:8000"
# WebSocket URL (default: ws://localhost:8000/ws)
export TEST_WS_URL="ws://localhost:8000/ws"
# Test timeout (default: 30s)
export TEST_TIMEOUT=30
```
### Prerequisites
1. **Server running:**
```bash
cd /home/luigi/rts/web
python start.py
```
2. **Dependencies installed:**
```bash
pip install -r ../requirements.txt
```
3. **Ports available:**
- 8000 (HTTP/WebSocket)
- 8080 (if testing multiple instances)
---
## ๐Ÿ› Troubleshooting
### Test Failures
**Connection Errors:**
```bash
# Check if server is running
curl http://localhost:8000/health
# Check WebSocket
wscat -c ws://localhost:8000/ws
```
**Harvester AI Tests Fail:**
```bash
# Verify AI module loaded
curl http://localhost:8000/api/game/state | grep harvester
# Check logs
tail -f server.log
```
**Docker Tests Fail:**
```bash
# Check Docker status
docker ps
docker logs rts-web
# Rebuild if needed
docker build -t rts-web .
docker run -p 8000:8000 rts-web
```
---
## ๐Ÿ“ˆ Test Results
### Expected Output
**โœ… Successful Run:**
```
[PASS] Server connection
[PASS] Game initialization
[PASS] Unit creation
[PASS] Building construction
[PASS] Combat system
[PASS] AI behavior
All tests passed!
```
**โŒ Failed Run:**
```
[FAIL] Unit creation - Timeout
[FAIL] Combat system - Assertion error
2 tests failed, 4 passed
```
---
## ๐Ÿ”„ Continuous Integration
### GitHub Actions Example
```yaml
name: RTS Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run Tests
run: |
cd web
python start.py &
sleep 5
./tests/test.sh
```
---
## ๐Ÿ“ Adding New Tests
### Test Script Template
```bash
#!/bin/bash
# Description: Test [feature name]
echo "Testing [feature]..."
# Setup
SERVER_URL=${TEST_SERVER_URL:-http://localhost:8000}
# Test logic
curl -f $SERVER_URL/api/[endpoint] || exit 1
echo "[PASS] [Feature] test"
```
### Python Test Template
```python
import requests
import time
def test_feature():
"""Test [feature name]"""
response = requests.get('http://localhost:8000/api/endpoint')
assert response.status_code == 200
print("[PASS] Feature test")
if __name__ == '__main__':
test_feature()
```
---
## ๐Ÿ†• Recent Updates
- โœ… All test scripts organized in dedicated directory
- โœ… Complete documentation for each test
- โœ… Docker testing added
- โœ… Harvester AI comprehensive tests
- โœ… CI/CD integration examples
---
**For main project README:** See `../README.md`
**For documentation:** See `../docs/`
---
## ๐Ÿ“ž Support
Issues with tests? Check:
1. Server logs: `server.log`
2. Documentation: `../docs/`
3. Troubleshooting guide: `../docs/TROUBLESHOOTING.md` (if exists)