mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-08 04:06:18 -04:00
fix(race-hub): consume canonical weekend context for #75 review
Address PR #82 review blockers: drop the competing /weekend default_analysis_session resolver, land bare /race-hub via /api/v1/weekend-context, derive Live/preparing/partial/unavailable from authoritative context with a moving clock, hide Local Coverage behind Diagnostics, isolate the future-session fixture from the shared seed, and strengthen return-to-Weekend context coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { sessionState, sessionStateLabel } from '../lib/sessionState'
|
||||
import type { DatasetInfo, Session, WeekendSession } from '../types'
|
||||
import {
|
||||
resolveSessionState,
|
||||
sessionState,
|
||||
sessionStateLabel,
|
||||
} from '../lib/sessionState'
|
||||
import type {
|
||||
ContextAvailability,
|
||||
ContextSession,
|
||||
DatasetInfo,
|
||||
Session,
|
||||
WeekendContext,
|
||||
WeekendSession,
|
||||
} from '../types'
|
||||
|
||||
const NOW = new Date('2025-06-01T00:00:00Z')
|
||||
|
||||
@@ -41,17 +52,57 @@ const FULL: Record<string, DatasetInfo> = Object.fromEntries(
|
||||
].map((k) => [k, { status: 'available', source: 'local', count: 1 }]),
|
||||
)
|
||||
|
||||
function availability(overrides: Partial<ContextAvailability> = {}): ContextAvailability {
|
||||
return {
|
||||
schedule: 'available',
|
||||
live_transport: 'unknown',
|
||||
live_session: 'inactive',
|
||||
archive: 'unavailable',
|
||||
local_analysis: 'complete',
|
||||
freshness: 'fresh',
|
||||
limitations: [],
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
function contextSession(
|
||||
session: Session,
|
||||
avail: Partial<ContextAvailability> = {},
|
||||
): ContextSession {
|
||||
return { session, availability: availability(avail) }
|
||||
}
|
||||
|
||||
function context(overrides: Partial<WeekendContext> = {}): WeekendContext {
|
||||
return {
|
||||
temporal_state: 'post_weekend',
|
||||
championship_round: 1,
|
||||
total_championship_rounds: 1,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
describe('sessionState', () => {
|
||||
it('marks a future session as upcoming', () => {
|
||||
const s = mk({ date_start: '2099-05-25T13:00:00+00:00', date_end: '2099-05-25T15:00:00+00:00' }, 'none')
|
||||
expect(sessionState(s, NOW)).toBe('upcoming')
|
||||
})
|
||||
|
||||
it('marks a running session as live', () => {
|
||||
it('does not mark Live from schedule alone', () => {
|
||||
const start = new Date(NOW.getTime() - 60_000).toISOString()
|
||||
const end = new Date(NOW.getTime() + 60_000).toISOString()
|
||||
const s = mk({ date_start: start, date_end: end }, 'partial')
|
||||
expect(sessionState(s, NOW)).toBe('live')
|
||||
const s = mk({ date_start: start, date_end: end }, 'none')
|
||||
expect(sessionState(s, NOW)).toBe('preparing')
|
||||
})
|
||||
|
||||
it('marks Live only when Weekend Context active identity matches', () => {
|
||||
const start = new Date(NOW.getTime() - 60_000).toISOString()
|
||||
const end = new Date(NOW.getTime() + 60_000).toISOString()
|
||||
const s = mk({ session_key: 42, date_start: start, date_end: end }, 'none')
|
||||
const ctx = context({
|
||||
temporal_state: 'session_live',
|
||||
active_session: contextSession(s.session, { live_session: 'active' }),
|
||||
})
|
||||
expect(resolveSessionState({ weekendSession: s, context: ctx, now: NOW })).toBe('live')
|
||||
})
|
||||
|
||||
it('marks a finished session with full local data as ready', () => {
|
||||
@@ -69,6 +120,18 @@ describe('sessionState', () => {
|
||||
expect(sessionState(s, NOW)).toBe('partial')
|
||||
})
|
||||
|
||||
it('marks unavailable from context availability', () => {
|
||||
const s = mk({ session_key: 7 }, 'none')
|
||||
const ctx = context({
|
||||
previous_completed_session: contextSession(s.session, {
|
||||
local_analysis: 'unavailable',
|
||||
}),
|
||||
})
|
||||
expect(resolveSessionState({ weekendSession: s, context: ctx, now: NOW })).toBe(
|
||||
'unavailable',
|
||||
)
|
||||
})
|
||||
|
||||
it('marks a cancelled session as cancelled', () => {
|
||||
const s = mk({}, 'cancelled')
|
||||
expect(sessionState(s, NOW)).toBe('cancelled')
|
||||
@@ -78,5 +141,6 @@ describe('sessionState', () => {
|
||||
expect(sessionStateLabel('ready')).toBe('Ready')
|
||||
expect(sessionStateLabel('upcoming')).toBe('Upcoming')
|
||||
expect(sessionStateLabel('partial')).toBe('Partial')
|
||||
expect(sessionStateLabel('unavailable')).toBe('Unavailable')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user