Files
Dune/tests/nexus-harkonnen-e3-preserve.test.ts
T
Quintine 007508185e
Verify and publish checkpoint container / container (push) Successful in 14m6s
Prototype Harkonnen Nexus with standalone E3 factions
2026-11-16 21:03:08 +11:00

89 lines
5.6 KiB
TypeScript

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
import { emperorNexusPools } from '../game/nexus-emperor-secret-ally';
import { orderE3NexusEcazSpice } from './fixture-e3-nexus-ecaz';
import { advanceNexusEmperorBank, nexusEmperorBankInventory,
nexusEmperorBankPlayer as player } from './fixture-nexus-emperor-bank';
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
const clean = (game: Game) => !game.phaseOpening && !game.response && !game.decision &&
!game.truthtrance && !game.pendingTreacheryDiscard;
/** Public Advanced E3 start, full first turn, real second-turn worm/alliance,
* and an original Nexus draw. Only the still-undealt Spice and Nexus singleton
* ordering is selected; no started room or held card is fabricated. */
function closing(native: 'ecaz' | 'moritani'): Game {
let game = createGame('HARKE3PRESERVE', newPlayer('e3', native, native), true, ['ecaz']);
for (const [id, faction] of [['h', 'harkonnen'], ['g', 'guild'], ['a', 'atreides']] as const)
joinGame(game, newPlayer(id, faction, faction));
game = act(game, 'e3', { type: 'moduleOption', module: 'nexusCards', enabled: true });
for (const seat of game.players) game = act(game, seat.id, { type: 'ready' });
game = act(game, 'e3', { type: 'start', advancedPreview: true });
assert.equal(game.advanced, true);
assert.equal(game.nexusHarkonnenBetrayalPreview, true);
game = advanceNexusEmperorBank(game, state => state.status === 'playing');
if (native === 'ecaz') assert.ok(game.ecazLoyalty?.card);
else assert.equal(game.moritaniAssassinatePreview, true);
nexusEmperorBankInventory(game);
orderE3NexusEcazSpice(game);
game = advanceNexusEmperorBank(game, state => state.turn === 2 && state.phase === 1 && clean(state) &&
!state.spiceSequence && !state.spiceResolution && !state.spiceWindow);
orderE3NexusEcazSpice(game, true);
game = advanceNexusEmperorBank(game, state => !!state.nexus && !state.spiceWindow && !state.spiceResolution && clean(state));
game = act(game, 'h', { type: 'alliance', target: 'g' });
game = act(game, 'g', { type: 'alliance', target: 'h' });
game = advanceNexusEmperorBank(game, state => state.nexusCards?.phase?.stage === 'drawing' && clean(state));
const cards = game.nexusCards!.cards!, index = cards.deck.indexOf('emperor'); assert.ok(index >= 0);
cards.deck.unshift(cards.deck.splice(index, 1)[0]);
assert.ok(game.nexusCards!.phase!.eligible.includes('e3'));
game = act(game, 'e3', { type: 'nexusCardChoice', turn: game.turn, card: null, choice: 'draw', ownRedraws: 0 });
assert.equal(game.nexusCards!.cards!.hands.e3, 'emperor');
game = advanceNexusEmperorBank(game, state => state.nexusCards?.phase?.stage === 'complete' && clean(state));
nexusEmperorBankInventory(game);
return game;
}
for (const native of ['ecaz', 'moritani'] as const) {
void test(`public Advanced ${native} retains Emperor Nexus normal bank purchase with the Harkonnen reaction stamp`, () => {
let game = closing(native);
game = advanceNexusEmperorBank(game, state => state.phase === 3 && !!state.auction && clean(state));
while (game.auction!.active !== 'e3') game = act(game, game.auction!.active, { type: 'passBid' });
const card = game.auction!.cards[game.auction!.index], wallet = player(game, 'e3').spice;
assert.ok(wallet >= 1);
game = act(game, 'e3', { type: 'bid', amount: 1, allyPayment: 0 });
game = advanceNexusEmperorBank(game, state => state.decision?.kind === 'auctionPayment');
const offer = viewGame(game, 'e3').nexusEmperorSecretAlly;
assert.ok(offer?.purchase && !offer.purchase.blocked, 'The physical Nexus must remain available at the native purchase boundary.');
const paid = act(game, 'e3', { type: 'nexusEmperorPurchase', event: offer.event });
assert.equal(player(paid, 'e3').spice, wallet);
assert.equal(paid.nexusCards!.cards!.hands.e3, null);
assert.equal(paid.nexusCards!.cards!.discard.filter(c => c === 'emperor').length, 1);
assert.equal(player(paid, 'e3').hand.filter(c => c.id === card.id).length, 1);
assert.equal(paid.nexusHarkonnenBetrayalPreview, true);
nexusEmperorBankInventory(paid);
assert.throws(() => act(paid, 'e3', { type: 'nexusEmperorPurchase', event: offer.event }));
});
void test(`public Advanced ${native} retains Emperor Nexus revival with the Harkonnen reaction stamp`, () => {
let game = closing(native);
game = advanceNexusEmperorBank(game, state => state.phase === 4 && clean(state));
// Conserved physical staging only: move three actual reserve forces to the
// Tanks at the real Revival boundary, preserving all force totals.
const seat = player(game, 'e3'); assert.ok(seat.reserves >= 3);
seat.reserves -= 3; seat.tanks += 3;
const before = emperorNexusPools(seat), offer = viewGame(game, 'e3').nexusEmperorSecretAlly;
assert.ok(offer && !offer.revival.blocked, 'The original held face must expose its native Revival action.');
const action: Action = { type: 'nexusEmperorRevive', event: offer.event, elite: 0 };
game = act(game, 'e3', action);
assert.equal(player(game, 'e3').reserves, before.reserves + 3);
assert.equal(player(game, 'e3').tanks, before.tanks - 3);
assert.equal(player(game, 'e3').revived, before.revived);
assert.equal(game.nexusCards!.cards!.hands.e3, null);
assert.equal(game.nexusCards!.cards!.discard.filter(c => c === 'emperor').length, 1);
assert.equal(game.nexusHarkonnenBetrayalPreview, true);
nexusEmperorBankInventory(game);
assert.throws(() => act(game, 'e3', action));
});
}