# S02: Pipeline Page: Head/Tail Log View + Token Count — UAT

**Milestone:** M006
**Written:** 2026-03-30T11:16:39.374Z

## UAT: Pipeline Page Head/Tail Log View + Token Count

### Preconditions
- Chrysopedia stack running on ub01 (`docker ps --filter name=chrysopedia` shows all services healthy)
- At least one video has been processed through the pipeline (has pipeline events)
- Browser can reach http://ub01:8096

### Test 1: Head/Tail Toggle Visibility
1. Navigate to http://ub01:8096
2. Open Admin dropdown → click Pipeline
3. Expand any video with pipeline events
4. **Expected:** Event log header shows "Head" and "Tail" buttons between the event count and the refresh button
5. **Expected:** "Tail" button is active by default (highlighted/selected state)

### Test 2: Tail Mode (Default) Shows Newest First
1. With Tail selected, observe the event timestamps
2. **Expected:** Events are ordered newest-first (descending `created_at`)
3. **Expected:** First event shown is from the latest pipeline stage (e.g., stage5_synthesis complete)

### Test 3: Head Mode Shows Oldest First
1. Click the "Head" button
2. **Expected:** Head button becomes active, Tail becomes inactive
3. **Expected:** Events reorder to oldest-first (ascending `created_at`)
4. **Expected:** First event shown is from the earliest pipeline stage (e.g., stage2_segmentation start)

### Test 4: Mode Switch Resets Pagination
1. In Tail mode, click "Next" to advance to page 2+
2. Click "Head" button
3. **Expected:** View jumps back to page 1 (offset resets to 0)
4. **Expected:** Events shown are the first page of oldest-first results

### Test 5: Pagination Works in Both Modes
1. In Head mode, click Next/Prev to page through events
2. **Expected:** Pagination works correctly — Next advances, Prev goes back
3. Switch to Tail mode, repeat
4. **Expected:** Same pagination behavior in Tail mode

### Test 6: Token Counts Visible
1. In either mode, look at event rows with `event_type: llm_call`
2. **Expected:** Token counts (prompt_tokens, completion_tokens, total_tokens) displayed on the row
3. Look at the video summary row
4. **Expected:** Aggregate token count visible per video

### Test 7: API — Invalid Order Parameter
1. Run: `curl -s -w '\n%{http_code}' 'http://ub01:8096/api/v1/admin/pipeline/events/{video_id}?order=invalid'`
2. **Expected:** HTTP 400 response

### Test 8: API — Backward Compatibility
1. Run: `curl -sf 'http://ub01:8096/api/v1/admin/pipeline/events/{video_id}?limit=3' | python3 -m json.tool`
2. **Expected:** Returns events in descending order (same as `?order=desc`) — no breaking change for callers omitting the parameter
