Compare commits

..
Author SHA1 Message Date
AmanTahilianiandCursor c736f8d353 fix(chapters): sync race-story titles after conflict trim
resolveConflicts already clips a still-open safety car so finish can
keep the last laps, but Title and EndTime stayed on the pre-trim
range. Rebuild range-bearing titles from the final laps and point
EndTime at the trimmed lap-index end.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 15:38:29 -04:00
6 changed files with 80 additions and 41 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="theme-color" content="#0d0d0d" />
<meta name="description" content="box-box: A premium Live F1 Dashboard and Timing Tower" />
+1 -3
View File
@@ -21,9 +21,7 @@ const rootRoute = createRootRoute({
component: () => (
<>
<Nav />
<main>
<Outlet />
</main>
<Outlet />
</>
),
})
+5 -5
View File
@@ -1434,7 +1434,7 @@ a { color: inherit; text-decoration: none; }
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
color: var(--text-2);
color: var(--text-3);
}
.dl-page-title {
@@ -1444,7 +1444,7 @@ a { color: inherit; text-decoration: none; }
.dl-page-sub {
font-size: 11px;
color: var(--text-2);
color: var(--text-3);
}
.dl-page-banner {
@@ -1470,7 +1470,7 @@ a { color: inherit; text-decoration: none; }
flex-wrap: wrap;
gap: var(--s5);
font-size: 11px;
color: var(--text-2);
color: var(--text-3);
letter-spacing: 0.05em;
text-transform: uppercase;
}
@@ -1554,7 +1554,7 @@ a { color: inherit; text-decoration: none; }
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--text-2);
color: var(--text-3);
}
.dl-stat-val {
@@ -1592,7 +1592,7 @@ a { color: inherit; text-decoration: none; }
.dl-content-meta {
font-size: 12px;
color: var(--text-2);
color: var(--text-3);
font-family: var(--f-mono);
}
+4 -27
View File
@@ -1,9 +1,7 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, waitFor } from '@testing-library/react'
import { render, screen, waitFor, fireEvent } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { RouterProvider, createRouter, createRootRoute, createRoute, Outlet } from '@tanstack/react-router'
import { RouterProvider, createRouter, createRootRoute, createRoute } from '@tanstack/react-router'
import { DataLibraryPage } from '../pages/DataLibraryPage'
import type { DatasetInfo, Meeting, Weekend } from '../types'
@@ -77,16 +75,14 @@ function renderPage() {
const rootRoute = createRootRoute({
component: () => (
<QueryClientProvider client={queryClient}>
<main>
<Outlet />
</main>
<DataLibraryPage />
</QueryClientProvider>
),
})
const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: DataLibraryPage,
component: () => null,
})
const router = createRouter({ routeTree: rootRoute.addChildren([indexRoute]) })
@@ -107,9 +103,6 @@ describe('DataLibraryPage', () => {
renderPage()
expect(await screen.findByTestId('data-library-empty')).toBeInTheDocument()
expect(screen.getByRole('main')).toContainElement(screen.getByTestId('data-library-empty'))
expect(screen.getByText('box-box · admin')).toBeInTheDocument()
expect(screen.getByText(/Local SQLite domain store/i)).toBeInTheDocument()
expect(screen.getByText(/No ingested seasons yet/i)).toBeInTheDocument()
expect(screen.getByText('box-box --ingest-year 2025')).toBeInTheDocument()
})
@@ -122,15 +115,10 @@ describe('DataLibraryPage', () => {
renderPage()
expect(await screen.findByTestId('data-library')).toBeInTheDocument()
expect(screen.getByRole('main')).toContainElement(screen.getByTestId('data-library'))
await waitFor(() => {
expect(mockFetchLocalMeetings).toHaveBeenCalledWith(2025)
})
expect(screen.getByText('box-box · admin')).toBeInTheDocument()
const statLabels = [...document.querySelectorAll('.dl-stat-label')].map((el) => el.textContent)
expect(statLabels).toEqual(expect.arrayContaining(['Full', 'Partial', 'Cancelled', 'Missing', 'Total']))
expect(document.querySelector('.dl-content-meta')).toHaveTextContent(/1 meeting/)
expect(await screen.findByTestId('meeting-detail')).toBeInTheDocument()
expect(screen.getAllByText('Monaco').length).toBeGreaterThan(0)
expect(screen.getByText('11/11')).toBeInTheDocument()
@@ -138,17 +126,6 @@ describe('DataLibraryPage', () => {
expect(screen.getByText('box-box --ingest-session 9472')).toBeInTheDocument()
})
it('does not disable pinch-zoom in the viewport meta', () => {
const html = readFileSync(resolve(__dirname, '../../index.html'), 'utf8')
const match = html.match(/<meta name="viewport" content="([^"]+)"/)
expect(match).not.toBeNull()
const content = match![1]
expect(content).toMatch(/width\s*=\s*device-width/)
expect(content).toMatch(/initial-scale\s*=\s*1/)
expect(content).not.toMatch(/user-scalable\s*=\s*no/i)
expect(content).not.toMatch(/maximum-scale/i)
})
it('shows partial badge for partial weekends', async () => {
const partialWeekend: Weekend = {
...weekend,
+33 -5
View File
@@ -72,7 +72,7 @@ func Detect(rc []RaceControl, positions []PositionSample, laps []Lap, totalLaps
chapters = append(chapters, detectDecisiveSwings(positions, lapIndex, totalLaps)...)
chapters = append(chapters, detectFinish(rc, lapIndex, totalLaps))
return resolveConflicts(chapters)
return resolveConflicts(chapters, lapIndex)
}
func normalizeTotalLaps(totalLaps int, laps []Lap, rc []RaceControl) int {
@@ -321,7 +321,7 @@ func detectPitPhases(laps []Lap, idx lapIndex) []Chapter {
}
ch := Chapter{
Kind: KindPitPhase,
Title: fmt.Sprintf("Pit phase (L%d-L%d)", start, end),
Title: pitPhaseTitle(start, end),
StartLap: start,
EndLap: end,
StartTime: idx.lapStart(start),
@@ -339,7 +339,7 @@ func detectPitPhases(laps []Lap, idx lapIndex) []Chapter {
drivers[driver] = true
}
last.DriverNumbers = sortedDriverNumbers(drivers)
last.Title = fmt.Sprintf("Pit phase (L%d-L%d)", last.StartLap, last.EndLap)
last.Title = pitPhaseTitle(last.StartLap, last.EndLap)
continue
}
windows = append(windows, ch)
@@ -479,7 +479,7 @@ func detectFinish(rc []RaceControl, idx lapIndex, totalLaps int) Chapter {
}
return Chapter{
Kind: KindFinish,
Title: fmt.Sprintf("Finish (L%d-L%d)", startLap, finishLap),
Title: finishTitle(startLap, finishLap),
StartLap: startLap,
EndLap: finishLap,
StartTime: idx.lapStart(startLap),
@@ -487,7 +487,31 @@ func detectFinish(rc []RaceControl, idx lapIndex, totalLaps int) Chapter {
}
}
func resolveConflicts(chapters []Chapter) []Chapter {
func pitPhaseTitle(startLap, endLap int) string {
return fmt.Sprintf("Pit phase (L%d-L%d)", startLap, endLap)
}
func finishTitle(startLap, endLap int) string {
return fmt.Sprintf("Finish (L%d-L%d)", startLap, endLap)
}
// titleForResolved rebuilds range-bearing titles from the final StartLap/EndLap
// after conflict resolution. Flag and pit-phase formatters are reused so stale
// pre-trim strings are never parsed.
func titleForResolved(ch Chapter) string {
switch ch.Kind {
case KindSafetyCar, KindVirtualSafetyCar, KindRedFlag:
return flagTitle(ch.Kind, ch.StartLap, ch.EndLap)
case KindPitPhase:
return pitPhaseTitle(ch.StartLap, ch.EndLap)
case KindFinish:
return finishTitle(ch.StartLap, ch.EndLap)
default:
return ch.Title
}
}
func resolveConflicts(chapters []Chapter, idx lapIndex) []Chapter {
normalized := make([]Chapter, 0, len(chapters))
for _, ch := range chapters {
if ch.StartLap <= 0 {
@@ -528,6 +552,7 @@ func resolveConflicts(chapters []Chapter) []Chapter {
if priority(ch.Kind) > priority(last.Kind) {
if last.StartLap < ch.StartLap {
last.EndLap = ch.StartLap - 1
last.EndTime = idx.lapEnd(last.EndLap)
out = append(out, ch)
} else {
*last = ch
@@ -541,6 +566,9 @@ func resolveConflicts(chapters []Chapter) []Chapter {
}
}
}
for i := range out {
out[i].Title = titleForResolved(out[i])
}
return out
}
+36
View File
@@ -125,6 +125,42 @@ func TestDetectDecisiveSwingPersistsToFinish(t *testing.T) {
}
}
func TestDetectSafetyCarTrimmedForFinishRewritesTitle(t *testing.T) {
rcs := []RaceControl{
rc(3, models.CategorySafetyCar, "", "SAFETY CAR DEPLOYED"),
rc(72, models.CategoryFlag, models.FlagChequered, "CHEQUERED FLAG"),
}
got := Detect(rcs, nil, testLaps(72, nil), 72)
sc := findKind(got, KindSafetyCar)
if sc == nil {
t.Fatalf("chapters = %+v, want safety car", got)
}
if sc.StartLap != 3 || sc.EndLap != 70 || sc.Title != "Safety Car (L3-L70)" {
t.Fatalf("safety car = %+v, want StartLap=3 EndLap=70 Title=%q", *sc, "Safety Car (L3-L70)")
}
if wantEnd := lapTime(71); sc.EndTime != wantEnd {
t.Fatalf("safety car EndTime = %q, want lap-index end of L70 (%q)", sc.EndTime, wantEnd)
}
fin := findKind(got, KindFinish)
if fin == nil || fin.StartLap != 71 || fin.EndLap != 72 {
t.Fatalf("finish = %+v, want L71-L72", got)
}
for i := 1; i < len(got); i++ {
if got[i].StartLap <= got[i-1].EndLap {
t.Fatalf("chapters overlap at %d: %+v then %+v", i, got[i-1], got[i])
}
}
headed := ApplyHeadlines(got, nil, rcs, 0)
if scH := findKind(headed, KindSafetyCar); scH == nil || scH.Headline != "Safety Car (L3-L70)" {
t.Fatalf("headline = %+v, want fallback to resolved title Safety Car (L3-L70)", headed)
}
}
func TestDetectFlagPeriodsWinOverConflictingChapters(t *testing.T) {
pitOuts := map[int][]int{
12: {1, 2},