feat(judging): judge finished heats, DSQ/DNF, reasons, own time and driver calls per EFRA (1.70.0)

This commit is contained in:
larssand committed 2026-11-05 23:31:01 +01:00
1 parent 2e3676d0cd
commit be99cfaab2
17 files changed
+399 -25

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
import assert from "node:assert/strict";
// Judging after the race: a finished qualifier can be picked under Judging (a protest, a car
// found illegal) - a time penalty with a reason and a DSQ change the result straight away.
export async function runJudgingAfterRaceSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs }) {
const dialogsAtStart = dialogs.length;
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 seeded = await savedState();
const startedAt = Date.now() - 900000;
const event = { id: "ja_event", name: "JA Cup", mode: "race", raceConfig: {} };
const heat = { id: "ja_q1", eventId: event.id, name: "Q1 H1", type: "qualification", mode: "race", status: "finished", durationMin: 5, startedAt, endedAt: startedAt + 300000 };
const competitor = (id, laps, lastTs) => ({ key: id, driverId: id, driverName: id, displayName: id, transponder: id, laps, bestLapMs: 18000, lastLapMs: 18000, startTimestamp: startedAt, lastTimestamp: lastTs });
await patchState({
drivers: [...seeded.drivers, { id: "JA Winner", name: "JA Winner", transponder: "8550001" }, { id: "JA Second", name: "JA Second", transponder: "8550002" }],
events: [...seeded.events, event],
sessions: [...seeded.sessions.map((session) => (["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)), heat],
resultsBySession: { ...seeded.resultsBySession, [heat.id]: { passings: [], adjustments: [], competitors: { "JA Winner": competitor("JA Winner", 17, startedAt + 300000), "JA Second": competitor("JA Second", 16, startedAt + 301000) } } },
activeSessionId: null,
});
const competitors = async () => (await savedState()).resultsBySession.ja_q1.competitors;
await navigate("judging", "speakerPanel");
await waitFor(async () => evaluate(`Boolean(document.querySelector('#judgingSessionSelect option[value="ja_q1"]'))`), "the finished heat can be picked");
await evaluate(`(() => { const select = document.getElementById("judgingSessionSelect"); select.value = "ja_q1"; select.dispatchEvent(new Event("change")); })()`);
await waitFor(async () => evaluate(`Boolean(document.getElementById("judgeDsq"))`), "the winner is selected with the penalty buttons");
assert.match(await evaluate(`document.querySelector(".judge-selected-row")?.textContent || ""`), /JA Winner/);
assert.equal(await evaluate(`Boolean(document.querySelector("[data-judge-call]"))`), false, "no calls to the driver after the race");
await evaluate(`(() => { document.getElementById("judgeReason").value = "Unfair overtake"; document.getElementById("judgeCustomSec").value = "10"; document.getElementById("judgeCustomApply").click(); })()`);
await waitFor(async () => (await competitors())["JA Winner"].manualTimeAdjustmentMs === 10000, "+10 s saved");
assert.ok((await savedState()).resultsBySession.ja_q1.adjustments.some((entry) => entry.reason === "Unfair overtake"), "the reason is logged");
await evaluate(`document.getElementById("judgeDsq").click()`);
await waitFor(async () => (await competitors())["JA Winner"].raceStatus === "dsq", "DSQ saved");
await waitFor(async () => /JA Second/.test(await evaluate(`document.querySelector("#judgingCompetitorFilter")?.closest(".panel")?.querySelector("tbody tr")?.textContent || ""`)), "the disqualified winner drops to last");
assert.ok(dialogs.slice(dialogsAtStart).some((dialog) => dialog.type === "confirm" && /JA Winner/.test(dialog.message)), "DSQ asks first");
dialogs.splice(dialogsAtStart);
console.log("PASS judging after the race: pick a finished heat, +10 s with a reason, DSQ puts the driver last");
}
+2
View File
@@ -13,6 +13,7 @@ import { runTrackLayoutsSmoke } from "./browser_track_layouts.js";
import { runPrologueSmoke } from "./browser_prologue.js";
import { runPracticeResetSmoke } from "./browser_practice_reset.js";
import { runPracticeRankingSmoke, runSpeakerPanelSmoke } from "./browser_practice_ranking.js";
import { runJudgingAfterRaceSmoke } from "./browser_judging_after.js";
import { runSuspectLapsSmoke } from "./browser_suspect_laps.js";
import { runOverlayDriverLinkSmoke } from "./browser_overlay_driver_link.js";
import { runProfileClassSmoke } from "./browser_profile_class.js";
@@ -169,6 +170,7 @@ try {
await runPracticeResetSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
await runPracticeRankingSmoke({ evaluate, navigate, savedState, waitFor, base });
await runSpeakerPanelSmoke({ evaluate, navigate, savedState, waitFor });
await runJudgingAfterRaceSmoke({ 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 });
+80
View File
@@ -0,0 +1,80 @@
import test from "node:test";
import assert from "node:assert/strict";
import { applyCompetitorCorrection, setCompetitorRaceStatus, logRaceControlCall, countOfficialWarnings, undoJudgingAdjustment, getJudgeFilteredLog } from "../src/judging_logic.js";
import { buildQualifyingStandings, buildFinalStandings, getQualifyingPointsValue, isHighPointsTable, compareNumberSet, hasQualifyingPrimaryTie, buildQualifyingTieBreakNote } from "../src/timing_logic.js";
function harness() {
const result = { passings: [], competitors: { d1: { key: "d1", driverName: "One" }, d2: { key: "d2", driverName: "Two" } }, adjustments: [] };
let id = 0;
const deps = { ensureSessionResult: () => result, uid: (p) => `${p}_${++id}`, t: (key) => key, formatLap: (ms) => `${ms}ms`, saveState: () => {}, findPassingByUndoMarker: () => null, recalculateCompetitorFromPassings: () => {} };
return { result, deps, session: { id: "s1", status: "finished" } };
}
test("a time penalty after the race keeps its reason in the log", () => {
const { result, deps, session } = harness();
applyCompetitorCorrection(session, result.competitors.d1, { timeMsDelta: 10000, reason: "Unfair overtake" }, deps);
assert.equal(result.competitors.d1.manualTimeAdjustmentMs, 10000);
assert.match(result.adjustments[0].detail, /Unfair overtake/);
assert.equal(result.adjustments[0].reason, "Unfair overtake");
});
test("DSQ / DNF are set, logged with the reason, and undone back to what was there", () => {
const { result, deps, session } = harness();
assert.equal(setCompetitorRaceStatus(session, result.competitors.d1, "dnf", {}, deps), true);
assert.equal(setCompetitorRaceStatus(session, result.competitors.d1, "dsq", { reason: "Car not legal" }, deps), true);
assert.equal(result.competitors.d1.raceStatus, "dsq");
assert.equal(result.adjustments[1].detail, "Car not legal");
assert.equal(setCompetitorRaceStatus(session, result.competitors.d1, "dsq", {}, deps), false, "no change, nothing logged");
assert.equal(undoJudgingAdjustment(session, result.adjustments[1].id, deps), true);
assert.equal(result.competitors.d1.raceStatus, "dnf");
assert.equal(undoJudgingAdjustment(session, result.adjustments[0].id, deps), true);
assert.equal(result.competitors.d1.raceStatus, undefined);
});
test("race-control calls are logged; official warnings are counted, undone ones not", () => {
const { result, deps, session } = harness();
logRaceControlCall(session, result.competitors.d2, "stop_and_go", { reason: "Hit a car" }, deps);
const first = logRaceControlCall(session, result.competitors.d2, "official_warning", {}, deps);
logRaceControlCall(session, result.competitors.d2, "official_warning", {}, deps);
assert.equal(logRaceControlCall(session, result.competitors.d2, "nonsense", {}, deps), null);
assert.equal(countOfficialWarnings(result, "d2"), 2);
undoJudgingAdjustment(session, first.id, deps);
assert.equal(countOfficialWarnings(result, "d2"), 1);
assert.equal(getJudgeFilteredLog(result.adjustments, "calls").length, 3);
});
const qualDeps = (rowsBySession, entrants) => ({
getSessionsForEvent: () => Object.keys(rowsBySession).map((id) => ({ id, type: "qualification", name: id, status: "finished" })),
buildLeaderboard: (session) => rowsBySession[session.id],
getSessionEntrants: () => entrants,
isHighPointsTable, getQualifyingPointsValue, compareNumberSet, hasQualifyingPrimaryTie,
buildQualifyingTieBreakNote: (row, tieBreak) => buildQualifyingTieBreakNote(row, tieBreak, { t: (key) => key, formatLap: (ms) => `${ms}` }),
formatLap: (ms) => `${ms}`, formatRaceClock: (ms) => `${ms}`, t: (key) => key,
});
test("EFRA: a DSQ in a qualifying round scores last-place points there, its laps don't count", () => {
const entrants = [{ id: "d1", name: "One" }, { id: "d2", name: "Two" }, { id: "d3", name: "Three" }];
const rows = {
q1: [
{ driverId: "d2", driverName: "Two", comparisonMs: 15000, bestLapMs: 15000, resultDisplay: "a" },
{ driverId: "d3", driverName: "Three", comparisonMs: 16000, bestLapMs: 16000, resultDisplay: "b" },
{ driverId: "d1", driverName: "One", comparisonMs: Number.MAX_SAFE_INTEGER, bestLapMs: 14000, resultDisplay: "DSQ", raceStatus: "dsq" },
],
};
const standings = buildQualifyingStandings({ id: "e", raceConfig: { qualifyingPointsTable: "rank_low" } }, qualDeps(rows, entrants));
assert.deepEqual(standings.map((row) => row.driverId), ["d2", "d3", "d1"]);
assert.equal(standings[2].bestSingleLapMs, Number.MAX_SAFE_INTEGER, "the disqualified run's fastest lap doesn't count");
});
test("a DSQ in a final is classified last in it, behind a driver who did not start", () => {
const sessions = [{ id: "a", type: "final", name: "A Final", status: "finished" }];
const rows = [
{ driverId: "d1", driverName: "One", totalElapsedMs: 300000, raceStatus: "dsq" },
{ driverId: "d2", driverName: "Two", totalElapsedMs: 301000 },
];
const standings = buildFinalStandings({ id: "e", raceConfig: {} }, {
getSessionsForEvent: () => sessions, buildLeaderboard: () => rows,
getSessionEntrants: () => [{ id: "d1", name: "One" }, { id: "d2", name: "Two" }, { id: "d3", name: "Three" }], t: (key) => key,
});
assert.deepEqual(standings.map((row) => row.driverId), ["d2", "d3", "d1"]);
});
+1 -1
View File
@@ -195,7 +195,7 @@ test("event catalog covers every supported race-audio event", () => {
[
"grid_open", "grid_closed", "race_1_minute", "race_30_seconds", "race_10_seconds", "drivers_ready", "start_sequence", "start_tone", "false_start", "restart_race", "staggered_release", "prologue_start", "prologue_minutes", "prologue_grid", "prologue_count", "prologue_hold", "prologue_resumed", "prologue_cancelled", "clock_running",
"transponder_pass", "lap_completed", "personal_best", "fastest_lap", "track_record", "training_stable_pace", "new_leader", "position_gain", "position_loss", "final_lap", "one_minute_remaining", "thirty_seconds_remaining", "ten_seconds_remaining", "time_expired", "race_finished",
"track_call", "track_clear", "yellow_flag", "red_flag", "race_paused", "race_resumed", "marshal_warning", "marshal_required", "penalty", "stop_and_go", "drive_through", "disqualified",
"track_call", "track_clear", "yellow_flag", "red_flag", "race_paused", "race_resumed", "marshal_warning", "marshal_required", "penalty", "stop_and_go", "drive_through", "disqualified", "driver_attention", "official_warning",
"pit_lane_open", "pit_lane_closed", "entering_pits", "leaving_pits", "pit_speed_warning",
"qualifying_start", "qualifying_remaining", "qualifying_finished", "provisional_pole", "pole_position",
"race_winner", "second_place", "third_place", "podium", "heat_winner", "overall_winner",
+1
View File
@@ -1,4 +1,5 @@
import "./auth.test.js";
import "./judging_penalties.test.js";
import "./practice_rank.test.js";
import "./team_race_logic.test.js";
import "./race_overview.test.js";