# System Integration Test: End-to-End Normal Flight

## Summary
Validate complete system flow from flight creation through image processing to final results for a standard flight scenario.

## Components Under Test
All ASTRAL-Next components in integrated system:
- REST API, Flight Manager, Image Input Pipeline
- Sequential VO (L1), Global PR (L2), Metric Refinement (L3)
- Factor Graph Optimizer, Result Manager, SSE Event Streamer
- Satellite Data Manager, Coordinate Transformer, Database Layer

## Detailed Description
This is a comprehensive end-to-end test simulating real operational usage. Tests the complete workflow:
1. User creates flight via REST API
2. Uploads images (AD000001-AD000030)
3. System processes images through all vision layers
4. Factor graph optimizes trajectory
5. Results streamed via SSE in real-time
6. Final results retrieved and validated against ground truth

## Test Scenario
**Flight**: Test_Baseline (30 images, normal spacing ~120m)
**Images**: AD000001-AD000030
**Expected Outcome**: Meet AC-1 and AC-2 accuracy targets

## Test Steps

1. **Setup (< 10s)**:
   - Start all system services
   - Initialize database
   - Load models (TensorRT engines)
   - Prepare satellite tiles

2. **Create Flight (< 1s)**:
   - POST /flights
   - Payload: start_gps, altitude=400m, camera_params
   - Verify: flight_id returned, state="created"

3. **Upload Images (< 30s)**:
   - POST /flights/{flightId}/images/batch
   - Upload AD000001-AD000030
   - Verify: All 30 queued, processing starts

4. **Monitor Processing via SSE (< 150s)**:
   - Connect to GET /flights/{flightId}/stream
   - Receive "image_processed" events as each image completes
   - Verify: Events received in < 1s of processing

5. **Await Completion (< 150s total)**:
   - Monitor flight status via GET /flights/{flightId}
   - Wait for state="completed"
   - Verify: No failures, all 30 images processed

6. **Retrieve Results (< 2s)**:
   - GET /flights/{flightId}/results?format=json
   - Download GPS coordinates for all images
   - Compare with ground truth

7. **Validate Accuracy**:
   - Calculate errors for all 30 images
   - Check: ≥80% within 50m (AC-1)
   - Check: ≥60% within 20m (AC-2)
   - Check: Mean error < 30m

8. **Export Results (< 5s)**:
   - GET /flights/{flightId}/results?format=csv
   - Verify CSV matches coordinates.csv format

## Expected Results
```json
{
  "test_status": "passed",
  "flight_id": "flight_123",
  "total_images": 30,
  "processed_images": 30,
  "failed_images": 0,
  "total_time_s": 145,
  "avg_time_per_image_s": 4.83,
  "accuracy_stats": {
    "mean_error_m": 24.5,
    "percent_under_50m": 93.3,
    "percent_under_20m": 66.7,
    "registration_rate": 100.0
  },
  "ac_compliance": {
    "AC-1": "PASS",
    "AC-2": "PASS",
    "AC-7": "PASS",
    "AC-8": "PASS",
    "AC-9": "PASS"
  }
}
```

## Success Criteria
- All 30 images processed successfully
- Processing time < 5s per image (AC-7)
- ≥80% accuracy within 50m (AC-1)
- ≥60% accuracy within 20m (AC-2)
- SSE events delivered in real-time (AC-8)
- Registration rate > 95% (AC-9)
- No system errors or crashes

## Maximum Expected Time
- Setup: < 10 seconds
- Processing 30 images: < 150 seconds (5s per image)
- Result retrieval: < 2 seconds
- Total test: < 180 seconds

## Pass/Fail Criteria
**Passes If**: All steps complete successfully, AC-1, AC-2, AC-7, AC-8, AC-9 requirements met
**Fails If**: Any component fails, accuracy targets missed, processing too slow, system errors

