Add browser coverage for heat/qualification/final/team_race start sequences

Unlike Open Practice, these session types run the real countdown/light/
audio sequence before a session transitions to "running" - this was
untested beyond Open Practice's instant-start shortcut. Confirms the
Start button shows a real ticking countdown, the right audio events
fire per type (qualifying_start only for qualification), and pause/
resume/finish behave the same as they already do for Open Practice.
All audio effects/voice are silenced via raceAudio.events so the test
depends only on the sequence's own timers, not on real audio/TTS
playback completing in a headless browser with no sound hardware.

Also logs a new roadmap item: indoor clubs that reconfigure the track
layout in the same venue have no way to tell the app a layout change
happened, so PBs/track records/pace baselines silently keep comparing
lap times across incomparable layouts. No design decided yet - open
questions recorded for a future dedicated conversation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
larssand
2026-09-10 13:53:08 +02:00
parent 4c463485e0
commit 90df3378a6
3 changed files with 155 additions and 1 deletions

View File

@@ -0,0 +1,138 @@
import assert from "node:assert/strict";
import { startFakeDecoder } from "./browser_fake_decoder.js";
import { RACE_AUDIO_EVENT_DEFINITIONS } from "../src/race_audio.js";
// Practice types skip the countdown/light/audio sequence entirely (see
// startSessionWithAudio in src/app.js) - already covered by browser_race_day.js.
// heat/qualification/final/team_race all run the real sequence in src/race_audio.js's
// runStartSequence, gating the session's transition to "running" until it completes -
// this file exercises that for each of those four types, plus pause/resume/finish.
//
// Every effect/voice is silenced via raceAudio.events so the sequence's own audio
// playback (real <audio> elements, speechSynthesis) never has to actually complete in a
// headless browser with no sound hardware - only the sequence's own timers (countdown,
// light stepping, start delay) gate progress, which this file sets to near-zero except
// for one full-length run (the heat scenario) that keeps a real countdown to prove the
// countdown display itself updates.
const SILENCED_EVENTS = Object.fromEntries(RACE_AUDIO_EVENT_DEFINITIONS.map((definition) => [definition.key, { effect: false, voice: false }]));
export async function runRaceDayStartSequencesSmoke({ evaluate, navigate, waitFor, pause, base, dialogs = [] }) {
const click = (id) => evaluate(`document.getElementById(${JSON.stringify(id)}).click()`);
const buttonDisabled = async (id) => await evaluate(`document.getElementById(${JSON.stringify(id)})?.disabled`);
const buttonText = async (id) => await evaluate(`document.getElementById(${JSON.stringify(id)})?.textContent`);
const savedState = async () => (await (await fetch(base + "/api/state")).json()).state;
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 findSession = async (id) => (await savedState()).sessions.find((session) => session.id === id);
const recentAudioEventKeys = async (count) => (await savedState()).audioEventLog.slice(0, count).map((entry) => entry.event);
const decoder = await startFakeDecoder();
const seeded = await savedState();
const classId = "rdts_class";
const driverA = { id: "rdts_driver_a", name: "RDTS Driver A", classId, transponder: "7710001" };
const driverB = { id: "rdts_driver_b", name: "RDTS Driver B", classId, transponder: "7710002" };
const event = {
id: "rdts_event",
name: "RDTS Event",
classId,
raceConfig: {
teams: [
{ id: "rdts_team_a", name: "RDTS Team A", driverIds: [driverA.id], carIds: [] },
{ id: "rdts_team_b", name: "RDTS Team B", driverIds: [driverB.id], carIds: [] },
],
},
};
const sessions = [
{ id: "rdts_heat", eventId: event.id, name: "RDTS Heat", type: "heat", durationMin: 5, status: "ready" },
{ id: "rdts_quali", eventId: event.id, name: "RDTS Qualification", type: "qualification", durationMin: 5, status: "ready" },
{ id: "rdts_final", eventId: event.id, name: "RDTS Final", type: "final", durationMin: 5, status: "ready" },
{ id: "rdts_team_race", eventId: event.id, name: "RDTS Team Race", type: "team_race", durationMin: 5, status: "ready" },
];
try {
await patchState({
classes: [...seeded.classes, { id: classId, name: "RDTS Class" }],
drivers: [...seeded.drivers, driverA, driverB],
events: [...seeded.events, event],
sessions: [...seeded.sessions, ...sessions],
settings: {
...seeded.settings,
autoReconnect: true,
wsUrl: `ws://127.0.0.1:${decoder.port}`,
raceAudio: {
...seeded.settings.raceAudio,
enabled: true,
muted: false,
startLights: true,
lightIntervalMs: 100,
randomStartDelay: false,
minStartDelay: 0,
maxStartDelay: 0,
startCountdownSeconds: 0,
events: SILENCED_EVENTS,
},
},
});
// --- Heat: full-length countdown, proving the countdown display itself ticks down
// (not just that the session eventually starts) for a competitive session type. ---
await patchState({ activeSessionId: sessions[0].id, settings: { ...(await savedState()).settings, raceAudio: { ...(await savedState()).settings.raceAudio, startCountdownSeconds: 10 } } });
await navigate("race_day", "raceDayStart");
await waitFor(async () => (await buttonDisabled("raceDayStart")) === false, "heat preflight ready (class-based participants accepted)");
await click("raceDayStart");
assert.equal((await findSession(sessions[0].id)).status, "ready", "heat does not jump straight to running like a practice session");
const observedCountdown = new Set();
const countdownDeadline = Date.now() + 4000;
while (Date.now() < countdownDeadline) {
observedCountdown.add(await buttonText("raceDayStart"));
await pause(300);
}
assert.ok([...observedCountdown].some((text) => /^\d+$/.test(String(text || ""))), "start button showed a ticking countdown digit: " + JSON.stringify([...observedCountdown]));
await waitFor(async () => (await findSession(sessions[0].id)).status === "running", "heat running after its full countdown+light sequence", 20000);
assert.deepEqual(await recentAudioEventKeys(2), ["start_sequence", "drivers_ready"], "heat's sequence announced drivers_ready then start_sequence, no qualifying_start");
console.log("PASS heat start runs a real countdown+light sequence instead of starting instantly");
await click("raceDayPause");
await waitFor(async () => (await findSession(sessions[0].id)).status === "paused", "heat paused");
await click("raceDayResume");
await waitFor(async () => (await findSession(sessions[0].id)).status === "running", "heat resumed");
await click("raceDayFinish");
await waitFor(async () => (await findSession(sessions[0].id)).status === "finished", "heat finished");
console.log("PASS heat pause/resume/finish transitions work the same as open practice");
// --- Qualification, final, team_race: countdownSeconds back to 0 to keep the run
// fast, but the light-stepping/audio-log sequence still runs (not skipped). ---
await patchState({ settings: { ...(await savedState()).settings, raceAudio: { ...(await savedState()).settings.raceAudio, startCountdownSeconds: 0 } } });
for (const [session, expectedRecentKeys, label] of [
[sessions[1], ["start_sequence", "qualifying_start", "drivers_ready"], "qualification"],
[sessions[2], ["start_sequence", "drivers_ready"], "final"],
[sessions[3], ["start_sequence", "drivers_ready"], "team_race"],
]) {
await patchState({ activeSessionId: session.id });
await navigate("race_day", "raceDayStart");
await waitFor(async () => (await buttonDisabled("raceDayStart")) === false, `${label} preflight ready`);
await click("raceDayStart");
await waitFor(async () => (await findSession(session.id)).status === "running", `${label} running after its sequence`, 10000);
assert.deepEqual(await recentAudioEventKeys(expectedRecentKeys.length), expectedRecentKeys, `${label} sequence announced the right events`);
await click("raceDayPause");
await waitFor(async () => (await findSession(session.id)).status === "paused", `${label} paused`);
await click("raceDayResume");
await waitFor(async () => (await findSession(session.id)).status === "running", `${label} resumed`);
await click("raceDayFinish");
await waitFor(async () => (await findSession(session.id)).status === "finished", `${label} finished`);
console.log(`PASS ${label} runs the real start sequence (not the practice shortcut) and supports pause/resume/finish`);
}
assert.deepEqual(dialogs, [], "no unexpected native dialog during the start-sequence flow");
} finally {
const cleanup = await savedState();
await patchState({ settings: { ...cleanup.settings, autoReconnect: false, raceAudio: seeded.settings.raceAudio } });
await decoder.close();
}
}