Files
Dune/tests/prototype-room.test.ts
T
Quintine 8e1cd7b75b Connect Emperor Nexus extra revival with private saved continuation
Add the absent-Emperor Secret Ally alternative returning exactly three eligible forces free in Basic/Advanced base-faction Nexus games. Preserve ordinary force/free-revival allowances and the shared Advanced Fedaykin cap. Keep the action optional and private, consume the physical Nexus once, and validate durable source receipts through later ordinary revival and Ghola. Purchase timing remains pending the earlier uniform winner-payment UX question; partial returns and combined-module interactions remain guarded. No mode or publication gate opens.

Connect private controls, explicit physical elite selection, all four legal AI profiles and a dedicated rules checklist entry. Extend the reusable local prototype writer with genuine twelve-card Nexus setup. Independent review covers rules timing, private projection, physical custody, JSON and production SQLite restore, lost-response replay and competing requests. Seventeen focused effect cases and four prototype-writer cases pass.

Validation: typecheck, lint, 4649 offline tests, production build and 43 HTTP tests passed with unchanged source. Genuine-start Basic and Advanced samples completed in 715 and 263 actions with 19 and 7 periodic JSON restores, respectively, and no Emperor uses. Two explicitly staged continuations completed in 18 and 17 actions with one normal-force Emperor return each. All four had zero rejections and preserved exact Treachery, force, elite and Nexus custody; all fourteen final seat views restored unchanged. They are bounded continuation evidence, not natural full-game acceptance of the effect or AI calibration.

In the conserved staged browser scenario, Advanced Fremen returned three forces including one Fedaykin using the Nexus, then three normal forces using the ordinary allowance. Reserves rose from three to nine, Tanks fell from seven to one, spice stayed three and the physical Nexus was spent once. The inspector was readable, the action notice displayed, and pending/resolved refresh restoration, physical custody and private projection passed.

After the reported power outage, all 733 opening games and original seat/recovery records were preserved (767 after HTTP checks); database integrity and foreign keys passed. All 734 rooms immediately before broad verification remained unchanged. Reused the healthy server without restart, reset or recurring automation.

Verified source tree: fd09a4bc71018cb7ef98c7e25c25dacc495ffed304dbd0cdfa223e539e8fa5e1
2026-09-14 01:05:11 +10:00

