fix(race): finish the lap you are on, one clock owner, edits survive refresh, participants editable (1.59.0)

This commit is contained in:
larssand committed 2026-11-04 21:34:06 +01:00
1 parent afb8829b16
commit db6a9f19e4
16 files changed
+313 -39

No files matched your search

+28 -3
View File
@@ -51,15 +51,40 @@ test("session timer emits each race-audio clock marker once without changing fin
setLastFinishAnnouncementSessionId: () => {},
announceRaceFinished: () => announced.push("race_finished"),
announceRaceClockEvent: (key) => announced.push(key),
getFinishWait: () => wait,
now: () => clock,
});
let clock = 1_000_000;
let wait = { allFinished: false, closeAt: clock + 20_000 };
run(); run();
remainingMs = 29_000; run();
remainingMs = 9_000; run();
remainingMs = 0; run();
assert.deepEqual(announced, ["one_minute_remaining", "thirty_seconds_remaining", "ten_seconds_remaining", "time_expired", "final_lap"]);
assert.equal(active.status, "running");
remainingMs = 0; run(); run();
assert.deepEqual(announced, ["one_minute_remaining", "thirty_seconds_remaining", "ten_seconds_remaining", "time_expired"], "said once, and no separate 'final lap'");
assert.equal(active.status, "running", "waits for the cars to finish their lap");
assert.ok(active.followUpStartedAt);
assert.equal(active.finishWaitUntil, wait.closeAt);
assert.ok(saves >= 4);
wait = { allFinished: true, closeAt: null }; run();
assert.equal(active.status, "finished", "closes as soon as every car has crossed after its time");
assert.deepEqual(announced.slice(-1), ["race_finished"]);
});
test("session timer: a car still out closes the heat at the wait limit; other windows stay quiet", () => {
const make = () => ({ id: "s2", eventId: "e1", type: "qualification", status: "running", startedAt: 1, followUpSec: 10, audioAnnouncements: [] });
const deps = (active, extra) => ({
getActiveSession: () => active, isUntimedSession: () => false,
getSessionTiming: () => ({ remainingMs: 0, targetMs: 300_000 }), saveState: () => {},
getLastFinishAnnouncementSessionId: () => null, setLastFinishAnnouncementSessionId: () => {},
announceRaceFinished: () => {}, announceRaceClockEvent: (key) => extra.announced.push(key), ...extra.deps,
});
const owner = make(); const ownerLog = { announced: [], deps: { getFinishWait: () => ({ allFinished: false, closeAt: 50_000 }), now: () => 50_001 } };
handleSessionTimerTickHelper(deps(owner, ownerLog));
assert.equal(owner.status, "finished");
const other = make(); const otherLog = { announced: [], deps: { isClockOwner: () => false, now: () => 310_000 } };
handleSessionTimerTickHelper(deps(other, otherLog));
assert.deepEqual(otherLog.announced, [], "a second window never calls the clock");
assert.equal(other.status, "running", "and leaves closing the heat to the race browser");
});
test("race audio can ignore a mismatched configured voice and select the announcement language", () => {
+10
View File
@@ -58,6 +58,16 @@ export async function runRaceSetupSmoke({ evaluate, navigate, fill, savedState,
assert.ok(quals.length >= 2 && quals.every((session) => /^Q[12] H\d+$/.test(session.name) && session.generated), `qualifying heats per round: ${quals.map((session) => session.name)}`);
assert.equal(club.raceConfig.qualifyingRounds, 2);
console.log("PASS wizard builds qualifying as Q<round> H<heat> heats");
// A driver left out can be ticked again, and the heats not run yet follow the list.
await click("event-manage-" + club.id);
await waitFor(async () => (await evaluate('document.querySelectorAll(".race-participant").length')) > 0, "participant list");
const first = await evaluate('document.querySelector(".race-participant:checked").value');
await evaluate(`document.querySelector('.race-participant[value="${first}"]').click()`);
await waitFor(async () => !(await savedState()).sessions.some((session) => session.eventId === club.id && session.type === "qualification" && session.driverIds.includes(first)), "unticked driver leaves the heats");
await waitFor(async () => Boolean(await evaluate(`Boolean(document.querySelector('.race-participant[value="${first}"]:not(:checked)'))`)), "unticked driver still listed");
await evaluate(`document.querySelector('.race-participant[value="${first}"]').click()`);
await waitFor(async () => (await savedState()).sessions.some((session) => session.eventId === club.id && session.type === "qualification" && session.driverIds.includes(first)), "ticked again: back in a heat");
console.log("PASS race participants can be changed after creation and the heats follow");
}
await navigate("race_setup", "raceWizardStepForm");
await editEvent(race, "race_setup", "raceWizardStepForm");
+60
View File
@@ -0,0 +1,60 @@
import test from "node:test";
import assert from "node:assert/strict";
import { getCompetitorEndTs, getFinishWait } from "../src/timing_logic.js";
import { syncParticipantsToSessions, applyFormatToPendingSessions } from "../src/event_race_logic.js";
import { keepIdentityById } from "../src/runtime_services.js";
test("finish the lap: each car's own end, then the heat closes when all crossed or the wait runs out", () => {
const flying = { type: "qualification", startMode: "flying", durationMin: 5, startedAt: 0, followUpSec: 10, totalPausedMs: 0 };
assert.equal(getCompetitorEndTs(flying, { startTimestamp: 4000 }), 304000, "own clock from own first crossing");
const mass = { ...flying, startMode: "position", startedAt: 1000 };
assert.equal(getCompetitorEndTs(mass, { startTimestamp: 1000 }), 301000);
assert.equal(getCompetitorEndTs({ ...mass, type: "open_practice" }, {}), null, "rolling practice has no end");
const out = { a: { laps: 10, startTimestamp: 1000, lastLapMs: 30000, finishedAt: 302000 }, b: { laps: 9, startTimestamp: 1000, lastLapMs: 32000 } };
const wait = getFinishWait(mass, out);
assert.equal(wait.allFinished, false);
assert.equal(wait.closeAt, 301000 + 48000, "1.5 x the slow car's own lap, longer than the 10 s follow-up");
assert.equal(getFinishWait(mass, out, { maxLapMs: 40000 }).closeAt, 301000 + 40000, "never longer than max lap time");
out.b.finishedAt = 320000;
assert.equal(getFinishWait(mass, out).allFinished, true);
});
test("the entry list reaches the sessions not run yet", () => {
const sessions = [
{ id: "p", type: "practice", status: "ready", driverIds: ["a", "b", "c"] },
{ id: "q11", name: "Q1 H1", type: "qualification", status: "ready", driverIds: ["a", "b"], manualGridIds: ["a", "b"] },
{ id: "q12", name: "Q1 H2", type: "qualification", status: "ready", driverIds: ["c"], manualGridIds: ["c"] },
{ id: "q21", name: "Q2 H1", type: "qualification", status: "ready", driverIds: ["a", "b"] },
{ id: "q22", name: "Q2 H2", type: "qualification", status: "ready", driverIds: ["c"] },
{ id: "done", name: "Q0 H1", type: "qualification", status: "finished", startedAt: 1, driverIds: ["a", "b"] },
];
syncParticipantsToSessions(sessions, ["a", "b", "c"], ["a", "c", "d"]);
const ids = (id) => sessions.find((session) => session.id === id).driverIds;
assert.deepEqual(ids("p"), ["a", "c", "d"]);
assert.ok(!ids("q11").includes("b") && !ids("q21").includes("b"), "b left every heat to run");
assert.deepEqual(ids("q11"), ["a", "d"], "d joins the smallest heat (a tie goes to the lower heat)");
assert.deepEqual(ids("q21"), ["a", "d"], "the same heat number in every round");
assert.deepEqual(ids("q12"), ["c"]);
assert.deepEqual(ids("done"), ["a", "b"], "a run heat is history");
});
test("a changed race format reaches the sessions not run yet", () => {
const sessions = [
{ type: "qualification", status: "ready", durationMin: 5, startMode: "flying" },
{ type: "qualification", status: "finished", startedAt: 1, durationMin: 5 },
{ type: "final", status: "ready", durationMin: 5 },
{ type: "practice", status: "ready", durationMin: 5 },
];
applyFormatToPendingSessions(sessions, { qualDurationMin: 5, finalDurationMin: 5, qualStartMode: "flying" }, { qualDurationMin: 3, finalDurationMin: 5, qualStartMode: "flying" });
assert.deepEqual(sessions.map((session) => session.durationMin), [3, 5, 5, 3]);
});
test("the background refresh keeps the objects a form already holds", () => {
const held = { id: "s1", durationMin: 5, old: true };
const next = keepIdentityById([held], [{ id: "s1", durationMin: 3 }, { id: "s2" }]);
assert.equal(next[0], held, "same object");
assert.deepEqual(held, { id: "s1", durationMin: 3 }, "with the server's values");
held.durationMin = 4;
assert.equal(next[0].durationMin, 4, "so an edit through the held reference is not lost");
});
+3 -1
View File
@@ -208,7 +208,9 @@ test("getEventDrivers follows the order participants were selected in, not the d
assert.deepEqual(getEventDrivers(event, { state }).map((driver) => driver.id), ["d4", "d2", "d1"], "matches selection order, not directory order, and excludes d3 who was never selected");
const stale = { classId: "2wd", raceConfig: { participantsConfigured: true, driverIds: ["d4", "d5", "d1"] } };
assert.deepEqual(getEventDrivers(stale, { state }).map((driver) => driver.id), ["d4", "d1"], "drops a selected id that no longer belongs to this event's class (d5 is 4wd)");
assert.deepEqual(getEventDrivers(stale, { state }).map((driver) => driver.id), ["d4", "d5", "d1"], "keeps a chosen driver from another class (one driver, two classes)");
const gone = { classId: "2wd", raceConfig: { participantsConfigured: true, driverIds: ["d4", "deleted", "d1"] } };
assert.deepEqual(getEventDrivers(gone, { state }).map((driver) => driver.id), ["d4", "d1"], "drops a driver that no longer exists");
const unconfigured = { classId: "2wd", raceConfig: {} };
assert.deepEqual(getEventDrivers(unconfigured, { state }).map((driver) => driver.id), ["d1", "d2", "d3", "d4"], "before participants are configured, falls back to every driver in the class");
+1
View File
@@ -1,4 +1,5 @@
import "./auth.test.js";
import "./race_day_fixes.test.js";
import "./race_list.test.js";
import "./day_schedule.test.js";
import "./race_day_live.test.js";