Grow sideways in the late game: localised eyeball traffic, spread AI campuses, PNIs by router, spill tiers

Traffic to networks that sell to homes now starts where their users live (#48),
giant AI circuits come from campuses in 34 metros and less often from crowded
ones (#61), a PNI bundles eight members per router up to 32 (#323), and
RouteScript spill tiers move overflow onto detours within a latency budget (#136).
This commit is contained in:
Frederic Jung 2026-11-10 07:25:21 +00:00
parent 80baa970e7
commit 69cdb3e372
No known key found for this signature in database
29 changed files with 340 additions and 36 deletions

134
tests/endgame-scale.test.js Normal file
View file

@ -0,0 +1,134 @@
// The late game grows sideways, plus one expensive way up: eyeball traffic starts where the eyeballs are (#48), giant AI
// circuits spread over many metros (#61), a PNI grows by eight members per router (#323), and Auto-TE spills early onto
// detours within a latency budget (#136).
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
const { lit } = require('../scripts/lib/js-literal');
const US = ['nyc', 'ash', 'chi', 'atn', 'den', 'sea', 'sjc', 'mia'];
// POPs in the given cities with the same home demand, a thin backbone between neighbours and transit at every POP.
function usNetwork(ev, cities, wave) {
ev(`ACT.start({});S.cash=1e10;S.lvl=6;S.day=500;S.biz=[];S.offers=[];S.links=[];S.pops={};S.pni=[];S.caches=[];S.transit=[];S.ixp={};S.peers={};S.rs={};
S.nextFail=1e9;S.nextEvent=1e9;const cs=${lit(cities)};
for(const c of cs){S.pops[c]={routers:2,rgen:3,gen:true,bb:{d:400},down:0};S.transit.push({id:'t'+c,net:'cog',city:c,tier:3,n:4,down:0});}
for(let i=0;i+1<cs.length;i++)S.links.push({id:'w'+i,a:cs[i],b:cs[i+1],kind:'wave',tier:${wave},km:kmBetween(cs[i],cs[i+1]),cut:0,mo:100});
compute();`);
}
test('#48: traffic to a network that sells to homes starts where its users live', () => {
const { ev, errors } = load();
usNetwork(ev, ['nyc'], 3);
const us = ev('R.demTo.cmc/R.demand');
usNetwork(ev, ['fra'], 3);
const de = ev('R.demTo.cmc/R.demand'), deDtk = ev('R.demTo.dtk/R.demand');
usNetwork(ev, ['nyc'], 3);
const usDtk = ev('R.demTo.dtk/R.demand');
assert.ok(us > ev('NSH.cmc') * 3, `a New York POP sends Comecast far more than its world share (${us})`);
assert.ok(us > de * 8, `and much more than a Frankfurt POP does (${us} vs ${de})`);
assert.ok(deDtk > usDtk * 8, `Doitsche Telekomm the other way round (${deDtk} vs ${usDtk})`);
// Only the split between home networks moves: content keeps its share, and a city's total demand stays the same.
assert.ok(Math.abs(ev("[...locSh(NSH,'nyc')].reduce((a,b)=>a+b,0)") - 1) < 1e-9, 'the shares still add up to one');
assert.equal(ev("locSh(NSH,'nyc')[LOC_NIX.get('ggl')]"), ev('NSH.ggl'), 'content is everywhere');
assert.ok(Math.abs(ev("cityNetSh('nyc','cmc')") - ev("locSh(NSH,'nyc')[LOC_NIX.get('cmc')]")) < 1e-12, 'box sizing reads the same split');
assert.deepEqual(errors, []);
});
test('#48: peering with an eyeball in more of the cities its users live in carries more of its traffic', () => {
const { ev, errors } = load();
// A 10G backbone: hauling Comecast's traffic to two PNIs fills it, and the rest leaves over transit.
usNetwork(ev, US, 0);
const share = pnis => {
ev(`S.pni=${lit(pnis)}.map(c=>({id:'cmc@'+c,city:c,net:'cmc',tier:3,n:4}));compute()`);
return ev('(R.netEg.cmc.p||0)/R.demTo.cmc');
};
const two = share(['nyc', 'ash']), all = share(US);
assert.ok(all > 0.95, `a PNI in every city takes nearly all of it (${all})`);
assert.ok(two < 0.6, `two PNIs only take what the backbone can haul to them (${two})`);
assert.ok(all - two > 0.35, `more PNI locations carry more (${two} → ${all})`);
assert.deepEqual(errors, []);
});
test('#61: giant AI circuits spread over many metros, busy ones a bit busier', () => {
const { ev, errors } = load();
ev(`ACT.start({});S.cash=1e12;S.lvl=11;S.biz=[];S.offers=[];for(const m of MEGA)if(!S.pops[m.c])S.pops[m.c]={routers:1,rgen:3,gen:true,bb:null,down:0};
for(const c of ['ash','nyc','chi','dal','mex','lax','hou','bos','was'])if(!S.pops[c])S.pops[c]={routers:1,rgen:3,gen:true,bb:null,down:0};`);
ev('__reseed(61)');
// Three hundred offers, each signed as it comes, the way a long game fills up.
const out = JSON.parse(ev(`(()=>{const cnt={};let n=0;for(let i=0;i<300;i++){const before=S.offers.length;spawnSpecial(['aiwan','mtrain','agi'][i%3]);
if(S.offers.length===before)continue;const o=S.offers.pop();S.biz.push(o);n++;for(const c of bCities(o))cnt[c]=(cnt[c]||0)+1;}return JSON.stringify({cnt,n});})()`));
const tot = Object.values(out.cnt).reduce((a, b) => a + b, 0);
const five = ['mex', 'chi', 'dal', 'ash', 'nyc'].reduce((a, c) => a + (out.cnt[c] || 0), 0);
assert.ok(out.n > 200, `offers came (${out.n})`);
assert.ok(Object.keys(out.cnt).length >= 25, `ends in many metros (${Object.keys(out.cnt).length})`);
assert.ok(five / tot < 0.35, `the old five metros no longer get most of it (${(five / tot).toFixed(2)})`);
const avg = tot / Object.keys(out.cnt).length;
assert.ok(out.cnt.ash > avg, `Ashburn stays a bit busier than the average metro (${out.cnt.ash} vs ${avg.toFixed(1)})`);
assert.ok(out.cnt.ash < tot * 0.15, `but never the only place (${out.cnt.ash} of ${tot})`);
assert.deepEqual(errors, []);
});
test('#323: a PNI grows by eight members per router at the POP, up to 32', () => {
const { ev, dom, errors } = load();
ev("ACT.start({});S.cash=1e12;S.lvl=13;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});S.pops.fra.rgen=RG_TOP;S.pops.fra.routers=1;S.rules={...(S.rules||{}),pnis:'instant'};");
ev("S.pni.push({id:'p1',city:'fra',net:'nfx',tier:3,n:8});compute()");
const n = () => ev("S.pni.find(p=>p.id==='p1').n");
assert.equal(ev("pniLagMax('fra')"), 8, 'one router: eight members, as before');
ev("ACT.lagP({id:'p1',d:1})");
assert.equal(n(), 8, 'a ninth member needs a second router');
assert.match(dom.window.document.getElementById('toasts').textContent, /already bundles 8 ports/);
ev("ACT.addRouter({city:'fra'})");
assert.equal(ev("pniLagMax('fra')"), 16);
ev("ACT.lagP({id:'p1',d:1})");
assert.equal(n(), 9, 'the second router takes eight more');
assert.ok(Math.abs(ev("R.nodeCap.fra") - ev("nodeCap('fra')")) < 1e-9);
// Taking that router away again would leave the bundle with nowhere to land.
ev("ACT.rmRouter({city:'fra'})");
assert.equal(ev('S.pops.fra.routers'), 2, 'the router stays while the PNI needs it');
assert.match(dom.window.document.getElementById('toasts').textContent, /Shrink a PNI first/);
ev("S.pops.fra.routers=6;");
assert.equal(ev("pniLagMax('fra')"), 32, 'never more than 32 members, however many routers');
for (let i = 0; i < 30; i++) ev("ACT.lagP({id:'p1',d:1})");
assert.equal(n(), 32);
// The panel offers a member while there is room and says why when there is none.
ev("S.pops.fra.routers=4;UI.sel={type:'city',id:'fra'};S.pni.find(p=>p.id==='p1').n=31;");
ev('window.innerWidth=390;renderAll()');
assert.deepEqual(errors, []);
});
test('#323: saves keep their LAGs, big ones included, and garbage is clamped', () => {
const { ev, errors } = load();
ev("ACT.start({});ACT.launchBB({city:'fra'});S.pops.fra.routers=3;");
ev("S.pni.push({id:'old',city:'fra',net:'nfx',tier:2,n:8},{id:'big',city:'fra',net:'ggl',tier:2,n:24,up:{tier:3,n:24,ready:S.day+30}},{id:'bad',city:'fra',net:'akm',tier:1,n:999})");
ev('const o=JSON.parse(JSON.stringify(S));sanitize(o);window.__o=o');
assert.equal(ev("__o.pni.find(p=>p.id==='old').n"), 8, 'an old save with an 8-port LAG loads as it was');
assert.equal(ev("__o.pni.find(p=>p.id==='big').n"), 24);
assert.equal(ev("__o.pni.find(p=>p.id==='big').up.n"), 24);
assert.equal(ev("__o.pni.find(p=>p.id==='bad').n"), 32, 'never past the biggest bundle');
assert.equal(ev("migrate(JSON.parse(JSON.stringify(S)))&&1"), 1);
assert.deepEqual(errors, []);
});
test('#136: spill tiers keep a hot link at its line while a detour within the latency budget has room', () => {
const { ev, errors } = load();
// New York reaches its upstream in Los Angeles over a direct 10G wave, or about 10 ms longer through Miami on 800G.
ev(`ACT.start({});S.cash=1e12;S.lvl=13;for(const g of GOALS)S.done[g.id]=0;for(const c of ['nyc','lax','mia'])if(!S.pops[c])ACT.buildPop({city:c});
for(const c of ['nyc','lax','mia']){S.pops[c].rgen=RG_TOP;S.pops[c].routers=RMAX;}if(!S.pops.nyc.bb)ACT.launchBB({city:'nyc'});S.pops.nyc.bb.d=400;
const L=(a,b,t)=>{UI.via=null;UI.lmode='wave';UI.route='main';openLinkModal(a,b);ACT.buildLink({tier:t});closeModal();};
L('nyc','lax',0);L('nyc','mia',3);L('mia','lax',3);S.links.forEach(l=>l.ready=0);
S.transit=[];const t=NETS.find(n=>n.price&&n.pops.includes('lax')&&n.type==='t1');ACT.buyTransit({city:'lax',net:t.id,tier:3});
S.ixp={};S.pni=[];S.caches=[];S.te={on:true,day:0};S.core={lv:2,run:2,legacy:true};S.nextFail=1e9;S.nextEvent=1e9;`);
const direct = "R.load[S.links.find(l=>l.a==='nyc'&&l.b==='lax').id]";
const run = s => { ev(`S.te.script=${lit(s)};compute()`); return { load: ev(direct), served: ev('R.served'), moved: ev('R.teMoved') }; };
const none = run(''), short = run('spill at 80% within 5 ms'), long = run('spill at 80% within 15 ms'), two = run('spill at 80% within 15 ms\nspill at 90% within 30 ms');
assert.ok(none.load > 9.99, 'without tiers the direct link fills up');
assert.ok(short.load > 9.99, 'a detour 10 ms longer is outside a 5 ms budget: the link fills up as before');
assert.ok(Math.abs(long.load - 8) < 1e-6, `within 15 ms the link stays at 80% (${long.load})`);
assert.ok(Math.abs(two.load - 8) < 1e-6, 'the 90% tier only opens once the 80% detours are full');
assert.ok(Math.abs(long.served - none.served) < 1e-6, 'and nothing is lost: the detour carries it');
assert.ok(long.moved > none.moved, 'Auto-TE moved it');
assert.equal(ev("teParse('spill at 80% within 500 ms').errors.length"), 1, 'a budget past 100 ms is refused');
assert.equal(ev("JSON.stringify(teParse('spill at 90% within 20 ms\\nspill at 80% within 10 ms').tiers)"), '[{"at":0.8,"ms":10},{"at":0.9,"ms":20}]');
assert.deepEqual(errors, []);
});

View file

@ -222,6 +222,16 @@ test('N7: presence is real: PoPs are cities, exchange ports only where the netwo
fail('N7', bad, 'an exchange port needs an exchange in that city and a PoP there');
});
test('N8: a POP\'s traffic to the networks that sell to homes goes mostly to those whose users live near it (#48)', () => {
// Every city keeps its total and content keeps its share: only the split between home networks follows geography.
const bad = J(`CITIES.filter(c=>{const a=locSh(NSH,c.id);let t=0;for(let j=0;j<NETS.length;j++){t+=a[j];if(!NETS[j].cc&&Math.abs(a[j]-(NSH[NETS[j].id]||0))>1e-12)return true;}return Math.abs(t-1)>1e-9;}).map(c=>c.id)`);
fail('N8', bad, 'locSh() must keep a city\'s total and every share of a network without home markets');
// At home a network's share is above its world share, far away below it.
const far = J(`NETS.filter(n=>n.cc&&NSH[n.id]>0).flatMap(n=>{const cc=[].concat(n.cc),home=CITIES.find(c=>cc.includes(c.cc)),away=CITIES.find(c=>!locNets()[LOC_NIX.get(n.id)].reg.has(c.reg));
const j=LOC_NIX.get(n.id),out=[];if(home&&!(locSh(NSH,home.id)[j]>NSH[n.id]))out.push(n.id+'@home');if(away&&!(locSh(NSH,away.id)[j]<NSH[n.id]))out.push(n.id+'@away');return out;})`);
fail('N8', far, 'LOC_HOME > LOC_REG > LOC_FAR, and home markets (cc) are where the users are');
});
// ---------- Modes and rules ----------
test('M1: On-call is the classic game: the default rules, and what old saves load as', () => {
@ -488,6 +498,18 @@ test('F8: a managed wave costs your own capacity, rides one optic, and is priced
// D1–D4: DDoS as networks see it (#242). tests/ddos-model.test.js plays each one in detail.
const ddFra = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=40;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.pops.fra.rgen=RG.findIndex(r=>r.fsN===8);S.biz.push({id:'g',type:'game',name:'G',city:'fra',bw:10,rate:1,mood:80,since:0,reqs:[]},{id:'d',type:'dia',name:'D',city:'fra',bw:5,rate:1,mood:80,since:0,reqs:[]});compute()");
const ddHit = (ev, g) => ev(`S.ev.ddos={id:'x',city:'fra',tgt:'g',vec:'dns',gbps:${g},start:S.day,until:S.day+2,bh:false};compute()`);
test('F9: growth goes sideways, plus one paid way up (#61, #323)', () => {
// A PNI bundles eight members per router at its POP, up to 32; every other LAG stays at eight.
assert.equal(ev('LAG_MAX'), 8, 'F9: transit, exchange and fabric LAGs hold eight members');
const lim = J("[1,2,3,4,5,16].map(r=>{const o=S.pops.fra;S.pops.fra={routers:r};const m=pniLagMax('fra');if(o)S.pops.fra=o;else delete S.pops.fra;return m;})");
assert.deepEqual(lim, [8, 16, 24, 32, 32, 32], 'F9: a PNI grows by eight members per router, up to 32');
// Giant AI circuits land at campuses spread over many metros, no city more than two.
const per = J("MEGA.reduce((m,x)=>(m[x.c]=(m[x.c]||0)+1,m),{})");
assert.ok(Object.keys(per).length >= 30, `F9: campuses in at least 30 metros (${Object.keys(per).length})`);
fail('F9', Object.entries(per).filter(([, n]) => n > 2).map(([c]) => c), 'no metro holds more than two campuses');
fail('F9', J("MEGA.filter(m=>!CITY[m.c]).map(m=>m.c)"), 'campuses sit in real cities');
});
test('D1: attack sizes come from the world, never from your network', () => {
const g = load();
ddFra(g.ev);

View file

@ -96,7 +96,7 @@ test('saves: PNIs on order survive, and garbage is repaired', () => {
setup(ev);
ev("S.pni.push({id:'x',city:'fra',net:'dtk',tier:0,g1:true,ready:S.day+30,up:{tier:'9',n:99,ready:'x'}},{id:'y',city:'fra',net:'nfx',tier:1,g1:true})");
ev('const o=JSON.parse(JSON.stringify(S));sanitize(o);window.__o=o');
assert.equal(ev("__o.pni.find(p=>p.id==='x').up.n"), ev('LAG_MAX'));
assert.equal(ev("__o.pni.find(p=>p.id==='x').up.n"), ev('PNI_LAG_MAX'));
assert.equal(ev("__o.pni.find(p=>p.id==='x').g1"), true);
assert.equal(ev("__o.pni.find(p=>p.id==='y').g1"), undefined, 'only Doitsche Telekomm does 1G');
assert.deepEqual(errors, []);

View file

@ -17,10 +17,10 @@ function pages() {
let base = head;
try { const b = path.join(os.tmpdir(), `tubes-fuzz-test-${process.pid}-base.html`); fs.writeFileSync(b, page.assembleRef('origin/main')); base = b; } catch (e) {}
let P = { base: openPage(base, 'base'), head: openPage(head, 'head') };
// A change to the world itself (cities, networks, cables) or to what links cost cannot route like main: there is no
// same game to compare. Then the base is this checkout too, and the cache on/off check still runs; equivalence with
// main resumes once it lands.
const world = (p) => p.ev("JSON.stringify([CITIES.map(c=>[c.id,c.land,c.P]),NETS.map(n=>[n.id,n.pops,n.ix,n.share,n.price,n.up]),CABLES.map(c=>[c.id,c.pairs.map(q=>[q[0],q[1]])]),[1,300,3000].map(k=>[dfLeaseMo(k),waveMo(k,false,2),dfBuildCost(k)])])");
// A change to the world itself (cities, networks, cables, AI campuses), to what links cost or to where each city's
// traffic goes (locSh(), #48) cannot route like main: there is no same game to compare. Then the base is this checkout
// too, and the cache on/off check still runs; equivalence with main resumes once it lands.
const world = (p) => p.ev("JSON.stringify([CITIES.map(c=>[c.id,c.land,c.P]),NETS.map(n=>[n.id,n.pops,n.ix,n.share,n.price,n.up]),CABLES.map(c=>[c.id,c.pairs.map(q=>[q[0],q[1]])]),[1,300,3000].map(k=>[dfLeaseMo(k),waveMo(k,false,2),dfBuildCost(k)]),MEGA.map(m=>m.c),['nyc','fra','sin'].map(c=>typeof locSh==='function'?Array.from(locSh(NSH,c)):null)])");
if (base !== head && world(P.base) !== world(P.head)) { console.log('# route fuzz: the world or its prices differ from main, so both pages are this checkout'); P = { base: openPage(head, 'base'), head: P.head }; }
return P;
}

View file

@ -367,7 +367,7 @@ test('Auto-TE routes around a full link exactly like the plain path', () => {
S.transit=[];const t=NETS.find(n=>n.price&&n.pops.includes('ams')&&n.type==='t1');ACT.buyTransit({city:'ams',net:t.id,tier:3});
S.ixp={};S.pni=[];S.caches=[];S.te={on:true,day:0};S.core={lv:2,run:2,legacy:true};S.nextFail=1e9;S.nextEvent=1e9;`);
const sig = () => ev('JSON.stringify({served:R.served,teMoved:R.teMoved,egT:R.egT,load:S.links.map(l=>R.load[l.id]||0),node:R.nodeLoad,t:R.useT})');
for (const script of ['', 'spill at 70%']) {
for (const script of ['', 'spill at 70%', 'spill at 80% within 5 ms\nspill at 90% within 20 ms']) {
ev(`S.te.script=${lit(script)}`);
ev('compute()'); const fast = sig();
ev('__plain()'); const ref = sig();