Standing orders: the spare wave kept by decommission sits in another trench than the big link

This commit is contained in:
Frederic Jung 2026-10-28 20:12:54 +01:00
parent d69e340f9a
commit 7b7d3ea1b3
No known key found for this signature in database
2 changed files with 15 additions and 1 deletions

View file

@ -138,7 +138,8 @@ const OPS_RUN={
for(const ls of by.values()){if(ls.length<2)continue;const live=ls.filter(l=>!linkDown(l)),big=live.reduce((a,l)=>!a||capOf(l)>capOf(a)?l:a,null);if(!big)continue;
let cap=live.reduce((a,l)=>a+capOf(l),0);const load=ls.reduce((a,l)=>a+((R.load&&R.load[l.id])||0),0);
const small=live.filter(l=>l!==big&&l.kind==='wave'&&!l.standby&&!l.premium&&capOf(l)<capOf(big)&&!S.biz.some(b=>b.link===l.id)).sort((a,b)=>capOf(b)-capOf(a));
if(keep)small.shift();
// The spare is there for when the big link's trench is cut, so it has to live in another trench.
if(keep&&small.length){const tr=l=>l.trench||l.id,i=small.findIndex(l=>tr(l)!==tr(big));small.splice(Math.max(0,i),1);}
for(const l of small.reverse()){if(cap-capOf(l)<load*1.25)break;if(!opsDecomSafe(l))continue;cap-=capOf(l);UI.confirm=l.id;ACT.rmLink({id:l.id});if(!S.links.includes(l))X.did('decom',l.a+'|'+l.b);}}},
};
// A wave can carry a promise: diverse paths, no subsea, a latency budget. Try the network without it first.

View file

@ -381,3 +381,16 @@ test('transit never comes from a provider that breaks a promise: no-Cogentle cus
assert.equal(ev("cheapestTransit('fra')"), undefined, 'a lone first upstream would break "two upstreams"');
assert.deepEqual(errors, []);
});
test('decommission keeps its spare in another trench than the big link', t => {
const { ev, errors } = game(t, "ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;for(const [id,tier,tr] of [['big',2,'T1'],['s1',1,'T1'],['s2',0,'T2']])S.links.push({id,a:'fra',b:'ams',kind:'wave',tier,km:400,sub:false,cut:0,mo:100,trench:tr});compute()");
hire(ev); on(ev, 'decom', { keep: true });
ev("R.load={big:1,s1:0,s2:0}");
shift(ev);
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links.map(l=>l.id).sort())")), ['big', 's2'], 'the 100G in the same trench goes, the 10G in its own trench stays');
// Every small wave shares the big one's trench: keep the largest, as before.
ev("S.links=S.links.filter(l=>l.id==='big');for(const [id,tier] of [['a',1],['b',0]])S.links.push({id,a:'fra',b:'ams',kind:'wave',tier,km:400,sub:false,cut:0,mo:100,trench:'T1'});compute();R.load={big:1}");
shift(ev);
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links.map(l=>l.id).sort())")), ['a', 'big']);
assert.deepEqual(errors, []);
});