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

@@ -136,6 +136,27 @@ test("flying start: a car first seen after the latest clock start gets that cloc
assert.equal(byDriver("driver_2").lastLapMs, 14_000);
});
test("personal best is per session and track layout - not per stint, and an old layout's time doesn't count", () => {
const harness = createHarness({ sessionType: "open_practice" });
harness.session.trackLayoutId = "layout_a";
const entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];
const pbs = () => harness.audioEvents.filter((event) => event === "personal_best").length;
harness.passing(21_000, "main"); // 20 s
harness.passing(39_000, "main"); // 18 s -> PB
assert.equal(pbs(), 1);
harness.passing(200_000, "main"); // long break: a new stint, but the 18 s best still stands
harness.passing(219_000, "main"); // 19 s - no PB
assert.equal(pbs(), 1, "a new stint doesn't reset the personal best");
assert.equal(entry().bestLapMs, 18_000);
harness.session.trackLayoutId = "layout_b"; // the track was rebuilt mid-practice
harness.passing(244_000, "main"); // 25 s on the new layout - first lap there, no PB call
assert.equal(entry().bestLapMs, 25_000, "the old layout's 18 s no longer counts");
harness.passing(268_000, "main"); // 24 s -> PB on the new layout
assert.equal(pbs(), 2);
assert.equal(harness.state.resultsBySession.session_1.passings.at(-1).trackLayoutId, "layout_b", "each lap remembers its layout");
});
test("pit entry and exit create one timed stop without adding laps", () => {
const harness = createHarness();
harness.passing(17_000, "main");