Files
Dune/tests/truth-phase-any-early-richese-semuta.test.ts
T
Quintine 3ede19c90a
Verify and publish checkpoint container / container (push) Successful in 11m28s
Compose early cache and phase-wide bid commitments
2026-11-16 20:01:53 +11:00

72 lines
4.5 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Game } from '../game/engine';
import {
actTruthtranceRichesePromises as act,
createTruthtranceRichesePromisesFixture as fixture, passTruthRicheseFreshDiscard,
truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player,
} from './fixture-truthtrance-richese-promises';
/** Genuine public Basic Richese setup; a second physical Truthtrance moves
* from unopened deck to Atreides and Semuta moves from Richese cache to its
* owner. No answer, bid, purse or reaction is manufactured. */
function source() {
const f=fixture({advanced:false});
const game=structuredClone(f.earlySource);
assert.equal(game.semutaPreview,true);
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);
const semutaAt=game.richeseCache!.findIndex(card => card.effect === 'semutaDrug'); assert.ok(semutaAt>=0);
const [semuta]=game.richeseCache!.splice(semutaAt,1); player(game,f.richese).hand.push(semuta);
assert.deepEqual(inventory(game),f.originalCards);
return {f,game,second:second.id,semuta:semuta.id};
}
function parent(game:Game) {
return structuredClone({turn:game.turn,phase:game.phase,active:game.active,ready:game.ready,order:game.order,
auction:game.auction,richeseAuction:game.richeseAuction,richeseBidding:game.richeseBidding,aid:game.aid});
}
for (const first of ['phase','early'] as const) for (const claim of [false,true]) void test(
`Basic early ${first} first: second Truth Semuta ${claim ? 'claim' : 'pass'} binds both waiting ledgers`,() => {
const f=source(), original=parent(f.game);
const phase={kind:'phaseAnyBid',target:f.f.emperor,turn:f.game.turn,minimum:4};
const early={kind:'earlyRicheseBid',target:f.f.emperor,turn:f.game.turn,minimum:6};
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 : early});
game=act(game,f.f.emperor,{type:'truthAnswer',answer:'yes'});
const single=game.pendingTreacheryDiscard; assert.ok(single?.reaction);
assert.equal(single.continuation.kind,'truthtranceDiscard');
assert.equal(single.continuation.jointEarlyPhaseBid,undefined,'The older single-answer receipt keeps its shape');
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' ? early : phase});
game=act(game,f.f.emperor,{type:'truthAnswer',answer:'yes'});
const pending=game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'truthtranceDiscard');
assert.equal(pending.continuation.jointEarlyPhaseBid,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), earlyPromises=structuredClone(game.earlyRicheseBidPromises);
assert.deepEqual(parent(game),original);
for (const family of ['phaseAnyBidPromises','earlyRicheseBidPromises'] 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 ${family}`);
}
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.earlyRicheseBidPromises,earlyPromises);
assert.deepEqual(parent(game),original);
assert.ok(game.earlyRicheseBidPromises?.some(row => row.player === f.f.emperor && !row.boundEvent && !row.released));
assert.deepEqual(inventory(game),f.f.originalCards);
});