Files
Dune/tests/truth-early-richese-advanced-market-release-native.test.ts
T
Quintine 6a30fdf376
Verify and publish checkpoint container / container (push) Successful in 12m4s
Compose market, early cache and phase bid promises
2026-11-16 20:51:03 +11:00

101 lines
6.1 KiB
TypeScript

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,
truthtranceRichesePromisesInventory as inventory,
truthtranceRichesePromisesPlayer as player,
} from './fixture-truthtrance-richese-promises';
/** Real Advanced R/A/E opening and actual market actions. Stage only the
* original second Truthtrance and Semuta into hands, then use Semuta to
* recover the first discarded Truthtrance for the third real question. */
function source(method:'silent'|'onceAround') {
const f=fixture({advanced:true}); let game:Game=structuredClone(f.earlySource);
const truthAt=game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
assert.ok(truthAt >= 0); const [second]=game.deck.splice(truthAt,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);
game=act(game,f.asker,{type:'card',card:f.truth});
game=advance(game,state => state.truthtrance?.stage === 'ask');
game=act(game,f.asker,{type:'truthAsk',question:{kind:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:2}});
game=act(game,f.emperor,{type:'truthAnswer',answer:'yes'});
const firstDiscard=game.pendingTreacheryDiscard; assert.ok(firstDiscard?.reaction);
assert.equal(viewGame(game,f.richese).semutaReaction?.canCommit,true);
game=act(game,f.richese,{type:'semutaCommit',event:firstDiscard.batch.event});
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
game=act(game,f.richese,{type:'semutaSelect',event:firstDiscard.batch.event,card:f.truth});
assert.ok(player(game,f.richese).hand.some(card => card.id === f.truth));
const early=game.earlyRicheseBidPromises?.find(row => row.player === f.emperor && row.answer); assert.ok(early);
game=advance(game,state => state.decision?.kind === 'richeseBlackMarket');
const open=(direction:'clockwise'|'counterclockwise') => act(game,f.richese,
{type:'decision',event:game.richeseBidding!.event,card:f.targetCard,method,
...(method === 'onceAround' ? {direction} : {})});
let market=open('clockwise');
// Both directions are genuine physical choices; select one whose first
// actor is not the respondent so the test can perform an external action.
if (method === 'onceAround' && market.richeseAuction?.active === f.emperor)
market=open('counterclockwise');
game=market;
while (game.response) {
const actor=game.players.find(seat => !game.response!.passed.includes(seat.id)); assert.ok(actor);
game=act(game,actor.id,{type:'passResponse'});
}
const lot=game.richeseAuction; assert.ok(lot && lot.source === 'blackMarket');
if (method === 'onceAround') assert.notEqual(lot.active,f.emperor);
const event=lot.event;
function ask(asker:string,card:string,minimum:number) {
game=act(game,asker,{type:'card',card});
game=advance(game,state => state.truthtrance?.stage === 'ask');
game=act(game,asker,{type:'truthAsk',question:{kind:'richeseBid',target:f.emperor,turn:game.turn,event,minimum}});
assert.ok(viewGame(game,f.emperor).truthRicheseBidAnswers?.includes('yes'));
game=passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'}));
}
ask(f.asker,second.id,4);
ask(f.richese,f.truth,8);
const low=game.richeseBidPromises?.find(row => row.event === event && row.player === f.emperor && row.minimum === 4);
const high=game.richeseBidPromises?.find(row => row.event === event && row.player === f.emperor && row.minimum === 8);
assert.ok(low && high);
assert.equal(player(game,f.emperor).spice,10);
assert.deepEqual(inventory(game),f.originalCards);
return {game,f,event,early,low,high};
}
for (const method of ['silent','onceAround'] as const) void test(
`Advanced ${method} market releases only the native Yes made impossible by an external loss`,() => {
const s=source(method); let game=structuredClone(s.game);
// Explicit external-loss supplement: cash falls from 10 to 7 while the
// original market remains open. Two must stay reserved for the cache,
// leaving a market ceiling of five. No cards or receipts are staged here.
player(game,s.f.emperor).spice=7;
const lot=game.richeseAuction!;
const actor=method === 'silent' ? s.f.asker : lot.active;
assert.ok(actor && actor !== s.f.emperor);
game=act(game,actor,{type:'richeseBid',event:s.event,amount:method === 'silent' ? 0 : null,allyPayment:0});
const low=game.richeseBidPromises?.find(row => row.id === s.low.id);
const high=game.richeseBidPromises?.find(row => row.id === s.high.id);
assert.ok(low && high);
assert.equal(!!low.fulfilled,false); assert.equal(!!low.released,false,'The affordable native Yes remains binding');
assert.equal(!!high.fulfilled,false); assert.equal(!!high.released,true,'Only the unaffordable native Yes releases');
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === s.early.id && !row.boundEvent && !row.released));
if (method === 'silent') {
assert.equal(viewGame(game,s.f.richese).richeseAuction?.revealedBids,null);
} else assert.equal(game.richeseAuction?.active,s.f.emperor);
const guide=viewGame(game,s.f.emperor).richeseBidPromiseGuide?.action; assert.ok(guide);
assert.equal(guide.type,'richeseBid'); assert.equal(guide.event,s.event); assert.equal(guide.amount,4);
assert.equal(guide.richeseBidPromiseId,s.low.id); assert.equal(guide.earlyRicheseBidPromiseId,s.early.id);
game=act(game,s.f.emperor,guide);
assert.ok(game.richeseBidPromises?.some(row => row.id === s.low.id && row.fulfilled));
assert.ok(game.richeseBidPromises?.some(row => row.id === s.high.id && row.released));
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === s.early.id && !row.boundEvent && !row.released));
assert.deepEqual(inventory(game),s.f.originalCards);
});