Rent low-orbit satellite capacity from Starblink (#83)

A Starblink gateway on a teleport at a POP on your fiber (level 5, within
56 degrees of the equator) rents LEO circuits of 5 to 50 Gbps to small
islands and remote towns within 1,200 km: a bent pipe 550 km up, about
30 ms round trip, 3% of the service counted as bad, and no selective
network refuses it. LEO puts GEO and MEO circuits on the same pair on
standby and waits beside a cable. The gateway's Infra section shows its
POP's forwarding load and the fiber out of the city, the islands'
bottleneck. A rare solar storm (and Pie's own) puts LEO in safe mode for
a day or two. Once your own crust carries traffic Starblink sells nothing
new. Rule O8. Hooks for island Wi-Fi: leoReachLL, leoKmLL, leoMsLL.
This commit is contained in:
jvanvik 2026-11-12 01:34:46 +01:00
parent 08eb349d87
commit 7967a29083
25 changed files with 692 additions and 46 deletions

View file

@ -2,8 +2,9 @@
// A server-run network's page loads the server's state with migrate() (it never trusts state it did not check), and
// the server checks every action against the save path; both need migrate(live S) to change nothing. A year of a big
// network with everything on (DDoS, failures, events, the intern on every order, the sales desk on auto, IPv6-only, and
// once before the year everything else a network can own: an own exchange, scrubbing centers, teleports, satellites,
// dark fiber, an own cable, a subsea seat, exchange points, the backbone core, the redundancy kit, the bulk orders),
// once before the year everything else a network can own: an own exchange, scrubbing centers, teleports, LEO gateways,
// satellites, dark fiber, an own cable, a subsea seat, exchange points, the backbone core, the redundancy kit, the bulk
// orders),
// checked every day. T1_BASE=<git ref> also plays the same year on the page at that ref: the same money, customers,
// incidents, dice and ids every day, so making the state canonical changed no play.
const test = require('node:test');
@ -29,6 +30,8 @@ function open(file) {
for(const c of pops.slice(0,40)){if(Object.keys(S.myIx).length)break;tryA('foundIx',{city:c});}
for(const c of pops.slice(0,6))tryA('buildScrub',{city:c});
for(const c of pops.slice(0,4))tryA('teleBuild',{city:c});
for(const c of pops.slice(0,4))tryA('teleLeo',{city:c});
{let n=0;for(const a of pops.slice(0,4))for(const b of satTargets(a)){if(n>=1)break;if(!satWhy(a,b,LEO_BIRD,5)){tryA('buySat',{a,b,bird:LEO_BIRD,g:5});n++;}}}
{let n=0;for(const a of pops.slice(0,12))for(const b of pops.slice(12,30)){if(n>=2)break;for(const bird of Object.keys(SATS))for(const g of [1,2,5,10]){if(n>=2)break;if(!satWhy(a,b,bird,g)){tryA('buySat',{a,b,bird,g});n++;}}}}
{let n=0;for(const a of pops.slice(0,10))for(const b of pops.slice(10,40)){if(n>=2)break;if(kmBetween(a,b)<900&&!noTalk(a,b)){UI.pending={a,b};UI.dfSrc='build';const k=S.links.length;tryA('orderDf');if(S.links.length>k)n++;}}}
{let n=0;for(const a of pops.slice(0,30))for(const b of Object.keys(CITY)){if(n>=1)break;if(S.pops[b]||a===b)continue;UI.pending={a,b};const k=S.links.length;if(!ownCabWhy(a,b)){tryA('orderCable');if(S.links.length>k)n++;}}}
@ -41,7 +44,7 @@ function open(file) {
UI.pending=null;closeModal();compute();`);
return h;
}
const BUILT = ['foundIx', 'buildScrub', 'teleBuild', 'buySat', 'orderDf', 'orderCable', 'seatBuy', 'coreUp', 'xpBuild', 'utilityKit', 'pniAll', 'bstdApply'];
const BUILT = ['foundIx', 'buildScrub', 'teleBuild', 'teleLeo', 'buySat', 'orderDf', 'orderCable', 'seatBuy', 'coreUp', 'xpBuild', 'utilityKit', 'pniAll', 'bstdApply'];
// In the page: every top-level key whose JSON differs between live S and what a reload makes of it, both ways a reload
// happens (the full state a page takes, and the save text). uidN and the dice are put back: a reload may draw ids.
@ -82,6 +85,7 @@ test(`a year of a big network with everything on: live state is what a reload ma
const did = JSON.parse(head.ev('JSON.stringify(__did)'));
assert.deepEqual(did.filter((x) => / threw /.test(x)), [], 'nothing threw while building');
for (const a of BUILT) assert.ok(did.includes(a), `${a} built something before the year (${did.join(', ')})`);
assert.ok(head.ev('S.links.some(l=>l.bird===LEO_BIRD)'), 'a LEO circuit before the year');
assert.equal(head.ev('S.slAuto.on'), true);
assert.ok(head.ev("Object.values(S.pops).filter(p=>p.bb&&(p.bb.v6||p.bb.v6e)).length") >= 3, 'IPv6-only homes on the way');
const seen = { ddos: 0, inc: 0, starts: 0 };

View file

@ -733,6 +733,32 @@ test('O7: a fresh Tier 1 cannot afford a full Shortcrust in its first year', ()
// O7's other half (a full lasered Shortcrust pays back in 5 to 10 years, never sooner) is played through the game loop
// in tests/pie-balance.test.js, so it counts launches, aging, incidents, churn and every running cost.
test('O8: rented LEO reaches only near a gateway on your fiber under its shell, stops selling once your crust carries, and costs more than a subsea wave', () => {
const g = load();
g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=SAT_ORB.leo.lv;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze')");
// Every pair the bird is sold on: at most km apart, both ends under the shell.
fail('O8', JSON.parse(g.ev("JSON.stringify((()=>{const O=SAT_ORB.leo,out=[];for(const A of CITIES)for(const B of CITIES){if(A.id>=B.id||!satPairOk(LEO_BIRD,A.id,B.id))continue;if(kmBetween(A.id,B.id)>O.km||Math.abs(A.lat)>O.lat||Math.abs(B.lat)>O.lat)out.push(A.id+'-'+B.id+' '+kmBetween(A.id,B.id)+' km');}return out;})())")),
'a LEO circuit beyond one satellite\'s bent pipe: keep SAT_ORB.leo.km and lat in satPairOk');
assert.ok(g.ev("Object.keys(SATS).filter(id=>SATS[id].orb==='leo').join()===LEO_BIRD"), 'O8: one rented LEO bird');
// The gateway sits on your fiber: an island only a satellite reaches cannot host one; beyond the shell, nobody can.
g.ev("ACT.buildPop({city:'suv'});ACT.teleBuild({city:'suv'});ACT.buildPop({city:'anc'});S.pops.anc.tele=1;ACT.buildPop({city:'ccs'});ACT.teleBuild({city:'ccs'})");
assert.notEqual(g.ev("leoGwWhy('suv')"), '', 'O8: a gateway on an island off your fiber');
assert.notEqual(g.ev("leoGwWhy('anc')"), '', 'O8: a gateway beyond the shell');
assert.notEqual(g.ev("satWhy('ccs','cur',LEO_BIRD,10)"), '', 'O8: a LEO circuit without a gateway');
g.ev("ACT.teleLeo({city:'ccs'});ACT.buySat({a:'ccs',b:'cur',bird:LEO_BIRD,g:10});closeModal();ACT.buyTransit({city:'ccs',net:'drz',tier:1});ACT.launchBB({city:'cur'});closeModal()");
assert.equal(g.ev('S.links.filter(l=>l.bird===LEO_BIRD).length'), 1, 'O8: a gateway on the mainland sells');
// Your own crust carries: nothing new from Starblink, not even growth; what you rent keeps running.
g.ev('S.pieV=1;pieInit();S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full,day:S.day,las:false}];S.day=S.links.find(l=>l.bird===LEO_BIRD).ready;compute()');
assert.ok(g.ev('Object.keys(CRUSTS).some(id=>pieCarry(id)>0)'), 'a crust carries');
for (const x of ["satWhy('ccs','gnd',LEO_BIRD,10)", "leoGwWhy('ccs')", 'leoGrowWhy(S.links.find(l=>l.bird===LEO_BIRD))']) assert.notEqual(g.ev(x), '', `O8: ${x} once your own constellation carries`);
assert.equal(g.ev("leoReachLL('ccs',CITY.cur.lat,CITY.cur.lon)"), false, 'O8: no WISP reach either');
assert.ok(g.ev('R.load[S.links.find(l=>l.bird===LEO_BIRD).id]') > 0, 'O8: a circuit you rent keeps carrying');
// Dearer per Gbps than any subsea wave over its whole reach, so a cable is always the better buy where one can go.
const dear = JSON.parse(g.ev('JSON.stringify(SAT_ORB.leo.g.flatMap(n=>LT.map((t,i)=>[n,t.g,satMo(LEO_BIRD,n)/n,waveMo(SAT_ORB.leo.km,true,i)/t.g])))'));
fail('O8', dear.filter((x) => x[2] <= x[3]).map((x) => `${x[0]}G LEO at ${Math.round(x[2])}/G is no dearer than a ${x[1]}G subsea wave at ${Math.round(x[3])}/G`), 'raise SAT_PROV.sbk.pg');
assert.deepEqual(g.errors, []);
});
test('no page errors while checking the rules', () => {
assert.deepEqual(errors, []);
});

364
tests/leo.test.js Normal file
View file

@ -0,0 +1,364 @@
// 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.el||kmBetween(A.id,B.id)>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, []);
});
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(), []);
});

