From a8996c4195eba5b2269e2bd8889fc003967f5c8a Mon Sep 17 00:00:00 2001 From: larssand Date: Tue, 3 Nov 2026 08:46:51 +0100 Subject: [PATCH] fix(race-day): run again resets the current heat, not a stale copy; show the set time before the start (1.54.2) --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- src/app.js | 11 +++++++++++ src/timing_logic.js | 3 ++- tests/browser_race_day_quick.js | 4 ++++ tests/race_timing_logic.test.js | 5 +++++ 7 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 388d359..5a1b5ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ The application version is maintained in `package.json` and displayed in the adm No changes recorded yet. +## 1.54.2 - 2026-11-03 + +### Fixed + +- ↻ Run again on a stopped heat could leave the clock at the time it was stopped (e.g. 4:32) and keep the laps. The page refreshes its data from the server every 15 s, and the button then still held an old copy of the heat; Run again, Start, Pause, Resume and Finish now always work on the heat as it is now. +- Before the start, a staggered heat's clock shows the time set for it (5:00) instead of 5 minutes plus the time it takes to release every car. + ## 1.54.1 - 2026-11-02 ### Fixed diff --git a/package-lock.json b/package-lock.json index c5cde1a..8150107 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rc-racecore", - "version": "1.54.1", + "version": "1.54.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rc-racecore", - "version": "1.54.1", + "version": "1.54.2", "hasInstallScript": true, "dependencies": { "better-sqlite3": "^12.11.1", diff --git a/package.json b/package.json index 3e6445d..38f2b49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-racecore", - "version": "1.54.1", + "version": "1.54.2", "private": true, "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "engines": { diff --git a/src/app.js b/src/app.js index fd78fad..112987f 100644 --- a/src/app.js +++ b/src/app.js @@ -530,7 +530,14 @@ const renderBoard = () => { // --- Race Day as the place where things are run -------------------------------------- // "New practice day": clears the session's laps on Timing for a new day; every lap so far // is first put in the training stats, where resultsResetAt keeps it (see syncTrainingLedger). +// The session as it is in state now. A background refresh from the server replaces every +// session object without redrawing the page, so a button may still hold an old copy; changing +// that copy would change nothing (e.g. Run again left the clock at 4:32). +function currentSession(session) { + return (session && state.sessions.find((item) => item.id === session.id)) || session; +} function resetSessionData(session) { + session = currentSession(session); if (!session) return false; syncTrainingLedger(); session.resultsResetAt = Date.now(); @@ -5627,6 +5634,7 @@ function saveState(options = {}) { } async function startOperationalSession(session, callbacks = {}) { + session = currentSession(session); if (!session) return { ok: false, message: t("race_day.start_failed") }; const { requirePreflight = false, onTone, ...sequenceCallbacks } = callbacks; if (session.mode === "track") { @@ -5709,6 +5717,7 @@ function saveOperationalLapWindow(session, minLapSec, maxLapSec) { } function finishOperationalSession(session) { + session = currentSession(session); if (!session) return false; cancelRaceStart(); state.activeSessionId = session.id; @@ -5722,6 +5731,7 @@ function finishOperationalSession(session) { } function pauseOperationalSession(session) { + session = currentSession(session); if (!pauseSessionControl(session)) return false; triggerRaceAudio("race_paused", { interrupt: true, force: true, logData: { raceId: session.eventId, sessionId: session.id } }); saveState(); @@ -5730,6 +5740,7 @@ function pauseOperationalSession(session) { } function resumeOperationalSession(session) { + session = currentSession(session); if (!resumeSessionControl(session)) return false; triggerRaceAudio("race_resumed", { interrupt: true, force: true, logData: { raceId: session.eventId, sessionId: session.id } }); saveState(); diff --git a/src/timing_logic.js b/src/timing_logic.js index 424fd44..1b73247 100644 --- a/src/timing_logic.js +++ b/src/timing_logic.js @@ -129,7 +129,8 @@ export function getSessionTiming(session, nowTs = Date.now(), { getSessionTarget return { targetMs, elapsedMs, - remainingMs: targetMs === null ? null : Math.max(0, targetMs - elapsedMs), + // Before the start the clock shows the time set for the heat (5:00), not the release extension. + remainingMs: targetMs === null ? null : !startedAt ? baseTargetMs : Math.max(0, targetMs - elapsedMs), untimed: targetMs === null, followUpActive, followUpRemainingMs, diff --git a/tests/browser_race_day_quick.js b/tests/browser_race_day_quick.js index 3ba0221..54baa99 100644 --- a/tests/browser_race_day_quick.js +++ b/tests/browser_race_day_quick.js @@ -58,12 +58,16 @@ export async function runRaceDayQuickSmoke({ evaluate, navigate, savedState, wai await evaluate(`(() => { const select = document.getElementById("raceDaySessionSelect"); select.value = "rq_done"; select.dispatchEvent(new Event("change")); })()`); await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayResetSession")`)), "Run again for the finished heat"); assert.equal(await evaluate(`document.getElementById("raceDayResetSession").textContent.trim()`), "↻ Run again"); + // The page refreshes its data from the server every 15 s without redrawing; Run again must + // still reset the heat itself, not an old copy of it (the clock used to stay at 4:32). + await new Promise((resolve) => setTimeout(resolve, 16000)); await evaluate(`document.getElementById("raceDayResetSession").click()`); await waitFor(async () => (await savedState()).sessions.find((session) => session.id === "rq_done")?.status === "ready", "the heat is ready to run again"); const reset = (await savedState()).sessions.find((session) => session.id === "rq_done"); assert.deepEqual([reset.startedAt || null, reset.endedAt || null, reset.finishedByTimer], [null, null, false], "the clock is back at zero"); assert.equal((await savedState()).resultsBySession.rq_done?.passings?.length || 0, 0, "its laps are cleared"); await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayStart")`)), "Start is offered again"); + assert.equal(await evaluate(`document.querySelector("[data-race-day-clock]").textContent.trim()`), "05:00", "the clock shows the full time again"); console.log("PASS a finished heat can be picked and reset: clock to zero, laps cleared, Start again"); // The race controller follows the heat on Race Day: order, laps, last/best lap, estimate. diff --git a/tests/race_timing_logic.test.js b/tests/race_timing_logic.test.js index fab3004..f51f271 100644 --- a/tests/race_timing_logic.test.js +++ b/tests/race_timing_logic.test.js @@ -620,6 +620,11 @@ test("session timing handles untimed practice, countdown, and follow-up", () => assert.equal(untimed.untimed, true); assert.equal(untimed.remainingMs, null); assert.equal(untimed.elapsedMs, 60000); + + // A staggered heat not (yet / again) started shows the time set for it, not the release extension. + const staggered = { type: "qualification", durationMin: 5, startMode: "staggered", staggerGapSec: 3, manualGridIds: ["a", "b", "c", "d", "e", "f"] }; + assert.equal(getSessionTiming(staggered, 5000, { getSessionTargetMs: getTarget }).remainingMs, 300000); + assert.equal(getSessionTiming({ ...staggered, startedAt: 1000 }, 1000, { getSessionTargetMs: getTarget }).remainingMs, 315000, "the running clock keeps the extension"); }); // Regression coverage for the user's report: a staggered-start qualifying heat with 4