Files
Dune/tests/sapho-testing-station-replay-compat.test.ts
T
Quintine 05f7fc8f20
Verify and publish checkpoint container / container (push) Successful in 11m20s
Allow recovered Sapho at Testing Station
2026-11-16 19:50:58 +11:00

90 lines
5.1 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { DISCOVERY_CARD_PLACEMENTS, validateDiscoveryState } from '../game/discoveries';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { advanceTestingStationContest } from './fixture-testing-station-contest';
import { moveSemutaEmperorCard } from './fixture-semuta-emperor-share';
import { reactSemutaSpecial } from './fixture-semuta-special-karama';
const SAPHO = 'richese-juice-of-sapho';
const STATION = 'ecological-testing-station';
const seat = (game: Game, id: string) => {
const player = game.players.find(row => row.id === id); assert.ok(player); return player;
};
/** Public setup followed by a controlled physical Station placement, reserve
* counters and conserved original Sapho/Semuta transfers. The pending discard
* is produced by the real card action and native Station queue. */
function pendingStationDiscard() {
let game = createGame('SAPHOSTATIONCOMPAT', newPlayer('richese', 'Richese', 'richese'), false, ['choam']);
for (const faction of ['atreides', 'emperor'] as const)
joinGame(game, newPlayer(faction, faction, faction));
game = applyAction(game, game.host, {type:'moduleOption', module:'discoveries', enabled:true});
for (const player of game.players) game = applyAction(game, player.id, {type:'ready'});
game = applyAction(game, game.host, {type:'start'});
game = advanceTestingStationContest(game, state => state.status === 'playing');
const token = game.discoveries!.tokens.find(row => row.face === STATION);
assert.ok(token && token.status === 'supply');
const placement = Object.values(DISCOVERY_CARD_PLACEMENTS).find(row => row.type === token.type);
assert.ok(placement);
Object.assign(token, {status:'placed', territory:placement.territory, sector:placement.sector, revealedTurn:game.turn});
validateDiscoveryState(game.discoveries!);
for (const id of ['richese', 'emperor']) {
const player = seat(game, id); assert.ok(player.reserves > 0);
player.reserves--;
player.forces[`${STATION}:0`] = (player.forces[`${STATION}:0`] ?? 0) + 1;
while (player.hand.length >= 4) game.deck.push(player.hand.pop()!);
}
moveSemutaEmperorCard(game, SAPHO, 'emperor');
moveSemutaEmperorCard(game, SEMUTA_DRUG_ID, 'richese');
game = advanceTestingStationContest(game, state => state.decision?.kind === 'ecologicalStorm');
const option = viewGame(game, 'emperor').saphoOptions.find(row => row.scope === 'testingStation');
assert.ok(option);
game = applyAction(game, 'emperor', {type:'card', card:SAPHO, scope:option.scope,
event:option.event, mode:option.mode});
assert.equal(game.pendingTreacheryDiscard?.continuation.kind, 'saphoStationDiscard');
return game;
}
void test('legacy saved pending Sapho discard resumes without installing the new replay-priority window', () => {
const game = pendingStationDiscard();
const pending = game.pendingTreacheryDiscard; assert.ok(pending);
const continuation = pending.continuation;
assert.equal(continuation.kind, 'saphoStationDiscard');
if (continuation.kind !== 'saphoStationDiscard') throw Error('Expected the station continuation');
assert.equal(continuation.stationReplayPriority, true);
// The old signature has exactly the same ordered JSON fields except the
// new optional marker; no historic station frame or pending parent changes.
const signature = JSON.parse(continuation.stateSignature) as Record<string, unknown>;
delete signature.stationReplayPriority;
delete continuation.stationReplayPriority;
continuation.stateSignature = JSON.stringify(signature);
const resumed = reactSemutaSpecial(game, 'richese', true);
assert.equal(resumed.pendingTreacheryDiscard, null);
assert.equal(resumed.saphoStationPriority, undefined);
assert.equal(resumed.decision?.kind, 'ecologicalStorm');
assert.ok(seat(resumed, 'richese').hand.some(card => card.id === SAPHO));
assert.ok(viewGame(resumed, 'richese').saphoOptions.some(row => row.scope === 'testingStation'));
});
void test('all minimal bot profiles legally pass each reopened Station priority', () => {
const game = reactSemutaSpecial(pendingStationDiscard(), 'richese', true);
assert.ok(game.saphoStationPriority);
const order = game.ecologicalStorm!.queue!.order;
for (const occupant of order) for (const difficulty of DIFFICULTIES) {
const bot = viewGame(game, occupant);
bot.players.find(row => row.id === occupant)!.bot = difficulty;
const action = botActions(bot)[0];
assert.deepEqual(action, {type:'saphoStationPass', event:game.saphoStationPriority.event});
let resumed = applyAction(game, occupant, action);
const other = order.find(id => id !== occupant); assert.ok(other);
resumed = applyAction(resumed, other, {type:'saphoStationPass', event:game.saphoStationPriority.event});
assert.equal(resumed.saphoStationPriority, undefined);
assert.equal(resumed.decision?.kind, 'ecologicalStorm');
assert.equal(resumed.ecologicalStorm?.queue?.choices.length, 0);
}
});