fix(sync): a save from an older copy can no longer put a run heat back to ready (1.89.37)

This commit is contained in:
larssand committed 2026-11-15 16:35:43 +01:00
1 parent 93c590e5b8
commit cea278518e
7 files changed
+104 -6

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
import test from "node:test";
import assert from "node:assert/strict";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const { keepStartedSessions } = require("../server/session_guard.js");
const stored = () => ({
sessions: [
{ id: "a1", status: "finished", startedAt: 100, endedAt: 400 },
{ id: "a2", status: "running", startedAt: 500 },
{ id: "a3", status: "ready", startedAt: null },
],
resultsBySession: { a1: { competitors: { k: { laps: 14 } } }, a2: { competitors: { k: { laps: 3 } } } },
});
test("a save from an older copy (the second computer, not master) can't put run heats back to ready", () => {
const incoming = {
sessions: [{ id: "a1", status: "ready", startedAt: null }, { id: "a2", status: "ready", startedAt: null }, { id: "a3", status: "ready", startedAt: null }],
resultsBySession: {},
};
const { state, kept } = keepStartedSessions(incoming, stored());
assert.deepEqual(kept, ["a1", "a2"]);
assert.equal(state.sessions[0].status, "finished");
assert.equal(state.sessions[1].status, "running");
assert.equal(state.resultsBySession.a1.competitors.k.laps, 14, "A final 1's laps are kept");
});
test("a copy from while a heat was running can't undo its finish", () => {
const incoming = { sessions: [{ id: "a1", status: "running", startedAt: 100 }], resultsBySession: { a1: { competitors: {} } } };
const { state, kept } = keepStartedSessions(incoming, stored());
assert.deepEqual(kept, ["a1"]);
assert.equal(state.sessions[0].status, "finished");
});
test("Reset still works, and a copy from before the reset can't bring the old run back", () => {
const reset = { sessions: [{ id: "a1", status: "ready", startedAt: null, resultsResetAt: 900 }], resultsBySession: { a1: { competitors: {} } } };
const after = keepStartedSessions(reset, stored());
assert.deepEqual(after.kept, []);
assert.equal(after.state.sessions[0].status, "ready");
const old = { sessions: [{ id: "a1", status: "finished", startedAt: 100 }] };
const { state, kept } = keepStartedSessions(old, { sessions: reset.sessions, resultsBySession: reset.resultsBySession });
assert.deepEqual(kept, ["a1"]);
assert.equal(state.sessions[0].resultsResetAt, 900);
});
test("normal progress, new and deleted heats pass through untouched", () => {
const incoming = { sessions: [{ id: "a2", status: "finished", startedAt: 500, endedAt: 800 }, { id: "a3", status: "running", startedAt: 900 }, { id: "new", status: "ready" }] };
const { state, kept } = keepStartedSessions(incoming, stored());
assert.deepEqual(kept, []);
assert.deepEqual(state.sessions.map((session) => session.id), ["a2", "a3", "new"], "a1 deleted on purpose stays deleted");
assert.equal(keepStartedSessions(null, stored()).state, null);
});