# FT-P-02 — Derkachi VIO drift between satellite anchors

**Task**: AZ-410_ft_p_02_derkachi_drift
**Name**: FT-P-02 cumulative drift between consecutive satellite-anchored fixes (AC-1.3)
**Description**: Implement the FT-P-02 scenario — full Derkachi replay; at each anchor frame compute drift between the propagated visual-only centre and the new satellite anchor centre; bin by `last_satellite_anchor_age_ms`; assert ≥95 % of anchor pairs satisfy drift bounds.
**Complexity**: 3 points
**Dependencies**: AZ-406, AZ-407
**Component**: Blackbox Tests / Positive (epic AZ-262)
**Tracker**: AZ-410
**Epic**: AZ-262 (E-BBT)

## Problem

Cumulative drift between consecutive satellite anchors is the most direct measure of the project's onboard-VIO + IMU-fusion behavior in flight. AC-1.3 must be measured on the Derkachi fixture (the only available real flight) — without this scenario the project has no closed-loop validation of the drift budget.

## Outcome

- pytest scenario at `e2e/tests/positive/test_ft_p_02_derkachi_drift.py`.
- Replays the full Derkachi fixture (video at 30 fps + IMU CSV at 10 Hz, 3 video frames per IMU row).
- For each frame whose outbound estimate carries `source_label = satellite_anchored`: records (a) the propagated centre estimate of the prior visual-only segment, (b) the new anchor centre.
- Per-anchor-pair drift = `‖propagated_centre − next_anchor_centre‖`; binned by `last_satellite_anchor_age_ms`.
- CSV evidence: `e2e-results/run-${RUN_ID}/ft-p-02.csv` (one row per anchor pair).
- Aggregate pass criteria (per AC-1.3): ≥95 % of anchor pairs satisfy `drift < 100 m` (visual-only) AND `drift < 50 m` when CombinedImuFactor IMU fusion is active in C5.

## Scope

### Included
- Full-replay test method (~8 min replay + parsing).
- Anchor-pair detection from the outbound estimate stream (`source_label` transitions).
- Drift binning + aggregate assertion.
- CSV evidence emission.

### Excluded
- Synthetic outage / spoof injection — owned by FT-N-01..04.
- Sharp-turn-segment-specific assertions — owned by FT-P-07 / FT-N-02.
- Frame-by-frame inter-emit latency — owned by NFT-PERF-02.

## Acceptance Criteria

**AC-1: anchor-pair detection**
Given a full Derkachi replay
Then the test identifies every transition from `visual_propagated` (or `dead_reckoned`) → `satellite_anchored` and records the pair.

**AC-2: drift bound (visual-only)**
Given anchor pairs whose preceding segment was visual-only (no IMU fusion active in C5)
Then ≥95 % of those pairs satisfy `drift < 100 m`.

**AC-3: drift bound (IMU-fused)**
Given anchor pairs whose preceding segment had CombinedImuFactor IMU fusion active in C5
Then ≥95 % of those pairs satisfy `drift < 50 m`.

**AC-4: drift distribution monotonic with anchor age**
Given drift bins by `last_satellite_anchor_age_ms` (e.g. {<1 s, 1-3 s, 3-10 s, 10-30 s, >30 s})
Then the bin medians grow monotonically with age; no anomalous spike (>2× median jump) between adjacent bins.

**AC-5: parameterization**
Given the conftest's `(fc_adapter, vio_strategy)` parameterization
Then the scenario runs once per parameterization and emits one row per parameterization in `report.csv`.

## System Under Test Boundary

End-to-end scenario through public boundaries.

- **Allowed inputs**: frame-source replay, IMU CSV replay through FC inbound proxy (passive).
- **Allowed observation**: SITL-side outbound message stream; FDR-side `source_label` transitions (FDR is a public artifact post-flight); `GLOBAL_POSITION_INT` GT from `data_imu.csv`.
- **Forbidden**: querying SUT internal C5 graph state, internal `source_label` state machine, or stubbing C5 / C8.
- If C8 outbound emission is not implemented, the scenario MUST fail (no fallback to a stubbed emit).

## Constraints

- Replay synchrony: 3 video frames per IMU row (per `test-data.md`).
- Drift is computed in metres in WGS84 via Vincenty; `propagated_centre` is the SUT's last-emitted position immediately before the anchor frame.
- IMU-fused-vs-visual-only classification: derived from FDR `source_label` history of the segment preceding each anchor (visual-only = entire segment was `visual_propagated` since the prior anchor; IMU-fused = at least one frame was `satellite_anchored` with active CombinedImuFactor — readable from FDR per AC-NEW-3 schema).

## Risks & Mitigation

**Risk: Derkachi fixture has too few satellite-anchor opportunities for statistical power**
- *Mitigation*: ≥95 % is the AC-1.3 budget; for a fixture with N anchors, the required passing count rounds up. The test reports the actual N, the pass count, and the percentage in the CSV; statistical significance flagged when N < 20.

## Document Dependencies

- `_docs/02_document/tests/blackbox-tests.md` § FT-P-02
- `_docs/02_document/tests/test-data.md` § Position accuracy (FT-P-02 row)
- `_docs/00_problem/input_data/flight_derkachi/data_imu.csv` (GT columns `GLOBAL_POSITION_INT.*`)
