import assert from 'node:assert/strict'; import test from 'node:test'; import { createGame, newPlayer, type Game } from '../game/engine'; import { richeseRevealInterruptSupported } from '../game/richese-reveal-interruption'; import { createStrongholdCards } from '../game/stronghold-cards'; import { createTechTokens } from '../game/tech-tokens'; /** These are quote fixtures, not claims that a staged phase is a full game. * Parent integration and actual physical markers belong to the runtime tests. */ function auction(advanced = false): Game { const game = createGame('REVEALPHASE', newPlayer('r', 'Richese', 'richese'), advanced, ['choam']); game.players.push(newPlayer('c', 'CHOAM', 'choam'), newPlayer('e', 'Emperor', 'emperor')); game.status = 'playing'; game.phase = 3; game.turn = 2; game.decision = {kind:'auctionPayment', player:'e'}; game.auction = {cards:[], index:0, bid:3, bidder:'e', active:'e', passed:[], opener:0}; return game; } function withModules(game: Game, tech: boolean, strongholds: boolean): Game { if (tech) { game.techTokens = createTechTokens(game.players); game.techTokens.axlotl.owner = 'c'; game.techTokens.axlotl.spice = 2; game.techTokens.axlotl.triggeredTurn = 1; } if (strongholds) { game.strongholdCards = createStrongholdCards(); game.strongholdCards.owners.arrakeen = 'e'; game.strongholdCards.claimedTurn = 1; } return game; } void test('actual selected phase-module custody admits the existing auction parent without changing it', () => { for (const [advanced, tech, strongholds] of [ [false, true, false], [true, true, false], [true, false, true], [true, true, true], ] as const) { const game = withModules(auction(advanced), tech, strongholds); const before = structuredClone(game); assert.equal(richeseRevealInterruptSupported(game), true, `${advanced}/${tech}/${strongholds}`); assert.deepEqual(game, before); } }); void test('phase modules admit the previously supported CHOAM market and Emperor gift parents', () => { for (const strongholds of [false, true]) { const market = withModules(auction(strongholds), true, strongholds); market.auction = null; market.decision = {kind:'choamMarket', player:'c'}; market.choamMarket = {owner:'c', resume:'phase', blocked:[]}; assert.equal(richeseRevealInterruptSupported(market), true); const gift = withModules(auction(strongholds), true, strongholds); gift.auction = null; gift.decision = null; gift.players[2].ally = 'r'; gift.players[0].ally = 'e'; gift.players[2].spice = 5; gift.response = {kind:'emperorGift', owner:'e', recipient:'r', amount:2, elite:0, passed:[]}; assert.equal(richeseRevealInterruptSupported(gift), true); } }); void test('phase modules require valid selected rosters, seat counts and physical component states', () => { const malformed: Array<(game: Game) => void> = [ game => { game.players.pop(); }, game => { game.players[1].faction = 'richese'; }, game => { game.players[1].faction = 'ixians'; }, game => { delete (game.techTokens as Partial>).axlotl; }, game => { game.techTokens!.production.owner = 'absent'; }, game => { game.techTokens!.production.spice = -1; }, game => { game.techTokens!.production.triggeredTurn = game.turn + 1; }, ]; for (const mutate of malformed) { const game = withModules(auction(), true, false); mutate(game); const before = structuredClone(game); assert.equal(richeseRevealInterruptSupported(game), false); assert.deepEqual(game, before); } for (const mutate of [ (game: Game) => { game.advanced = false; }, (game: Game) => { delete (game.strongholdCards!.owners as Partial['owners']>).arrakeen; }, (game: Game) => { game.strongholdCards!.owners.arrakeen = 'absent'; }, (game: Game) => { game.strongholdCards!.claimedTurn = game.turn + 1; }, ]) { const game = withModules(auction(true), false, true); mutate(game); assert.equal(richeseRevealInterruptSupported(game), false); } }); void test('phase modules do not remove existing child, truth or commitment restrictions', () => { const cases: Array<(game: Game) => void> = [ game => { game.leaderSkills = {} as NonNullable; }, game => { game.discoveryEnabled = true; }, game => { game.pendingNullentropy = {} as NonNullable; }, game => { game.shipmentPromises = [{turn:game.turn, player:'e', asker:'r', answer:true, territory:'carthag', minimum:3}]; }, game => { delete game.truthHistory; }, ]; for (const mutate of cases) { const game = withModules(auction(true), true, true); mutate(game); assert.equal(richeseRevealInterruptSupported(game), false); } });