Support scheduled travel agreements
Verify and publish checkpoint container / container (push) Successful in 11m8s

This commit is contained in:
Quintine committed 2026-10-29 08:19:52 +11:00
1 parent e1e02fc1a1
commit 1e81ce8ad8
13 files changed
+767 -56

No files matched your search

+55 -2
View File
@@ -39,6 +39,14 @@ void test('the offer packet retains legacy two-party terms and validates an expl
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.deepEqual(publicDealOfferAction(['b'], 'Terms', undefined, 'a', 2, {...travel,dueTurn:2}),
{type:'dealOffer', target:'b', terms:'Terms', travel}, 'Current-turn packet keeps the legacy shape.');
assert.deepEqual(publicDealOfferAction(['b'], 'Terms', payment, 'a', 2, {...travel,dueTurn:4}),
{type:'dealOffer', target:'b', terms:'Terms', payment, travel:{...travel,dueTurn:4}});
assert.deepEqual(publicDealOfferAction(['b','c'], 'Terms', undefined, 'a', 2, {...travel,actor:'c',dueTurn:4}),
{type:'dealOffer', targets:['b','c'], terms:'Terms', travel:{...travel,actor:'c',dueTurn:4}});
for (const dueTurn of [0, 1, 2.5, Number.NaN, undefined])
assert.equal(publicDealOfferAction(['b'], 'Terms', undefined, 'a', 2, {...travel,dueTurn}), null);
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);
@@ -67,7 +75,7 @@ void test('the combined offer explains payment timing and the recipient can acce
const html = markup(offered);
assert.match(html, /Alice \(Atreides\) pays 2 spice to Basil \(Harkonnen\) on final acceptance/);
assert.match(html, /recipient collects their share at the next Mentat opening/);
assert.match(html, /cannot use this payment to fund the current travel/);
assert.match(html, /cannot spend this payment before its next Mentat collection/);
const sent:Action[] = [];
const tree = PublicDealList({game:offered, disabled:false, act(action) {sent.push(action);}});
const accept = elements(tree).find(node => node.props.children === 'Accept deal');
@@ -218,6 +226,51 @@ void test('the group offer form selects an invited traveler and revalidates part
ui.check(3); assert.equal(button()?.props.disabled,true, 'Group travel cannot be combined with payment.');
});
void test('the author chooses a future travel turn and can return to the legacy current-turn packet', () => {
const ui = combinedForm();
ui.check(0); ui.check(2);
ui.select(2,'carthag');
const terms = ui.render().find(node => node.type === 'textarea'); assert.ok(terms);
(terms.props.onChange as (event:{target:{value:string}}) => void)({target:{value:'Later journey'}});
const deadline = () => ui.render().find(node => node.type === 'input' && node.props.type === 'number' && node.props.min === 2);
const submit = () => ui.render().find(node => node.type === 'button' && node.props.type === 'submit');
assert.ok(deadline());
(deadline()!.props.onChange as (event:{target:{value:string}}) => void)({target:{value:'4'}});
const form = ui.render().find(node => node.type === 'form'); assert.ok(form);
assert.equal(submit()?.props.disabled,false);
(form.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[0])), {type:'dealOffer',target:'b',terms:'Later journey',
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true,dueTurn:4}});
(deadline()!.props.onChange as (event:{target:{value:string}}) => void)({target:{value:'1'}});
assert.equal(submit()?.props.disabled,true);
(deadline()!.props.onChange as (event:{target:{value:string}}) => void)({target:{value:'2'}});
assert.equal(submit()?.props.disabled,false);
const current = ui.render().find(node => node.type === 'form'); assert.ok(current);
(current.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[1])), {type:'dealOffer',target:'b',terms:'Later journey',
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true}});
});
void test('future offers stay actionable until the selected turn and scheduled terms do not prompt the traveler early', () => {
const offered = {...base,turn:3, deals:[{...deal,status:'offered',travel:{...travel,dueTurn:4}}],
dealTravelStatus:{}} as unknown as GameView;
assert.match(markup(offered), /during turn 4/);
assert.match(markup(offered), /Before turn 4, this term reserves no forces or spice/);
const accept = (game:GameView) => elements(PublicDealList({game,disabled:false,act() {}}))
.find(node => node.props.children === 'Accept deal');
assert.equal(accept(offered)?.props.disabled,false);
assert.equal(accept({...offered,turn:4})?.props.disabled,false);
const expired = {...offered,turn:5};
assert.equal(accept(expired)?.props.disabled,true);
assert.match(markup(expired), /travel term’s turn has passed/);
const scheduled = {...offered, deals:[{...deal,travel:{...travel,dueTurn:4}}],
dealTravelStatus:{deal:'scheduled'}} as unknown as GameView;
assert.match(markup(scheduled), /Travel status: scheduled/);
assert.deepEqual(publicDealRequests(scheduled), []);
assert.deepEqual(publicDealRequests({...scheduled,turn:4,dealTravelStatus:{deal:'pending'}} as unknown as GameView),
[['travel','deal']]);
});
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/);
@@ -275,7 +328,7 @@ void test('the recipient guide distinguishes a void deal from unanimous release'
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, /Include 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/);
});