feat: complete advanced Sudoku workbench

This commit is contained in:
2026-08-31 08:20:30 +02:00
parent 8ca9300ab3
commit 0a1bdc1a8c
99 changed files with 20793 additions and 923 deletions
@@ -0,0 +1,36 @@
import { describe, expect, it } from "vitest";
import {
createGameplayHistory,
parseGameplayHistory,
serializeGameplayHistory,
} from "../../src/state/playHistory";
import { createSession } from "../../src/state/session";
describe("gameplay history persistence", () => {
it("round-trips independent bounded history", () => {
const history = createGameplayHistory(
createSession(Array<number>(16).fill(0)),
);
const encoded = serializeGameplayHistory(history, 4);
const decoded = parseGameplayHistory(encoded, 4);
expect(decoded).toEqual(history);
(decoded.moments[0]!.state.values as number[])[0] = 4;
expect(history.moments[0]!.state.values[0]).toBe(0);
});
it("rejects dangling and oversized persisted state", () => {
const history = createGameplayHistory(
createSession(Array<number>(16).fill(0)),
);
const raw = JSON.parse(serializeGameplayHistory(history, 4)) as {
history: { currentMomentId: string };
};
raw.history.currentMomentId = "missing";
expect(() => parseGameplayHistory(JSON.stringify(raw), 4)).toThrow(
/missing active branch or moment/u,
);
expect(() => parseGameplayHistory("x".repeat(1_048_577), 4)).toThrow(
/too large/u,
);
});
});