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
This commit is contained in:
Quintine committed 2026-09-14 01:05:11 +10:00
1 parent d0dc7007d9
commit 8e1cd7b75b
20 files changed
+1332 -17

No files matched your search

@@ -0,0 +1,74 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { applyAction, viewGame } from '../game/engine';
import { botActions } from '../game/bots';
import { nexusEmperorRevivalAction } from '../game/nexus-emperor-secret-ally-options';
import {
nexusEmperorSecretAllyFixture,
emperorNexusPhysical,
} from './nexus-emperor-secret-ally-fixture';
void test('all four profiles use the actual additional revival without ordinary quota or hidden-information access', () => {
for (const advanced of [false, true]) {
for (const difficulty of ['Easy', 'Medium', 'Hard', 'Brutal'] as const) {
const { g, owner } = nexusEmperorSecretAllyFixture({ advanced });
const before = g.players.find((player) => player.id === owner)!;
before.bot = difficulty;
const view = viewGame(g, owner);
for (const rival of view.players.filter(
(player) => player.id !== owner,
)) {
for (const key of ['hand', 'spice', 'traitors'])
Object.defineProperty(rival, key, {
get() {
throw new Error('Rival private field read.');
},
});
}
const [action] = botActions(view);
assert.equal(action.type, 'nexusEmperorRevive');
const after = applyAction(g, owner, action);
const actual = after.players.find((player) => player.id === owner)!;
assert.equal(actual.reserves, before.reserves + 3);
assert.equal(actual.tanks, before.tanks - 3);
assert.equal(actual.spice, before.spice);
assert.equal(actual.revived, before.revived);
assert.equal(actual.freeForcesRevived, before.freeForcesRevived);
assert.deepEqual(emperorNexusPhysical(after), emperorNexusPhysical(g));
assert.equal(after.nexusCards!.cards!.hands[owner], null);
assert.equal(
after.nexusCards!.cards!.discard.filter((card) => card === 'emperor')
.length,
1,
);
assert.equal(nexusEmperorRevivalAction(viewGame(after, owner), 0), null);
}
}
});
void test('Fremen bot choices preserve real elite limits and unavailable grants are not offered', () => {
for (const difficulty of ['Easy', 'Medium', 'Hard', 'Brutal'] as const) {
const { g, owner, observer } = nexusEmperorSecretAllyFixture({
advanced: true,
owner: 'p',
eliteTanks: 2,
});
g.players.find((player) => player.id === owner)!.bot = difficulty;
const before = emperorNexusPhysical(g);
const [action] = botActions(viewGame(g, owner));
assert.equal(action.type, 'nexusEmperorRevive');
const after = applyAction(g, owner, action);
assert.ok(
after.players.find((player) => player.id === owner)!.elites!.revived <= 1,
);
assert.deepEqual(emperorNexusPhysical(after), before);
assert.equal(nexusEmperorRevivalAction(viewGame(g, owner), 2), null);
assert.equal(nexusEmperorRevivalAction(viewGame(g, observer), 0), null);
}
const { g, owner } = nexusEmperorSecretAllyFixture({ tanks: 2 });
assert.ok(
!botActions(viewGame(g, owner)).some(
(action) => action.type === 'nexusEmperorRevive',
),
);
});
@@ -0,0 +1,66 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { registerHooks } from 'node:module';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { NexusEmperorSecretAlly } from '../components/nexus-emperor-secret-ally';
import type { GameView } from '../game/engine';
const aliases = registerHooks({
resolve(specifier, context, next) {
return next(specifier === 'next/image' ? 'vinext/shims/image' : specifier, context);
},
});
function view(overrides: Record<string, unknown> = {}) {
return {
me: 'a',
players: [
{ id: 'a', name: 'House A', faction: 'atreides', ally: null },
{ id: 'b', name: 'House B', faction: 'harkonnen', ally: null },
],
status: 'playing',
phase: 4,
response: null,
truthtrance: null,
phaseOpening: null,
automaticContinuationPending: false,
nexusCards: { card: 'emperor', waiting: [] },
nexusTraitors: { pending: null },
nexusEmperorSecretAlly: {
event: 'emperor-1',
revival: { blocked: null, eliteOptions: [0, 1] },
purchase: null,
},
...overrides,
} as unknown as GameView;
}
function markup(game: GameView, busy = false) {
return renderToStaticMarkup(createElement(NexusEmperorSecretAlly, { game, act() {}, busy }));
}
void test('eligible private Emperor card shows revival explanation and legal elite selector', () => {
const html = markup(view());
assert.match(html, /revive 3 additional forces for free/);
assert.match(html, /Elite forces to revive/);
assert.match(html, /value="0"/);
assert.match(html, /value="1"/);
assert.match(html, /Revive 3 additional forces/);
});
void test('stale, nonowner, blocked and busy states stay guarded', () => {
assert.equal(markup(view({ phase: 5 })), '');
assert.equal(markup(view({ me: 'b', nexusEmperorSecretAlly: null })), '');
assert.equal(markup(view({ nexusCards: { card: 'emperor', waiting: ['b'] } })), '');
const blocked = markup(view({ nexusEmperorSecretAlly: {
event: 'emperor-1', revival: { blocked: 'Elite revival is unavailable.', eliteOptions: [] }, purchase: null,
} }));
assert.match(blocked, /Elite revival is unavailable/);
assert.match(blocked, /disabled=""/);
assert.match(markup(view({ nexusEmperorSecretAlly: {
event: 'emperor-1', revival: { blocked: null, eliteOptions: [1] }, purchase: null,
} }), true), /disabled=""/);
});
aliases.deregister();
+101
View File
@@ -0,0 +1,101 @@
import assert from 'node:assert/strict';
import { applyAction, viewGame, type Game } from '../game/engine';
import {
nexusTurnTwo,
orderNexusSpice,
finishNexusSpice,
nexusReady,
nexusInventory,
} from './fixture-nexus-cards';
/** Genuine Basic/Advanced initializer and real Nexus draw/bidding actions.
* Shared setup returns starting hands to the deck; controlled physical spice
* and Nexus order supplies the draw. The focused loss topology moves existing
* reserve counters to Tanks; this is not an untouched full-game sample. */
export function nexusEmperorSecretAllyFixture(
options: {
advanced?: boolean;
owner?: 'p' | 'q' | 'r';
seatIds?: [string, string, string];
tanks?: number;
eliteTanks?: number;
} = {},
) {
const seatIds: [string,string,string] = options.seatIds ?? ['p', 'q', 'r'];
const owner = seatIds[['p', 'q', 'r'].indexOf(options.owner ?? 'q')];
let g = nexusTurnTwo({ advanced: options.advanced, seatIds });
orderNexusSpice(g, ['worm', 'land', 'land']);
g = nexusReady(nexusReady(g));
const others = g.players.filter((p) => p.id !== owner).map((p) => p.id);
g = applyAction(g, others[0], { type: 'alliance', target: others[1] });
g = applyAction(g, others[1], { type: 'alliance', target: others[0] });
g = finishNexusSpice(g);
assert.equal(g.nexusCards!.phase!.stage, 'drawing');
const cards = g.nexusCards!.cards!;
cards.deck = ['emperor', ...cards.deck.filter((card) => card !== 'emperor')];
g = applyAction(g, owner, {
type: 'nexusCardChoice',
turn: g.turn,
card: null,
choice: 'draw',
ownRedraws: 0,
});
for (const id of g.nexusCards!.phase!.eligible)
if (!g.nexusCards!.phase!.done.includes(id))
g = applyAction(g, id, {
type: 'nexusCardChoice',
turn: g.turn,
card: null,
choice: 'keep',
ownRedraws: 0,
});
assert.equal(g.phase, 2);
g = nexusReady(g);
for (let i = 0; g.phase === 3 && i < 15; i++) {
if (g.phaseOpening)
g = applyAction(
g,
g.players.find((p) => !g.phaseOpening!.passed.includes(p.id))!.id,
{ type: 'ready' },
);
else if (g.auction)
g = applyAction(g, g.auction.active, { type: 'passBid' });
else g = nexusReady(g);
}
assert.equal(g.phase, 4);
assert.equal(g.decision, null);
const p = g.players.find((p) => p.id === owner)!;
const tanks = options.tanks ?? 6,
elite = options.eliteTanks ?? 0;
assert.ok(tanks <= p.reserves && elite <= (p.elites?.reserves ?? 0));
p.reserves -= tanks;
p.tanks += tanks;
if (p.elites) {
p.elites.reserves -= elite;
p.elites.tanks += elite;
}
const offer = viewGame(g, owner).nexusEmperorSecretAlly!;
assert.ok(offer);
const action = {
type: 'nexusEmperorRevive',
event: offer.event,
elite: elite ? 1 : 0,
};
nexusInventory(g);
const [target, observer] = g.players
.filter((p) => p.id !== owner)
.map((p) => p.id);
return { g, owner, target, observer, action };
}
export function emperorNexusPhysical(g: Game) {
nexusInventory(g);
return g.players.map((p) => ({
id: p.id,
total:
p.reserves + p.tanks + Object.values(p.forces).reduce((a, b) => a + b, 0),
elite:
(p.elites?.reserves ?? 0) +
(p.elites?.tanks ?? 0) +
Object.values(p.elites?.forces ?? {}).reduce((a, b) => a + b, 0),
}));
}
@@ -0,0 +1,207 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { DatabaseSync } from 'node:sqlite';
import { unitStore } from './fixture-nexus-room-store';
import {
nexusEmperorSecretAllyFixture,
emperorNexusPhysical,
} from './nexus-emperor-secret-ally-fixture';
import { viewGame, type Game } from '../game/engine';
import type { RoomsClock } from '../db/rooms';
const clock: RoomsClock = { now: () => 10000, sleep: async () => {} };
const rows = (db: DatabaseSync) =>
db.prepare('SELECT state,version FROM rooms ORDER BY code').all();
async function fixture(
t: test.TestContext,
advanced: boolean,
owner: 'p' | 'q',
) {
const store = unitStore();
t.after(() => store.sqlite.close());
const made = await store.rooms.createRoom(
'Emperor Nexus recovery',
'fremen',
advanced,
[],
);
const code = made.view.code,
tokens = [made.token];
for (const faction of ['atreides', 'harkonnen'] 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 ids = auths.map((auth) => auth.playerId) as [string, string, string];
const f = nexusEmperorSecretAllyFixture({
advanced,
owner,
seatIds: ids,
eliteTanks: owner === 'p' ? 2 : 0,
});
f.g.code = code;
f.g.version = (await store.rooms.readRoom(code)).version;
store.sqlite
.prepare('UPDATE rooms SET state = ?, version = ? WHERE code = ?')
.run(JSON.stringify(f.g), f.g.version, code);
store.writes.length = 0;
return {
...store,
...f,
code,
tokens,
auths,
ids,
ownerIndex: owner === 'p' ? 0 : 1,
};
}
type Fixture = Awaited<ReturnType<typeof fixture>>;
async function restored(f: Fixture, expected: Game) {
const before = rows(f.sqlite);
for (const [index, token] of f.tokens.entries()) {
const rooms = f.restart(),
auth = await rooms.authenticate(f.code, token);
const view = await rooms.readSeatView(f.code, auth);
assert.deepEqual(view, viewGame(expected, f.ids[index]));
assert.equal('nexusEmperorSecretHistory' in view, false);
assert.equal('nexusEmperorSecretEvents' in view, false);
if (index !== f.ownerIndex) assert.equal(view.nexusEmperorSecretAlly, null);
for (const rival of view.players.filter(
(player) => player.id !== f.ids[index],
)) {
assert.equal('hand' in rival, false);
assert.equal('spice' in rival, false);
}
}
await f.restart().continueRoomAutomatic(f.code, clock);
assert.deepEqual(rows(f.sqlite), before);
}
void test('private Emperor revival survives SQLite restart and lost-response replay with exactly one physical return', async (t) => {
for (const advanced of [false, true]) {
const f = await fixture(t, advanced, advanced ? 'p' : 'q');
const initial = f.g,
owner = initial.players.find((player) => player.id === f.owner)!;
const seats = f.sqlite
.prepare('SELECT * FROM seats ORDER BY player_id')
.all();
await restored(f, initial);
const unchanged = rows(f.sqlite);
await assert.rejects(
f.rooms.act(
f.code,
f.auths[(f.ownerIndex + 1) % 3],
initial.version,
f.action,
clock,
),
);
await assert.rejects(
f.rooms.act(
f.code,
f.auths[f.ownerIndex],
initial.version,
{ ...f.action, event: 'old' },
clock,
),
);
await assert.rejects(
f.rooms.act(
f.code,
f.auths[f.ownerIndex],
initial.version,
{ ...f.action, amount: 2 },
clock,
),
);
assert.deepEqual(rows(f.sqlite), unchanged);
const rooms = f.restart(),
auth = await rooms.authenticate(f.code, f.tokens[f.ownerIndex]);
await rooms.act(f.code, auth, initial.version, f.action, clock);
const done = await f.restart().readRoom(f.code);
const actual = done.players.find((player) => player.id === f.owner)!;
assert.equal(done.version, initial.version + 1);
assert.equal(actual.reserves, owner.reserves + 3);
assert.equal(actual.tanks, owner.tanks - 3);
assert.equal(actual.spice, owner.spice);
assert.equal(actual.revived, owner.revived);
assert.equal(actual.freeForcesRevived, owner.freeForcesRevived);
assert.deepEqual(actual.hand, owner.hand);
assert.deepEqual(actual.leaders, owner.leaders);
assert.deepEqual(emperorNexusPhysical(done), emperorNexusPhysical(initial));
assert.equal(done.nexusEmperorSecretHistory!.length, 1);
assert.equal(done.nexusCards!.cards!.hands[f.owner], null);
assert.equal(
done.nexusCards!.cards!.discard.filter((card) => card === 'emperor')
.length,
1,
);
if (advanced)
assert.equal(actual.elites!.revived, owner.elites!.revived + 1);
await restored(f, done);
const saved = rows(f.sqlite);
await assert.rejects(
f.restart().act(f.code, auth, initial.version, f.action, clock),
/table changed/,
);
await assert.rejects(
f.restart().act(f.code, auth, done.version, f.action, clock),
);
assert.deepEqual(rows(f.sqlite), saved);
assert.deepEqual(
f.sqlite.prepare('SELECT * FROM seats ORDER BY player_id').all(),
seats,
);
assert.deepEqual(
f.writes.map((write) => write.changes),
[1],
);
}
});
void test('competing normal/elite Emperor Nexus choices commit only one return and one discarded card', async (t) => {
const f = await fixture(t, true, 'p');
let arrivals = 0,
release!: () => void;
const gate = new Promise<void>((resolve) => {
release = resolve;
});
f.hooks.beforeWrite = async () => {
if (++arrivals === 2) release();
await gate;
};
const timer = setTimeout(release, 2000);
let outcomes: PromiseSettledResult<unknown>[];
try {
outcomes = await Promise.allSettled(
[0, 1].map((elite) =>
f
.restart()
.act(f.code, f.auths[0], f.g.version, { ...f.action, elite }, clock),
),
);
} finally {
clearTimeout(timer);
delete f.hooks.beforeWrite;
}
assert.equal(arrivals, 2);
assert.equal(
outcomes.filter((result) => result.status === 'fulfilled').length,
1,
);
const done = await f.restart().readRoom(f.code),
owner = done.players[0];
assert.equal(done.version, f.g.version + 1);
assert.equal(owner.reserves, f.g.players[0].reserves + 3);
assert.equal(owner.tanks, f.g.players[0].tanks - 3);
assert.ok(owner.elites!.revived === 0 || owner.elites!.revived === 1);
assert.equal(done.nexusEmperorSecretHistory!.length, 1);
assert.deepEqual(emperorNexusPhysical(done), emperorNexusPhysical(f.g));
assert.deepEqual(
f.writes.map((write) => write.changes).sort((a, b) => a - b),
[0, 1],
);
await restored(f, done);
});
+313
View File
@@ -0,0 +1,313 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
applyAction,
normalizeAutomaticGame,
viewGame,
type Game,
} from '../game/engine';
import {
emperorNexusPools,
emperorNexusSignature,
} from '../game/nexus-emperor-secret-ally';
import { forceRevivalRemaining, freeRevivalRemaining } from '../game/revival';
import {
nexusEmperorSecretAllyFixture,
emperorNexusPhysical,
} from './nexus-emperor-secret-ally-fixture';
import { nexusReject, nexusReload, nexusReady } from './fixture-nexus-cards';
import { nexusTraitorFixture } from './fixture-nexus-traitors';
void test('a later real Ghola return and phase advance preserve historical Nexus proof without replaying its physical grant', () => {
const f = nexusEmperorSecretAllyFixture();
const card = f.g.deck.find((c) => c.effect === 'ghola')!;
f.g.deck = f.g.deck.filter((c) => c.id !== card.id);
f.g.players.find((p) => p.id === f.owner)!.hand.push(card);
f.g.players.find((p) => p.id === f.owner)!.spice = 0;
const physical = emperorNexusPhysical(f.g);
let g = applyAction(f.g, f.owner, f.action);
const receipt = nexusReload(g).nexusEmperorSecretHistory;
g = applyAction(nexusReload(g), f.owner, {
type: 'card',
card: card.id,
amount: 3,
elite: 0,
});
assert.equal(g.players.find((p) => p.id === f.owner)!.tanks, 0);
assert.equal(g.players.find((p) => p.id === f.owner)!.revived, 0);
assert.equal(g.players.find((p) => p.id === f.owner)!.spice, 0);
assert.deepEqual(g.nexusEmperorSecretHistory, receipt);
assert.deepEqual(emperorNexusPhysical(g), physical);
g = nexusReload(nexusReady(g));
assert.equal(g.phase, 5);
assert.deepEqual(normalizeAutomaticGame(nexusReload(g)), g);
nexusReject(g, f.owner, f.action);
});
for (const advanced of [false, true])
void test(`${advanced ? 'Advanced' : 'Basic'} Emperor Secret Ally revives exactly three physical forces without ordinary payment or quota usage`, () => {
const f = nexusEmperorSecretAllyFixture({ advanced }),
before = nexusReload(f.g),
p = before.players.find((p) => p.id === f.owner)!;
const physical = emperorNexusPhysical(before),
quota = forceRevivalRemaining(before, p),
free = freeRevivalRemaining(before, p);
const g = applyAction(f.g, f.owner, f.action),
after = g.players.find((p) => p.id === f.owner)!;
assert.deepEqual(f.g, before);
assert.deepEqual(emperorNexusPools(after), {
...emperorNexusPools(p),
reserves: p.reserves + 3,
tanks: p.tanks - 3,
});
assert.equal(forceRevivalRemaining(g, after), quota);
assert.equal(freeRevivalRemaining(g, after), free);
assert.deepEqual(
g.players.filter((p) => p.id !== f.owner),
before.players.filter((p) => p.id !== f.owner),
);
assert.deepEqual(after.hand, p.hand);
assert.deepEqual(after.leaders, p.leaders);
assert.deepEqual(emperorNexusPhysical(g), physical);
assert.equal(g.nexusCards!.cards!.hands[f.owner], null);
assert.equal(
g.nexusCards!.cards!.discard.filter((c) => c === 'emperor').length,
1,
);
assert.equal(g.nexusEmperorSecretHistory!.length, 1);
assert.equal(g.phase, 4);
assert.equal(g.response, null);
assert.equal(g.decision, null);
const ordinary = applyAction(g, f.owner, {
type: 'revive',
amount: 3,
elite: 0,
});
const revived = ordinary.players.find((p) => p.id === f.owner)!;
assert.equal(revived.tanks, 0);
assert.equal(revived.revived, 3);
assert.equal(revived.spice, p.spice - 2);
assert.deepEqual(emperorNexusPhysical(ordinary), physical);
nexusReject(ordinary, f.owner, f.action);
assert.deepEqual(normalizeAutomaticGame(nexusReload(ordinary)), ordinary);
});
void test('Emperor additional return still works after the ordinary three-force and free allowances are exhausted', () => {
const f = nexusEmperorSecretAllyFixture();
const paid = applyAction(f.g, f.owner, {
type: 'revive',
amount: 3,
elite: 0,
});
const before = emperorNexusPools(paid.players.find((p) => p.id === f.owner)!);
const done = applyAction(paid, f.owner, f.action);
assert.deepEqual(
emperorNexusPools(done.players.find((p) => p.id === f.owner)!),
{ ...before, reserves: before.reserves + 3, tanks: before.tanks - 3 },
);
});
void test('Advanced Fedaykin use typed Tanks and share the actual one-per-turn cap with ordinary revival', () => {
for (const nexusFirst of [false, true]) {
const f = nexusEmperorSecretAllyFixture({
advanced: true,
owner: 'p',
tanks: 7,
eliteTanks: 2,
});
const before = emperorNexusPhysical(f.g);
assert.deepEqual(
viewGame(f.g, f.owner).nexusEmperorSecretAlly!.revival.eliteOptions,
[0, 1],
);
nexusReject(f.g, f.owner, { ...f.action, elite: 2 });
let g: Game;
if (nexusFirst) {
g = applyAction(f.g, f.owner, f.action);
nexusReject(
g,
f.owner,
{ type: 'revive', amount: 1, elite: 1 },
/one elite/,
);
g = applyAction(g, f.owner, { type: 'revive', amount: 3, elite: 0 });
} else {
g = applyAction(f.g, f.owner, { type: 'revive', amount: 3, elite: 1 });
assert.deepEqual(
viewGame(g, f.owner).nexusEmperorSecretAlly!.revival.eliteOptions,
[0],
);
nexusReject(g, f.owner, f.action);
g = applyAction(g, f.owner, { ...f.action, elite: 0 });
}
assert.equal(g.players[0].elites!.revived, 1);
assert.equal(g.players[0].elites!.tanks, 1);
assert.deepEqual(emperorNexusPhysical(g), before);
}
});
void test('short total or typed groups are explicitly unavailable without spending a card or fabricating partial forces', () => {
for (const options of [
{ tanks: 2 },
{ advanced: true, owner: 'p' as const, tanks: 3, eliteTanks: 2 },
]) {
const f = nexusEmperorSecretAllyFixture(options);
assert.deepEqual(
viewGame(f.g, f.owner).nexusEmperorSecretAlly!.revival.eliteOptions,
[],
);
assert.match(
viewGame(f.g, f.owner).nexusEmperorSecretAlly!.revival.blocked!,
/exactly three/,
);
nexusReject(f.g, f.owner, f.action, /exactly three/);
assert.equal(f.g.nexusCards!.cards!.hands[f.owner], 'emperor');
}
});
void test('only the private absent-Emperor holder gets revival choices; nonholders retain ordinary phase progress', () => {
const f = nexusEmperorSecretAllyFixture();
assert.equal(viewGame(f.g, f.owner).nexusEmperorSecretAlly!.purchase, null);
for (const id of [f.target, f.observer]) {
const v = viewGame(f.g, id);
assert.equal(v.nexusEmperorSecretAlly, null);
assert.equal(v.nexusCards!.card, null);
assert.equal(v.decision, null);
assert.equal(Object.hasOwn(v, 'nexusEmperorSecretHistory'), false);
}
const next = nexusReady(f.g);
assert.equal(next.phase, 5);
assert.equal(next.nexusCards!.cards!.hands[f.owner], 'emperor');
nexusReject(next, f.owner, f.action, /Revival/);
const ready = applyAction(f.g, f.owner, { type: 'ready' });
// As with ordinary revival, a Ready vote does not end the printed phase
// while other players are still acting; the existing timing remains valid.
assert.equal(
viewGame(ready, f.owner).nexusEmperorSecretAlly!.revival.blocked,
null,
);
assert.equal(
applyAction(ready, f.owner, f.action).nexusEmperorSecretHistory!.length,
1,
);
});
void test('stale, wrong-owner, malformed and leader-revival requests reject before any resource or random commitment', () => {
const f = nexusEmperorSecretAllyFixture(),
before = nexusReload(f.g);
for (const action of [
{ ...f.action, event: 'stale' },
{ ...f.action, elite: -1 },
{ ...f.action, elite: 0.5 },
{ ...f.action, amount: 2 },
{ ...f.action, leader: f.g.players[0].leaders[0].id },
{ type: f.action.type, event: f.action.event },
])
nexusReject(f.g, f.owner, action);
nexusReject(f.g, f.target, f.action);
assert.deepEqual(f.g, before);
const card = f.g.deck.find((c) => c.effect === 'truthtrance')!;
f.g.deck = f.g.deck.filter((c) => c.id !== card.id);
f.g.players.find((p) => p.id === f.target)!.hand.push(card);
const pending = applyAction(f.g, f.target, { type: 'card', card: card.id });
assert.ok(pending.truthtrance);
nexusReject(pending, f.owner, f.action, /current interaction/);
});
void test('ordinary Fremen aid to the other allied seat does not suppress this unallied owner', () => {
const f = nexusEmperorSecretAllyFixture();
const granted = applyAction(f.g, 'p', { type: 'grantRevival' });
assert.ok(granted.freeRevival.includes('r'));
assert.equal(
viewGame(granted, f.owner).nexusEmperorSecretAlly!.revival.blocked,
null,
);
const done = applyAction(granted, f.owner, f.action);
assert.deepEqual(done.freeRevival, granted.freeRevival);
});
void test('combined modules and applicable revival suppression stay explicit, while native and Betrayal modes never expose Secret Ally', () => {
const f = nexusEmperorSecretAllyFixture();
for (const damage of [
(g: Game) => {
g.expansions = ['ix'];
},
(g: Game) => {
g.discoveryEnabled = true;
},
(g: Game) => {
g.revivalRules!.expanded = [f.owner];
},
(g: Game) => {
g.revivalRules!.freeBlocked = [f.owner];
},
(g: Game) => {
g.revivalPrevention = { player: f.owner, turn: g.turn };
},
]) {
const g = nexusReload(f.g);
damage(g);
nexusReject(g, f.owner, f.action, /Nexus|Discover|revival/);
}
for (const native of [false, true]) {
const g = nexusTraitorFixture({
ownerFaction: native ? 'emperor' : 'atreides',
opponentFaction: native ? 'guild' : 'emperor',
phase: 4,
});
const cards = g.nexusCards!.cards!,
old = cards.hands.p!;
cards.deck[cards.deck.indexOf('emperor')] = old;
cards.hands.p = 'emperor';
assert.equal(viewGame(g, 'p').nexusEmperorSecretAlly, null);
nexusReject(g, 'p', f.action);
}
});
void test('JSON restoration keeps signed source history private and rejects missing markers, duplicate uses and changed physical quotes', () => {
const f = nexusEmperorSecretAllyFixture(),
done = applyAction(f.g, f.owner, f.action);
for (const p of done.players)
assert.deepEqual(viewGame(nexusReload(done), p.id), viewGame(done, p.id));
assert.deepEqual(normalizeAutomaticGame(nexusReload(done)), done);
nexusReject(done, f.owner, f.action);
for (const damage of [
(g: Game) => {
delete g.nexusEmperorSecretHistory;
},
(g: Game) => {
delete g.nexusEmperorSecretEvents;
},
(g: Game) => {
g.nexusEmperorSecretEvents![0] = 'forged';
},
(g: Game) => {
g.nexusEmperorSecretHistory!.push(g.nexusEmperorSecretHistory![0]);
g.nexusEmperorSecretEvents!.push(g.nexusEmperorSecretEvents![0]);
},
(g: Game) => {
g.nexusEmperorSecretHistory![0].after.reserves++;
},
(g: Game) => {
const r = g.nexusEmperorSecretHistory![0];
r.elite = 1;
r.signature = emperorNexusSignature(r);
},
(g: Game) => {
const cards = g.nexusCards!.cards!;
cards.discard = cards.discard.filter((c) => c !== 'emperor');
cards.hands[f.owner] = 'emperor';
},
]) {
const g = nexusReload(done);
damage(g);
const before = nexusReload(g);
assert.throws(() => viewGame(g, f.owner), /Emperor Nexus/);
assert.throws(() => normalizeAutomaticGame(g), /Emperor Nexus/);
assert.throws(
() => applyAction(g, f.owner, { type: 'ready' }),
/Emperor Nexus/,
);
assert.deepEqual(g, before);
}
});
+52 -1
View File
@@ -1,7 +1,13 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { DatabaseSync } from 'node:sqlite';
import { createGame, joinGame, newPlayer } from '../game/engine';
import {
createGame,
joinGame,
newPlayer,
viewGame,
type Game,
} from '../game/engine';
import {
startIxPrototypeRoom,
startPrototypeRoom,
@@ -146,3 +152,48 @@ void test('Leader Skills prototype saves the real private setup once without cha
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,
);
});