# Test — Detection Endpoints (Sync / Async / Long-Video)

**Task**: AZ-461_test_detection_endpoints
**Name**: Detection endpoints — sync image + async video (Phase B target) + long-video header
**Description**: Implement the three blackbox tests that exercise the `detect/` service's three detection paths from the SPA: sync image detect (FT-P-11), async video detect SSE (FT-P-12, quarantined as Phase B target), and the `X-Refresh-Token` header carried on long-video detect (FT-P-13).
**Complexity**: 2 points
**Dependencies**: AZ-456_test_infrastructure
**Component**: 06_annotations (detection sub-surface) (Blackbox Tests)
**Tracker**: AZ-461
**Epic**: AZ-455

## Problem

Detection is multimodal: sync for images (today), async with SSE updates for video (Phase B per AC-25), and long-video has its own header contract for token rotation. Without targeted tests, regressions slip in mode-by-mode.

## Outcome

- 3 test scenarios are present in their declared profile and reference their `results_report.md` rows.
- FT-P-12 is QUARANTINEd in CI with a clear marker until the async-video path lands.

## Scope

### Included

| Scenario | Profile | Source file | results_report row |
|----------|---------|-------------|--------------------|
| FT-P-11 — sync image detect endpoint | fast + e2e | blackbox-tests.md | per FT-P-11 |
| FT-P-12 — async video detect endpoint + SSE (target — Phase B) | fast (quarantined) | blackbox-tests.md | per FT-P-12 |
| FT-P-13 — long-video detect carries `X-Refresh-Token` header | fast | blackbox-tests.md | per FT-P-13 |

### Excluded

- Annotation save after detect (covered in 05_test_annotations_endpoint).
- Detection class CRUD (covered in 17_test_detection_classes).

## Acceptance Criteria

**AC-1: Sync image detect URL + body**
FT-P-11 asserts the outbound POST URL + body shape for sync image detect against the contract.

**AC-2: Async video detect — quarantined**
FT-P-12 is implemented and registered, but marked `Result: QUARANTINE` in the CSV report until AC-25 (Phase B) lands. The test code itself runs (does not just `xit`) and produces a clear log entry "FT-P-12 awaits AC-25 / async video detect impl".

**AC-3: Header carried**
FT-P-13 asserts every long-video detect request carries the `X-Refresh-Token` header.

## System Under Test Boundary

- System under test: the SPA's `<AnnotationsPage>` (or its detect-trigger sub-component) + `src/api/client.ts`.
- Allowed stubs: MSW for `/api/detect/*` (fast); real `detect/` service (e2e — async video path stays quarantined until the suite has it).
- Disallowed: stubbing the SPA components or constructing the request manually from a unit test.
- Expected observables per `results_report.md` rows for FT-P-11, 12, 13.

## Constraints

- FT-P-12 is QUARANTINE in CI, NOT skipped — the result must appear in the report with that status, traceable to AC-25.

## Risks & Mitigation

**Risk 1 — Async video detect path lands while tests are being implemented**
- *Risk*: AC-25 may go from target to shipped, flipping FT-P-12 from QUARANTINE to PASS / FAIL.
- *Mitigation*: FT-P-12 reads the runtime UI to detect whether the path exists; the QUARANTINE marker is conditional on absence.
