The engine and the bot no longer import each other: geometry, movement
and captures live in src/lib/game/board.ts and both use it. The escape
test, the four directions, the king's neighbours and the enumeration of
a side's moves each exist once; the tally counts by the named end
sentences rather than by regex over them; exports nobody imports are
exports no more. The tests pin the bot's opening move and the three-
beside-the-throne capture they named but never exercised.
In the client: .small, the word-as-button, the × that dismisses, the
visually-hidden rule and the frame of the reading pages are in app.css
once; the preferences panel and the report slip share one modal shape;
the room store drops the simultaneous-round fields this game never read
and gains seatEmpty and seatUnheld, which the lobby and the join page
read instead of three spellings of their own. The wire shapes for
reports and the tally are declared in view.ts for both sides. The
artwork component is re-indented for the top level it lives at.
On the server and in deploy: the plaintext-token fallback and its
migration script guarded ledgers this game never wrote; the seat line
now requires the hash and the start line the rules revision. The route
table lists every route. The visitors digest and the nightly rollup
count Caddy's log through deploy/traffic.py, and the rollup writes the
finished-games count it had been computing behind "and False". The
reports digest is one program, deploy/report-digest.ts, that
pull-reports.sh and the desk skill both use. The deploy README, the
visitors skill and the reports skill no longer describe a browser-only
game, a /play route or a rules text in docs/; conventions.md carries
the kit's Preferences and tally sections.
Kit-shared files touched, to port back: server/src/{index,rooms,store,
tally,reports}.ts, deploy/{deploy.sh,replay-ledgers.ts,pull-reports.sh,
traffic.py,report-digest.ts,*-rollup.sh,*-visitors.sh,*-pulse.sh},
src/lib/net/{client.ts,room.svelte.ts,view.ts}, Preferences.svelte,
ReportSlip.svelte, TableTalk.svelte.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GwFKMuQnPAEHJ5yA1q4orh
77 lines
3.0 KiB
TypeScript
77 lines
3.0 KiB
TypeScript
// Replays every ledger in a directory with THIS checkout's engine and, when
|
|
// a server address is given, compares the result with what that server is
|
|
// showing for the room: the round reached and the outcome. A ledger the
|
|
// engine cannot replay, or replays differently, is reported and fails the
|
|
// run. Used by deploy/verify-ledgers.sh.
|
|
// tsx deploy/replay-ledgers.ts <ledger-dir> [https://host]
|
|
|
|
import { readdirSync, readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { game } from '../src/lib/game';
|
|
import type { SeatId } from '../src/lib/game/spec';
|
|
|
|
interface Seat {
|
|
id: SeatId;
|
|
name: string;
|
|
bot: boolean;
|
|
}
|
|
|
|
const [dir, host] = process.argv.slice(2);
|
|
if (!dir) {
|
|
console.error('usage: replay-ledgers.ts <ledger-dir> [https://host]');
|
|
process.exit(2);
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
const files = readdirSync(dir).filter((f) => f.endsWith('.jsonl'));
|
|
let failures = 0;
|
|
for (const file of files) {
|
|
const code = file.slice(0, -'.jsonl'.length);
|
|
const lines = readFileSync(join(dir, file), 'utf8')
|
|
.split('\n')
|
|
.filter((l) => l.trim())
|
|
.map((l) => JSON.parse(l));
|
|
const seats: Seat[] = [];
|
|
let state: ReturnType<typeof game.create> | null = null;
|
|
let turns = 0;
|
|
// The host's table options ride the room line; a game created without them is a different game.
|
|
const options = (lines[0]?.t === 'room' ? lines[0].options : undefined) as Record<string, string> | undefined;
|
|
try {
|
|
for (const line of lines) {
|
|
if (line.t === 'seat') seats.push(line);
|
|
else if (line.t === 'unseat') seats.splice(seats.findIndex((s) => s.id === line.id), 1);
|
|
else if (line.t === 'start') state = game.create(Object.fromEntries(seats.map((s) => [s.id, s.name])), line.seed, line.rules, options);
|
|
else if (line.t === 'turn' && state) {
|
|
state = game.resolve(state, line.inputs);
|
|
turns += 1;
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.log(`${code}: REFUSED at turn ${turns + 1}: ${e instanceof Error ? e.message : String(e)}`);
|
|
failures += 1;
|
|
continue;
|
|
}
|
|
const outcome = state ? game.over(state) : null;
|
|
let verdict = state ? `${turns} turns, ${outcome ? 'over' : 'in play'}` : 'not started';
|
|
if (host && state) {
|
|
// The gallery's view carries the round and the outcome, which is all the comparison needs.
|
|
const res = await fetch(`${host}/api/rooms/${code}`);
|
|
if (!res.ok) {
|
|
verdict += `, server ${res.status}`;
|
|
} else {
|
|
const theirs = (await res.json()) as { turn: number | null; over: { winner: SeatId | null } | null };
|
|
const same = theirs.turn === game.turn(state) && (theirs.over?.winner ?? null) === (outcome?.winner ?? null);
|
|
if (!same) {
|
|
failures += 1;
|
|
verdict += `, DIFFERS from the server (server round ${theirs.turn}, local round ${game.turn(state)})`;
|
|
} else verdict += ', matches the server';
|
|
}
|
|
}
|
|
console.log(`${code}: ${verdict}`);
|
|
}
|
|
console.log(`${files.length} ledger${files.length === 1 ? '' : 's'}, ${failures} problem${failures === 1 ? '' : 's'}`);
|
|
process.exit(failures ? 1 : 0);
|
|
}
|
|
|
|
void main();
|