View file

@ -228,7 +228,7 @@ test('a dry run prices every command that has a price, and changes nothing', ()
opsHire: { id: ev('Object.keys(INTERNS)[0]') }, opsNewPop: { city: 'nyc' }, pniAll: { net: 'cog', tier: 1 }, seatBuy: { n: 2 }, layShip: { id: df }, seaRush: { id: df },
utilityKit: { city: 'fra' }, utilityCaches: { city: 'fra' }, acceptFix: { id: 'none' }, ptApply: { city: 'fra', k: 'medium' }, ptAll: { k: 'medium' }, teDeploy: { script: 'spill at 85%' }, upLinkX: {},
pieRd: { k: 'reuse' }, pieAnt: { id: 'none' }, ip4Buy: { len: 24 }, ip4Lease: { len: 22 }, ip6Go: { city: 'fra' },
teleBuild: { city: 'fra' }, teleTrk: { city: 'fra' }, buySat: { a: 'fra', b: 'rek', bird: 'is37', g: 1 }, satSize: { id: wave, g: 2 },
teleBuild: { city: 'fra' }, teleTrk: { city: 'fra' }, teleLeo: { city: 'fra' }, buySat: { a: 'fra', b: 'rek', bird: 'is37', g: 1 }, satSize: { id: wave, g: 2 },
};
const missing = quoted.filter((n) => !sample[n] && T('schema', { section: 'commands' })[n].args.some((a) => a.required));
assert.deepEqual(missing, [], 'every priced command with arguments has a sample here');

