A "practice" session used as a scheduled slot in a structured race/sponsor event's session plan silently skipped the entire countdown/lights/start-tone ceremony and jumped straight to running, unlike qualifying/heat/final. Narrowed the ceremony-skip check to only the standalone "Quick Open Practice" shortcut and free_practice (both rolling/best-lap ranked with no fixed roster) - "practice" is already ranked like a real timed session in every other respect and now gets the same start sequence. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
158 lines
9.8 KiB
JavaScript
158 lines
9.8 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { startFakeDecoder } from "./browser_fake_decoder.js";
|
|
import { RACE_AUDIO_EVENT_DEFINITIONS } from "../src/race_audio.js";
|
|
|
|
// Only the casual, come-and-go practice modes (open_practice - the standalone "Quick Open
|
|
// Practice" shortcut - and free_practice) skip the countdown/light/audio sequence entirely
|
|
// (see startSessionWithAudio in src/app.js). "practice" is a proper scheduled slot in a
|
|
// structured event's session plan and, like heat/qualification/final/team_race, runs 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 five types,
|
|
// plus pause/resume/finish, and separately confirms open_practice still skips it.
|
|
//
|
|
// 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" },
|
|
{ id: "rdts_practice", eventId: event.id, name: "RDTS Practice", type: "practice", durationMin: 5, status: "ready" },
|
|
{ id: "rdts_open_practice", eventId: event.id, name: "RDTS Open Practice", type: "open_practice", 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"],
|
|
[sessions[4], ["start_sequence", "drivers_ready"], "practice"],
|
|
]) {
|
|
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`);
|
|
}
|
|
|
|
// --- open_practice: the standalone "Quick Open Practice" shortcut still skips the
|
|
// ceremony entirely and jumps straight to running, unlike the scheduled "practice"
|
|
// type just proven above. ---
|
|
const beforeOpenPracticeLog = (await savedState()).audioEventLog.length;
|
|
await patchState({ activeSessionId: sessions[5].id });
|
|
await navigate("race_day", "raceDayStart");
|
|
await waitFor(async () => (await buttonDisabled("raceDayStart")) === false, "open_practice preflight ready");
|
|
await click("raceDayStart");
|
|
await waitFor(async () => (await findSession(sessions[5].id)).status === "running", "open_practice jumps straight to running", 5000);
|
|
const afterOpenPracticeLog = (await savedState()).audioEventLog;
|
|
const newOpenPracticeEntries = afterOpenPracticeLog.slice(0, afterOpenPracticeLog.length - beforeOpenPracticeLog);
|
|
assert.deepEqual(newOpenPracticeEntries.map((entry) => entry.event), [], "open_practice still skips the whole ceremony - no new audio events logged: " + JSON.stringify(newOpenPracticeEntries.map((e) => e.event)));
|
|
console.log("PASS open_practice (Quick Open Practice shortcut) still skips the countdown/lights/audio ceremony entirely");
|
|
|
|
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();
|
|
}
|
|
}
|