200 lines
6.4 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { DatabaseSync } from 'node:sqlite';
import {
createGame,
joinGame,
newPlayer,
viewGame,
type Game,
} from '../game/engine';
import {
startIxPrototypeRoom,
startPrototypeRoom,
} from '../tools/prototype-room';
function fixture(t: test.TestContext) {
const db = new DatabaseSync(':memory:');
t.after(() => db.close());
db.exec(
'CREATE TABLE rooms(code TEXT PRIMARY KEY, state TEXT, version INTEGER, updated_at INTEGER); CREATE TABLE seats(room_code TEXT, player_id TEXT, token_hash TEXT);',
);
const game = createGame(
'PROTOTYP',
newPlayer('i', 'Ix player', 'ixians'),
true,
);
game.expansions = ['ix'];
joinGame(game, newPlayer('t', 'Tleilaxu player', 'tleilaxu'));
game.players.forEach((player) => {
player.ready = true;
});
db.prepare('INSERT INTO rooms VALUES(?,?,?,?)').run(
game.code,
JSON.stringify(game),
7,
100,
);
db.prepare('INSERT INTO rooms VALUES(?,?,?,?)').run(
'KEEPME00',
'{"unchanged":true}',
3,
50,
);
db.prepare('INSERT INTO seats VALUES(?,?,?)').run(
game.code,
'i',
'unchanged-private-session',
);
return { db, game };
}
void test('local prototype starts the named ready lobby once, retaining every seat and other room', (t) => {
const { db } = fixture(t);
const seats = db.prepare('SELECT * FROM seats').all();
const other = db
.prepare('SELECT * FROM rooms WHERE code = ?')
.get('KEEPME00');
const result = startIxPrototypeRoom(db, 'PROTOTYP', 7);
assert.equal(result.version, 8);
assert.equal(result.status, 'setup');
const saved = db
.prepare('SELECT state, version FROM rooms WHERE code = ?')
.get('PROTOTYP')!;
assert.equal(JSON.parse(saved.state as string).version, saved.version);
assert.deepEqual(db.prepare('SELECT * FROM seats').all(), seats);
assert.deepEqual(
db.prepare('SELECT * FROM rooms WHERE code = ?').get('KEEPME00'),
other,
);
const rows = db.prepare('SELECT * FROM rooms ORDER BY code').all();
assert.throws(() => startIxPrototypeRoom(db, 'PROTOTYP', 7), /changed/);
assert.throws(() => startIxPrototypeRoom(db, 'PROTOTYP', 8), /fresh lobby/);
assert.deepEqual(db.prepare('SELECT * FROM rooms ORDER BY code').all(), rows);
});
void test('unready, wrong identity and incompatible lobbies fail without writing any room or seat', (t) => {
const { db, game } = fixture(t);
for (const mutate of [
() => {
game.players[0].ready = false;
},
() => {
game.players[0].ready = true;
game.code = 'NOTMATCH';
},
() => {
game.code = 'PROTOTYP';
game.expansions = [];
},
]) {
mutate();
db.prepare('UPDATE rooms SET state = ? WHERE code = ?').run(
JSON.stringify(game),
'PROTOTYP',
);
const before = db.prepare('SELECT * FROM rooms ORDER BY code').all();
assert.throws(() => startIxPrototypeRoom(db, 'PROTOTYP', 7));
assert.deepEqual(
db.prepare('SELECT * FROM rooms ORDER BY code').all(),
before,
);
assert.equal(
db.prepare('SELECT count(*) AS count FROM seats').get()!.count,
1,
);
}
});
void test('Leader Skills prototype saves the real private setup once without changing other rooms or seats', (t) => {
const { db } = fixture(t);
const game = createGame(
'PROTOTYP',
newPlayer('i', 'Atreides', 'atreides'),
true,
);
joinGame(game, newPlayer('h', 'Harkonnen', 'harkonnen'));
game.players.forEach((p) => {
p.ready = true;
});
db.prepare('UPDATE rooms SET state = ? WHERE code = ?').run(
JSON.stringify(game),
game.code,
);
const seats = db.prepare('SELECT * FROM seats').all();
const other = db
.prepare('SELECT * FROM rooms WHERE code = ?')
.get('KEEPME00');
const result = startPrototypeRoom(db, game.code, 7, 'leader-skills');
assert.equal(result.version, 8);
const saved = JSON.parse(
db.prepare('SELECT state FROM rooms WHERE code = ?').get(game.code)!
.state as string,
);
assert.equal(saved.version, 8);
assert.equal(saved.setupStage, 'leaderSkills');
assert.equal(saved.leaderSkills.offers.i.cards.length, 2);
assert.equal(saved.leaderSkills.offers.h.cards.length, 2);
assert.equal(saved.players[0].hand.length, 1);
assert.equal(saved.players[1].hand.length, 2);
const rooms = db.prepare('SELECT * FROM rooms ORDER BY code').all();
assert.throws(
() => startPrototypeRoom(db, game.code, 8, 'leader-skills'),
/redeal/,
);
assert.deepEqual(
db.prepare('SELECT * FROM rooms ORDER BY code').all(),
rooms,
);
assert.deepEqual(db.prepare('SELECT * FROM seats').all(), seats);
assert.deepEqual(
db.prepare('SELECT * FROM rooms WHERE code = ?').get('KEEPME00'),
other,
);
});
void test('Nexus prototype initializes all twelve hidden cards once and preserves unrelated saved state', (t) => {
const { db } = fixture(t);
const game = createGame(
'PROTOTYP',
newPlayer('i', 'Atreides', 'atreides'),
true,
);
joinGame(game, newPlayer('h', 'Harkonnen', 'harkonnen'));
game.players.forEach((player) => {
player.ready = true;
});
db.prepare('UPDATE rooms SET state = ? WHERE code = ?').run(
JSON.stringify(game),
game.code,
);
const seats = db.prepare('SELECT * FROM seats').all();
const other = db
.prepare('SELECT * FROM rooms WHERE code = ?')
.get('KEEPME00');
startPrototypeRoom(db, game.code, 7, 'nexus');
const saved = JSON.parse(
db.prepare('SELECT state FROM rooms WHERE code = ?').get(game.code)!
.state as string,
) as Game;
assert.equal(saved.version, 8);
assert.equal(saved.status, 'setup');
assert.equal(saved.nexusCards!.cards!.deck.length, 12);
assert.equal(new Set(saved.nexusCards!.cards!.deck).size, 12);
for (const player of saved.players) {
const view = viewGame(saved, player.id);
assert.equal(view.nexusCards!.card, null);
assert.equal(view.nexusCards!.deckCount, 12);
assert.equal('deck' in view.nexusCards!, false);
}
const rows = db.prepare('SELECT * FROM rooms ORDER BY code').all();
assert.throws(() => startPrototypeRoom(db, game.code, 7, 'nexus'), /changed/);
assert.throws(() => startPrototypeRoom(db, game.code, 8, 'nexus'));
assert.deepEqual(db.prepare('SELECT * FROM rooms ORDER BY code').all(), rows);
assert.deepEqual(db.prepare('SELECT * FROM seats').all(), seats);
assert.deepEqual(
db.prepare('SELECT * FROM rooms WHERE code = ?').get('KEEPME00'),
other,
);
});