# System Integration Test: Real-Time Streaming Pipeline

## Summary
Validate real-time streaming of results via SSE as images are processed (AC-8 requirement).

## Components Under Test
- Image Input Pipeline
- Vision Layers (L1, L2, L3)
- Factor Graph Optimizer
- Result Manager
- SSE Event Streamer
- Flight Manager

## Test Scenario
Per AC-8: "Results of image processing should appear immediately to user, so that user shouldn't wait for the whole route to complete."

Test that:
1. Images uploaded and queued
2. Processing starts immediately
3. Results streamed to client < 1s after processing
4. Refinements sent when trajectory updated
5. User can analyze early results before flight completes

## Test Cases

### Test Case 1: Immediate Result Delivery
- Upload 10 images
- Connect SSE client
- Measure time from image processed to event received
- **Target**: < 1 second latency (AC-8 "immediately")

### Test Case 2: Progressive Results
- Upload 30 images
- Monitor SSE stream
- Verify first results available before image 30 processed
- **Target**: First result within 10 seconds of upload

### Test Case 3: Refinement Notifications
- Process 20 images
- New GPS anchor added (image 20)
- Factor graph refines trajectory for images 1-19
- Verify "trajectory_refined" event sent
- **Target**: Refinement notification within 2 seconds

### Test Case 4: Multiple Concurrent Clients
- 3 clients connect to same flight SSE stream
- All receive events simultaneously
- No delays between clients
- **Target**: All clients receive within 100ms of each other

### Test Case 5: Late-Joining Client
- Flight already processing (10 images done)
- New client connects
- Receives catch-up of existing results plus live stream
- **Target**: Seamless experience

### Test Case 6: Backpressure Handling
- Process images rapidly (50 images in 60 seconds)
- Verify SSE can handle high event rate
- No event loss or buffer overflow
- **Target**: All events delivered, no loss

## Success Criteria
- Result latency < 1 second (AC-8)
- First results available immediately
- Refinements streamed when they occur
- Multiple clients supported
- No event loss under load

## Maximum Expected Time
- Setup: < 5 seconds
- Process 30 images with streaming: < 150 seconds
- Total test: < 180 seconds

## Pass/Fail Criteria
**Passes If**: AC-8 requirements met, latency < 1s, refinements streamed, no event loss
**Fails If**: Latency > 2s, events lost, clients not notified of refinements

