Files
Dune/tests/truth-phase-bid-revival-shipment-joint.test.ts
T
Quintine 9536c77062
Verify and publish checkpoint container / container (push) Successful in 10m33s
Compose Basic bid revival and shipment commitments
2026-11-16 14:05:28 +11:00

82 lines
4.7 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Game } from '../game/engine';
import { actTruthBid as act, advanceTruthBid as advance, truthBidClean as clean,
truthBidInventory as inventory, truthBidPlayer as player } from './fixture-truth-bid';
import { advanceTruthRevival, truthRevivalClean } from './fixture-truth-revival';
import { createTruthTurnBidFixture } from './fixture-truth-turn-bid';
/** Public H/A/E Basic setup and real turn-1 Charity. Because Basic has only
* two physical Truthtrances, one earlier shipment Yes is explicitly staged;
* the bid and revival commitments are asked and answered through real cards.
* Three existing reserves are moved to Tanks, and unopened Spice is ordered. */
function fixture() {
const f = createTruthTurnBidFixture();
let game = structuredClone(f.afterSetup);
for (const {position, from, card} of f.spiceOrder) {
const [selected] = game.spiceDeck.splice(from, 1);
assert.deepEqual(selected, card);
game.spiceDeck.splice(position, 0, selected);
}
game = advance(game,state => state.turn === 1 && state.phase === 2 && clean(state));
const emperor = player(game,f.target);
assert.equal(emperor.spice,10); assert.ok(emperor.reserves >= 3);
emperor.reserves -= 3; emperor.tanks += 3;
game.shipmentPromises = [{turn:game.turn,player:f.target,asker:f.asker,
territory:'carthag',minimum:2,answer:true}];
assert.deepEqual(inventory(game),f.originalCards);
return {f,game};
}
function ask(game: Game, asker: string, card: string, question: object): Game {
game = act(game,asker,{type:'card',card});
for (let count = 0; game.truthtrance?.stage === 'priority' && count < game.players.length; count++) {
const seat = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(seat);
game = act(game,seat.id,{type:'truthPass'});
}
assert.equal(game.truthtrance?.stage,'ask');
return act(game,asker,{type:'truthAsk',question});
}
for (const first of ['bid','revival'] as const) for (const affordable of [true,false]) {
void test(`Basic pre-Bidding bid, Revival and staged shipment share a purse in ${first}-first order (${affordable ? 'funded' : 'one short'})`, () => {
const {f,game:initial} = fixture();
const minimum = affordable ? 4 : 5;
const bid = {kind:'phaseBid',target:f.target,turn:initial.turn,minimum};
const revival = {kind:'revival',target:f.target,turn:initial.turn,counter:'total',minimum:3};
const questions = first === 'bid' ? [bid,revival] : [revival,bid];
let game = ask(initial,f.asker,f.truths[0],questions[0]);
const firstAnswers = first === 'bid' ? viewGame(game,f.target).truthPhaseBidAnswers : viewGame(game,f.target).truthRevivalAnswers;
assert.ok(firstAnswers?.includes('yes'), 'The first answer and earlier shipment fit the purse');
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = ask(game,f.asker,f.truths[1],questions[1]);
const answers = first === 'bid' ? viewGame(game,f.target).truthRevivalAnswers : viewGame(game,f.target).truthPhaseBidAnswers;
assert.ok(answers?.includes('no'));
assert.equal(answers?.includes('yes'),affordable, 'A bid, two paid returns and two shipped forces cost the same 10-spice purse');
if (!affordable) {
const before = structuredClone(game);
assert.throws(() => act(game,f.target,{type:'truthAnswer',answer:'yes'}));
assert.deepEqual(game,before);
return;
}
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = advance(game,state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
game = act(game,f.target,{type:'bid',amount:4,allyPayment:0});
assert.ok(game.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled));
game = advance(game,state => clean(state) && state.phase === 4);
assert.equal(player(game,f.target).spice,6);
game = act(game,f.target,{type:'revive',amount:3,elite:0});
game = advanceTruthRevival(game,truthRevivalClean);
assert.equal(player(game,f.target).spice,2);
assert.ok(game.revivalPromises?.some(row => row.player === f.target && row.fulfilled));
game = advance(game,state => clean(state) && state.phase === 5 && state.active === f.target);
const ship = viewGame(game,f.target).shipmentCompletion?.actions.at(-1);
assert.ok(ship && ship.type === 'ship'); assert.equal(ship.amount,2);
game = act(game,f.target,ship);
game = advance(game,state => clean(state) && !!state.shipmentPromises?.some(row => row.player === f.target && row.fulfilled));
assert.equal(player(game,f.target).spice,0);
assert.equal(player(game,f.target).forces['carthag:11'],2);
assert.deepEqual(inventory(game),f.originalCards);
});
}