# ASF TestArena - Setup Guide

## Phase 1 Implementation Status ✅

The following features have been implemented:

1. ✅ Login System
   - Secure authentication with Flask-Login
   - Session management
   - Default admin account (username: admin, password: admin123)

2. ✅ Modern Theme
   - Gradient background design
   - Clean, modern UI components
   - Responsive layout
   - Custom logo integration

3. ✅ Admin Dashboard
   - User creation with role assignment
   - Password reset functionality
   - User deletion
   - User list with role badges

4. ✅ User Dashboard
   - Job list panel (left side)
   - Job details panel (right side)
   - Status indicators with colored icons
   - Real-time job selection

5. ✅ Submit Page
   - Multi-step wizard (5 steps)
   - Branch selection
   - Scenario selection with checkboxes
   - Environment selection (Sensor Hub / Main Board)
   - Test mode selection (Devbench Simulator / Testbench HIL)
   - Additional options (keep devbenches, reuse results)

6. ✅ Docker Compose Setup
   - PostgreSQL database
   - Flask web application
   - Caddy proxy integration ready
   - Volume management for test results

## Next Steps (Phase 2)

The following features need to be implemented:

1. ⏳ Git Integration
   - Branch checkout functionality
   - Scenario detection script integration
   - Repository management

2. ⏳ Test Execution Engine
   - Background job processing
   - Script execution
   - Status updates
   - Process management

3. ⏳ Results Management
   - HTML report generation
   - Results storage
   - Automatic cleanup (7-day retention)

4. ⏳ Real-time Updates
   - WebSocket integration for live status updates
   - Progress tracking

## Configuration Steps

### 1. Update Docker Compose for Caddy

Edit `docker-compose.yml` and uncomment the Caddy network section:

```yaml
networks:
  testarena_network:
    driver: bridge
  caddy_network:  # Uncomment this
    external: true  # Uncomment this
```

Then add the network to the web service:

```yaml
web:
  # ... other config ...
  networks:
    - testarena_network
    - YOUR_CADDY_NETWORK_NAME  # Add your actual Caddy network name
```

### 2. Configure Caddy

Add to your Caddyfile (see `Caddyfile.example`):

```
testarena.nabd-co.com {
    reverse_proxy testarena_web:5000
}
```

### 3. Update Environment Variables

Copy `.env.example` to `.env` and update:

```bash
SECRET_KEY=your-secure-random-key-here
DATABASE_URL=postgresql://testarena_user:your-secure-password@db:5432/testarena
```

### 4. Start the Application

Run `start.bat` or:

```bash
docker-compose up -d --build
```

## File Structure

```
testarena/
├── app/
│   ├── __init__.py           # Flask app initialization
│   ├── models.py             # Database models
│   ├── routes/
│   │   ├── auth.py          # Authentication routes
│   │   ├── admin.py         # Admin management routes
│   │   ├── dashboard.py     # Dashboard routes
│   │   └── jobs.py          # Job submission routes
│   ├── templates/
│   │   ├── base.html        # Base template
│   │   ├── login.html       # Login page
│   │   ├── admin/
│   │   │   └── dashboard.html
│   │   ├── dashboard/
│   │   │   └── index.html
│   │   └── jobs/
│   │       ├── submit.html
│   │       ├── submit_step2.html
│   │       ├── submit_step3.html
│   │       └── submit_step4.html
│   └── static/
│       ├── css/
│       │   └── style.css    # Modern theme styles
│       └── uploads/
│           └── icon.png     # Logo
├── docker-compose.yml        # Docker orchestration
├── Dockerfile               # Web app container
├── requirements.txt         # Python dependencies
├── wsgi.py                 # WSGI entry point
└── README.md               # Documentation
```

## Database Schema

### Users Table
- id (Primary Key)
- username (Unique)
- password_hash
- is_admin (Boolean)
- created_at (Timestamp)

### Jobs Table
- id (Primary Key)
- user_id (Foreign Key → Users)
- branch_name
- scenarios (JSON)
- environment
- test_mode
- status (in_progress, passed, failed, aborted)
- submitted_at (Timestamp)
- completed_at (Timestamp, nullable)
- duration (Integer, seconds)
- keep_devbenches (Boolean)
- reuse_results (Boolean)
- results_path (String, nullable)

## API Endpoints

### Authentication
- `GET /login` - Login page
- `POST /login` - Login submission
- `GET /logout` - Logout

### Dashboard
- `GET /dashboard/` - Main dashboard

### Admin
- `GET /admin/` - Admin dashboard
- `POST /admin/users/create` - Create user
- `POST /admin/users/<id>/reset-password` - Reset password
- `POST /admin/users/<id>/delete` - Delete user

### Jobs
- `GET /jobs/submit` - Submit form (step 1)
- `POST /jobs/submit/step1` - Process step 1
- `POST /jobs/submit/step2` - Process step 2
- `POST /jobs/submit/step3` - Process step 3
- `POST /jobs/submit/final` - Submit job
- `GET /jobs/<id>` - Get job details (JSON)
- `POST /jobs/<id>/abort` - Abort job

## Security Notes

1. Change default admin password immediately
2. Update SECRET_KEY in production
3. Use strong database passwords
4. Enable HTTPS via Caddy
5. Regular security updates

## Troubleshooting

### Container won't start
```bash
docker-compose logs web
```

### Database connection issues
Check DATABASE_URL in docker-compose.yml

### Can't access the site
- Verify Docker containers are running: `docker ps`
- Check logs: `docker-compose logs -f`
- Verify Caddy configuration

## Support

For issues or questions, contact the development team.
