feat(decoder): warn when the decoder's clock is off (1.42.4)

The decoder's time is never changed. Passings (also during warm-up)
measure it against the computer's clock, and Race Day's preflight and
the decoder diagnostics warn when it is over a minute off, e.g. after
the switch to winter time.
This commit is contained in:
larssand committed 2026-10-25 18:40:35 +01:00
1 parent ca88fd9ecc
commit 35eb3eb059
14 files changed
+180 -5

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
import assert from "node:assert/strict";
import { startFakeDecoder } from "./browser_fake_decoder.js";
// The decoder's clock is set by hand and missed the switch to winter time: one hour ahead.
// RaceCore never changes it, but Race Day's preflight and the decoder diagnostics say so - from
// passings before the heat starts (warm-up), so it can be fixed before the first lap counts.
export async function runDecoderClockSmoke({ evaluate, navigate, savedState, waitFor, base }) {
const patchState = async (patch) => {
const current = await savedState();
Object.assign(current, patch);
const response = await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(current) });
assert.equal(response.ok, true);
};
const decoder = await startFakeDecoder();
const seeded = await savedState();
await patchState({
events: [...seeded.events, { id: "dc_event", name: "DC Race", mode: "race", raceConfig: {} }],
sessions: [...seeded.sessions.map((session) => (["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)), { id: "dc_heat", eventId: "dc_event", name: "DC Heat", type: "heat", status: "ready", durationMin: 5 }],
activeSessionId: "dc_heat",
settings: { ...seeded.settings, autoReconnect: true, wsUrl: `ws://127.0.0.1:${decoder.port}` },
});
const preflightText = () => evaluate(`document.getElementById("view").innerText`);
try {
await navigate("race_day", "raceDaySessionSelect");
await waitFor(async () => evaluate('document.getElementById("connectionBadge")?.classList.contains("badge-online")'), "decoder connected");
assert.doesNotMatch(await preflightText(), /Decoder clock/, "nothing before a passing");
decoder.sendPassing("8660001", Date.now() + 3600000);
await waitFor(async () => /Decoder clock[\s\S]*1 h ahead of the computer/.test(await preflightText()), "Race Day warns that the decoder is one hour ahead");
assert.equal((await savedState()).sessions.find((session) => session.id === "dc_heat").status, "ready", "measured during warm-up, nothing started");
console.log("PASS Race Day warns before the start when the decoder's clock is an hour off (summer/winter time)");
await navigate("settings", "settingsForm");
await evaluate(`document.querySelector('[data-settings-tab="connection"]').click()`);
await evaluate(`(() => { const details = document.getElementById("decoderDiagnostics"); details.open = true; details.dispatchEvent(new Event("toggle")); })()`);
decoder.sendPassing("8660001", Date.now() + 3600000);
await waitFor(async () => /Decoder clock: 1 h ahead of the computer/.test(await evaluate(`document.getElementById("decoderDiagnostics").innerText`)), "the diagnostics show it too");
console.log("PASS the decoder diagnostics show how far the decoder's clock is off");
} finally {
const current = await savedState();
await patchState({
settings: { ...current.settings, autoReconnect: false },
sessions: current.sessions.filter((session) => session.id !== "dc_heat"),
events: current.events.filter((event) => event.id !== "dc_event"),
activeSessionId: "",
});
await decoder.close();
}
}
+2
View File
@@ -15,6 +15,7 @@ import { runPracticeResetSmoke } from "./browser_practice_reset.js";
import { runSuspectLapsSmoke } from "./browser_suspect_laps.js";
import { runOverlayDriverLinkSmoke } from "./browser_overlay_driver_link.js";
import { runProfileClassSmoke } from "./browser_profile_class.js";
import { runDecoderClockSmoke } from "./browser_decoder_clock.js";
import { runCorrectionsScopeSmoke } from "./browser_corrections_scope.js";
import { runDriversPageSmoke } from "./browser_drivers_page.js";
import { runSeriesSmoke } from "./browser_series.js";
@@ -166,6 +167,7 @@ try {
await runPracticeResetSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
await runSuspectLapsSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
await runOverlayDriverLinkSmoke({ evaluate, navigate, savedState, waitFor, base, send });
await runDecoderClockSmoke({ evaluate, navigate, savedState, waitFor, base });
await runCorrectionsScopeSmoke({ evaluate, navigate, savedState, waitFor, base });
await runDriversPageSmoke({ evaluate, navigate, savedState, waitFor, base });
await runSeriesSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
+31
View File
@@ -0,0 +1,31 @@
import test from "node:test";
import assert from "node:assert/strict";
import { createDecoderClockCheck, describeDecoderClockSkew } from "../src/decoder_clock_check.js";
const HOUR = 3600000;
test("a decoder still on summer time shows as one hour ahead; one in step shows nothing", () => {
const check = createDecoderClockCheck();
const now = Date.UTC(2026, 9, 25, 17, 21, 0);
check.record("main", now + HOUR + 40, now); // decoder says 19:21, the computer 18:21
assert.deepEqual(describeDecoderClockSkew(check.skewMs("main")), { ahead: true, hours: 1, minutes: 0 });
const inStep = createDecoderClockCheck();
inStep.record("main", now - 30, now); // 30 ms on the network
assert.equal(describeDecoderClockSkew(inStep.skewMs("main")), null);
assert.equal(describeDecoderClockSkew(null), null, "nothing before the first passing");
});
test("a passing delivered late doesn't make the clock look wrong", () => {
const check = createDecoderClockCheck();
const now = 10 * HOUR;
check.record("main", now - 20, now);
check.record("main", now - 10 * 60000, now + 50); // resent after a reconnect, 10 minutes old
assert.equal(describeDecoderClockSkew(check.skewMs("main")), null);
});
test("minutes off are reported as minutes, behind as not ahead", () => {
const check = createDecoderClockCheck();
check.record("main", 1_000_000, 1_000_000 + 12 * 60000);
assert.deepEqual(describeDecoderClockSkew(check.skewMs("main")), { ahead: false, hours: 0, minutes: 12 });
assert.equal(check.skewMs("split"), null, "each decoder is measured on its own");
});
+11
View File
@@ -113,3 +113,14 @@ test("preflight shortcuts respect driver, shared-car and team setup", async () =
assert.equal(action({ id: "lap_window", level: "warning" }, { mode: "race" }).field, "minLapSec");
assert.equal(action({ id: "decoder", level: "ok" }), null);
});
test("Race Day preflight warns when the decoder's clock is off, but never blocks the start", () => {
const state = createState();
state.decoder.clockSkewMs = -3600000 - 40; // the decoder still on summer time: one hour ahead
const result = buildRaceDayPreflight(state, state.sessions[0], { backendAvailable: true });
const clock = result.checks.find((item) => item.id === "decoder_clock");
assert.deepEqual({ level: clock.level, ahead: clock.ahead, hours: clock.hours, minutes: clock.minutes }, { level: "warning", ahead: true, hours: 1, minutes: 0 });
assert.equal(result.ready, true, "a warning: the operator decides");
state.decoder.clockSkewMs = 25; // network delay only
assert.equal(buildRaceDayPreflight(state, state.sessions[0], { backendAvailable: true }).checks.some((item) => item.id === "decoder_clock"), false);
});
+1
View File
@@ -1,4 +1,5 @@
import "./auth.test.js";
import "./decoder_clock_check.test.js";
import "./practice_callouts_logic.test.js";
import "./local_cache.test.js";
import "./prologue_logic.test.js";