import assert from 'node:assert/strict'; import test from 'node:test'; import { viewGame, type Game } from '../game/engine'; import { actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance, createTruthtranceRichesePromisesFixture as fixture, passTruthRicheseFreshDiscard, truthtranceRichesePromisesClean as clean, truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player, } from './fixture-truthtrance-richese-promises'; /** Real Advanced CHOAM/Richese setup and ordinary auction. The conserved * supplements move the second original Truthtrance from the unopened deck to * Atreides and Semuta from Richese's cache to Richese; no bid, wallet, answer * or reaction is installed. */ function source() { const f = fixture({advanced:true}); let game = structuredClone(f.earlySource); const secondAt = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(secondAt >= 0); const [second] = game.deck.splice(secondAt,1); player(game,f.asker).hand.push(second); game = advance(game,state => state.phase === 3 && !!state.auction && clean(state)); if (game.auction!.active === f.asker) game = act(game,f.asker,{type:'passBid'}); const target = game.auction!.active; assert.ok(target && target !== f.asker); const cache = game.richeseCache!; const semutaAt = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(semutaAt >= 0); const [semuta] = cache.splice(semutaAt,1); player(game,f.richese).hand.push(semuta); assert.deepEqual(inventory(game),f.originalCards); return {f,game,target,second:second.id,semuta:semuta.id}; } function parent(game: Game) { return structuredClone({auction:game.auction,richeseAuction:game.richeseAuction, richeseBidding:game.richeseBidding,richeseFunding:game.richeseFunding,aid:game.aid, turn:game.turn,phase:game.phase,active:game.active,order:game.order}); } for (const first of ['phase','lot'] as const) for (const claim of [false,true]) void test( `Advanced ordinary ${first} first: second Truth Semuta ${claim ? 'claim' : 'pass'} preserves joint promises`, () => { const f = source(); const lot = f.game.auction!.index+1; const phase = {kind:'phaseAnyBid',target:f.target,turn:f.game.turn,minimum:1}; const native = {kind:'bid',target:f.target,turn:f.game.turn,lot,minimum:1}; const auction = parent(f.game); let game = act(f.game,f.f.asker,{type:'card',card:f.f.truth,cards:[f.second]}); while (game.truthtrance?.stage === 'priority') { const actor = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(actor); game = act(game,actor.id,{type:'truthPass'}); } assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.f.truth,f.second]); game = act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? phase : native}); game = act(game,f.target,{type:'truthAnswer',answer:'yes'}); game = passTruthRicheseFreshDiscard(game); assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.second]); game = act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? native : phase}); game = act(game,f.target,{type:'truthAnswer',answer:'yes'}); const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction); assert.equal(pending.continuation.kind,'truthtranceDiscard'); assert.equal(pending.continuation.jointOrdinaryPhaseBid,true); assert.equal(pending.batch.entries[0].card.id,f.second); assert.equal(viewGame(game,f.f.richese).semutaReaction?.canCommit,true); const phasePromises = structuredClone(game.phaseAnyBidPromises), lotPromises = structuredClone(game.bidPromises); assert.deepEqual(parent(game),auction); for (const family of ['phaseAnyBidPromises','bidPromises'] as const) { const tampered = structuredClone(game); tampered[family]![0].minimum++; assert.throws(() => act(tampered,f.f.richese,{type:'semutaCommit',event:pending.batch.event}), `The completed answer binds its ${family} receipts`); } game = claim ? act(game,f.f.richese,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game); assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null); assert.equal(player(game,f.f.richese).hand.some(card => card.id === f.second),claim); assert.equal(game.discard.some(card => card.id === f.semuta),claim); assert.deepEqual(game.phaseAnyBidPromises,phasePromises); assert.deepEqual(game.bidPromises,lotPromises); assert.deepEqual(parent(game),auction); const view = viewGame(game,f.target), guide = view.phaseAnyBidGuide?.action; assert.ok(guide); assert.deepEqual(guide,view.bidPromiseGuide?.action); game = act(game,f.target,guide); assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.target && row.fulfilled)); assert.ok(game.bidPromises?.some(row => row.player === f.target && row.fulfilled)); assert.deepEqual(inventory(game),f.f.originalCards); });