# Acceptance Test: AC-5 - Multi-Fragment Route Connection

## Summary
Validate Acceptance Criterion 5 (partial): "System should try to operate when UAV made a sharp turn, and all the next photos has no common points with previous route. In that situation system should try to figure out location of the new piece of the route and connect it to the previous route. Also this separate chunks could be more than 2."

## Linked Acceptance Criteria
**AC-5**: Connect multiple disconnected route fragments

## Preconditions
1. System with "Atlas" multi-map capability (factor graph with native chunk support)
2. F02.2 Flight Processing Engine running
3. F11 Failure Recovery Coordinator (chunk orchestration)
4. F12 Route Chunk Manager functional (chunk lifecycle)
5. F10 Factor Graph Optimizer with multi-chunk support (subgraph operations)
6. F08 Global Place Recognition (chunk semantic matching via `retrieve_candidate_tiles_for_chunk()`)
7. F09 Metric Refinement (chunk LiteSAM matching)
8. Geodetic map-merging logic implemented (Sim(3) transform via F10.merge_chunk_subgraphs())
9. Test dataset: Simulate 3 disconnected route fragments

## Test Description
Test system's ability to handle completely disconnected route segments (no overlap between segments) and eventually connect them into a coherent trajectory using global GPS anchors.

## Test Steps

### Step 1: Create Multi-Fragment Flight
- **Action**: Create flight with 3 disconnected segments:
  - Fragment 1: AD000001-010 (sequential, connected)
  - Fragment 2: AD000025-030 (sequential, no overlap with Fragment 1)
  - Fragment 3: AD000050-055 (sequential, no overlap with Fragments 1 or 2)
- **Expected Result**: Flight created with all 18 images

### Step 2: Process Fragment 1
- **Action**: Process AD000001-010
- **Expected Result**:
  - L1 provides sequential tracking
  - L3 provides GPS anchors
  - Local trajectory fragment created (Map_Fragment_1)
  - Accurate GPS estimates

### Step 3: Detect Discontinuity (Fragment 1 → 2)
- **Action**: Process AD000025 after AD000010
- **Expected Result**:
  - L1 fails (no overlap, large displacement ~2km)
  - System **proactively creates new chunk** (Map_Fragment_2)
  - Processing continues immediately in new chunk
  - Chunk matching attempted asynchronously

### Step 4: Process Fragment 2 Independently
- **Action**: Process AD000025-030
- **Expected Result**:
  - New sequential tracking starts in chunk_2
  - Frames processed within chunk_2 context
  - Relative factors added to chunk_2's subgraph
  - Chunk_2 optimized independently for local consistency
  - Chunk semantic matching attempted when ready (5-20 frames)
  - Chunk LiteSAM matching with rotation sweeps attempted

### Step 5: Process Fragment 3 
- **Action**: Process AD000050-055 after AD000030
- **Expected Result**:
  - Another discontinuity detected
  - Map_Fragment_3 initialized
  - Independent processing

### Step 6: Global Map Merging
- **Action**: Factor graph attempts geodetic map-merging
- **Expected Result**:
  - All 3 chunks have GPS anchors from chunk LiteSAM matching
  - Chunks merged via Sim(3) transform (translation, rotation, scale)
  - Fragments aligned in global coordinate frame
  - Single consistent trajectory created
  - Global optimization performed

### Step 7: Validate Fragment Connections
- **Action**: Verify all 18 images have global GPS coordinates
- **Expected Result**:
  - All fragments successfully located
  - Internal consistency within each fragment
  - Global alignment across fragments

### Step 8: Accuracy Validation
- **Action**: Compare all 18 estimates vs ground truth
- **Expected Result**:
  - Each fragment individually accurate
  - No systematic bias between fragments
  - Overall accuracy meets AC-1 (≥ 80% < 50m)

## Success Criteria

**Primary Criterion (AC-5)**:
- System processes all 3 disconnected fragments
- Fragments successfully localized in global frame
- No manual intervention required (unless extreme failures)

**Supporting Criteria**:
- Each fragment internally consistent
- GPS anchors (L3) connect fragments globally
- Final trajectory is coherent
- Accuracy maintained across all fragments

## Expected Results

```
Multi-Fragment Flight:
- Fragment 1: AD000001-010 (10 images)
  Internal consistency: Excellent
  Global location: Accurate via L3 anchors
  
- Fragment 2: AD000025-030 (6 images)
  Disconnected from Fragment 1 (~2km gap)
  Internal consistency: Excellent
  Global location: Recovered via L2/L3
  
- Fragment 3: AD000050-055 (6 images)
  Disconnected from Fragment 2 (~1.5km gap)
  Internal consistency: Excellent
  Global location: Recovered via L2/L3

Merging Results:
- All 18 images localized globally
- No fragments "lost"
- Overall accuracy: 16/18 < 50m (88.9%)
- Mean error: 27.3m

AC-5 Status: PASS
Processing Mode: Multi-Map Atlas
```

## Pass/Fail Criteria

**TEST PASSES IF**:
- All 3 fragments processed successfully
- Fragments localized in global frame via GPS anchors
- No fragment lost or unlocatable
- Overall accuracy acceptable (≥ 75% < 50m)

**TEST FAILS IF**:
- Any fragment completely fails to localize
- Fragments have large systematic bias (> 100m offset)
- System requires manual intervention for each fragment
- Merging produces inconsistent trajectory

## Architecture Elements

**Multi-Map "Atlas"** (per solution document):
- Each disconnected segment gets own local map via F12.create_chunk()
- Local maps independently optimized via F10.optimize_chunk()
- GPS anchors provide global reference via F10.add_chunk_anchor()
- Geodetic merging aligns all maps via F10.merge_chunk_subgraphs()

**Recovery Mechanisms**:
- **Proactive chunk creation** via F11.create_chunk_on_tracking_loss() (immediate, not reactive)
- Chunk semantic matching via F08.retrieve_candidate_tiles_for_chunk() (aggregate DINOv2)
- Chunk LiteSAM matching via F06.try_chunk_rotation_steps() + F09.align_chunk_to_satellite()
- F10 creates new chunk subgraph
- Sim(3) transform merges chunks via F12.merge_chunks() → F10.merge_chunk_subgraphs()

**Fragment Detection**:
- Large displacement (> 500m) from last image
- Low/zero overlap (F07 VO fails)
- L1 failure triggers **proactive** new chunk creation
- Chunks processed independently with local optimization
- Multiple chunks can exist simultaneously (F10 supports multi-chunk factor graph)

## Notes
- AC-5 describes realistic operational scenario (multiple turns, disconnected segments)
- System must not assume continuous flight path
- GPS anchors (L3) are critical for connecting fragments
- Without L3, fragments would be isolated with scale ambiguity
- This validates core ASTRAL-Next architecture: hierarchical + anchor topology

