Both on a one-member PNI splits the LAG when the augment lands (#219)

A PNI's second member is an augment that arrives months later, so siteSet returned before setting the site and the new member joined the first building. The augment now carries site 'ab' (kept by sanitize), applies it on delivery if the POP still has two sites, and the panel shows Both as chosen while it is on order. Choosing A or B meanwhile drops the intent.
This commit is contained in:
Frederic Jung 2026-10-30 18:25:12 +01:00
parent abd55c0846
commit 5f2dd38d2d
No known key found for this signature in database
6 changed files with 47 additions and 5 deletions

View file

@ -970,7 +970,8 @@ test('#69 embedded caches can sit in either metro building, so one dark building
assert.equal(up(), 1);
assert.equal(ev("R.useCache[S.caches.find(x=>x.site==='a').id]||0"), 0, 'the box in the dark building carries nothing');
assert.ok(ev("R.useCache[S.caches.find(x=>x.site==='b').id]||0") > 0, 'the box in B still serves');
ev("UI.sel={type:'city',id:'fra'};UI.tab='peer';renderPanel()");
ev("selectCity('fra');ACT.tab({t:'peer'})");
assert.equal(ev(`[...document.querySelectorAll('[data-act=siteSet].pink')].filter(b=>JSON.parse(b.dataset.args).k==='p').map(b=>JSON.parse(b.dataset.args).s).join()`), 'ab', 'Both is shown as chosen');
assert.match(ev("$('panelBody').textContent"), /Boxes: 1 in A · 1 in B/);
// old saves: caches without a site are in A; dropping the second site moves them back
ev("delete S.caches[0].site;S=migrate(JSON.parse(JSON.stringify(S)))");
@ -1344,3 +1345,38 @@ test('link redundancy trials distinguish a bridge, a full fallback and a healthy
ev("window.saveRef=S;window.liveRef=R;window.originalCompute=compute;compute=()=>{throw Error('trial failed')}");assert.throws(()=>ev("linkTrial('main')"),/trial failed/);ev('compute=originalCompute');assert.equal(ev('S===saveRef&&R===liveRef'),true,'even a failed trial restores the live state');
assert.deepEqual(errors,[]);
});
test('#219 splitting a one-member PNI across both sites splits it when the augment lands', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e8;UI.speed=0;for(const g of GOALS)S.done[g.id]=0;Object.assign(S.pops.fra,{site2:true,routers:4});S.pni.push({id:'x',net:'nfx',city:'fra',tier:1,ready:0});compute()");
const cash = ev('S.cash');
ev("ACT.siteSet({k:'p',id:'x',s:'ab'})");
assert.equal(ev('S.pni[0].up.n'), 2, 'second member ordered');
assert.equal(ev('S.pni[0].up.site'), 'ab', 'remembers the split');
assert.ok(ev('S.cash') < cash, 'paid once');
// clicking again while it is on order buys nothing more
const paid = ev('S.cash');
ev("ACT.siteSet({k:'p',id:'x',s:'ab'})");
assert.equal(ev('S.cash'), paid);
// the panel shows Both as chosen meanwhile
assert.equal(ev("(()=>{const m=siteCtl('p','x','fra',S.pni[0].up&&S.pni[0].up.site==='ab'?'ab':S.pni[0].site).match(/<button[^>]*class=\"[^\"]*pink[^>]*>(.*?)<\\/button>/);return m&&m[1].includes(tr('common.site'))?'':m&&m[1]})()").startsWith('Both'), true);
// survives a save and load
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
assert.equal(ev('S.pni[0].up.site'), 'ab');
ev('S.day=S.pni[0].up.ready-1;dayTick()');
assert.equal(ev('S.pni[0].n'), 2);
assert.equal(ev('S.pni[0].site'), 'ab', 'one member in each building');
assert.equal(ev("liveN('fra','ab',2)"), 2);
assert.deepEqual(errors, []);
});
test('#219 choosing one site again while the augment is on order keeps the LAG in that site', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e8;UI.speed=0;for(const g of GOALS)S.done[g.id]=0;Object.assign(S.pops.fra,{site2:true,routers:4});S.pni.push({id:'x',net:'nfx',city:'fra',tier:1,ready:0});compute()");
ev("ACT.siteSet({k:'p',id:'x',s:'ab'})");
ev("ACT.siteSet({k:'p',id:'x',s:'b'})");
assert.equal(ev('S.pni[0].up.site'), undefined);
ev('S.day=S.pni[0].up.ready-1;dayTick()');
assert.equal(ev('S.pni[0].site'), 'b');
assert.deepEqual(errors, []);
});