// Rented low-orbit capacity (#83): a Starblink gateway on a teleport at a POP on your fiber sells LEO circuits (5 to // 50 Gbps, about 30 ms round trip) to small islands and remote towns within 1,200 km. A circuit is a link (kind 'sat') like // GEO and MEO ones; selective networks peer over it as over a cable; the islands behind a gateway lean on its POP; a rare // solar storm puts every LEO circuit in safe mode; once your own constellation carries traffic Starblink sells you nothing. const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const { load } = require('./harness'); const { createSession, TOOLS } = require('../scripts/lib/mcp-game'); const SAVE = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8'); // Level 5, Change Freeze (nothing breaks, lead times quick), plenty of cash. const BASE = "ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;S.lvl=5;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');"; // Caracas: a POP with transit (Caracas sells drz, mvs and llt) and a teleport. const CAR = "ACT.buildPop({city:'ccs'});ACT.buyTransit({city:'ccs',net:'drz',tier:1});ACT.teleBuild({city:'ccs'});"; const GW = CAR + "ACT.teleLeo({city:'ccs'});"; function game(t, setup = '') { const h = load(); t.after(() => h.dom.window.close()); h.ev(BASE + setup); return h; } const J = (ev, s) => JSON.parse(ev(`JSON.stringify(${s})`)); const leo = "S.links.find(l=>l.bird==='sb53')", geo = "S.links.find(l=>l.kind==='sat'&&SATS[l.bird].orb==='geo')"; const ready = 'S.day=Math.max(...S.links.map(l=>l.ready||0));compute()'; const pie = "S.pieV=1;pieInit();S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full,day:S.day,las:false}];"; test('the footprint and the physics: a bent pipe 550 km up, regional, about 30 ms', (t) => { const { ev, errors } = game(t); assert.deepEqual(J(ev, "['tbu','cur','ome','hpa'].map(c=>satSees('sb53',c))"), [true, true, false, false], 'the shell misses Nome and Haparanda'); assert.deepEqual(J(ev, "[['suv','tbu'],['suv','vli'],['ccs','cur'],['syd','tbu']].map(([a,b])=>satPairOk('sb53',a,b))"), [true, true, true, false], 'Sydney to Tonga is too far for one satellite'); // Every LEO pair on sale with an island or a remote town in it clears the floor at the midpoint and the reach. const bad = J(ev, "(()=>{const O=SAT_ORB.leo,out=[];for(const A of CITIES)for(const B of CITIES){if(A.id>=B.id||!(satRemote(A.id)||satRemote(B.id))||!satPairOk('sb53',A.id,B.id))continue;if(satElev(satArc(A.lat,A.lon,B.lat,B.lon)/2,O.h)O.km||satKm('sb53',A.id,B.id)<2*O.h)out.push(A.id+'-'+B.id);}return out;})()"); assert.deepEqual(bad, []); for (const [a, b] of [['ccs', 'cur'], ['suv', 'vli']]) { const rtt = ev(`satRtt('sb53','${a}','${b}')`); assert.ok(rtt >= 25 && rtt <= 45, `${a}-${b}: about 30 ms round trip, got ${rtt}`); } assert.ok(ev("satKm('sb53','ccs','cur')") >= 2 * 550, 'up to the shell and back down'); // The orbits are told apart by their loss in satEdges/satAfter, so none may share one. assert.equal(new Set(J(ev, 'Object.values(SAT_ORB).map(o=>o.loss)')).size, 3); assert.deepEqual(J(ev, 'Object.keys(SAT_ORB)'), ['geo', 'meo', 'leo']); assert.equal(J(ev, "satBirds('ccs','cur')").pop(), 'sb53', 'orbit order: GEO, MEO, then LEO'); assert.deepEqual(errors, []); }); test('the WISP hooks: radio path, one-way ms and reach for any point on the globe, and they change nothing', (t) => { const { ev, errors } = game(t, CAR); const P = "CITY.cur.lat,CITY.cur.lon"; assert.equal(ev(`leoKmLL('ccs',${P})`), ev("satKm('sb53','ccs','cur')"), 'the same radio path as a circuit to the city there'); assert.ok(Math.abs(ev(`leoMsLL('ccs',${P})`) - ev("satLat({bird:'sb53',km:satKm('sb53','ccs','cur')})")) < 1e-9); assert.equal(ev(`leoReachLL('ccs',${P})`), false, 'no gateway yet'); ev("ACT.teleLeo({city:'ccs'})"); const s0 = ev('JSON.stringify(S)'); assert.equal(ev(`leoReachLL('ccs',${P})`), true); assert.equal(ev("leoReachLL('ccs',25,-77)"), false, 'Nassau’s point is too far for one satellite'); assert.equal(ev("leoReachLL('ccs',60,-66)"), false, 'beyond the shell'); assert.equal(ev('JSON.stringify(S)'), s0, 'pure'); assert.equal(ev(`S.lvl=4;leoReachLL('ccs',${P})`), false, 'below level 5'); ev('S.lvl=5;' + pie); assert.equal(ev(`leoReachLL('ccs',${P})`), false, 'your own constellation flies'); assert.equal(ev('leoStorm()'), false); assert.deepEqual(errors, []); }); test('a gateway: level 5, a teleport under the shell on your fiber, its price; closing it asks twice', (t) => { const { ev, errors } = game(t, CAR); let c0 = ev('S.cash'); ev("S.lvl=4;ACT.teleLeo({city:'ccs'})"); assert.equal(ev("'leo' in S.pops.ccs"), false, 'LEO unlocks at level 5'); assert.equal(ev('S.cash'), c0, 'nothing charged'); ev("S.lvl=5;ACT.teleLeo({city:'ccs'});compute()"); assert.equal(ev('S.pops.ccs.leo'), 1); assert.equal(c0 - ev('S.cash'), ev('LEO_GW_COST')); assert.equal(ev('R.cost.sat'), ev('TPORT_MO+LEO_GW_MO'), 'the gateway bills with the teleports'); // Suva with a teleport and only a satellite out: no gateway until a wave of yours is lit there. ev("ACT.buildPop({city:'syd'});ACT.buyTransit({city:'syd',net:'cog',tier:1});ACT.buildPop({city:'suv'});ACT.teleBuild({city:'suv'})"); assert.equal(ev("teleOf('suv')"), 1); assert.match(ev("leoGwWhy('suv')"), /fiber/); c0 = ev('S.cash'); ev("ACT.teleLeo({city:'suv'})"); assert.equal(ev("'leo' in S.pops.suv"), false); assert.equal(ev('S.cash'), c0); ev("UI.pending={a:'syd',b:'suv'};ACT.buildLink({tier:1});closeModal();S.links.find(l=>l.kind==='wave').ready=S.day+5"); assert.match(ev("leoGwWhy('suv')"), /fiber/, 'still being built'); ev("S.day=S.links.find(l=>l.kind==='wave').ready"); assert.equal(ev("leoGwWhy('suv')"), '', 'lit: Suva is on your fiber'); // Anchorage is beyond the shell; Edinburgh, just inside it, needs no tracking antennas. ev("ACT.buildPop({city:'anc'});S.pops.anc.tele=1;ACT.buildPop({city:'edi'});ACT.teleBuild({city:'edi'})"); assert.match(ev("leoGwWhy('anc')"), /56°/); assert.equal(ev("leoGwWhy('edi')"), ''); assert.match(ev("leoGwWhy('lon')"), /no POP/); // Closing: refused while a LEO circuit starts there, and two taps. ev("ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:5});closeModal();ACT.teleLeoRm({city:'ccs'});ACT.teleLeoRm({city:'ccs'})"); assert.equal(ev('S.pops.ccs.leo'), 1, 'not while a LEO circuit starts there'); ev(`ACT.rmLink({id:${leo}.id});ACT.rmLink({id:${leo}.id})`); assert.equal(ev(`!!${leo}`), false); ev("UI.confirm=null;ACT.teleLeoRm({city:'ccs'})"); assert.equal(ev('S.pops.ccs.leo'), 1, 'the first tap only arms it'); ev("ACT.teleLeoRm({city:'ccs'})"); assert.equal(ev("'leo' in S.pops.ccs"), false); assert.equal(ev("teleOf('ccs')"), 1, 'the teleport stays'); // Closing the teleport takes the gateway along. ev("ACT.teleLeo({city:'ccs'});UI.confirm=null;ACT.teleRm({city:'ccs'});ACT.teleRm({city:'ccs'})"); assert.equal(ev("teleOf('ccs')"), 0); assert.equal(ev("'leo' in S.pops.ccs"), false); assert.deepEqual(errors, []); }); test('a LEO circuit: price, lead time, about 30 ms, users hardly notice; refused without a gateway or beyond the bent pipe', (t) => { const { ev, errors } = game(t, CAR); assert.match(ev("satWhy('ccs','cur','sb53',10)"), /gateway/); ev("ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10})"); assert.equal(ev(`!!${leo}`), false, 'no gateway, no circuit'); ev("ACT.teleLeo({city:'ccs'})"); const c0 = ev('S.cash'); ev("ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10})"); const l = J(ev, leo); assert.ok(ev('!!S.pops.cur'), 'the order builds the POP'); assert.equal(c0 - ev('S.cash'), ev("satMo('sb53',10)+popCost('cur')")); assert.equal(l.mo, ev("satMo('sb53',10)")); assert.equal(l.ready, ev('S.day+leadDays(14)')); assert.equal(!!l.standby, false); ev('compute()'); assert.equal(ev(`linkDown(${leo})`), true, 'down while it is pointed'); ev("ACT.launchBB({city:'cur'});closeModal();" + ready); assert.ok(ev(`R.load[${leo}.id]`) > 0); const ms = ev(`linkLat(${leo})`); assert.ok(ms >= 12 && ms <= 23, 'one way: ' + ms); assert.ok(Math.abs(ev('R.latF.cur') - 0.97) < 1e-9, 'users count 3% as bad'); assert.ok(ev("sfOf(R,'cur')") >= 0.95, 'so broadband keeps growing'); assert.equal(ev("/fact bad/.test(satFact('cur'))"), false, 'a plain chip: they hardly notice'); assert.match(ev("satFact('cur')"), /users ride a satellite/); // Beyond the bent pipe: both under the shell but 1,958 km apart. assert.match(ev("satWhy('ccs','nas','sb53',10)"), /bent pipe.*1,200 km.*1,958 km/); assert.match(ev("satWhy('ccs','cur','sb53',7)"), /No such satellite circuit/); // The price ladder: half MEO per Gbps; the smallest order dearer than the cheapest GEO; far dearer than a subsea wave. assert.ok(ev("satMo('sb53',20)/20") < ev("satMo('o3b',20)/20")); assert.ok(ev("satMo('sb53',5)") > ev("satMo('kac1',1)")); const wave = ev("waveMo(kmBetween('suv','tbu'),true,1)/LT[1].g"); for (const g of [10, 50]) assert.ok(ev(`satMo('sb53',${g})/${g}`) > 3 * wave, `LEO ${g}G per Gbps against a wave`); assert.deepEqual(errors, []); }); test('selective peers do not refuse an island only LEO reaches; a circuit being pointed does not change their verdict', (t) => { const { ev, errors } = game(t, CAR + "ACT.buySat({a:'ccs',b:'cur',bird:'is37',g:5});closeModal();"); ev(ready + ";ACT.buyIx({city:'cur',tier:0});closeModal();compute()"); assert.equal(ev("satOnly('cur').bird"), 'is37'); const sel = J(ev, "ixMembers('cur').filter(id=>NET[id].pol==='selective')"); const geoNo = sel.filter((id) => ev(`noSat('${id}','geo')`)); assert.ok(geoNo.length > 0, 'some members of Blue-Curaçao-IX refuse GEO: ' + sel.join(',')); for (const id of geoNo) assert.equal(J(ev, `peerOk('${id}','ix','cur')`).sat, true, id + ' over GEO'); // LEO ordered: the GEO circuit goes on standby, but until LEO is commissioned the GEO one is the way out they judge. ev("ACT.teleLeo({city:'ccs'});ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10});closeModal();compute()"); assert.equal(ev(`${geo}.standby`), true); assert.equal(ev("satOnly('cur').bird"), 'is37', 'a circuit being pointed does not count yet'); ev(ready); assert.equal(ev("satOnly('cur').bird"), 'sb53', 'still a satellite island'); for (const id of geoNo) { for (const via of ['ix', 'pni']) assert.ok(!J(ev, `peerOk('${id}','${via}','cur')`).sat, `${id} ${via} over LEO`); ev(`S.peers['${id}@cur']=true`); } ev('compute()'); for (const id of geoNo) assert.equal(ev(`ixSessions('cur').has('${id}')`), true, id + ' peers over LEO'); assert.ok(J(ev, 'NETS.map(n=>n.id)').every((id) => !ev(`noSat('${id}','leo')`)), 'nobody minds LEO'); // MEO first, commissioned, then LEO being pointed: the MEO circuit, on standby now, is still the one they judge. ev("S.links=S.links.filter(l=>l.kind!=='sat');S.pops.ccs.tele=2;ACT.buySat({a:'ccs',b:'cur',bird:'o3b',g:5});closeModal();" + ready); ev("ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10});closeModal();compute()"); assert.equal(ev("S.links.find(l=>l.bird==='o3b').standby"), true); assert.equal(ev("satOnly('cur').bird"), 'o3b'); assert.deepEqual(errors, []); }); test('one satellite a pair: LEO puts GEO on standby, GEO ordered beside LEO waits, and carries when LEO is down', (t) => { const { ev, errors } = game(t, GW + "ACT.buySat({a:'ccs',b:'cur',bird:'is37',g:5});closeModal();"); ev(ready + ";ACT.launchBB({city:'cur'});closeModal();ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10});closeModal();renderAll()"); assert.equal(ev(`${geo}.standby`), true, 'the GEO circuit waits'); assert.equal(!!ev(`${leo}.standby`), false); assert.match(ev("document.querySelector('#toasts').textContent"), /goes on standby/); ev(ready); assert.ok(ev(`R.load[${leo}.id]`) > 0 && !(ev(`R.load[${geo}.id]`) > 0), 'LEO carries, GEO stands by'); // A solar storm: the GEO circuit carries the island. ev('S.ev.sky=S.day+2;compute()'); assert.equal(ev(`linkDown(${leo})`), true); assert.ok(ev(`R.load[${geo}.id]`) > 0, 'GEO takes over'); // GEO ordered beside an active LEO circuit starts on standby. ev(`S.ev.sky=0;S.links=S.links.filter(l=>l.bird!=='is37');ACT.buySat({a:'ccs',b:'cur',bird:'gx19',g:5});closeModal()`); assert.equal(ev("S.links.find(l=>l.bird==='gx19').standby"), true); assert.equal(!!ev(`${leo}.standby`), false); // A cable laid later puts LEO on standby too. ev("UI.pending={a:'ccs',b:'cur'};ACT.buildLink({tier:1});closeModal()"); assert.equal(ev(`${leo}.standby`), true); assert.deepEqual(errors, []); }); test('the gateway POP is the islands’ bottleneck: its fiber full, every island behind it slows down, and the Infra tab says so', (t) => { const isl = ['cur', 'gnd', 'svd', 'slu']; const { ev, errors } = game(t, "ACT.buildPop({city:'ccs'});ACT.teleBuild({city:'ccs'});ACT.teleLeo({city:'ccs'});ACT.buildPop({city:'bog'});ACT.buyTransit({city:'bog',net:NETS.find(n=>sellsAt(n,'bog')).id,tier:1});UI.pending={a:'ccs',b:'bog'};ACT.buildLink({tier:0});closeModal();"); assert.equal(ev("noTalk('ccs','bog')"), ''); ev(`for(const c of ${JSON.stringify(isl)}){ACT.buySat({a:'ccs',b:c,bird:'sb53',g:10});closeModal();ACT.launchBB({city:c});closeModal();S.pops[c].bb.d=7;}` + ready); const srv = () => ev(`${JSON.stringify(isl)}.reduce((a,c)=>a+(R.citySrv[c]||0),0)`); assert.ok(ev(`${JSON.stringify(isl)}.reduce((a,c)=>a+R.cityDem[c],0)`) >= 25); assert.ok(srv() <= 10 + 1e-6, 'four islands through one 10G wave: ' + srv()); const panel = () => { ev("UI.sel={type:'city',id:'ccs'};UI.tab='links';renderAll()"); return ev("document.querySelector('#panel').textContent"); }; let p = panel(); assert.match(p, /every island behind this gateway slows down/); assert.match(p, /Landing here from orbit/); assert.match(p, /Fiber and cables out of Caracas/); ev("UI.pending={a:'ccs',b:'bog'};ACT.buildLink({tier:1});closeModal();" + ready); assert.ok(srv() >= 0.9 * 28, 'a 100G wave lets them through: ' + srv()); p = panel(); assert.doesNotMatch(p, /every island behind this gateway slows down/); assert.deepEqual(errors, []); }); // An island gateway whose only way out is a transit port (someone else's cable) is on your fiber all the same // (satWired): its section shows that port's load, not "0.0 Gbps / 0.0 Gbps" of fiber, and warns when it fills. test('a gateway out over transit only: the teleport section shows the transit port, and says when it is the bottleneck', (t) => { const { ev, errors } = game(t, "ACT.buildPop({city:'suv'});ACT.buyTransit({city:'suv',net:NETS.find(n=>sellsAt(n,'suv')).id,tier:0});ACT.teleBuild({city:'suv'});ACT.teleLeo({city:'suv'});ACT.wispSat({z:'vanualevu',bird:'sb53',g:10});"); assert.equal(ev("S.links.some(l=>l.a==='suv'||l.b==='suv')"), false, 'no fiber, no cable of yours'); assert.equal(ev("satWired('suv')"), true, 'a transit port is a way out'); ev("S.day=wispZ('vanualevu').sat.ready;wispZ('vanualevu').d=6;compute()"); const panel = () => { ev("UI.sel={type:'city',id:'suv'};UI.tab='links';renderAll()"); return ev("document.querySelector('#panel').textContent"); }; let p = panel(); assert.match(p, /Landing here from orbit6\.0 Gbps/); assert.doesNotMatch(p, /Fiber and cables out of Suva/, 'no fiber row without fiber'); const tl = ev("S.transit.filter(t=>t.city==='suv').reduce((a,t)=>a+(R.useT[t.id]||0),0)"); assert.ok(tl >= 6 - 1e-6, 'the islands leave over transit: ' + tl); assert.ok(p.includes(`Transit out of Suva${ev(`fmtG(${tl})`)} / ${ev('fmtG(10)')}`), 'the port\'s load and size'); assert.doesNotMatch(p, /every island behind this gateway slows down/); // The port fills: the islands slow down with it, and the section says so. ev("ACT.launchBB({city:'suv'});closeModal();S.pops.suv.bb.d=8;compute()"); assert.ok(ev("S.transit.filter(t=>t.city==='suv').reduce((a,t)=>a+(R.useT[t.id]||0),0)") >= 9.5); assert.match(panel(), /Suva is full: every island behind this gateway slows down/); assert.deepEqual(errors, []); }); test('Pie in the Sky: once your crust carries, Starblink sells you nothing new; what you rent keeps running, on its own bill', (t) => { const { ev, errors } = game(t, GW + "ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10});closeModal();ACT.launchBB({city:'cur'});closeModal();ACT.buildPop({city:'bog'});ACT.teleBuild({city:'bog'});"); ev(ready); assert.equal(ev('leoRival()'), false); ev(pie + 'compute()'); assert.equal(ev('leoRival()'), true, 'a full Shortcrust carries'); assert.match(ev("satWhy('ccs','gnd','sb53',10)"), /rival constellation/); ev("ACT.buySat({a:'ccs',b:'gnd',bird:'sb53',g:10})"); assert.equal(ev("S.links.some(l=>l.b==='gnd')"), false, 'no new circuit'); const c0 = ev('S.cash'); ev(`ACT.satSize({id:${leo}.id,g:20})`); assert.equal(ev(`${leo}.g`), 10, 'no growing'); assert.equal(ev('S.cash'), c0); assert.match(ev(`leoGrowWhy(${leo})`), /rival constellation/); assert.match(ev("leoGwWhy('bog')"), /rival constellation/); ev("ACT.teleLeo({city:'bog'})"); assert.equal(ev("'leo' in S.pops.bog"), false, 'no new gateway'); ev(`ACT.satSize({id:${leo}.id,g:5});compute()`); assert.equal(ev(`${leo}.g`), 5, 'shrinking works'); assert.ok(ev(`R.load[${leo}.id]`) > 0, 'the circuit still carries'); assert.ok(ev('R.cost.sat') >= ev(`${leo}.mo+LEO_GW_MO`), 'rented LEO is on the satellite bill'); const spent = ev('S.pie.book.spent'); ev('dayTick()'); assert.equal(ev('S.pie.book.spent'), spent, 'never on the rocket company’s books'); assert.deepEqual(errors, []); }); test('a solar storm: every LEO circuit in safe mode for a day or two, no cut, no bill; Pie’s storms are the same sun', (t) => { const { ev, errors } = game(t, GW + "ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10});closeModal();ACT.buySat({a:'ccs',b:'gnd',bird:'is37',g:5});closeModal();"); ev(ready); assert.equal(ev('leoLive()'), true); const c0 = ev('S.cash'); ev("fireFailure('leostorm')"); const d = ev('S.ev.sky-S.day'); assert.ok(d >= 1 && d <= 2, 'one or two days: ' + d); assert.equal(ev(`linkDown(${leo})`), true); assert.equal(ev(`linkDown(${geo})`), false, 'GEO flies on'); assert.equal(ev("S.links.filter(l=>l.kind==='sat').every(l=>!l.cut)"), true, 'nobody cut a satellite'); assert.equal(ev("incTitle('leostorm')"), 'Solar storm'); const i = J(ev, "S.inc.find(x=>x.type==='leostorm')"); assert.equal(i.until, ev('S.ev.sky')); assert.equal(i.cost, 0, 'nothing to rush'); assert.equal(ev('S.cash'), c0); assert.match(ev(`satPanel(${leo})`), /Safe mode through a solar storm: back in \d days?\./); ev('S.day=S.ev.sky'); assert.equal(ev(`linkDown(${leo})`), false, 'back when it passes'); // Clearing the incident clears the storm, and leaves the key. ev("S.inc=[];S.ev.sky=0;fireFailure('leostorm');clearInc(S.inc.find(x=>x.type==='leostorm'))"); assert.equal(ev('S.ev.sky'), 0); // Spicy chaos stretches it, and the outage follows, within what a save keeps. ev("S.inc=[];S.rules.chaos='spicy';fireFailure('leostorm');S.rules.chaos='none'"); assert.equal(ev("S.inc.find(x=>x.type==='leostorm').until"), ev('S.ev.sky')); assert.ok(ev('S.ev.sky-S.day') <= ev('LEO_STORM_MAX')); // Saves: the day is a number no later than LEO_STORM_MAX ahead, and the key stays. ev("S.ev.sky='junk';S=migrate(JSON.parse(JSON.stringify(S)))"); assert.equal(ev('S.ev.sky'), 0); assert.equal(ev("'sky' in S.ev"), true); ev('S.ev.sky=S.day+999;S=migrate(JSON.parse(JSON.stringify(S)))'); assert.ok(ev('S.ev.sky') <= ev('S.day+LEO_STORM_MAX')); ev('S.ev.sky=0'); const ev0 = ev('JSON.stringify(S.ev)'); ev('S=migrate(JSON.parse(JSON.stringify(S)))'); assert.equal(ev('JSON.stringify(S.ev)'), ev0, 'a live 0 loads as it was'); // One sun: a storm that drags your own pies down puts Starblink in safe mode too, but only with LEO circuits up. ev("S.inc=[];" + pie + "S.pie.co={name:PIE_NAMES[0]};pieIncFire('storm')"); assert.ok(ev('S.ev.sky>S.day'), 'Starblink in safe mode'); assert.ok(ev("S.inc.some(x=>x.type==='piestorm')&&S.inc.some(x=>x.type==='leostorm')")); ev("S.inc=[];S.ev.sky=0;S.links=S.links.filter(l=>l.bird!=='sb53');pieIncFire('storm')"); assert.equal(ev('S.ev.sky'), 0, 'no LEO circuits, nothing to put in safe mode'); assert.deepEqual(errors, []); }); test('saves: gateways and circuits survive a round trip, broken ones are repaired, old saves load as they were', (t) => { const { ev, errors } = game(t, GW + "ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10});closeModal();ACT.buySat({a:'ccs',b:'gnd',bird:'is37',g:5});closeModal();"); const before = ev("JSON.stringify([S.pops.ccs,S.links.filter(l=>l.kind==='sat')])"); ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()'); assert.equal(ev("JSON.stringify([S.pops.ccs,S.links.filter(l=>l.kind==='sat')])"), before); ev('S.pops.ccs.leo=7;S=migrate(JSON.parse(JSON.stringify(S)))'); assert.equal(ev("'leo' in S.pops.ccs"), false, 'a gateway is 1'); assert.equal(ev(`!!${leo}`), false, 'no gateway, no LEO circuit'); assert.equal(ev(`!!${geo}`), true, 'the GEO circuit stays'); ev('S.pops.ccs.leo=1;delete S.pops.ccs.tele;S=migrate(JSON.parse(JSON.stringify(S)))'); assert.equal(ev("'leo' in S.pops.ccs"), false, 'no teleport, no gateway'); // A save from before LEO: nothing about it changes. ev('S=migrate(JSON.parse(' + JSON.stringify(SAVE) + '));UI.started=true;UI.pitched=true;UI.speed=0;closeModal();compute()'); assert.equal(ev("Object.values(S.pops).some(p=>'leo' in p)||'sky' in S.ev"), false); assert.equal(ev("'sat' in R.cost"), false); assert.ok(ev('R.served') > 0); assert.deepEqual(errors, []); }); test('on a phone: the gateway, its readout, the order sheet and a LEO circuit’s panel, at 360 px', (t) => { const { ev, errors } = game(t, CAR); ev('window.innerWidth=360;window.innerHeight=740;window.dispatchEvent(new window.Event("resize"))'); assert.equal(ev('isPhone()'), true); const text = (sel) => ev(`(document.querySelector('${sel}')||{}).textContent||''`); const acts = (sel) => J(ev, `[...document.querySelectorAll('${sel} [data-act]')].map(b=>b.dataset.act)`); const infra = "UI.sel={type:'city',id:'ccs'};UI.tab='links';renderAll()"; ev('S.lvl=4;' + infra); assert.match(text('#panel'), /Low-orbit capacity \(about 30 ms round trip\) comes at level 5/); ev('S.lvl=5;' + infra); assert.match(text('#panel'), /LEO gateway/); assert.ok(acts('#panel').includes('teleLeo')); ev("ACT.teleLeo({city:'ccs'});" + infra); assert.match(text('#panel'), /islands and remote towns within 1,200 km of this gateway/); assert.ok(acts('#panel').includes('teleLeoRm')); ev("ACT.satOpen({a:'ccs',b:'cur'})"); assert.ok(J(ev, "[...document.querySelectorAll('#modalCard [data-act=\"buySat\"]')].filter(b=>JSON.parse(b.dataset.args).bird==='sb53')").length >= 4, 'four sizes'); assert.match(text('#modalCard'), /Over LEO, about 30 ms round trip/); ev("ACT.buySat({a:'ccs',b:'cur',bird:'sb53',g:10});ACT.launchBB({city:'cur'});closeModal();" + ready + ';' + infra); assert.match(text('#panel'), /Landing here from orbit/); assert.ok(!acts('#panel').includes('teleLeoRm'), 'no closing while a circuit starts there'); ev(`UI.sel={type:'link',id:${leo}.id};renderAll()`); assert.match(text('#panel'), /round trip/); assert.match(text('#panel'), /Bent pipe from 550 km up/); ev("S.ev.sky=S.day+2;compute();renderAll()"); assert.match(text('#panel'), /Safe mode through a solar storm: back in 2 days/); ev("UI.sel={type:'city',id:'cur'};UI.tab='cust';renderAll()"); for (const s of ['#panel', '#modalCard', '#toasts']) assert.doesNotMatch(text(s), /satellites\.|undefined|NaN/, s); assert.deepEqual(errors, []); }); test('MCP: the gateway and LEO circuits quote what the game then charges, and say no once your crust flies', () => { const s = createSession(), T = (n, a = {}) => TOOLS.find((x) => x.name === n).run(s, a), ev = (x) => s.game.ev(x); T('new_game', { city: 'ccs', preset: 'sandbox', seed: 7, name: 'Probe' }); ev('S.cash=1e9'); T('act', { action: 'teleBuild', args: { city: 'ccs' } }); const q = T('act', { action: 'teleLeo', args: { city: 'ccs' }, dryRun: true }).quote; assert.equal(q.setup, ev('LEO_GW_COST')); assert.equal(q.monthly, ev('LEO_GW_MO')); assert.deepEqual(q.blocked, []); let c0 = ev('S.cash'); T('act', { action: 'teleLeo', args: { city: 'ccs' } }); assert.equal(c0 - ev('S.cash'), q.setup); assert.match(T('act', { action: 'teleLeo', args: { city: 'ccs' }, dryRun: true }).quote.blocked.join(' '), /already/); const b = T('act', { action: 'buySat', args: { a: 'ccs', b: 'cur', bird: 'sb53', g: 10 }, dryRun: true }).quote; assert.deepEqual(b.blocked, []); c0 = ev('S.cash'); T('act', { action: 'buySat', args: { a: 'ccs', b: 'cur', bird: 'sb53', g: 10 } }); assert.equal(c0 - ev('S.cash'), b.setup, 'the quote is the bill'); assert.equal(b.monthly, ev("S.links.find(l=>l.bird==='sb53').mo")); const id = ev("S.links.find(l=>l.bird==='sb53').id"); assert.deepEqual(T('act', { action: 'satSize', args: { id, g: 20 }, dryRun: true }).quote.blocked, []); ev(pie); assert.match(T('act', { action: 'satSize', args: { id, g: 20 }, dryRun: true }).quote.blocked.join(' '), /rival constellation/); assert.deepEqual(T('act', { action: 'satSize', args: { id, g: 5 }, dryRun: true }).quote.blocked, [], 'shrinking is fine'); assert.deepEqual(s.errors(), []); });