fix(#74): settle on just-finished session and coherent feed health
Prefer previous_completed_session for Live settling link/poll/readiness so an older ready default cannot short-circuit handoff; show reconnecting when phase is disconnected even if browser SSE stays open; refresh Live visuals and add active responsive snapshots against the Weekend shell. Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -256,7 +256,8 @@ const weekendContext = (localAnalysis: string) => ({
|
||||
date_end: '2026-07-05T16:00:00Z',
|
||||
year: 2026,
|
||||
},
|
||||
default_analysis_session: {
|
||||
// Just-finished session lives in previous_completed_session (canonical contract).
|
||||
previous_completed_session: {
|
||||
session: {
|
||||
session_key: 9472,
|
||||
session_name: 'Race',
|
||||
@@ -280,6 +281,31 @@ const weekendContext = (localAnalysis: string) => ({
|
||||
total_championship_rounds: 1,
|
||||
})
|
||||
|
||||
/** Archive-only just-finished Race + older already-ready Practice default. */
|
||||
const archiveOnlySettlingContext = (previousAnalysis: string) => ({
|
||||
...weekendContext(previousAnalysis),
|
||||
default_analysis_session: {
|
||||
session: {
|
||||
session_key: 9001,
|
||||
session_name: 'Practice 1',
|
||||
session_type: 'Practice',
|
||||
meeting_key: 1,
|
||||
date_start: '2026-07-04T12:00:00Z',
|
||||
date_end: '2026-07-04T13:00:00Z',
|
||||
gmt_offset: '',
|
||||
},
|
||||
availability: {
|
||||
schedule: 'available',
|
||||
live_transport: 'unknown',
|
||||
live_session: 'inactive',
|
||||
archive: 'available',
|
||||
local_analysis: 'complete',
|
||||
freshness: 'fresh',
|
||||
limitations: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const heartbeatStream = (route: import('@playwright/test').Route) =>
|
||||
route.fulfill({ contentType: 'text/event-stream', body: 'event: heartbeat\ndata: {}\n\n' })
|
||||
|
||||
@@ -353,9 +379,40 @@ test.describe('Live Timing (no session)', () => {
|
||||
await expect(analysis).toContainText(/analysis will fill in as data ingests/i)
|
||||
})
|
||||
|
||||
test('settling targets archive-only previous_completed_session over older default', async ({ page }) => {
|
||||
await page.route('**/api/v1/live/state', (route) =>
|
||||
route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
is_live: false,
|
||||
data: null,
|
||||
last_snapshot: { ...raceSnapshot.data, SessionStatus: 'Finished' },
|
||||
last_snapshot_at: '2026-07-04T14:00:00Z',
|
||||
}),
|
||||
}),
|
||||
)
|
||||
await page.route('**/api/v1/weekend-context', (route) =>
|
||||
route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(archiveOnlySettlingContext('pending')),
|
||||
}),
|
||||
)
|
||||
await page.route('**/api/v1/live/stream', heartbeatStream)
|
||||
|
||||
await page.goto('/live')
|
||||
await expect(page.getByTestId('live-settling')).toBeVisible()
|
||||
const analysis = page.getByTestId('live-handoff-analysis')
|
||||
await expect(analysis).toHaveAttribute('href', '/race-hub?session_key=9472')
|
||||
await expect(analysis).toHaveAttribute('data-ready', 'false')
|
||||
await expect(analysis).toContainText('Open Race analysis')
|
||||
await expect(analysis).not.toContainText('Practice 1')
|
||||
})
|
||||
|
||||
test('retains the last live snapshot with a disconnected warning on a feed drop', async ({ page }) => {
|
||||
// is_live=false but SessionStatus is still "Started": the FIA feed dropped
|
||||
// mid-session. The page must warn + retain the live tower, never settle.
|
||||
// Keep the browser SSE open via a long-lived stream so transport stays connected
|
||||
// while phase is disconnected — health must still say Reconnecting.
|
||||
await page.route('**/api/v1/live/state', (route) =>
|
||||
route.fulfill({
|
||||
contentType: 'application/json',
|
||||
@@ -370,7 +427,21 @@ test.describe('Live Timing (no session)', () => {
|
||||
await page.route('**/api/v1/weekend-context', (route) =>
|
||||
route.fulfill({ contentType: 'application/json', body: JSON.stringify(weekendContext('pending')) }),
|
||||
)
|
||||
await page.route('**/api/v1/live/stream', heartbeatStream)
|
||||
await page.route('**/api/v1/live/stream', async (route) => {
|
||||
const body = [
|
||||
'event: heartbeat',
|
||||
'data: {}',
|
||||
'',
|
||||
'event: heartbeat',
|
||||
'data: {}',
|
||||
'',
|
||||
].join('\n')
|
||||
await route.fulfill({
|
||||
contentType: 'text/event-stream',
|
||||
headers: { 'Cache-Control': 'no-cache' },
|
||||
body,
|
||||
})
|
||||
})
|
||||
|
||||
await page.goto('/live')
|
||||
await expect(page.getByTestId('live-page')).toHaveAttribute('data-phase', 'disconnected')
|
||||
@@ -378,5 +449,7 @@ test.describe('Live Timing (no session)', () => {
|
||||
await expect(page.getByText('Timing Tower')).toBeVisible()
|
||||
await expect(page.getByTestId('live-settling')).toHaveCount(0)
|
||||
await expect(page.getByTestId('live-archive-strip')).toHaveCount(0)
|
||||
await expect(page.getByTestId('live-feed-health')).toContainText(/reconnecting/i)
|
||||
await expect(page.getByTestId('live-feed-health')).not.toContainText(/feed healthy/i)
|
||||
})
|
||||
})
|
||||
|
||||
BIN
tests/visual/__snapshots__/desktop/live-active.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 56 KiB |
BIN
tests/visual/__snapshots__/mobile/live-active.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 34 KiB |
BIN
tests/visual/__snapshots__/tablet/live-active.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 45 KiB |
@@ -68,6 +68,156 @@ export async function gotoLiveInactiveReady(page: Page): Promise<void> {
|
||||
// With BOXBOX_DISABLE_LIVE=1 the feed is silent, so the page settles into the
|
||||
// inactive weekend-context handoff sourced from /api/v1/weekend-context.
|
||||
await expect(page.getByTestId('live-inactive')).toBeVisible()
|
||||
// Integrated #73 shell — stale Command/Live/Race Hub baselines must not pass.
|
||||
await expect(page.getByRole('navigation')).toContainText('Weekend')
|
||||
await expect(page.getByRole('navigation')).not.toContainText('Command')
|
||||
await waitForScreenshotReady(page)
|
||||
}
|
||||
|
||||
/** Deterministic active Live hierarchy (mocked snapshot + sticky SSE). */
|
||||
export async function gotoLiveActiveReady(page: Page): Promise<void> {
|
||||
await page.addInitScript(() => {
|
||||
window.localStorage.clear()
|
||||
class StickyEventSource {
|
||||
onopen: ((ev: Event) => void) | null = null
|
||||
onerror: ((ev: Event) => void) | null = null
|
||||
constructor(_url: string | URL) {
|
||||
queueMicrotask(() => this.onopen?.(new Event('open')))
|
||||
}
|
||||
addEventListener(_type: string, _listener: EventListenerOrEventListenerObject) {}
|
||||
close() {}
|
||||
}
|
||||
Object.defineProperty(window, 'EventSource', {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: StickyEventSource,
|
||||
})
|
||||
})
|
||||
|
||||
const driver = (
|
||||
num: string,
|
||||
pos: number,
|
||||
interval: string,
|
||||
gap: string,
|
||||
overrides: Record<string, unknown> = {},
|
||||
) => ({
|
||||
RacingNumber: num,
|
||||
Position: pos,
|
||||
PrevPosition: pos,
|
||||
GapToLeader: gap,
|
||||
Interval: interval,
|
||||
LastLapTime: '1:21.345',
|
||||
LastLapPB: false,
|
||||
LastLapOB: false,
|
||||
BestLapTime: '1:20.987',
|
||||
BestLapPB: true,
|
||||
BestLapOB: false,
|
||||
BestLapNum: 22,
|
||||
InPit: false,
|
||||
PitOut: false,
|
||||
Retired: false,
|
||||
KnockedOut: false,
|
||||
Cutoff: false,
|
||||
OnFlyingLap: false,
|
||||
NumberOfLaps: 30,
|
||||
SpeedTrap: '312',
|
||||
Sectors: [],
|
||||
...overrides,
|
||||
})
|
||||
const info = (num: string, tla: string, first: string, last: string, team: string, colour: string) => ({
|
||||
RacingNumber: num,
|
||||
BroadcastName: `${first[0]} ${last.toUpperCase()}`,
|
||||
Tla: tla,
|
||||
TeamName: team,
|
||||
TeamColour: colour,
|
||||
FirstName: first,
|
||||
LastName: last,
|
||||
})
|
||||
|
||||
const liveState = {
|
||||
is_live: true,
|
||||
data: {
|
||||
Drivers: {
|
||||
'1': driver('1', 1, '', ''),
|
||||
'4': driver('4', 2, '+0.523', '+0.523'),
|
||||
'44': driver('44', 3, '+3.214', '+3.737'),
|
||||
'63': driver('63', 4, '+12.001', '+15.738', { InPit: true }),
|
||||
},
|
||||
DriverInfo: {
|
||||
'1': info('1', 'VER', 'Max', 'Verstappen', 'Red Bull Racing', '3671C6'),
|
||||
'4': info('4', 'NOR', 'Lando', 'Norris', 'McLaren', 'FF8000'),
|
||||
'44': info('44', 'HAM', 'Lewis', 'Hamilton', 'Ferrari', 'E80020'),
|
||||
'63': info('63', 'RUS', 'George', 'Russell', 'Mercedes', '27F4D2'),
|
||||
},
|
||||
Tyres: {
|
||||
'1': { Compound: 'HARD', New: false, Age: 12 },
|
||||
'4': { Compound: 'MEDIUM', New: false, Age: 8 },
|
||||
'44': { Compound: 'MEDIUM', New: true, Age: 3 },
|
||||
'63': { Compound: 'HARD', New: true, Age: 0 },
|
||||
},
|
||||
Stints: {
|
||||
'1': [
|
||||
{ Compound: 'MEDIUM', New: true, Laps: 18 },
|
||||
{ Compound: 'HARD', New: false, Laps: 12 },
|
||||
],
|
||||
'4': [
|
||||
{ Compound: 'SOFT', New: true, Laps: 14 },
|
||||
{ Compound: 'MEDIUM', New: true, Laps: 16 },
|
||||
],
|
||||
},
|
||||
RCMessages: [
|
||||
{
|
||||
Time: '2026-07-03T14:05:00Z',
|
||||
Category: 'Flag',
|
||||
Flag: 'YELLOW',
|
||||
Message: 'YELLOW IN SECTOR 2',
|
||||
Lap: 29,
|
||||
},
|
||||
],
|
||||
Weather: {
|
||||
AirTemp: 22.5,
|
||||
TrackTemp: 41.3,
|
||||
Humidity: 58,
|
||||
WindSpeed: 3.4,
|
||||
WindDir: 180,
|
||||
Rainfall: false,
|
||||
},
|
||||
Session: {
|
||||
MeetingName: 'Testonia Grand Prix',
|
||||
CircuitName: 'Testring',
|
||||
SessionType: 'Race',
|
||||
SessionName: 'Race',
|
||||
Path: '',
|
||||
},
|
||||
TeamRadio: [],
|
||||
SessionStatus: 'Started',
|
||||
TrackStatus: '2',
|
||||
CurrentLap: 30,
|
||||
TotalLaps: 57,
|
||||
// Fixed empty clock → "--:--:--" (no live extrapolation drift).
|
||||
Clock: '',
|
||||
ClockRefTime: '',
|
||||
ClockExtrapolating: false,
|
||||
Telemetry: {},
|
||||
},
|
||||
}
|
||||
|
||||
await page.route('**/api/v1/live/state', (route) =>
|
||||
route.fulfill({ contentType: 'application/json', body: JSON.stringify(liveState) }),
|
||||
)
|
||||
await page.route('**/api/v1/live/stream', (route) =>
|
||||
route.fulfill({
|
||||
contentType: 'text/event-stream',
|
||||
body: 'event: heartbeat\ndata: {}\n\n',
|
||||
}),
|
||||
)
|
||||
|
||||
await page.goto('/live')
|
||||
await expect(page.getByTestId('live-page')).toHaveAttribute('data-phase', 'live')
|
||||
await expect(page.getByTestId('live-session-flag')).toContainText('LIVE SESSION')
|
||||
await expect(page.getByText('Timing Tower')).toBeVisible()
|
||||
await expect(page.getByRole('navigation')).toContainText('Weekend')
|
||||
await expect(page.getByRole('navigation')).not.toContainText('Command')
|
||||
await waitForScreenshotReady(page)
|
||||
}
|
||||
|
||||
|
||||
9
tests/visual/live-active.spec.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { gotoLiveActiveReady, screenshotPage } from './helpers'
|
||||
|
||||
test.describe('Live active visual regression', () => {
|
||||
test('live-active', async ({ page }) => {
|
||||
await gotoLiveActiveReady(page)
|
||||
await screenshotPage(page, 'live-active')
|
||||
})
|
||||
})
|
||||