Files
Dune/tests/sapho-truth-auction-advanced-semuta.test.ts
T
Quintine dd4222ee92
Verify and publish checkpoint container / container (push) Canceled after 0s
Support Advanced Semuta at Sapho auction ordering
2026-11-16 18:54:59 +11:00

89 lines
5.8 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Game } from '../game/engine';
import { createSaphoTruthRicheseFixture, assertRicheseParent } from './fixture-sapho-truth-richese';
import { createSaphoTruthAuctionFixture, assertAuctionParent, act, inventory, player } from './fixture-sapho-truth-auction';
import { passTruthOrder, playSaphoTruthOrder, finishOriginalTruthQuestions, passFreshDiscard } from './fixture-sapho-truth-order';
/** All games start through native Advanced setup and bidding. Cache cases use
* the fixture's disclosed physical cache/hand swaps. The ordinary case swaps
* the original cached Semuta with a held card after the actual Sapho purchase. */
for (const method of ['onceAround','silent'] as const) for (const claim of [false,true]) void test(
`Advanced ${method} cache Sapho Semuta ${claim ? 'claim' : 'pass'} restores the original auction and queued questions`, () => {
const f = createSaphoTruthRicheseFixture({advanced:true,method,standingBid:true,semuta:true});
assert.equal(f.game.semutaAdvancedOrdinaryPreview,true); assert.ok(f.semuta);
let game = passTruthOrder(f.game,f.other);
game = playSaphoTruthOrder(game,f.owner,f.card,f.mode);
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'saphoTruthOrderDiscard');
assert.equal(pending.batch.entries[0].card.id,f.card);
assert.equal(viewGame(game,f.semutaHolder).semutaReaction?.canCommit,true);
assertRicheseParent(game,f.parent);
if (method === 'silent') {
assert.equal(viewGame(game,f.semutaHolder).richeseAuction?.ownBid,1);
assert.equal(viewGame(game,f.owner).richeseAuction?.revealedBids,null);
}
game = claim ? act(game,f.semutaHolder,{type:'semutaCommit',event:pending.batch.event}) : passFreshDiscard(game);
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance?.stage,'ask');
assert.equal(f.mode === 'first' ? game.truthtrance!.queue[0].player : game.truthtrance!.queue.at(-1)!.player,f.owner);
assert.equal(player(game,f.semutaHolder).hand.some(card => card.id === f.card),claim);
assert.equal(game.discard.some(card => card.id === f.semuta),claim);
assertRicheseParent(game,f.parent);
game = finishOriginalTruthQuestions(game); assert.equal(game.truthtrance,null);
assertRicheseParent(game,f.parent); assert.deepEqual(inventory(game),f.originalCards);
const lot = game.richeseAuction!;
const actor = method === 'onceAround' ? lot.active : lot.eligible.find(id => !Object.hasOwn(lot.sealed,id));
assert.ok(actor);
game = act(game,actor,{type:'richeseBid',event:f.lot,amount:method === 'silent' ? 0 : null,allyPayment:0});
assert.deepEqual(inventory(game),f.originalCards);
},
);
for (const claim of [false,true]) void test(
`Advanced ordinary standing bid survives Sapho Truth-order Semuta ${claim ? 'claim' : 'pass'}`, () => {
const f = createSaphoTruthAuctionFixture({advanced:true,standingBid:true,mode:'first'});
let game: Game = structuredClone(f.game);
assert.equal(game.semutaAdvancedOrdinaryPreview,true);
const claimant = player(game,'atreides'), cache = game.richeseCache;
assert.ok(cache && claimant.hand.length);
const index = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(index >= 0);
const [semuta] = cache.splice(index,1), [exchange] = claimant.hand.splice(0,1);
claimant.hand.push(semuta); cache.push(exchange);
assertAuctionParent(game,f.parent); assert.deepEqual(inventory(game),f.originalCards);
game = passTruthOrder(game,f.other);
game = playSaphoTruthOrder(game,f.owner,f.card,'first');
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'saphoTruthOrderDiscard');
assert.equal(viewGame(game,'atreides').semutaReaction?.canCommit,true);
assertAuctionParent(game,f.parent);
game = claim ? act(game,'atreides',{type:'semutaCommit',event:pending.batch.event}) : passFreshDiscard(game);
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance?.stage,'ask');
assert.equal(game.truthtrance?.queue[0].player,f.owner);
assert.equal(player(game,'atreides').hand.some(card => card.id === f.card),claim);
assert.equal(game.discard.some(card => card.id === semuta.id),claim);
assertAuctionParent(game,f.parent);
game = finishOriginalTruthQuestions(game); assert.equal(game.truthtrance,null);
assertAuctionParent(game,f.parent); assert.deepEqual(inventory(game),f.originalCards);
game = act(game,game.auction!.active,{type:'passBid'});
assert.equal(game.auction?.bid,1); assert.equal(game.auction?.bidder,f.parent.auction!.bidder);
assert.deepEqual(inventory(game),f.originalCards);
},
);
void test('an older Advanced cache game without the Semuta preview marker keeps its original synchronous Sapho continuation', () => {
const f = createSaphoTruthRicheseFixture({advanced:true,method:'silent',standingBid:true,semuta:true});
const older = structuredClone(f.game);
delete older.semutaAdvancedOrdinaryPreview; // Simulate a saved start predating the marker.
assert.ok(f.semuta && player(older,f.semutaHolder).hand.some(card => card.id === f.semuta));
let game = passTruthOrder(older,f.other);
game = playSaphoTruthOrder(game,f.owner,f.card,f.mode);
assert.equal(game.pendingTreacheryDiscard ?? null,null);
assert.equal(game.truthtrance?.stage,'ask');
assert.equal(f.mode === 'first' ? game.truthtrance!.queue[0].player : game.truthtrance!.queue.at(-1)!.player,f.owner);
assert.ok(player(game,f.semutaHolder).hand.some(card => card.id === f.semuta));
assertRicheseParent(game,f.parent);
game = finishOriginalTruthQuestions(game);
assert.equal(game.truthtrance,null); assertRicheseParent(game,f.parent);
assert.deepEqual(inventory(game),f.originalCards);
});