Preserve travel funding in deal payment quotes
Verify and publish checkpoint container / container (push) Canceled after 0s
Verify and publish checkpoint container / container (push) Canceled after 0s
This commit is contained in:
1 parent
5e294215be
commit
0b8a147388
5 files changed
+191
-2
No files matched your search
@@ -17,6 +17,14 @@ open mode gates.
|
||||
|
||||
## Current checkpoint and work
|
||||
|
||||
**Deferred travel funding and bribe quotes — 16 November. Prototyped / Partial.**
|
||||
Due-turn payments preserve known routes for earlier scheduled travel, and the
|
||||
bribe quote accounts for accepted due payments and travel without reserving
|
||||
future debts. Thirty-two related offline files pass 194 cases; two authenticated
|
||||
HTTP cases, type checking and lint pass. Multiple payments in one offer, wider
|
||||
interactions and deployed acceptance remain open.
|
||||
[Scope](PUBLIC_DEALS.md#scheduled-travel-and-discretionary-bribes--16-november-2026).
|
||||
|
||||
**Public travel with deferred payment — 16 November. Prototyped / Partial.**
|
||||
Two-party and group offers can pair a travel term with one deferred payment;
|
||||
due-now acceptance checks a shared funded route, and participants can complete
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
# Public deal records
|
||||
|
||||
## Scheduled travel and discretionary bribes — 16 November 2026
|
||||
|
||||
**Prototyped / Partial.** When evaluating a due payment, each detached native
|
||||
payment now preserves a previously witnessed route for a scheduled travel
|
||||
term. An unaffordable current payment can no longer be accepted merely because
|
||||
the travel was agreed in an earlier turn. The ordinary bribe control also
|
||||
quotes the amount left after current due payments and travel; a separately
|
||||
identified deal payment still uses its own Pay control. Future-due payments do
|
||||
not reserve this turn's funds. The existing policy for a scheduled route with
|
||||
no known completion remains provisional rather than claiming impossibility.
|
||||
|
||||
[Public-game regressions](../tests/public-deals-future-travel-funding.test.ts)
|
||||
exercise scheduled and separate or combined deals, affordability, rollback and
|
||||
actual payment/shipment. [Bribe-quote cases](../tests/public-deals-deferred-travel-bribe-quote.test.ts)
|
||||
cover both payer roles, a fully committed purse and future deadlines. Complete
|
||||
deal coverage, multiple payments in one offer, other modules and deployed
|
||||
acceptance remain open. Thirty-two related offline files pass 194 cases; two
|
||||
authenticated HTTP cases, type checking and lint pass.
|
||||
|
||||
## Travel with a deferred payment — 16 November 2026
|
||||
|
||||
**Prototyped / Partial.** In supported Basic classic tables, a two-party or
|
||||
|
||||
+12
-2
@@ -6103,6 +6103,10 @@ function publicDealCompletion(g: Game, payer: Player): boolean {
|
||||
const trial = structuredClone(candidate);
|
||||
try {
|
||||
quoteOrdinaryPayments(trial,payer.id,[{recipient:debt.recipient,amount:debt.amount}]);
|
||||
// A scheduled travel term may have acquired a legal route since
|
||||
// acceptance. Preserve that route across every hypothetical
|
||||
// payment, using the actual state immediately before that payment.
|
||||
reconcileTravelPromises(trial,payer.id,{type:'bribe'},candidate.phase,candidate);
|
||||
if (visit(trial,remaining.filter((_,position) => position !== index))) return true;
|
||||
} catch (error) { if (!(error instanceof RuleError)) throw error; }
|
||||
}
|
||||
@@ -17783,10 +17787,12 @@ function bribePaymentPreservesPromises(g: Game, p: Player, recipient: string, am
|
||||
actor.spice -= amount;
|
||||
const voluntary = { actor: p.id, action: { type: 'bribe' } };
|
||||
reconcileBattlePromises(trial, voluntary);
|
||||
reconcileTravelPromises(trial,p.id,voluntary.action,g.phase,g);
|
||||
reconcileShipmentPromises(trial, voluntary);
|
||||
if (hasMovementPromises(trial, p.id, true) &&
|
||||
!groundMovementCompletion(trial, p.id)) return false;
|
||||
reconcileRevivalPromises(trial, voluntary);
|
||||
if (publicDealCompletion(g,p) && !publicDealCompletion(trial,actor)) return false;
|
||||
return liveTurnActionPromises(trial.turnActionPromises ?? [], p.id, trial.turn).length
|
||||
? !!turnActionCompletion(trial, p.id) : !hasBribePromises(trial, p.id) || !!bribePromiseCompletion(trial, actor);
|
||||
} catch (error) { if (error instanceof BribeExpressionPromiseError || error instanceof BribePromiseError || error instanceof RuleError) return false; throw error; }
|
||||
@@ -17860,10 +17866,12 @@ function basicBribeInterrupt(g: Game, p: Player): boolean {
|
||||
function projectedBribes(g: Game, p: Player): BribeOptions {
|
||||
const available = Math.max(0, uncommittedSpice(g, p)),
|
||||
blocked = basicBribeInterrupt(g, p) ? null : bribeTimingBlock(g);
|
||||
const dueDeals = pendingPublicDealPayments(g.deals ?? [],p.id,g.turn)
|
||||
.some(debt => !bribeAllied(g,p,debt.recipient));
|
||||
const constrained = liveTurnActionPromises(g.turnActionPromises ?? [], p.id, g.turn).length > 0 || hasBribePromises(g, p.id) ||
|
||||
g.battle?.truthPromises?.some(promise => promise.player === p.id && !promise.released && !g.battle?.revealed && !g.battle?.plans[p.id]) ||
|
||||
liveShipmentPromises(g.shipmentPromises ?? [], p.id, g.turn).length ||
|
||||
hasMovementPromises(g, p.id, true) ||
|
||||
hasMovementPromises(g, p.id) || dueDeals ||
|
||||
liveRevivalPromises(g.revivalPromises ?? [], p.id, g.turn).some(promise => promise.answer) ||
|
||||
liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [], p.id, g.turn).some(promise => promise.answer) ||
|
||||
liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [], p.id, g.turn).some(promise => promise.answer);
|
||||
@@ -17871,7 +17879,9 @@ function projectedBribes(g: Game, p: Player): BribeOptions {
|
||||
targets: g.players.filter(target => target.id !== p.id && !bribeAllied(g, p, target.id)).map(target => {
|
||||
let limit = !blocked && constrained ? maximumBribe(available,
|
||||
amount => bribePaymentPreservesPromises(g, p, target.id, amount)) : available;
|
||||
let limitation: string | null = limit < available ? 'Your Truthtrance answers limit this recipient’s payment.' : null;
|
||||
let limitation: string | null = limit < available
|
||||
? dueDeals || hasPublicDealTravel(g,p.id) ? 'Your accepted commitments limit this recipient’s payment.'
|
||||
: 'Your Truthtrance answers limit this recipient’s payment.' : null;
|
||||
if (!blocked && limit >= 5) {
|
||||
try { checkBureaucratContributors(g, target.id, [{ payer: p.id, amount: limit }]); }
|
||||
catch (error) {
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Action, type Game } from '../game/engine';
|
||||
import { bribeAction } from '../game/bribe-options';
|
||||
import { actTruthTravel as act, createTruthTravelFixture as fixture,
|
||||
settleTruthTravel as settle, truthTravelInventory as inventory,
|
||||
truthTravelPlayer as player } from './fixture-truth-travel';
|
||||
|
||||
/** Public Basic native setup and a genuine active shipment opportunity.
|
||||
* Only the shared fixture's unopened starting deal and Spice order are staged. */
|
||||
function combined(payerRole: 'traveler' | 'proposer', remainder: number, later = false) {
|
||||
const f = fixture(), payer = payerRole === 'traveler' ? f.target : f.asker;
|
||||
const recipient = payerRole === 'traveler' ? f.asker : f.target;
|
||||
const cash = player(f.game,payer).spice;
|
||||
const travelCost = payer === f.target ? f.shipmentCost : 0;
|
||||
const amount = cash - travelCost - remainder;
|
||||
assert.ok(amount > 0);
|
||||
let game = act(f.game,f.asker,{type:'dealOffer',target:f.target,terms:'Pay the agreed spice and make the shipment.',
|
||||
payment:{kind:'deferredBribe',payer,recipient,amount,dueTurn:f.game.turn + Number(later)},
|
||||
travel:{kind:'ship',territory:f.shipmentTerritory,minimum:1,answer:true}});
|
||||
const id = game.deals!.at(-1)!.id;
|
||||
game = act(game,f.target,{type:'dealRespond',deal:id,accept:true});
|
||||
assert.equal(game.deals!.find(row => row.id === id)!.paymentStatus,'pending');
|
||||
return {f,game,payer,recipient,cash,amount,id,travelCost};
|
||||
}
|
||||
|
||||
function reject(game: Game, actor: string, action: Action) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game,actor,action));
|
||||
assert.deepEqual(game,before);
|
||||
}
|
||||
|
||||
for (const payerRole of ['traveler','proposer'] as const) {
|
||||
void test(`public bribe quote reserves current deal debt and travel when ${payerRole} pays`, () => {
|
||||
const {f,game:initial,payer,recipient,cash,amount,id,travelCost} = combined(payerRole,1);
|
||||
const quote = viewGame(initial,payer).bribeOptions;
|
||||
const target = quote.targets.find(row => row.id === recipient); assert.ok(target);
|
||||
assert.equal(target.maximum,1,'Only the spice left after both current commitments is discretionary');
|
||||
assert.ok(target.limitation,'The player can see why a smaller payment is available');
|
||||
assert.deepEqual(bribeAction(quote,recipient,1),{type:'bribe',target:recipient,amount:1});
|
||||
assert.equal(bribeAction(quote,recipient,2),null);
|
||||
reject(initial,payer,{type:'bribe',target:recipient,amount:2});
|
||||
let game = act(initial,payer,{type:'bribe',target:recipient,amount:1});
|
||||
assert.equal(player(game,payer).spice,cash-1);
|
||||
assert.equal(viewGame(game,payer).bribeOptions.targets.find(row => row.id === recipient)?.maximum,0);
|
||||
game = act(game,payer,{type:'dealPay',deal:id});
|
||||
assert.equal(game.deals!.find(row => row.id === id)!.paymentStatus,'paid');
|
||||
assert.equal(player(game,payer).spice,cash-1-amount);
|
||||
game = settle(act(game,f.target,f.shipmentAction));
|
||||
assert.equal(viewGame(game,f.target).dealTravelStatus[id],'fulfilled');
|
||||
assert.equal(player(game,payer).spice,cash-1-amount-travelCost);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
}
|
||||
|
||||
void test('a fully committed purse offers no ordinary bribe while the exact deal payment remains available', () => {
|
||||
const {f,game:initial,payer,recipient,id,amount,travelCost} = combined('traveler',0);
|
||||
const quote = viewGame(initial,payer).bribeOptions;
|
||||
assert.equal(quote.targets.find(row => row.id === recipient)?.maximum,0);
|
||||
assert.equal(bribeAction(quote,recipient,1),null);
|
||||
reject(initial,payer,{type:'bribe',target:recipient,amount:1});
|
||||
assert.equal(viewGame(initial,payer).deferredDealPaymentOptions[id]?.blocked,null);
|
||||
let game = act(initial,payer,{type:'dealPay',deal:id});
|
||||
assert.equal(player(game,payer).spice,travelCost);
|
||||
assert.equal(game.deals!.find(row => row.id === id)!.paymentStatus,'paid');
|
||||
game = settle(act(game,f.target,f.shipmentAction));
|
||||
assert.equal(viewGame(game,f.target).dealTravelStatus[id],'fulfilled');
|
||||
assert.equal(player(game,payer).spice,0);
|
||||
assert.ok(amount > 0);
|
||||
});
|
||||
|
||||
void test('future debt does not reserve today’s discretionary spice', () => {
|
||||
const {f,game,payer,recipient} = combined('traveler',0,true);
|
||||
const quote = viewGame(game,payer).bribeOptions.targets.find(row => row.id === recipient);
|
||||
assert.ok(quote);
|
||||
assert.equal(quote.maximum,player(game,payer).spice-f.shipmentCost);
|
||||
assert.doesNotThrow(() => act(game,payer,{type:'bribe',target:recipient,amount:1}));
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { 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';
|
||||
|
||||
function reject(game: Game, actor: string, action: Action) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game,actor,action));
|
||||
assert.deepEqual(game,before);
|
||||
}
|
||||
|
||||
/** Genuine Basic setup, one accepted next-turn shipment, and real advancement
|
||||
* to its due Movement phase. The original fixture only orders unopened cards. */
|
||||
function dueTravel() {
|
||||
const f = fixture(), dueTurn = f.game.turn + 1;
|
||||
let game = act(f.game,f.asker,{type:'dealOffer',target:f.target,terms:'Ship next turn.',
|
||||
travel:{kind:'ship',territory:f.shipmentTerritory,minimum:1,answer:true,dueTurn}});
|
||||
const travelId = game.deals!.at(-1)!.id;
|
||||
game = act(game,f.target,{type:'dealRespond',deal:travelId,accept:true});
|
||||
game = settle(act(game,f.target,f.currentEnd));
|
||||
game = advance(game,state => state.turn === dueTurn && state.phase === 5 &&
|
||||
state.active === f.target && clean(state) && !state.pendingShipment);
|
||||
assert.equal(viewGame(game,f.target).dealTravelStatus[travelId],'pending');
|
||||
assert.ok(player(game,f.target).spice > f.shipmentCost);
|
||||
assert.equal(player(game,f.target).hand.some(card => card.effect === 'karama'),false);
|
||||
return {f,game,travelId,dueTurn,cards:inventory(game)};
|
||||
}
|
||||
|
||||
for (const combined of [false,true]) for (const affordable of [false,true]) void test(
|
||||
`a due scheduled shipment and ${combined ? 'combined' : 'separate'} current payment ${affordable ? 'share sufficient funds' : 'reject overspending'}`, () => {
|
||||
const {f,game:initial,travelId,dueTurn,cards} = dueTravel();
|
||||
const cash = player(initial,f.target).spice;
|
||||
const amount = affordable ? cash - f.shipmentCost : cash;
|
||||
let game = act(initial,f.asker,{type:'dealOffer',target:f.target,terms:'Pay with optional matching travel.',
|
||||
payment:{kind:'deferredBribe',payer:f.target,recipient:f.asker,amount,dueTurn},
|
||||
...(combined ? {travel:{kind:'ship',territory:f.shipmentTerritory,minimum:1,answer:true}} : {})});
|
||||
const paymentId = game.deals!.at(-1)!.id;
|
||||
if (!affordable) {
|
||||
reject(game,f.target,{type:'dealRespond',deal:paymentId,accept:true});
|
||||
assert.equal(game.deals!.find(deal => deal.id === paymentId)?.status,'offered');
|
||||
assert.equal(viewGame(game,f.target).dealTravelStatus[travelId],'pending');
|
||||
assert.equal(player(game,f.target).spice,cash);
|
||||
assert.deepEqual(inventory(game),cards);
|
||||
return;
|
||||
}
|
||||
game = act(game,f.target,{type:'dealRespond',deal:paymentId,accept:true});
|
||||
assert.equal(game.deals!.find(deal => deal.id === paymentId)?.paymentStatus,'pending');
|
||||
game = act(game,f.target,{type:'dealPay',deal:paymentId});
|
||||
assert.equal(player(game,f.target).spice,f.shipmentCost);
|
||||
game = settle(act(game,f.target,f.shipmentAction));
|
||||
assert.equal(viewGame(game,f.target).dealTravelStatus[travelId],'fulfilled');
|
||||
if (combined) assert.equal(viewGame(game,f.target).dealTravelStatus[paymentId],'fulfilled');
|
||||
assert.equal(game.deals!.find(deal => deal.id === paymentId)?.paymentStatus,'paid');
|
||||
assert.equal(player(game,f.target).spice,0);
|
||||
assert.deepEqual(inventory(game),cards);
|
||||
},
|
||||
);
|
||||
|
||||
void test('a due payment already accepted prevents adding an unaffordable current shipment', () => {
|
||||
const f = fixture(), original = inventory(f.game), cash = player(f.game,f.target).spice;
|
||||
let game = act(f.game,f.asker,{type:'dealOffer',target:f.target,terms:'Pay this turn.',
|
||||
payment:{kind:'deferredBribe',payer:f.target,recipient:f.asker,amount:cash,dueTurn:f.game.turn}});
|
||||
const paymentId = game.deals!.at(-1)!.id;
|
||||
game = act(game,f.target,{type:'dealRespond',deal:paymentId,accept:true});
|
||||
game = act(game,f.asker,{type:'dealOffer',target:f.target,terms:'Also ship this turn.',
|
||||
travel:{kind:'ship',territory:f.shipmentTerritory,minimum:1,answer:true}});
|
||||
const travelId = game.deals!.at(-1)!.id;
|
||||
reject(game,f.target,{type:'dealRespond',deal:travelId,accept:true});
|
||||
assert.equal(game.deals!.find(deal => deal.id === paymentId)?.paymentStatus,'pending');
|
||||
assert.equal(game.deals!.find(deal => deal.id === travelId)?.status,'offered');
|
||||
assert.deepEqual(inventory(game),original);
|
||||
});
|
||||
Reference in new issue
Block a user