Merge #246: Transit headroom: an Already connected provider choice (#227)

Transit headroom: an Already connected provider choice (#227)
This commit is contained in:
Frederic Jung 2026-10-31 14:10:27 +01:00 • committed by GitHub
commit 63a332947b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 46 additions and 11 deletions

View file

@ -596,6 +596,30 @@ test('#228 the intern names the exchanges it peered at, even one that shares its
assert.deepEqual(errors, []);
});
test('#227 transit "Already connected" grows the providers you have, the smallest first, and never signs a new one', t => {
const { ev, errors } = game(t, "ACT.buyTransit({city:'fra',net:'ntt',tier:1});compute()");
hire(ev); on(ev, 'transit', { x: 1.5, prov: 'have' });
const capOf = net => ev(`(()=>{const t=S.transit.find(x=>x.city==='fra'&&x.net==='${net}');return lagCap(PORT[t.tier].g,t.n)})()`);
const c0 = capOf('cog'), n0 = capOf('ntt');
assert.equal(c0, n0, 'two equal ports to start');
ev('for(const t of S.transit)t.hist=[100]'); shift(ev);
assert.equal(ev("JSON.stringify(S.transit.filter(t=>t.city==='fra').map(t=>t.net).sort())"), '["cog","ntt"]', 'no new provider');
assert.ok(capOf('cog') > c0 && capOf('ntt') > n0, 'both grew, not just one');
assert.equal(capOf('cog'), capOf('ntt'), 'evenly, smallest first');
// a POP whose only upstream is not the cheapest never gets the cheapest added (Cheapest would buy Cogentle there)
ev("ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;ACT.launchBB({city:'ams'});ACT.buyTransit({city:'ams',net:'ntt',tier:1});compute()");
assert.equal(ev("cheapestTransit('ams').id"), 'cog');
ev("for(const t of S.transit)t.hist=[400]"); ev('S.day++'); shift(ev);
assert.equal(ev("JSON.stringify(S.transit.filter(t=>t.city==='ams').map(t=>t.net))"), '["ntt"]');
// the setting cycles through it, reads "Already connected" and survives a save
ev("S.ops.p.transit.prov='cheap';ACT.opsParam({k:'transit',p:'prov'})");
assert.equal(ev("opsP('transit','prov')"), 'have');
assert.equal(ev("opsVal('transit','prov')"), 'Already connected');
ev('S=migrate(JSON.parse(JSON.stringify(S)))');
assert.equal(ev("opsP('transit','prov')"), 'have');
assert.deepEqual(errors, []);
});
test('#244 the PNI order counts the traffic the PNI list shows at that POP, not what cache boxes there already serve', t => {
const { ev, errors } = game(t, "ACT.buildPop({city:'ham'});for(const c of ['fra','ham']){S.pops[c].rgen=mainRG(4);S.pops[c].routers=6;if(!S.pops[c].bb)ACT.launchBB({city:c});S.pops[c].bb.d=CITY[c].P*0.9;}UI.pending={a:'fra',b:'ham'};ACT.buildLink({tier:3});closeModal();ACT.buyTransit({city:'fra',net:'cog',tier:3});ACT.buyTransit({city:'ham',net:'cog',tier:3});for(let i=0;i<6;i++)S.caches.push({id:'nfx'+i,city:'ham',net:'nfx'});compute()");
// Hamburg's users want a lot from NetChill, but its cache boxes there serve most of it: little is left for a PNI