fix(lap): keep best laps per track layout and count the current session for records

A layout switch during a running open practice kept every driver's
old-layout best lap, blocking personal-best calls and skewing the
practice leaderboard. Best laps now restart on a new layout and each
lap records its layout. The track record baseline now includes the
current session so the same record isn't called twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
larssand
2026-10-03 21:14:19 +02:00
parent ebd0f74f40
commit 8b63dd2372
12 changed files with 125 additions and 8 deletions

View File

@@ -48,12 +48,31 @@ export async function runTrackLayoutsSmoke({ evaluate, navigate, savedState, wai
assert.equal(await layoutButtonVisible(), true, "New layout is offered when Open Practice is in focus");
console.log("PASS Race Day only offers a new layout when a practice session is in focus");
// A running open practice moves onto the new layout and its best laps start over, so the
// old layout's times can't block or fake a personal best on the rebuilt track.
await patchState({
sessions: (await savedState()).sessions.map((session) => (session.id === practice.id ? { ...session, status: "running", startedAt: Date.now() - 60000 } : session)),
resultsBySession: { ...(await savedState()).resultsBySession, [practice.id]: { passings: [], competitors: { tl_driver: { key: "tl_driver", driverName: "TL Driver", laps: 3, bestLapMs: 18000, bestLapLayoutId: (await savedState()).trackLayouts[0].id } } } },
});
await navigate("training", "view");
await evaluate(`document.querySelector("[data-track-layout-new]").click()`);
await waitFor(async () => (await savedState()).trackLayouts?.length === 2, "second layout created");
const afterSwitch = await savedState();
const newLayoutId = afterSwitch.trackLayouts[1].id;
assert.equal(afterSwitch.sessions.find((session) => session.id === practice.id).trackLayoutId, newLayoutId, "the running practice moved onto the new layout");
const competitor = afterSwitch.resultsBySession[practice.id].competitors.tl_driver;
assert.equal(competitor.bestLapMs, null, "the old layout's best lap no longer counts");
assert.equal(competitor.bestLapLayoutId, newLayoutId);
assert.equal(competitor.laps, 3, "laps already driven are kept");
await patchState({ sessions: (await savedState()).sessions.map((session) => (session.id === practice.id ? { ...session, status: "finished", endedAt: Date.now() } : session)) });
console.log("PASS a new layout during open practice restarts every driver's best lap");
await patchState({ sessions: (await savedState()).sessions.map((session) => (session.id === quali.id ? { ...session, status: "running", startedAt: Date.now() } : session)) });
await navigate("training", "view");
const dialogCount = dialogs.length;
await evaluate(`document.querySelector("[data-track-layout-new]").click()`);
await waitFor(async () => dialogs.slice(dialogCount).some((dialog) => dialog.type === "alert" && dialog.message.includes("TL Q1")), "blocked with a message naming the running race");
assert.equal((await savedState()).trackLayouts.length, 1, "no layout was added while the race ran");
assert.equal((await savedState()).trackLayouts.length, 2, "no layout was added while the race ran");
console.log("PASS a new track layout is refused while a race session is running");
} finally {
dialogs.splice(dialogsAtStart);