View file

@ -30,11 +30,11 @@ test('SEND is the agent\'s game commands without the puzzles, teCheck, traceRun
});
/* A rich network with something behind every two-click button: the big fixture, an intern, a sales head, a scrubbing
center, a teleport, an own exchange. Its S also goes to the realm, so both sides start the same. */
center, a teleport with a LEO gateway, an own exchange. Its S also goes to the realm, so both sides start the same. */
function rich() {
const P = page({ save: bigScenic() });
P.ev(`S.lvl=Math.max(S.lvl,6);ACT.opsHire({id:'kevin'});closeModal();ACT.salesHire({id:'eng'});closeModal();
ACT.buildScrub({city:'fra'});closeModal();ACT.teleBuild({city:'sea'});closeModal();UI.confirm=null;UI.sel=null;
ACT.buildScrub({city:'fra'});closeModal();ACT.teleBuild({city:'sea'});closeModal();ACT.teleLeo({city:'sea'});closeModal();UI.confirm=null;UI.sel=null;
S.day=Math.max(S.day,IP4_HOLD+30);S=migrate(JSON.parse(JSON.stringify(S)));compute();`);
// (Address blocks are held two years before they may be sold: these were bought long ago.)
return P;
@ -72,7 +72,8 @@ test('two-click buttons: the first click arms SRV_ARM\'s key (or waits for ok),
const found = {};
for (const [a, args] of crawl(ev)) if (A.CONFIRM[a] && !found[a]) found[a] = args;
ev('UI.confirm=null;UI.sel=null;closeModal();');
Object.assign(found, { rmScrub: { city: 'fra' }, teleRm: { city: 'sea' }, cancelVxc: found.cancelVxc || { id: 'nolink' }, dkOptOut: found.dkOptOut || { city: 'fra', n: 'Nobody' } }, found);
// (The gateway closes before its teleport, which would take it along.)
Object.assign(found, { rmScrub: { city: 'fra' }, teleLeoRm: { city: 'sea' }, teleRm: { city: 'sea' }, cancelVxc: found.cancelVxc || { id: 'nolink' }, dkOptOut: found.dkOptOut || { city: 'fra', n: 'Nobody' } }, found);
const missing = Object.keys(A.CONFIRM).filter((a) => !found[a] && a !== 'repayLoan');
assert.deepEqual(missing, [], 'a button for every two-click act');
const changed = {};
@ -98,7 +99,7 @@ test('two-click buttons: the first click arms SRV_ARM\'s key (or waits for ok),
if (changed[a]) assert.equal(r.outcome, 'applied', a);
}
// The ones with a real target were really done.
for (const a of ['cancelTransit', 'cancelIx', 'cancelPni', 'rmLink', 'rmSite', 'dropBiz', 'salesFire', 'opsFire', 'rmScrub', 'teleRm', 'connCancel']) if (found[a]) assert.equal(changed[a], true, `${a} did its thing`);
for (const a of ['cancelTransit', 'cancelIx', 'cancelPni', 'rmLink', 'rmSite', 'dropBiz', 'salesFire', 'opsFire', 'rmScrub', 'teleLeoRm', 'teleRm', 'connCancel']) if (found[a]) assert.equal(changed[a], true, `${a} did its thing`);
assert.deepEqual(P.errors, []);
});
const closeAll = (ev) => ev('closeModal();');