Support group travel agreements
Verify and publish checkpoint container / container (push) Successful in 11m13s

This commit is contained in:
Quintine committed 2026-10-29 08:04:30 +11:00
1 parent 82d857b667
commit e1e02fc1a1
10 files changed
+432 -56

No files matched your search

+67 -5
View File
@@ -30,13 +30,19 @@ const base = {status:'playing', turn:2, me:'b', roomControl:null, coalitionState
const markup = (game:GameView, disabled = false) =>
renderToStaticMarkup(createElement(PublicDealList, {game, act() {}, disabled}));
void test('the offer packet retains the original recipient action and validates one exact physical term', () => {
void test('the offer packet retains legacy two-party terms and validates an explicitly named group traveler', () => {
assert.deepEqual(publicDealOfferAction(['b'], ' Terms ', undefined, 'a', 2, travel),
{type:'dealOffer', target:'b', terms:'Terms', travel});
const avoid = {...travel, kind:'move' as const, answer:false, minimum:20};
assert.deepEqual(publicDealOfferAction(['b'], 'Avoid', undefined, 'a', 2, avoid),
{type:'dealOffer', target:'b', terms:'Avoid', travel:avoid});
assert.equal(publicDealOfferAction(['b','c'], 'Terms', undefined, 'a', 2, travel), null);
assert.deepEqual(publicDealOfferAction(['b','c'], 'Terms', undefined, 'a', 2, {...travel, actor:'c'}),
{type:'dealOffer', targets:['b','c'], terms:'Terms', travel:{...travel, actor:'c'}});
assert.equal(publicDealOfferAction(['b','c'], 'Terms', undefined, 'a', 2, {...travel, actor:'a'}), null);
assert.equal(publicDealOfferAction(['b','c'], 'Terms', undefined, 'a', 2, {...travel, actor:'d'}), null);
assert.equal(publicDealOfferAction(['b'], 'Terms', undefined, 'a', 2, {...travel, actor:'b'}), null);
assert.equal(publicDealOfferAction(['b','c'], 'Terms', payment, 'a', 2, {...travel, actor:'c'}), null);
assert.deepEqual(publicDealOfferAction(['b'], 'Terms', payment, 'a', 2, travel),
{type:'dealOffer', target:'b', terms:'Terms', payment, travel});
assert.equal(publicDealOfferAction(['b'], 'Terms', {...payment,payer:'b',recipient:'a'}, 'a', 2, travel), null);
@@ -75,7 +81,7 @@ void test('the combined offer explains payment timing and the recipient can acce
});
/** Stateful VM exercises the actual authoring callbacks without claiming browser hydration. */
function combinedForm() {
function combinedForm(gameOverride?: GameView) {
const states:unknown[] = [], sent:Action[] = [];
let cursor = 0;
const exported:{PublicDeals?:typeof PublicDeals} = {};
@@ -96,7 +102,7 @@ function combinedForm() {
throw new Error(`Unexpected import ${name}`);
}});
assert.ok(exported.PublicDeals);
const game = {...base, me:'a', deals:[]} as GameView;
const game = gameOverride ?? {...base, me:'a', deals:[]} as GameView;
const render = () => {cursor = 0; return elements(exported.PublicDeals!({game,busy:false,act(action) {sent.push(action);}}));};
const check = (index:number) => {
const node = render().filter(element => element.type === 'input' && element.props.type === 'checkbox')[index];
@@ -156,6 +162,62 @@ void test('the public deal shows the exact recipient, travel intent, turn and au
assert.match(markup({...base, dealTravelStatus:{deal:status}} as unknown as GameView), new RegExp(`Travel status: ${status}`));
});
void test('group offers name the traveler, require their last vote and still permit declining early', () => {
const players = [...base.players, {id:'c',name:'Cora',faction:'emperor',ally:null},
{id:'d',name:'Dara',faction:'guild',ally:null}];
const group = {...deal, participants:['a','b','c','d'], acceptVotes:['a','b'], status:'offered',
travel:{...travel,actor:'c'}};
const game = {...base, players, deals:[group], me:'c', dealTravelStatus:{}} as unknown as GameView;
assert.match(markup(game), /Cora \(Emperor\) would make a reserve shipment/);
assert.match(markup(game), /Cora \(Emperor\) must accept last/);
const actions:Action[] = [];
const early = elements(PublicDealList({game,disabled:false,act(action) {actions.push(action);}}));
assert.equal(early.find(node => node.props.children === 'Accept deal')?.props.disabled,true);
const decline = early.find(node => node.props.children === 'Decline deal');
assert.ok(decline); assert.equal(decline.props.disabled,false);
(decline.props.onClick as () => void)();
assert.deepEqual(actions,[{type:'dealRespond',deal:'deal',accept:false}]);
assert.deepEqual(publicDealRequests(game), [['offer','deal','waiting']], 'The traveler can see and decline the offer before other votes are in.');
const ordinary = {...game,me:'d'};
assert.deepEqual(publicDealRequests(ordinary), [['offer','deal']]);
assert.equal(elements(PublicDealList({game:ordinary,disabled:false,act() {}}))
.find(node => node.props.children === 'Accept deal')?.props.disabled,false);
const final = {...game,deals:[{...group,acceptVotes:['a','b','d']}]} as unknown as GameView;
assert.deepEqual(publicDealRequests(final), [['offer','deal','ready']], 'A changed request reopens the panel for the final vote.');
const finalActions:Action[] = [];
const accept = elements(PublicDealList({game:final,disabled:false,act(action) {finalActions.push(action);}}))
.find(node => node.props.children === 'Accept deal');
assert.ok(accept); assert.equal(accept.props.disabled,false);
(accept.props.onClick as () => void)();
assert.deepEqual(finalActions.at(-1),{type:'dealRespond',deal:'deal',accept:true});
const active = {...game, deals:[{...group,status:'active',acceptVotes:['a','b','c','d']}],
dealTravelStatus:{deal:'pending'}} as unknown as GameView;
assert.deepEqual(publicDealRequests(active), [['travel','deal']]);
assert.deepEqual(publicDealRequests({...active,me:'b'}), []);
});
void test('the group offer form selects an invited traveler and revalidates participant changes', () => {
const game = {...base, me:'a', deals:[], players:[...base.players,
{id:'c',name:'Cora',faction:'emperor',ally:null}, {id:'d',name:'Dara',faction:'guild',ally:null}]} as unknown as GameView;
const ui = combinedForm(game);
ui.check(0); ui.check(1); ui.check(4); // Basil, Cora, then travel.
const button = () => ui.render().find(node => node.type === 'button' && node.props.type === 'submit');
ui.select(0,'c'); ui.select(3,'carthag');
const terms = ui.render().find(node => node.type === 'textarea'); assert.ok(terms);
(terms.props.onChange as (event:{target:{value:string}}) => void)({target:{value:'Group travel'}});
assert.equal(button()?.props.disabled,false);
const form = ui.render().find(node => node.type === 'form'); assert.ok(form);
(form.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[0])), {type:'dealOffer',targets:['b','c'],terms:'Group travel',
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true,actor:'c'}});
const cora = ui.render().filter(node => node.type === 'input' && node.props.type === 'checkbox')[1];
(cora.props.onChange as (event:{target:{checked:boolean}}) => void)({target:{checked:false}});
ui.check(2); // Add Dara after removing the chosen traveler.
assert.equal(button()?.props.disabled,true);
ui.select(0,'d'); assert.equal(button()?.props.disabled,false);
ui.check(3); assert.equal(button()?.props.disabled,true, 'Group travel cannot be combined with payment.');
});
void test('only the obligated recipient gets a persistent pending reminder', () => {
assert.deepEqual(publicDealRequests(base), [['travel','deal']]);
assert.match(renderToStaticMarkup(createElement(PublicDeals,{game:base,act() {},busy:false})), /Public deals · travel term pending/);
@@ -211,9 +273,9 @@ void test('the recipient guide distinguishes a void deal from unanimous release'
}
});
void test('the real offer form explains single-recipient eligibility before a travel term is selected', () => {
void test('the real offer form asks for recipients before a travel term is selected', () => {
const html = renderToStaticMarkup(createElement(PublicDeals,{game:base,act() {},busy:false}));
assert.match(html, /Include a current-turn travel term/);
assert.match(html, /Select exactly one human recipient to add a travel term/);
assert.match(html, /Select at least one human recipient to add a travel term/);
assert.match(html, /cannot automatically enforce free-text promises/);
});