Support deferred payments with travel deals
Verify and publish checkpoint container / container (push) Successful in 11m29s
Verify and publish checkpoint container / container (push) Successful in 11m29s
This commit is contained in:
1 parent
9536c77062
commit
5e294215be
16 files changed
+603
-100
No files matched your search
@@ -118,7 +118,21 @@ void test('an optional gross bribe is bound to two distinct participants', () =>
|
||||
assert.equal(publicDealOfferAction(['b'], 'Terms', payment), null);
|
||||
});
|
||||
|
||||
void test('all players can review the gross payment and only final acceptance is held at a blocked payment window', () => {
|
||||
void test('a deferred payment and travel show each participant and due turn in the deal history', () => {
|
||||
const payment = {kind:'deferredBribe', payer:'a', recipient:'b', amount:3, dueTurn:4};
|
||||
const travel = {kind:'ship', territory:'carthag', minimum:2, answer:true, actor:'e', dueTurn:3};
|
||||
const combined = {...offer, participants:['a','b','e'], acceptVotes:['a','b','e'], status:'active',
|
||||
payment, paymentStatus:'pending', travel};
|
||||
const game = {...base, turn:2, players:base.players.map(player => ({...player, ally:null})),
|
||||
deals:[combined], dealTravelStatus:{'deal-1':'scheduled'}} as unknown as GameView;
|
||||
const html = render(game);
|
||||
assert.match(html, /Alice \(Atreides\) pays exactly 3 spice to Basil \(Harkonnen\) on or before the end of turn 4/);
|
||||
assert.match(html, /Emperor \(Emperor\) agrees to make a reserve shipment of at least 2 physical forces in one action to Carthag during turn 3/);
|
||||
assert.match(html, /Payment status: pending/);
|
||||
assert.match(html, /Travel status: scheduled/);
|
||||
});
|
||||
|
||||
void test('the payer’s own blocked payment quote applies at final acceptance without using another seat’s quote', () => {
|
||||
const payment = { kind: 'immediateBribe' as const, payer: 'b', recipient: 'a', amount: 3 };
|
||||
const multi = { ...offer, participants: ['a', 'b', 'e'], acceptVotes: ['a'], payment };
|
||||
const game = { ...base, players: base.players.map(player =>
|
||||
@@ -135,10 +149,14 @@ void test('all players can review the gross payment and only final acceptance is
|
||||
assert.equal(first.find(node => node.props.children === 'Accept deal')?.props.disabled, false);
|
||||
const lastGame = { ...game, me: 'e', deals: [{ ...multi, acceptVotes: ['a', 'b'] }] } as unknown as GameView;
|
||||
const last = actions(lastGame, []);
|
||||
assert.equal(last.find(node => node.props.children === 'Accept deal')?.props.disabled, true);
|
||||
assert.equal(last.find(node => node.props.children === 'Accept deal')?.props.disabled, false,
|
||||
'A final recipient cannot use their private quote to block another payer.');
|
||||
assert.equal(last.find(node => node.props.children === 'Decline deal')?.props.disabled, false);
|
||||
assert.match(render(lastGame), /Final acceptance must wait: Finish the current decision before paying a bribe/);
|
||||
const unblocked = { ...lastGame, bribeOptions: { ...lastGame.bribeOptions, blocked: null } } as GameView;
|
||||
assert.doesNotMatch(render(lastGame), /Final acceptance must wait:/);
|
||||
const payerFinal = {...lastGame, deals:[{...multi, acceptVotes:['a','b'], payment:{...payment,payer:'e'}}]} as GameView;
|
||||
assert.equal(actions(payerFinal, []).find(node => node.props.children === 'Accept deal')?.props.disabled, true);
|
||||
assert.match(render(payerFinal), /Final acceptance must wait: Finish the current decision before paying a bribe/);
|
||||
const unblocked = { ...payerFinal, bribeOptions: { ...payerFinal.bribeOptions, blocked: null } } as GameView;
|
||||
assert.equal(actions(unblocked, []).find(node => node.props.children === 'Accept deal')?.props.disabled, false);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// @dune-suite integration
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import type { GameView } from '../game/engine';
|
||||
|
||||
const base = process.env.DUNE_TEST_URL ?? 'http://localhost:3000';
|
||||
async function request(path: string, cookie?: string, body?: unknown, selected?: string) {
|
||||
const response = await fetch(base + path, {
|
||||
method: body === undefined ? 'GET' : 'POST', signal: AbortSignal.timeout(15_000),
|
||||
headers: {
|
||||
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
||||
...(cookie ? { cookie } : {}),
|
||||
...(selected ? { 'X-Dune-Seat': selected } : {}),
|
||||
},
|
||||
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
||||
});
|
||||
return { status: response.status, cookie: response.headers.get('set-cookie')?.split(';')[0],
|
||||
data: await response.json() as GameView & { error?: string } };
|
||||
}
|
||||
|
||||
/** A fresh test room is created; no existing room is used or removed. Both
|
||||
* terms retain the same original agreement identity. */
|
||||
void test('authenticated players can consent to and pay a deferred travel agreement', async () => {
|
||||
const host = await request('/api/rooms', undefined, {
|
||||
name: 'Deferred travel recipient', faction: 'atreides', advanced: false, expansions: [],
|
||||
});
|
||||
assert.equal(host.status, 201, JSON.stringify(host.data)); assert.ok(host.cookie);
|
||||
const path = `/api/rooms/${host.data.code}`;
|
||||
const guest = await request(path, undefined, { type: 'join', name: 'Deferred traveler', faction: 'harkonnen' });
|
||||
assert.equal(guest.status, 200, JSON.stringify(guest.data)); assert.ok(guest.cookie);
|
||||
const seats = [{id:host.data.me,cookie:host.cookie}, {id:guest.data.me,cookie:guest.cookie}];
|
||||
let view = guest.data;
|
||||
const act = async (cookie: string, action: object) => {
|
||||
const next = await request(path, cookie, { version: view.version, action });
|
||||
assert.equal(next.status, 200, JSON.stringify(next.data)); view = next.data;
|
||||
};
|
||||
for (const seat of seats) await act(seat.cookie, {type:'ready'});
|
||||
await act(host.cookie, {type:'start'});
|
||||
for (const seat of seats) {
|
||||
const own = await request(path, seat.cookie);
|
||||
assert.equal(own.status, 200, JSON.stringify(own.data)); view = own.data;
|
||||
const choices = own.data.players.find(player => player.id === seat.id)?.traitorChoices;
|
||||
if (choices?.length) await act(seat.cookie, {type:'traitor', leader:choices[0]});
|
||||
}
|
||||
assert.equal(view.status, 'playing');
|
||||
const before = await request(path, guest.cookie);
|
||||
assert.equal(before.status, 200, JSON.stringify(before.data)); view = before.data;
|
||||
const spice = before.data.players.find(player => player.id === guest.data.me)?.spice;
|
||||
assert.ok(typeof spice === 'number' && spice >= 2);
|
||||
const dueTurn = view.turn + 1;
|
||||
const payment = {kind:'deferredBribe',payer:guest.data.me,recipient:host.data.me,amount:2,dueTurn};
|
||||
const travel = {kind:'ship',territory:'polar_sink',minimum:1,answer:true,dueTurn};
|
||||
await act(host.cookie, {type:'dealOffer',target:guest.data.me,
|
||||
terms:'Ship to Polar Sink and pay two spice next turn.',payment,travel});
|
||||
const offered = view.deals.at(-1); assert.ok(offered);
|
||||
assert.equal(offered.status, 'offered'); assert.deepEqual(offered.payment, payment);
|
||||
assert.deepEqual(offered.travel, travel);
|
||||
const acceptance = {type:'dealRespond',deal:offered.id,accept:true};
|
||||
const forged = await request(path, host.cookie, {version:view.version,action:acceptance}, guest.data.me);
|
||||
assert.equal(forged.status, 409, JSON.stringify(forged.data));
|
||||
await act(guest.cookie, acceptance);
|
||||
for (const seat of seats) {
|
||||
const read = await request(path,seat.cookie);
|
||||
assert.equal(read.status, 200, JSON.stringify(read.data));
|
||||
const active: GameView['deals'][number] | undefined = read.data.deals.find(deal => deal.id === offered.id); assert.ok(active);
|
||||
assert.equal(active.status, 'active'); assert.equal(active.paymentStatus, 'pending');
|
||||
assert.deepEqual(active.payment, payment); assert.deepEqual(active.travel, travel);
|
||||
assert.equal(read.data.dealTravelStatus[offered.id], 'scheduled');
|
||||
if (seat.id === guest.data.me)
|
||||
assert.equal(read.data.players.find(player => player.id === guest.data.me)?.spice, spice);
|
||||
}
|
||||
const wrongPayer = await request(path, host.cookie,
|
||||
{version:view.version,action:{type:'dealPay',deal:offered.id}});
|
||||
assert.equal(wrongPayer.status, 409, JSON.stringify(wrongPayer.data));
|
||||
await act(guest.cookie, {type:'dealPay',deal:offered.id});
|
||||
const paid = await request(path, guest.cookie);
|
||||
assert.equal(paid.status, 200, JSON.stringify(paid.data));
|
||||
assert.equal(paid.data.deals.find(deal => deal.id === offered.id)?.paymentStatus, 'paid');
|
||||
assert.equal(paid.data.dealTravelStatus[offered.id], 'scheduled');
|
||||
assert.equal(paid.data.players.find(player => player.id === guest.data.me)?.spice, spice - 2);
|
||||
});
|
||||
@@ -0,0 +1,220 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { actTruthTravel as act, advanceTruthTravel as advance, createTruthTravelFixture as fixture,
|
||||
settleTruthTravel as settle, truthTravelClean as clean, truthTravelInventory as inventory,
|
||||
truthTravelPlayer as player } from './fixture-truth-travel';
|
||||
import { nextStrongholdFactionsNativeStep as nextNative } from './fixture-stronghold-factions';
|
||||
|
||||
function reject(game: Game, actor: string, action: Action) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game, actor, action));
|
||||
assert.deepEqual(game, before, 'Rejected action must not partially mutate the source game.');
|
||||
}
|
||||
function deal(game: Game, id: string) {
|
||||
const found = game.deals?.find(row => row.id === id); assert.ok(found); return found;
|
||||
}
|
||||
function offer(game: Game, proposer: string, target: string, payer: string, recipient: string,
|
||||
territory: string, amount: number, dueTurn: number, travelTurn?: number) {
|
||||
const next = act(game, proposer, {type:'dealOffer', target, terms:'Pay the agreed amount and make the agreed shipment.',
|
||||
payment:{kind:'deferredBribe', payer, recipient, amount, dueTurn},
|
||||
travel:{kind:'ship', territory, minimum:1, answer:true, ...(travelTurn === undefined ? {} : {dueTurn:travelTurn})}});
|
||||
const offered = next.deals?.at(-1); assert.ok(offered);
|
||||
return {game:next, id:offered.id};
|
||||
}
|
||||
function accept(game: Game, target: string, id: string) {
|
||||
return act(game, target, {type:'dealRespond', deal:id, accept:true});
|
||||
}
|
||||
function status(game: Game, viewer: string, id: string) {
|
||||
return viewGame(game, viewer).dealTravelStatus[id];
|
||||
}
|
||||
|
||||
/** Genuine public Basic two-seat setup and native phase-five window; the
|
||||
* fixture stages only unopened cards/Spice. Every offer, vote, payment and
|
||||
* shipment below is executed through public player actions. */
|
||||
for (const payerRole of ['traveler','proposer'] as const) for (const order of ['pay-first','travel-first'] as const) {
|
||||
void test(`current-turn deferred payment and shipment coexist with ${payerRole} paying (${order})`, () => {
|
||||
const f = fixture(), before = f.game, payer = payerRole === 'traveler' ? f.target : f.asker;
|
||||
const recipient = payerRole === 'traveler' ? f.asker : f.target;
|
||||
const cash = player(before,payer).spice, travelCash = player(before,f.target).spice;
|
||||
const escrow = player(before,recipient).bribes;
|
||||
assert.ok(cash >= (payerRole === 'traveler' ? f.shipmentCost + 1 : 1));
|
||||
const offered = offer(before,f.asker,f.target,payer,recipient,f.shipmentTerritory,1,before.turn);
|
||||
assert.equal(deal(offered.game,offered.id).status,'offered');
|
||||
assert.equal(player(offered.game,payer).spice,cash);
|
||||
assert.equal(offered.game.travelPromises?.some(row => row.sourceDeal === offered.id) ?? false,false);
|
||||
let game = accept(offered.game,f.target,offered.id);
|
||||
assert.equal(deal(game,offered.id).status,'active');
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'pending');
|
||||
assert.equal(status(game,f.target,offered.id),'pending');
|
||||
assert.equal(player(game,payer).spice,cash);
|
||||
assert.equal(game.travelPromises?.filter(row => row.sourceDeal === offered.id).length,1);
|
||||
reject(game,f.asker,{type:'dealRespond',deal:offered.id,accept:true});
|
||||
if (order === 'pay-first') {
|
||||
game = act(game,payer,{type:'dealPay',deal:offered.id});
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'paid');
|
||||
assert.equal(player(game,recipient).bribes,escrow+1);
|
||||
game = settle(act(game,f.target,f.shipmentAction));
|
||||
} else {
|
||||
game = settle(act(game,f.target,f.shipmentAction));
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'pending');
|
||||
game = act(game,payer,{type:'dealPay',deal:offered.id});
|
||||
}
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'paid');
|
||||
assert.equal(status(game,f.target,offered.id),'fulfilled');
|
||||
assert.equal(player(game,f.target).forces['polar_sink:0'],1);
|
||||
assert.equal(player(game,payer).spice,cash - 1 - (payerRole === 'traveler' ? f.shipmentCost : 0));
|
||||
if (payerRole === 'proposer') assert.equal(player(game,f.target).spice,travelCash-f.shipmentCost);
|
||||
assert.equal(player(game,recipient).bribes,escrow+1);
|
||||
reject(game,payer,{type:'dealPay',deal:offered.id});
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
}
|
||||
|
||||
void test('current-turn joint consent rejects an unaffordable payer-traveler without creating either obligation', () => {
|
||||
const f = fixture(), cash = player(f.game,f.target).spice;
|
||||
assert.ok(cash > 0 && f.shipmentCost > 0);
|
||||
const offered = offer(f.game,f.asker,f.target,f.target,f.asker,f.shipmentTerritory,cash,f.game.turn);
|
||||
const before = structuredClone(offered.game);
|
||||
reject(offered.game,f.target,{type:'dealRespond',deal:offered.id,accept:true});
|
||||
assert.deepEqual(offered.game,before);
|
||||
assert.equal(deal(offered.game,offered.id).status,'offered');
|
||||
assert.equal(offered.game.travelPromises?.some(row => row.sourceDeal === offered.id) ?? false,false);
|
||||
assert.equal(player(offered.game,f.target).spice,cash);
|
||||
});
|
||||
|
||||
void test('both participants must release the unpaid payment and matching travel together', () => {
|
||||
const f = fixture();
|
||||
const offered = offer(f.game,f.asker,f.target,f.target,f.asker,f.shipmentTerritory,1,f.game.turn);
|
||||
let game = accept(offered.game,f.target,offered.id);
|
||||
game = act(game,f.asker,{type:'dealRelease',deal:offered.id,agree:true});
|
||||
assert.equal(status(game,f.target,offered.id),'pending');
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'pending');
|
||||
reject(game,f.target,f.currentEnd);
|
||||
game = act(game,f.target,{type:'dealRelease',deal:offered.id,agree:true});
|
||||
assert.equal(status(game,f.target,offered.id),'released');
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'released');
|
||||
reject(game,f.target,{type:'dealPay',deal:offered.id});
|
||||
game = settle(act(game,f.target,f.currentEnd));
|
||||
assert.equal(status(game,f.target,offered.id),'released');
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
|
||||
for (const payerRole of ['traveler','proposer'] as const) void test(
|
||||
`future-due deferred payment and shipment survive rollover with ${payerRole} paying`, () => {
|
||||
const f = fixture(), dueTurn = f.game.turn+1, payer = payerRole === 'traveler' ? f.target : f.asker;
|
||||
const recipient = payerRole === 'traveler' ? f.asker : f.target;
|
||||
const offered = offer(f.game,f.asker,f.target,payer,recipient,f.shipmentTerritory,1,dueTurn,dueTurn);
|
||||
let game = accept(offered.game,f.target,offered.id);
|
||||
assert.equal(status(game,f.target,offered.id),'scheduled');
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'pending');
|
||||
game = settle(act(game,f.target,f.currentEnd));
|
||||
game = advance(game,state => state.turn === dueTurn && state.phase === 2 && clean(state));
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'pending');
|
||||
game = act(game,payer,{type:'dealPay',deal:offered.id});
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'paid');
|
||||
game = advance(game,state => state.turn === dueTurn && state.phase === 5 && state.active === f.target && clean(state));
|
||||
game = settle(act(game,f.target,f.shipmentAction));
|
||||
assert.equal(status(game,f.target,offered.id),'fulfilled');
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'paid');
|
||||
assert.equal(player(game,f.target).forces['polar_sink:0'],1);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
},
|
||||
);
|
||||
|
||||
const groupProposer = 'atreides', groupTraveler = 'emperor', groupPayer = 'harkonnen', groupOther = 'fremen';
|
||||
const groupShipment: Action = {type:'ship',territory:'polar_sink',sector:0,amount:1,elite:0,allyPayment:0};
|
||||
function groupReach(game: Game, until: (state: Game) => boolean): Game {
|
||||
for (let count = 0; count < 1600; count++) {
|
||||
if (until(game)) return game;
|
||||
assert.notEqual(game.status,'finished');
|
||||
const step = nextNative(game); assert.ok(step, `Native continuation needed at ${game.turn}/${game.phase}`);
|
||||
game = act(game,step.actor,step.action);
|
||||
}
|
||||
throw Error('The original group-deal programme did not reach its requested boundary.');
|
||||
}
|
||||
/** Four original human Basic seats. Only unopened starting cards and two land
|
||||
* Spice cards are ordered; no resource, vote, promise, or force is fabricated. */
|
||||
function groupFixture(): Game {
|
||||
let game = createGame('GROUPDEFERTRAVEL',newPlayer(groupProposer,'Atreides','atreides'),false,[]);
|
||||
for (const [id,faction] of [[groupTraveler,'emperor'],[groupPayer,'harkonnen'],[groupOther,'fremen']] as const)
|
||||
joinGame(game,newPlayer(id,id,faction));
|
||||
for (const seat of game.players) game = act(game,seat.id,{type:'ready'});
|
||||
game = act(game,groupProposer,{type:'start'});
|
||||
const cards = game.deck.filter(card => ['projectile','poison','shield','snooper'].includes(card.kind)).slice(0,4);
|
||||
assert.equal(cards.length,4);
|
||||
for (const [position,card] of cards.entries()) {
|
||||
const from = game.deck.findIndex(row => row.id === card.id); assert.ok(from >= position);
|
||||
[game.deck[position],game.deck[from]] = [game.deck[from],game.deck[position]];
|
||||
}
|
||||
game = groupReach(game,state => state.status === 'playing');
|
||||
for (let position = 0; position < 2; position++) {
|
||||
const from = game.spiceDeck.findIndex((card,index) => index >= position && 'territory' in card && !card.discovery);
|
||||
assert.ok(from >= position);
|
||||
game.spiceDeck.splice(position,0,game.spiceDeck.splice(from,1)[0]);
|
||||
}
|
||||
game = groupReach(game,state => state.turn === 1 && state.phase === 5 && state.active === groupTraveler && clean(state));
|
||||
assert.ok(player(game,groupTraveler).spice >= 2);
|
||||
return game;
|
||||
}
|
||||
function groupOffer(game: Game, payer: string, amount: number, dueTurn: number, travelTurn?: number) {
|
||||
const next = act(game,groupProposer,{type:'dealOffer',targets:[groupPayer,groupTraveler],
|
||||
terms:'Deferred payment and a shared journey.',
|
||||
payment:{kind:'deferredBribe',payer,recipient:groupProposer,amount,dueTurn},
|
||||
travel:{actor:groupTraveler,kind:'ship',territory:'polar_sink',minimum:1,answer:true,
|
||||
...(travelTurn === undefined ? {} : {dueTurn:travelTurn})}});
|
||||
const offered = next.deals?.at(-1); assert.ok(offered); return {game:next,id:offered.id};
|
||||
}
|
||||
|
||||
for (const payer of [groupTraveler,groupPayer]) void test(
|
||||
`three-party deferred travel requires the traveler last and retains ${payer}'s pending payment`, () => {
|
||||
const initial = groupFixture(), cards = inventory(initial), cash = player(initial,payer).spice;
|
||||
assert.ok(cash >= (payer === groupTraveler ? 3 : 1));
|
||||
const offered = groupOffer(initial,payer,1,initial.turn);
|
||||
let game = offered.game;
|
||||
reject(game,groupTraveler,{type:'dealRespond',deal:offered.id,accept:true});
|
||||
game = accept(game,groupPayer,offered.id);
|
||||
assert.equal(deal(game,offered.id).status,'offered');
|
||||
assert.equal(game.travelPromises?.some(row => row.sourceDeal === offered.id) ?? false,false);
|
||||
assert.equal(player(game,payer).spice,cash);
|
||||
game = accept(game,groupTraveler,offered.id);
|
||||
assert.equal(deal(game,offered.id).status,'active');
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'pending');
|
||||
assert.equal(status(game,groupTraveler,offered.id),'pending');
|
||||
assert.equal(player(game,payer).spice,cash);
|
||||
game = act(game,payer,{type:'dealPay',deal:offered.id});
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'paid');
|
||||
game = groupReach(act(game,groupTraveler,groupShipment),state => clean(state) && !state.pendingShipment);
|
||||
assert.equal(status(game,groupTraveler,offered.id),'fulfilled');
|
||||
assert.equal(player(game,groupTraveler).forces['polar_sink:0'],1);
|
||||
assert.equal(player(game,payer).spice,cash - 1 - (payer === groupTraveler ? 2 : 0));
|
||||
assert.deepEqual(inventory(game),cards);
|
||||
},
|
||||
);
|
||||
|
||||
void test('final group consent rolls back when the traveling payer cannot fund both obligations', () => {
|
||||
const initial = groupFixture(), cash = player(initial,groupTraveler).spice;
|
||||
const offered = groupOffer(initial,groupTraveler,cash,initial.turn);
|
||||
const waiting = accept(offered.game,groupPayer,offered.id);
|
||||
reject(waiting,groupTraveler,{type:'dealRespond',deal:offered.id,accept:true});
|
||||
assert.equal(deal(waiting,offered.id).status,'offered');
|
||||
assert.equal(player(waiting,groupTraveler).spice,cash);
|
||||
assert.equal(waiting.travelPromises?.some(row => row.sourceDeal === offered.id) ?? false,false);
|
||||
});
|
||||
|
||||
void test('a third-party deferred payer and named traveler fulfill their actual next-turn group obligations', () => {
|
||||
const initial = groupFixture(), cards = inventory(initial), dueTurn = initial.turn+1;
|
||||
const offered = groupOffer(initial,groupPayer,1,dueTurn,dueTurn);
|
||||
let game = accept(offered.game,groupPayer,offered.id);
|
||||
game = accept(game,groupTraveler,offered.id);
|
||||
assert.equal(status(game,groupTraveler,offered.id),'scheduled');
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'pending');
|
||||
game = groupReach(act(game,groupTraveler,{type:'endMovement'}),state => state.turn === dueTurn && clean(state));
|
||||
game = act(game,groupPayer,{type:'dealPay',deal:offered.id});
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'paid');
|
||||
game = groupReach(game,state => state.turn === dueTurn && state.phase === 5 && state.active === groupTraveler && clean(state));
|
||||
game = groupReach(act(game,groupTraveler,groupShipment),state => clean(state) && !state.pendingShipment);
|
||||
assert.equal(status(game,groupTraveler,offered.id),'fulfilled');
|
||||
assert.equal(deal(game,offered.id).paymentStatus,'paid');
|
||||
assert.deepEqual(inventory(game),cards);
|
||||
});
|
||||
@@ -1,14 +1,9 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Action, type Game } from '../game/engine';
|
||||
import { actTruthTravel as act, createTruthTravelFixture as fixture,
|
||||
import { viewGame, type Game } from '../game/engine';
|
||||
import { actTruthTravel as act, advanceTruthTravel as advance, createTruthTravelFixture as fixture,
|
||||
settleTruthTravel as settle, truthTravelClean as clean,
|
||||
truthTravelInventory as inventory, truthTravelPlayer as player } from './fixture-truth-travel';
|
||||
|
||||
function reject(game: Game, actor: string, action: Action) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game, actor, action));
|
||||
assert.deepEqual(game, before, 'Conflicting consent must leave the source game unchanged.');
|
||||
}
|
||||
function travelOffer(game: Game, proposer: string, traveler: string, dueTurn: number) {
|
||||
const next = act(game, proposer, {type:'dealOffer', target:traveler, terms:'Travel in a future turn.',
|
||||
travel:{kind:'ship', territory:'polar_sink', minimum:1, answer:true, dueTurn}});
|
||||
@@ -31,38 +26,45 @@ function deal(game: Game, id: string) {
|
||||
/** Each case uses the genuine Basic Atreides/Emperor setup and actual native
|
||||
* first-turn pre-shipment window. These are independent two-party offers and
|
||||
* acceptances; no wallet, force, pending debt or travel receipt is staged. */
|
||||
void test('a same-turn deferred debt cannot be accepted after the payer schedules travel', () => {
|
||||
const f = fixture(), dueTurn = f.game.turn + 1, originalCards = inventory(f.game);
|
||||
const future = travelOffer(f.game, f.asker, f.target, dueTurn);
|
||||
let game = accept(future.game, f.target, future.id);
|
||||
assert.equal(viewGame(game, f.target).dealTravelStatus[future.id], 'scheduled');
|
||||
const payment = paymentOffer(game, f.asker, f.target, f.target, f.asker, dueTurn);
|
||||
game = payment.game;
|
||||
const purse = player(game, f.target).spice;
|
||||
reject(game, f.target, {type:'dealRespond', deal:payment.id, accept:true});
|
||||
assert.equal(deal(game, future.id).status, 'active');
|
||||
assert.equal(deal(game, payment.id).status, 'offered');
|
||||
assert.equal(game.travelPromises?.filter(row => row.sourceDeal === future.id).length, 1);
|
||||
assert.equal(player(game, f.target).spice, purse);
|
||||
assert.deepEqual(inventory(game), originalCards);
|
||||
});
|
||||
for (const order of ['travel-first', 'payment-first'] as const) void test(
|
||||
`the same future due turn retains travel and deferred payment when accepted ${order}`, () => {
|
||||
const f = fixture(), dueTurn = f.game.turn + 1, originalCards = inventory(f.game);
|
||||
let game = f.game, travelId: string, paymentId: string;
|
||||
if (order === 'travel-first') {
|
||||
const future = travelOffer(game, f.asker, f.target, dueTurn); travelId = future.id;
|
||||
game = accept(future.game, f.target, travelId);
|
||||
const payment = paymentOffer(game, f.asker, f.target, f.target, f.asker, dueTurn); paymentId = payment.id;
|
||||
game = accept(payment.game, f.target, paymentId);
|
||||
} else {
|
||||
const payment = paymentOffer(game, f.asker, f.target, f.target, f.asker, dueTurn); paymentId = payment.id;
|
||||
game = accept(payment.game, f.target, paymentId);
|
||||
const future = travelOffer(game, f.asker, f.target, dueTurn); travelId = future.id;
|
||||
game = accept(future.game, f.target, travelId);
|
||||
}
|
||||
assert.equal(deal(game, travelId).status, 'active');
|
||||
assert.equal(viewGame(game, f.target).dealTravelStatus[travelId], 'scheduled');
|
||||
assert.equal(game.travelPromises?.filter(row => row.sourceDeal === travelId).length, 1);
|
||||
assert.equal(deal(game, paymentId).paymentStatus, 'pending');
|
||||
assert.equal(player(game, f.target).spice, player(f.game, f.target).spice);
|
||||
assert.deepEqual(inventory(game), originalCards);
|
||||
|
||||
void test('a same-turn scheduled journey cannot be accepted after the traveler owes a deferred debt', () => {
|
||||
const f = fixture(), dueTurn = f.game.turn + 1, originalCards = inventory(f.game);
|
||||
const payment = paymentOffer(f.game, f.asker, f.target, f.target, f.asker, dueTurn);
|
||||
let game = accept(payment.game, f.target, payment.id);
|
||||
assert.equal(deal(game, payment.id).paymentStatus, 'pending');
|
||||
const future = travelOffer(game, f.asker, f.target, dueTurn);
|
||||
game = future.game;
|
||||
const purse = player(game, f.target).spice;
|
||||
reject(game, f.target, {type:'dealRespond', deal:future.id, accept:true});
|
||||
assert.equal(deal(game, payment.id).status, 'active');
|
||||
assert.equal(deal(game, payment.id).paymentStatus, 'pending');
|
||||
assert.equal(deal(game, future.id).status, 'offered');
|
||||
assert.equal(game.travelPromises?.some(row => row.sourceDeal === future.id) ?? false, false);
|
||||
assert.equal(player(game, f.target).spice, purse);
|
||||
assert.deepEqual(inventory(game), originalCards);
|
||||
});
|
||||
// Finish the original current turn, then settle the actual separate
|
||||
// payment and shipment on their shared future due turn.
|
||||
game = settle(act(game, f.target, f.currentEnd));
|
||||
game = advance(game, state => state.turn === dueTurn && state.phase === 2 && clean(state));
|
||||
assert.equal(viewGame(game, f.target).dealTravelStatus[travelId], 'pending');
|
||||
const beforePayment = player(game, f.target).spice;
|
||||
game = settle(act(game, f.target, {type:'dealPay', deal:paymentId}));
|
||||
assert.equal(deal(game, paymentId).paymentStatus, 'paid');
|
||||
assert.equal(player(game, f.target).spice, beforePayment - 2);
|
||||
game = advance(game, state => state.turn === dueTurn && state.phase === 5 &&
|
||||
state.active === f.target && clean(state) && !state.pendingShipment);
|
||||
game = settle(act(game, f.target, f.shipmentAction));
|
||||
assert.equal(viewGame(game, f.target).dealTravelStatus[travelId], 'fulfilled');
|
||||
assert.equal(deal(game, paymentId).paymentStatus, 'paid');
|
||||
assert.deepEqual(inventory(game), originalCards);
|
||||
},
|
||||
);
|
||||
|
||||
for (const order of ['travel-first', 'payment-first'] as const) void test(
|
||||
`different future due turns coexist when accepted ${order}`, () => {
|
||||
|
||||
@@ -166,18 +166,48 @@ for (const answer of [true, false]) void test(`group movement ${answer ? 'requir
|
||||
assert.equal(status(game, first, offered.id), 'fulfilled');
|
||||
});
|
||||
|
||||
void test('the traveler may decline early; malformed or uninvited actors and payment combinations reject', () => {
|
||||
void test('the traveler may decline early; malformed or uninvited actors and invalid payments reject', () => {
|
||||
const initial = fixture(), term:Term = {actor:traveler, kind:'ship', territory:'polar_sink', minimum:1, answer:true};
|
||||
for (const bad of [proposer, second, 'unknown'])
|
||||
reject(initial, proposer, {type:'dealOffer', targets:[first, traveler], terms:'Terms', travel:{...term, actor:bad}});
|
||||
reject(initial, proposer, {type:'dealOffer', targets:[first, traveler], terms:'Terms', travel:term,
|
||||
payment:{kind:'deferredBribe', payer:proposer, recipient:traveler, amount:1, dueTurn:initial.turn}});
|
||||
payment:{kind:'deferredBribe', payer:proposer, recipient:proposer, amount:1, dueTurn:initial.turn}});
|
||||
reject(initial, proposer, {type:'dealOffer', targets:[first, traveler], terms:'Terms', travel:term,
|
||||
payment:{kind:'deferredBribe', payer:proposer, recipient:second, amount:1, dueTurn:initial.turn}});
|
||||
reject(initial, proposer, {type:'dealOffer', targets:[first, traveler], terms:'Terms', travel:term,
|
||||
payment:{kind:'deferredBribe', payer:proposer, recipient:traveler, amount:1, dueTurn:initial.turn - 1}});
|
||||
const offered = offer(initial, [first, traveler], term);
|
||||
const declined = respond(offered.game, traveler, offered.id, false);
|
||||
assert.equal(declined.deals!.at(-1)!.status, 'declined');
|
||||
assert.equal(declined.travelPromises?.some(row => row.sourceDeal === offered.id) ?? false, false);
|
||||
});
|
||||
|
||||
void test('a group offer combines deferred payment and travel through consent, payment and shipment', () => {
|
||||
const initial = fixture(), originalCards = inventory(initial);
|
||||
const payment = {kind:'deferredBribe', payer:first, recipient:proposer, amount:1, dueTurn:initial.turn};
|
||||
const travel = {actor:traveler, kind:'ship', territory:'polar_sink', minimum:1, answer:true};
|
||||
let game = act(initial, proposer, {type:'dealOffer', targets:[first,traveler],
|
||||
terms:'Pay one spice and make the journey.', payment, travel});
|
||||
const offered = game.deals!.at(-1)!;
|
||||
assert.deepEqual(offered.payment, payment);
|
||||
reject(game, traveler, {type:'dealRespond', deal:offered.id, accept:true});
|
||||
game = respond(game, first, offered.id);
|
||||
game = respond(game, traveler, offered.id);
|
||||
const active = game.deals!.find(deal => deal.id === offered.id)!;
|
||||
assert.equal(active.status, 'active');
|
||||
assert.equal(active.paymentStatus, 'pending');
|
||||
assert.equal(status(game, traveler, offered.id), 'pending');
|
||||
const balance = player(game, first).spice, incoming = player(game, proposer).bribes;
|
||||
reject(game, proposer, {type:'dealPay', deal:offered.id});
|
||||
game = act(game, first, {type:'dealPay', deal:offered.id});
|
||||
assert.equal(player(game, first).spice, balance - 1);
|
||||
assert.equal(player(game, proposer).bribes, incoming + 1);
|
||||
assert.equal(game.deals!.find(deal => deal.id === offered.id)!.paymentStatus, 'paid');
|
||||
game = settle(act(game, traveler, shipment));
|
||||
assert.equal(status(game, traveler, offered.id), 'fulfilled');
|
||||
assert.deepEqual(inventory(game), originalCards);
|
||||
});
|
||||
|
||||
void test('an unavailable journey rejects only the final traveler consent and leaves the group offer open', () => {
|
||||
const alreadyShipped = settle(act(fixture(), traveler, shipment));
|
||||
const offered = offer(alreadyShipped, [first, traveler],
|
||||
|
||||
@@ -117,12 +117,27 @@ void test('unanimous release ends the pending travel obligation without refundin
|
||||
assert.equal(player(game, f.target).bribes, escrow);
|
||||
});
|
||||
|
||||
void test('paid travel excludes deferred and multiparty payment variants', () => {
|
||||
void test('travel can include a deferred payment while invalid participant lists still reject', () => {
|
||||
const f = fixture(), travel = { kind: 'ship', territory: f.shipmentTerritory, minimum: 1, answer: true };
|
||||
const base = { type: 'dealOffer', target: f.target, terms: 'Travel.', travel } satisfies Action;
|
||||
reject(f.game, f.asker, { ...base, payment: { kind: 'deferredBribe', payer: f.asker, recipient: f.target, amount: 1, dueTurn: f.game.turn } });
|
||||
const payment = { kind: 'deferredBribe', payer: f.asker, recipient: f.target, amount: 1, dueTurn: f.game.turn };
|
||||
const offered = act(f.game, f.asker, { ...base, payment });
|
||||
const deal = offered.deals!.at(-1)!;
|
||||
let game = accept(offered, f.target, deal.id);
|
||||
assert.equal(game.deals!.find(row => row.id === deal.id)!.paymentStatus, 'pending');
|
||||
assert.equal(status(game, f.target, deal.id), 'pending');
|
||||
const payerBefore = player(game, f.asker).spice, recipientBefore = player(game, f.target).bribes;
|
||||
game = act(game, f.asker, {type:'dealPay', deal:deal.id});
|
||||
assert.equal(player(game, f.asker).spice, payerBefore - 1);
|
||||
assert.equal(player(game, f.target).bribes, recipientBefore + 1);
|
||||
assert.equal(game.deals!.find(row => row.id === deal.id)!.paymentStatus, 'paid');
|
||||
game = settle(act(game, f.target, f.shipmentAction));
|
||||
assert.equal(status(game, f.target, deal.id), 'fulfilled');
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
reject(f.game, f.asker, { type: 'dealOffer', targets: [f.target, f.asker], terms: 'Travel.', travel,
|
||||
payment: { kind: 'immediateBribe', payer: f.asker, recipient: f.target, amount: 1 } });
|
||||
reject(f.game, f.asker, { ...base, payment: { ...payment, dueTurn: f.game.turn - 1 } });
|
||||
reject(f.game, f.asker, { ...base, payment: { ...payment, recipient: f.asker } });
|
||||
});
|
||||
|
||||
void test('the travelling recipient can pay the proposer at final consent and then complete shipment', () => {
|
||||
|
||||
@@ -54,13 +54,18 @@ void test('the offer packet retains legacy two-party terms and validates an expl
|
||||
{type:'dealOffer', targets:['b','c'], terms:'Terms', payment, travel:{...travel, actor:'c'}});
|
||||
assert.deepEqual(publicDealOfferAction(['b','c'], 'Terms', {...payment,payer:'b',recipient:'c'}, 'a', 2, {...travel, actor:'c'}),
|
||||
{type:'dealOffer', targets:['b','c'], terms:'Terms', payment:{...payment,payer:'b',recipient:'c'}, travel:{...travel, actor:'c'}});
|
||||
assert.equal(publicDealOfferAction(['b','c'], 'Terms', {kind:'deferredBribe',payer:'a',recipient:'b',amount:2,dueTurn:2}, 'a', 2, {...travel, actor:'c'}), null);
|
||||
const deferred = {kind:'deferredBribe' as const,payer:'a',recipient:'b',amount:2,dueTurn:2};
|
||||
assert.deepEqual(publicDealOfferAction(['b','c'], 'Terms', deferred, 'a', 2, {...travel, actor:'c'}),
|
||||
{type:'dealOffer', targets:['b','c'], terms:'Terms', payment:deferred, travel:{...travel, actor:'c'}});
|
||||
assert.deepEqual(publicDealOfferAction(['b'], 'Terms', payment, 'a', 2, travel),
|
||||
{type:'dealOffer', target:'b', terms:'Terms', payment, travel});
|
||||
const reverse = {...payment,payer:'b',recipient:'a'};
|
||||
assert.deepEqual(publicDealOfferAction(['b'], 'Terms', reverse, 'a', 2, travel),
|
||||
{type:'dealOffer', target:'b', terms:'Terms', payment:reverse, travel});
|
||||
assert.equal(publicDealOfferAction(['b'], 'Terms', {kind:'deferredBribe',payer:'a',recipient:'b',amount:2,dueTurn:2}, 'a', 2, travel), null);
|
||||
assert.deepEqual(publicDealOfferAction(['b'], 'Terms', deferred, 'a', 2, travel),
|
||||
{type:'dealOffer', target:'b', terms:'Terms', payment:deferred, travel});
|
||||
assert.equal(publicDealOfferAction(['b'], 'Terms', {...deferred,dueTurn:1}, 'a', 2, travel), null);
|
||||
assert.equal(publicDealOfferAction(['b','c'], 'Terms', {...deferred,recipient:'outsider'}, 'a', 2, {...travel,actor:'c'}), null);
|
||||
assert.equal(publicDealOfferAction(['b','c'], 'Terms', payment, 'a', 2, travel), null);
|
||||
assert.equal(publicDealOfferAction(['a'], 'Terms', undefined, 'a', 2, travel), null);
|
||||
assert.equal(publicDealOfferAction(['b'], 'Terms', undefined, undefined, 2, travel), null);
|
||||
@@ -130,7 +135,7 @@ function combinedForm(gameOverride?: GameView) {
|
||||
return {render, check, select, sent};
|
||||
}
|
||||
|
||||
void test('the authoring controls compose a proposer payment with recipient travel and reject invalid combinations', () => {
|
||||
void test('the authoring controls compose immediate or deferred payment with recipient travel', () => {
|
||||
const ui = combinedForm();
|
||||
ui.check(0); // Select recipient.
|
||||
ui.check(1); // Include payment.
|
||||
@@ -146,12 +151,19 @@ void test('the authoring controls compose a proposer payment with recipient trav
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[0])), {type:'dealOffer',target:'b',terms:'Travel for spice',
|
||||
payment:{kind:'immediateBribe',payer:'a',recipient:'b',amount:1},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true}});
|
||||
ui.select(0,'deferredBribe'); assert.equal(button()?.props.disabled,true);
|
||||
ui.select(0,'deferredBribe'); assert.equal(button()?.props.disabled,false);
|
||||
assert.ok(ui.render().some(node => node.type === 'p' && typeof node.props.children === 'string' &&
|
||||
node.props.children.includes('an immediate payment or a payment due by the end of a selected turn')));
|
||||
const deferredForm = ui.render().find(node => node.type === 'form'); assert.ok(deferredForm);
|
||||
(deferredForm.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[1])), {type:'dealOffer',target:'b',terms:'Travel for spice',
|
||||
payment:{kind:'deferredBribe',payer:'a',recipient:'b',amount:1,dueTurn:2},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true}});
|
||||
ui.select(0,'immediateBribe'); ui.select(1,'b'); ui.select(2,'a');
|
||||
assert.equal(button()?.props.disabled,false);
|
||||
const reverseForm = ui.render().find(node => node.type === 'form'); assert.ok(reverseForm);
|
||||
(reverseForm.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[1])), {type:'dealOffer',target:'b',terms:'Travel for spice',
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[2])), {type:'dealOffer',target:'b',terms:'Travel for spice',
|
||||
payment:{kind:'immediateBribe',payer:'b',recipient:'a',amount:1},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true}});
|
||||
});
|
||||
@@ -247,7 +259,12 @@ void test('the group offer form selects an invited traveler and revalidates part
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[1])), {type:'dealOffer',targets:['b','d'],terms:'Group travel',
|
||||
payment:{kind:'immediateBribe',payer:'b',recipient:'d',amount:1},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true,actor:'d'}});
|
||||
ui.select(0,'deferredBribe'); assert.equal(button()?.props.disabled,true, 'Deferred group payment remains unavailable.');
|
||||
ui.select(0,'deferredBribe'); assert.equal(button()?.props.disabled,false);
|
||||
const deferredForm = ui.render().find(node => node.type === 'form'); assert.ok(deferredForm);
|
||||
(deferredForm.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[2])), {type:'dealOffer',targets:['b','d'],terms:'Group travel',
|
||||
payment:{kind:'deferredBribe',payer:'b',recipient:'d',amount:1,dueTurn:2},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true,actor:'d'}});
|
||||
});
|
||||
|
||||
void test('the author chooses a future travel turn and can return to the legacy current-turn packet', () => {
|
||||
|
||||
@@ -119,11 +119,11 @@ void test('a released deal cannot retain an unfulfilled live travel receipt', ()
|
||||
reject(corrupted, f.target, f.currentEnd);
|
||||
});
|
||||
|
||||
void test('travel terms reject payment combinations, multiparty packets and malformed claims', () => {
|
||||
void test('travel terms reject invalid payment, participant and malformed travel claims', () => {
|
||||
const f = fixture(), term: Term = { kind: 'ship', territory: f.shipmentTerritory, minimum: 1, answer: true };
|
||||
const basic = { type: 'dealOffer', target: f.target, terms: 'Agreed travel.', travel: term } satisfies Action;
|
||||
reject(f.game, f.asker, { ...basic, payment: { kind: 'deferredBribe', payer: f.target,
|
||||
recipient: f.asker, amount: 1, dueTurn: f.game.turn } });
|
||||
recipient: f.asker, amount: 1, dueTurn: f.game.turn - 1 } });
|
||||
reject(f.game, f.asker, { type: 'dealOffer', targets: [f.target, f.asker], terms: 'Travel.', travel: term });
|
||||
reject(f.game, f.asker, { ...basic, travel: { ...term, minimum: 0 } });
|
||||
reject(f.game, f.asker, { ...basic, travel: { ...term, answer: 'yes' } });
|
||||
@@ -162,7 +162,7 @@ void test('final consent to a conflicting obligation rolls back without disturbi
|
||||
assert.equal(status(completed, f.target, first.id), 'fulfilled');
|
||||
});
|
||||
|
||||
void test('a pending travel term prevents final consent to a separate current-turn deferred bribe', () => {
|
||||
void test('a pending travel term can coexist with a separately accepted current-turn deferred bribe', () => {
|
||||
const f = fixture(), offered = offer(f.game, f.asker, f.target,
|
||||
{ kind: 'ship', territory: f.shipmentTerritory, minimum: 1, answer: true });
|
||||
let game = accept(offered.game, f.target, offered.id);
|
||||
@@ -171,15 +171,22 @@ void test('a pending travel term prevents final consent to a separate current-tu
|
||||
const payment = game.deals!.at(-1)!;
|
||||
assert.notEqual(payment.id, offered.id);
|
||||
assert.equal(payment.status, 'offered');
|
||||
const before = structuredClone(game);
|
||||
reject(game, f.target, { type: 'dealRespond', deal: payment.id, accept: true });
|
||||
assert.deepEqual(game, before);
|
||||
const cash = player(game, f.target).spice, incoming = player(game, f.asker).bribes;
|
||||
assert.ok(cash >= f.shipmentCost + 1);
|
||||
game = accept(game, f.target, payment.id);
|
||||
assert.equal(game.deals!.find(deal => deal.id === offered.id)!.status, 'active');
|
||||
assert.equal(game.deals!.find(deal => deal.id === payment.id)!.status, 'offered');
|
||||
assert.equal(game.deals!.find(deal => deal.id === payment.id)!.status, 'active');
|
||||
assert.equal(game.deals!.find(deal => deal.id === payment.id)!.paymentStatus, 'pending');
|
||||
assert.equal(status(game, f.target, offered.id), 'pending');
|
||||
assert.equal(receipt(game, offered.id).released, false);
|
||||
game = act(game, f.target, {type:'dealPay', deal:payment.id});
|
||||
assert.equal(player(game, f.target).spice, cash - 1);
|
||||
assert.equal(player(game, f.asker).bribes, incoming + 1);
|
||||
assert.equal(game.deals!.find(deal => deal.id === payment.id)!.paymentStatus, 'paid');
|
||||
const completed = settle(act(game, f.target, f.shipmentAction));
|
||||
assert.equal(status(completed, f.target, offered.id), 'fulfilled');
|
||||
assert.equal(player(completed, f.target).spice, cash - 1 - f.shipmentCost);
|
||||
assert.deepEqual(inventory(completed), f.originalCards);
|
||||
});
|
||||
|
||||
void test('final travel consent rejects a target with a live native Truthtrance bribe promise', () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createMultipartyPublicDeal, createPublicDeal, parsePublicDealTravel, PublicDealError,
|
||||
createMultipartyPublicDeal, createPublicDeal, markPublicDealPaid, parsePublicDealTravel, PublicDealError,
|
||||
publicDealTravelActor, publicDealTravelDueTurn,
|
||||
releasePublicDeal, respondPublicDeal, setPublicDealTravel, validatePublicDeals, withdrawPublicDeal,
|
||||
type PublicDeal, type PublicDealSeat,
|
||||
@@ -195,13 +195,19 @@ for (const [payer, recipient] of [['a', 'b'], ['b', 'a']] as const) void test(`a
|
||||
assert.equal(released.status, 'released');
|
||||
});
|
||||
|
||||
void test('paid travel rejects deferred and forged persisted payment shapes', () => {
|
||||
void test('deferred paid travel survives the two-party lifecycle and forged payment shapes reject', () => {
|
||||
const deferred = { kind: 'deferredBribe', payer: 'a', recipient: 'b', amount: 1, dueTurn: 3 } as const;
|
||||
const paid = { kind: 'immediateBribe', payer: 'a', recipient: 'b', amount: 1 } as const;
|
||||
for (const payment of [deferred]) {
|
||||
const offer = createPublicDeal(seats, 'a', 'b', 'Terms', 3, `invalid-${payment.kind}`, payment);
|
||||
assert.throws(() => setPublicDealTravel(offer, term, seats), PublicDealError);
|
||||
assert.throws(() => validatePublicDeals([{ ...offer, travel: term }], seats), PublicDealError);
|
||||
const offer = setPublicDealTravel(createPublicDeal(seats, 'a', 'b', 'Terms', 3, 'deferred-travel', deferred), term, seats);
|
||||
const active = respondPublicDeal(offer, seats, 'b', true);
|
||||
assert.equal(active.paymentStatus, 'pending');
|
||||
const paidDeal = markPublicDealPaid(active, seats, 'a');
|
||||
assert.equal(paidDeal.paymentStatus, 'paid');
|
||||
for (const deal of [offer,active,paidDeal]) {
|
||||
const roundtrip = JSON.parse(JSON.stringify(deal)) as PublicDeal;
|
||||
validatePublicDeals([roundtrip], seats);
|
||||
assert.deepEqual(roundtrip.payment, deferred);
|
||||
assert.deepEqual(roundtrip.travel, term);
|
||||
}
|
||||
const multi = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'multi-paid', paid);
|
||||
for (const invalid of [
|
||||
@@ -247,11 +253,19 @@ for (const payer of ['a', 'b', 'c']) for (const recipient of ['a', 'b', 'c']) {
|
||||
});
|
||||
}
|
||||
|
||||
void test('group travel still rejects deferred payments and forged party identities', () => {
|
||||
void test('group travel accepts deferred payments but rejects forged party identities', () => {
|
||||
const deferred = { kind: 'deferredBribe', payer: 'a', recipient: 'b', amount: 1, dueTurn: 3 } as const;
|
||||
const group = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'group-deferred', deferred);
|
||||
assert.throws(() => setPublicDealTravel(group, { ...term, actor: 'b' }, seats), PublicDealError);
|
||||
assert.throws(() => validatePublicDeals([{ ...group, travel: { ...term, actor: 'b' } }], seats), PublicDealError);
|
||||
const offered = setPublicDealTravel(group, { ...term, actor: 'b' }, seats);
|
||||
assert.throws(() => respondPublicDeal(offered, seats, 'b', true), PublicDealError);
|
||||
const active = respondPublicDeal(respondPublicDeal(offered, seats, 'c', true), seats, 'b', true);
|
||||
assert.equal(active.paymentStatus, 'pending');
|
||||
const settled = markPublicDealPaid(active, seats, 'a');
|
||||
for (const deal of [offered,active,settled]) {
|
||||
validatePublicDeals([JSON.parse(JSON.stringify(deal))], seats);
|
||||
assert.deepEqual(deal.payment, deferred);
|
||||
assert.deepEqual(deal.travel, { ...term, actor: 'b' });
|
||||
}
|
||||
const immediate = { kind: 'immediateBribe', payer: 'a', recipient: 'b', amount: 1 } as const;
|
||||
const paid = setPublicDealTravel(createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'group-paid', immediate),
|
||||
{ ...term, actor: 'b' }, seats);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, viewGame, type Game } from '../game/engine';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { actTruthBid as act, advanceTruthBid as advance, truthBidClean as clean,
|
||||
truthBidInventory as inventory, truthBidPlayer as player } from './fixture-truth-bid';
|
||||
import { createTruthTurnBidFixture } from './fixture-truth-turn-bid';
|
||||
|
||||
/** Real public Basic setup and Truthtrances. Stage unopened Spice order and
|
||||
* move existing force/leader pieces into Tanks for the requested Revival. */
|
||||
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);
|
||||
const leader = emperor.leaders.find(row => row.strength === 2); assert.ok(leader);
|
||||
for (const disc of emperor.leaders) { disc.dead = true; disc.deaths = 1; }
|
||||
emperor.reserves -= 3; emperor.tanks += 3;
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
return {f, game, leader:leader.id};
|
||||
}
|
||||
|
||||
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 mode of ['forces', 'leader', 'expression'] as const) {
|
||||
for (const first of ['bid', 'revival'] as const) {
|
||||
void test(`Basic ${mode} and phase-bid commitments give all bot difficulties a legal bid (${first} first)`, () => {
|
||||
const {f, game:initial, leader} = fixture();
|
||||
const bid = {kind:'phaseBid', target:f.target, turn:initial.turn, minimum:4};
|
||||
const revival = mode === 'forces'
|
||||
? {kind:'revival', target:f.target, turn:initial.turn, counter:'total', minimum:3}
|
||||
: mode === 'leader'
|
||||
? {kind:'leaderRevival', target:f.target, turn:initial.turn, leader}
|
||||
: {kind:'revivalExpression', target:f.target, turn:initial.turn, claim:{kind:'and', terms:[
|
||||
{kind:'forces', counter:'total', minimum:3}, {kind:'leader', leader},
|
||||
]}};
|
||||
const questions = first === 'bid' ? [bid, revival] : [revival, bid];
|
||||
let game = ask(initial, f.asker, f.truths[0], questions[0]);
|
||||
game = act(game, f.target, {type:'truthAnswer', answer:'yes'});
|
||||
game = ask(game, f.asker, f.truths[1], questions[1]);
|
||||
game = act(game, f.target, {type:'truthAnswer', answer:'yes'});
|
||||
game = advance(game, state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
|
||||
assert.ok(viewGame(game, f.target).phaseBidPromiseGuide, 'The server has a legal qualifying bid guide');
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const view = viewGame(game, f.target);
|
||||
view.players.find(row => row.id === f.target)!.bot = difficulty;
|
||||
const action = botActions(view)[0]; assert.ok(action);
|
||||
assert.equal(action.type, 'bid', `${difficulty} must honor the outstanding phase bid`);
|
||||
assert.doesNotThrow(() => applyAction(game, f.target, action));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user