Fix lap limits and five-minute stint statistics

This commit is contained in:
larssand
2026-09-02 19:36:25 +02:00
parent f561dd8feb
commit 483a9dbd5a
14 changed files with 356 additions and 110 deletions

View File

@@ -4,12 +4,12 @@ import assert from "node:assert/strict";
import { connectDecoderHelper, processDecoderMessageHelper } from "../src/decoder_runtime.js";
import { ensureSessionResult } from "../src/timing_logic.js";
function createHarness() {
function createHarness(options = {}) {
const session = {
id: "session_1",
eventId: "event_1",
mode: "race",
type: "team_race",
type: options.sessionType || "team_race",
status: "running",
startMode: "mass",
startedAt: 1_000,
@@ -36,7 +36,10 @@ function createHarness() {
getActiveSession: () => session,
ensureSessionResult: (sessionId) => ensureSessionResult(sessionId, { state }),
normalizeStartMode: () => "mass",
getSessionLapWindow: () => ({ minLapMs: 0, maxLapMs: Number.POSITIVE_INFINITY }),
getSessionLapWindow: () => ({
minLapMs: Number(options.minLapMs || 0),
maxLapMs: options.maxLapMs == null ? Number.POSITIVE_INFINITY : Number(options.maxLapMs),
}),
findEventTeamForPassing: (event, driverId) => event.teams.find((team) => team.driverIds.includes(driverId)) || null,
persistPassingToBackend: () => {},
pushOverlayEvent: (type, label) => overlayEvents.push({ type, label }),
@@ -74,6 +77,28 @@ test("split decoder records intermediate time without changing main lap state",
assert.equal(result.passings.length, 1);
});
test("minimum lap time rejects a shortcut without adding a lap", () => {
const harness = createHarness({ minLapMs: 10_000, maxLapMs: 120_000 });
harness.passing(6_000, "main");
const result = harness.state.resultsBySession.session_1;
assert.equal(result.competitors.team_team_1.laps, 0);
assert.equal(result.passings[0].validLap, false);
assert.equal(result.passings[0].invalidReason, "below_min");
});
test("maximum lap time starts a statistics stint but still counts the race lap", () => {
const harness = createHarness({ minLapMs: 10_000, maxLapMs: 60_000 });
harness.passing(121_001, "main");
const result = harness.state.resultsBySession.session_1;
assert.equal(result.competitors.team_team_1.laps, 1);
assert.equal(result.passings[0].validLap, true);
assert.equal(result.passings[0].validationWarning, "above_max_stint");
assert.equal(result.passings[0].excludedFromPace, true);
assert.equal(result.passings[0].stintBoundary, true);
});
test("pit entry and exit create one timed stop without adding laps", () => {
const harness = createHarness();
harness.passing(17_000, "main");