Files
Dune/tests/fremen-ecaz-victory-recovery.test.ts
Quintine 9ca17a66a0 Honor allied Fremen victory and prevent deferred shipment deadlocks
Reciprocal allied Ecaz and Fremen with fighters in Sietch Tabr now satisfy that part of the Fremen final-turn victory, as explicitly clarified by the GF9 Ecaz/Moritani p15 FAQ. One public board quote drives automatic victory and the table guide; the chronicle explains the result. Other blockers, ordinary stronghold/BG prediction precedence, Guild fallback, advisor posture and concealed marker privacy remain intact. Habbanya symmetry and full mode/publication acceptance remain unfinished.

A genuine Advanced sample also exposed a pre-existing accepted Guild shipment which could never finish: allowance opened BG accompaniment and then hit the Ambassador arrival guard. Prior HEAD replay reproduced the exact 90-action failure. Fresh shipment preflight now rejects unsupported arrival combinations before accepting their pending windows. A valid legacy ordinary Guild allowance can return its unspent declaration to choose another destination; special parent/card receipts retain their separate gates. The change does not invent simultaneous reaction order or refund spent cards.

Independent rules/privacy/persistence review and focused engine/controls tests pass. Seventeen Fremen/Ecaz tests include all four profiles and authenticated final readiness/restart/concurrent writes. Shipment regressions cover pre-declaration immutability, supported arrival, malformed saved declarations and authenticated unspent return/replacement/reconnect/concurrency. All 4716 offline tests, types, lint, production build and 43 HTTP tests passed against unchanged source.

The original fixed seeds were repeated after repair and the exact failed snapshot resumed with documented new continuation seed 202609147: resume-advanced-202609147: 842 accepted, 109 guarded rejections, 22 periodic JSON restores; genuine-basic-202609145: 563 accepted, 14 guarded rejections, 15 periodic JSON restores; genuine-advanced-202609146: 806 accepted, 81 guarded rejections, 21 periodic JSON restores. All three finish and preserve physical custody/private views. These samples do not establish naturally reached allied Fremen special wins; a separate conserved browser final-turn fixture verifies the actual Ready-to-win transition, public guide/log, private hand and pending/finished refresh.

All 835 opening games and original seat/recovery records remain unchanged (902 after checks). All 869 rooms and records present after the reported outage also remain unchanged; database integrity and foreign keys pass. The healthy server and finished browser seat recovered without restart, reset or recurring automation. Full rules coverage and release gates remain open work.

Verified source tree: 1d9fcf30b54132f66be5f994f410dec6ec019683ee66b24fd4efb7a6aa7f7bbd
2026-09-14 02:59:50 +10:00

75 lines
4.5 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { DatabaseSync } from 'node:sqlite';
import { viewGame, type Game } from '../game/engine';
import type { RoomsClock } from '../db/rooms';
import { unitStore } from './fixture-nexus-room-store';
import { fremenEcazFinalTurn, fremenEcazCustody } from './fixture-fremen-ecaz-victory';
const clock: RoomsClock = { now: () => 42000, sleep: async () => {} };
const savedRows = (sqlite: DatabaseSync) => sqlite.prepare('SELECT state, version FROM rooms').all();
async function fixture(t: test.TestContext) {
const store = unitStore(); t.after(() => store.sqlite.close());
const made = await store.rooms.createRoom('Ecaz victory QA', 'ecaz', false, ['ecaz']);
const code = made.view.code, tokens = [made.token];
for (const faction of ['fremen', 'guild', 'beneGesserit'] as const) tokens.push((await store.rooms.joinRoom(code, faction, faction)).token!);
const auths = await Promise.all(tokens.map((token) => store.rooms.authenticate(code, token)));
const g = fremenEcazFinalTurn(true, auths.map((a) => a.playerId));
g.code = code; g.version = (await store.rooms.readRoom(code)).version;
store.sqlite.prepare('UPDATE rooms SET state=?, version=? WHERE code=?').run(JSON.stringify(g), g.version, code);
for (const auth of auths.slice(0, -1)) {
const current = await store.rooms.readRoom(code);
await store.rooms.act(code, auth, current.version, { type: 'ready' }, clock);
}
const pending = await store.rooms.readRoom(code);
assert.equal(pending.phase, 7); assert.equal(pending.status, 'playing');
store.writes.length = 0;
return { ...store, code, tokens, auths, pending };
}
void test('restored final readiness awards the same allied win once and preserves private seats and physical custody', async (t) => {
const f = await fixture(t), before = savedRows(f.sqlite);
const seatRows = f.sqlite.prepare('SELECT * FROM seats').all();
for (const [i, token] of f.tokens.entries()) {
const rooms = f.restart(), auth = await rooms.authenticate(f.code, token);
assert.deepEqual(await rooms.readSeatView(f.code, auth), viewGame(f.pending, f.auths[i].playerId));
}
assert.deepEqual(savedRows(f.sqlite), before);
const rooms = f.restart(), auth = await rooms.authenticate(f.code, f.tokens[3]);
await rooms.act(f.code, auth, f.pending.version, { type: 'ready' }, clock);
const done = await f.restart().readRoom(f.code);
assert.equal(done.status, 'finished');
assert.deepEqual(done.winner, [f.auths[1].playerId, f.auths[0].playerId]);
assert.deepEqual(fremenEcazCustody(done), fremenEcazCustody(f.pending));
assert.equal(done.log.filter((entry) => entry.text.includes('Fremen special victory')).length, 1);
const resolvedRows = savedRows(f.sqlite);
for (const [i, token] of f.tokens.entries()) {
const restored = f.restart(), seat = await restored.authenticate(f.code, token);
const view = await restored.readSeatView(f.code, seat);
assert.deepEqual(view, viewGame(done, f.auths[i].playerId));
assert.deepEqual(viewGame(JSON.parse(JSON.stringify(done)) as Game, seat.playerId), view);
for (const rival of view.players.filter((p) => p.id !== seat.playerId))
for (const key of ['hand', 'traitors', 'spice', 'prediction']) assert.equal(key in rival, false);
}
await f.restart().continueRoomAutomatic(f.code, clock);
await assert.rejects(f.restart().act(f.code, auth, f.pending.version, { type: 'ready' }, clock));
await assert.rejects(f.restart().act(f.code, auth, done.version, { type: 'ready' }, clock));
assert.deepEqual(savedRows(f.sqlite), resolvedRows);
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), seatRows);
});
void test('competing final-readiness writes cannot duplicate victory settlement', async (t) => {
const f = await fixture(t);
let entered = 0; let release!: () => void;
const both = new Promise<void>((resolve) => { release = resolve; });
f.hooks.beforeWrite = async () => { if (++entered === 2) release(); await both; };
const results = await Promise.allSettled([0, 1].map(() => f.rooms.act(f.code, f.auths[3], f.pending.version, { type: 'ready' }, clock)));
f.hooks.beforeWrite = undefined;
assert.equal(results.filter((r) => r.status === 'fulfilled').length, 1);
assert.deepEqual(f.writes.map((w) => w.changes).sort((a, b) => a - b), [0, 1]);
const done = await f.restart().readRoom(f.code);
assert.equal(done.version, f.pending.version + 1);
assert.equal(done.log.filter((entry) => entry.text.includes('Fremen special victory')).length, 1);
assert.deepEqual(fremenEcazCustody(done), fremenEcazCustody(f.pending));
});