Island Wi-Fi for 18 groups of outer islands, by satellite and spur cable (#83)

Each zone (Vanua Levu & Taveuni off Suva, the Out Islands off Nassau, and
16 more) is a pool of island homes at your POP in its city: no node and no
link on the map, its Gbps join the city's demand. Rent backhaul at the
city's teleport (about 35% sign up over GEO, 75% over MEO, 90% over
Starblink from a gateway there) or, from level 3, lay a spur cable and
everyone may sign up. The first order brings the island kit. Islanders pay
island prices, their homes are IPv6-only in the NAT64 pool, and investors
on a revenue share take their cut. A spur can be cut for weeks (failure
'wspur', chaos only): a satellite kept beside it carries the islands. Zones
are off in puzzles, the Architect, scenarios and below level 2.

The satellite geometry works on points now (satSeesAt, satPairAt, satKmAt;
the city functions wrap them, with the same answers). Starblink serves a
zone only from a gateway in its own city (16 of 18; a gateway anywhere in
reach would serve the same 16), with its storm and rival rule; Nunavut and
Southeast Alaska stay on GEO. Rules W6 and F12.
This commit is contained in:
jvanvik 2026-11-12 02:12:21 +01:00
parent 7967a29083
commit 6f0c080875
44 changed files with 1087 additions and 65 deletions

View file

@ -11,7 +11,7 @@ const { load } = require('./harness');
const BAD = ['__proto__', 'constructor', 'prototype', 'toString', 'hasOwnProperty', 'valueOf'];
// The other args an action may need before it looks the name up: ptSave a kind, ptApply a kind and a price.
const WITH = { k: 'micro', cost: 0 };
const ARGS = ['city', 'id', 'net', 'k', 'c', 'v', 'a', 'b', 'to', 'from', 'link', 's'];
const ARGS = ['city', 'id', 'net', 'k', 'c', 'v', 'a', 'b', 'to', 'from', 'link', 's', 'z'];
test('no action reaches a built-in through an arg that names one', (t) => {
// The development page: API_CMD is every action an agent may send (the MCP facade), the sent ones of a server's page.

View file

@ -3,8 +3,8 @@
// 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, LEO gateways,
// satellites, dark fiber, an own cable, a subsea seat, exchange points, the backbone core, the redundancy kit, the bulk
// orders),
// satellites, an island Wi-Fi zone with a circuit and a spur, 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');
@ -32,6 +32,7 @@ function open(file) {
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++;}}}
tryA('buildPop',{city:'suv'});tryA('teleBuild',{city:'suv'});tryA('wispSat',{z:'vanualevu',bird:'kac1',g:2});tryA('wispSpur',{z:'vanualevu'});
{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++;}}}
@ -44,7 +45,7 @@ function open(file) {
UI.pending=null;closeModal();compute();`);
return h;
}
const BUILT = ['foundIx', 'buildScrub', 'teleBuild', 'teleLeo', 'buySat', 'orderDf', 'orderCable', 'seatBuy', 'coreUp', 'xpBuild', 'utilityKit', 'pniAll', 'bstdApply'];
const BUILT = ['foundIx', 'buildScrub', 'teleBuild', 'teleLeo', 'buySat', 'wispSat', 'wispSpur', '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.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -171,6 +171,14 @@ test('W5: every island city can be reached: it shares its land, has a cable, or
fail('W5', bad, 'land a cable there or give it beach:true');
});
test('W6: every island Wi-Fi zone hangs off a satellite city within 1,000 km, seen with it by a GEO bird; pool 3 to 12 G; a spur of at most 1,500 km or none', () => {
const ids = J('Object.keys(WISP)');
assert.deepEqual(ids, [...ids].sort(), 'W6: zone ids sorted');
fail('W6', J(`Object.keys(WISP).filter(z=>{const W=WISP[z],C=CITY[W.c];return !C||!satRemote(W.c)||hav(C.lon,C.lat,W.lon,W.lat)>1000
||!Object.keys(SATS).some(id=>SATS[id].orb==='geo'&&satPairAt(id,C,W))||!(W.P>=3&&W.P<=12)||!(W.km===0||W.km>0&&W.km<=1500)||typeof W.n!=='string'||!W.n.trim();}).map(z=>z+' ('+WISP[z].c+')')`),
'hang the zone off the island city it looks to (one a satellite serves), within 1,000 km, where a GEO bird sees both; 3 to 12 G of homes; a spur of at most 1,500 km, or km:0');
});
// ---------- Networks ----------
test('N1: network ids and ASNs are unique, ASNs are valid', () => {
@ -555,6 +563,21 @@ test('F10: growth goes sideways, plus one paid way up (#61, #323)', () => {
fail('F10', J("MEGA.filter(m=>!CITY[m.c]).map(m=>m.c)"), 'campuses sit in real cities');
});
test('F12: island Wi-Fi pays on its own books on some way in; a spur beats every satellite, and pays back within 5 years up to 250 km, 10 up to 1,000 km', () => {
// The zone's own books at full take-up, era 1: its homes at island prices, less the towers' upkeep and the backhaul
// rent. The teleport, tracking antennas and a Starblink gateway serve more than one zone and are left out. Each way in
// at its best size; a spur at its price before the market moves it.
const rows = J(`Object.keys(WISP).map(z=>{const W=WISP[z],R=wispRate(z),up=wispUpMo(z),o={z,km:W.km};
for(const id of wispBirds(z)){const orb=SATS[id].orb;for(const g of SAT_ORB[orb].g){const pl=Math.min(W.P*SAT_ORB[orb].wisp,g)*R-wispSatMo(id,g)-up;if(o[orb]===undefined||pl>o[orb])o[orb]=pl;}}
if(W.km){o.sp=W.P*R-up-wispSpurMo(z);o.cost=Math.round((WISP_SPUR+WISP_SPUR_KM*W.km)/1000)*1000;}return o;})`);
fail('F12', rows.filter((r) => !(Math.max(r.geo ?? -Infinity, r.meo ?? -Infinity, r.leo ?? -Infinity, r.sp ?? -Infinity) > 0)).map((r) => r.z), 'every zone makes money on at least one way in: raise WISP_ARPU or WISP_SHARE, or the pool');
fail('F12', rows.filter((r) => r.sp !== undefined && ['geo', 'meo', 'leo'].some((o) => r[o] !== undefined && r[o] >= r.sp)).map((r) => r.z), 'a spur earns more than any satellite option');
fail('F12', rows.filter((r) => r.meo !== undefined && r.geo !== undefined && r.meo < r.geo || r.leo !== undefined && r.meo !== undefined && r.leo < r.meo).map((r) => r.z), 'MEO earns at least as much as GEO, and LEO as MEO, where both reach');
// Payback in whole months against the best GEO or MEO stage (LEO needs a level-5 gateway, off the zone's books).
const pay = (r) => Math.round(r.cost / (r.sp - Math.max(r.geo ?? 0, r.meo ?? 0, 0)));
fail('F12', rows.filter((r) => r.sp !== undefined && (r.km <= 250 && pay(r) > 60 || r.km <= 1000 && pay(r) > 120)).map((r) => `${r.z} (${r.km} km): ${pay(r)} months`), 'spurs up to 250 km pay back within 5 years, up to 1,000 km within 10');
});
test('D1: attack sizes come from the world, never from your network', () => {
const g = load();
ddFra(g.ev);

View file

@ -229,6 +229,7 @@ test('a dry run prices every command that has a price, and changes nothing', ()
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' }, teleLeo: { city: 'fra' }, buySat: { a: 'fra', b: 'rek', bird: 'is37', g: 1 }, satSize: { id: wave, g: 2 },
wispSat: { z: 'vanualevu', bird: 'kac1', g: 2 }, wispSatSize: { z: 'vanualevu', g: 5 }, wispSpur: { z: 'vanualevu' },
};
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,13 @@ 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 with a LEO gateway, 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, an island Wi-Fi zone with a circuit. 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();ACT.teleLeo({city:'sea'});closeModal();UI.confirm=null;UI.sel=null;
ACT.buildScrub({city:'fra'});closeModal();ACT.teleBuild({city:'sea'});closeModal();ACT.teleLeo({city:'sea'});closeModal();
ACT.buildPop({city:'suv'});ACT.teleBuild({city:'suv'});ACT.wispSat({z:'vanualevu',bird:'kac1',g:2});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;
@ -74,6 +76,8 @@ test('two-click buttons: the first click arms SRV_ARM\'s key (or waits for ok),
ev('UI.confirm=null;UI.sel=null;closeModal();');
// (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);
// (A zone's circuit is cancelled before the zone, which would take it along.)
for (const a of ['wispSatRm', 'wispRm']) { const v = found[a] || { z: 'vanualevu' }; delete found[a]; found[a] = v; }
const missing = Object.keys(A.CONFIRM).filter((a) => !found[a] && a !== 'repayLoan');
assert.deepEqual(missing, [], 'a button for every two-click act');
const changed = {};
@ -99,7 +103,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', 'teleLeoRm', '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', 'wispSatRm', 'wispRm', 'connCancel']) if (found[a]) assert.equal(changed[a], true, `${a} did its thing`);
assert.deepEqual(P.errors, []);
});
const closeAll = (ev) => ev('closeModal();');

375
tests/wisp-zones.test.js Normal file
View file

@ -0,0 +1,375 @@
// Island Wi-Fi (#83): 18 zones of outer islands, each a pool of homes hanging off one island city. Your POP there brings
// them online over satellite capacity from its teleport (GEO about 35% sign up, MEO about 75%, Starblink LEO from a
// gateway there about 90%) or a spur cable (all of them). Their Gbps join the city's demand; they are IPv6-only homes;
// a spur can be cut for weeks, and a satellite kept beside it carries the islands meanwhile.
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 SAVE = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
// Level 3, Change Freeze (nothing breaks by itself, 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=3;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');";
// Suva: a POP with transit (so its traffic gets out) and a teleport.
const SUV = "ACT.buildPop({city:'suv'});ACT.buyTransit({city:'suv',net:NETS.find(n=>sellsAt(n,'suv')).id,tier:1});ACT.teleBuild({city:'suv'});";
const VL = "ACT.wispSat({z:'vanualevu',bird:'kac1',g:2});";
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 Z = "wispZ('vanualevu')";
// Past the day the zone's circuit (or a move) is commissioned.
const ready = `S.day=Math.max(${Z}.sat?${Z}.sat.ready:0,${Z}.nxt?${Z}.nxt.ready:0,${Z}.sp?${Z}.sp.ready:0);compute()`;
const days = (ev, n) => ev(`for(let i=0;i<${n};i++)dayTick()`);
// The first top-level keys whose JSON differs between two states (never deepEqual on S).
const firstDiff = (a, b) => { const A = JSON.parse(a), B = JSON.parse(b); return [...new Set([...Object.keys(A), ...Object.keys(B)])].filter((k) => JSON.stringify(A[k]) !== JSON.stringify(B[k])).slice(0, 5); };
test('the catalog and the geometry: zones off satellite cities, seen by a GEO bird; points give exactly the city answers', (t) => {
const { ev, errors } = game(t);
const ids = J(ev, 'Object.keys(WISP)');
assert.equal(ids.length, 18);
assert.deepEqual(ids, [...ids].sort(), 'ids sorted');
const bad = J(ev, `Object.keys(WISP).filter(z=>{const W=WISP[z],C=CITY[W.c];return !C||!satRemote(W.c)||hav(C.lon,C.lat,W.lon,W.lat)>1000||!Object.keys(SATS).some(id=>SATS[id].orb==='geo'&&satPairAt(id,C,W))
||!(W.P>=3&&W.P<=12)||!(W.km===0||W.km>=50&&W.km<=1500)||typeof W.n!=='string'||!W.n;})`);
assert.deepEqual(bad, []);
// The point versions, on cities, are the city versions: every bird, every satellite city against every city.
const diff = J(ev, `(()=>{const out=[];for(const id of Object.keys(SATS))for(const A of CITIES.filter(C=>satRemote(C.id))){if(satSeesAt(id,A)!==satSees(id,A.id))out.push('sees '+id+A.id);
for(const B of CITIES){if(A.id===B.id)continue;const p=satPairOk(id,A.id,B.id);if(p!==satPairAt(id,A,B))out.push(id+A.id+B.id);else if(p&&satKmAt(id,A,B)!==satKm(id,A.id,B.id))out.push('km '+id+A.id+B.id);}}return out.slice(0,5);})()`);
assert.deepEqual(diff, []);
// Starblink reaches a zone from a gateway in its own city wherever both are under the shell: all but the two beyond 56°.
assert.deepEqual(J(ev, "Object.keys(WISP).filter(z=>!wispBirds(z).includes(LEO_BIRD))"), ['nunavut', 'seak']);
assert.deepEqual(J(ev, "wispBirds('nunavut').map(b=>SATS[b].orb)"), ['geo'], 'Nunavut: GEO only');
assert.deepEqual(J(ev, "wispBirds('vanualevu').map(b=>SATS[b].orb)"), ['geo', 'geo', 'meo', 'leo'], 'GEO first, cheapest first, then MEO and LEO');
assert.deepEqual(errors, []);
});
test('launch over GEO: the kit and the first month, homes at the floor, then the city carries them and they pay island prices', (t) => {
const { ev, errors } = game(t, SUV + "ACT.launchBB({city:'suv'});");
ev('compute()');
const eye0 = ev('R.cityEye.suv'), c0 = ev('S.cash');
ev(VL);
assert.equal(c0 - ev('S.cash'), ev("wispKit('vanualevu')+wispSatMo('kac1',2)"), 'the island kit and the first month');
assert.equal(ev(`${Z}.d`), ev("wispStart('vanualevu')"));
assert.equal(ev('R.wisp.vanualevu.car'), 0, 'nothing before the circuit is commissioned');
assert.equal(ev('R.cost.sat'), ev("TPORT_MO+wispSatMo('kac1',2)"), 'the rent from the order on');
assert.equal(ev('R.cost.wisp'), ev("wispUpMo('vanualevu')"));
ev(ready);
const car = ev('R.wisp.vanualevu.car');
assert.ok(car > 0);
assert.ok(Math.abs(ev('R.cityWisp.suv') - car) < 1e-9, 'the city carries the homes');
assert.ok(Math.abs(ev('R.cityEye.suv') - eye0) < 1e-9, 'broadband stays broadband');
assert.ok(ev('R.wisp.vanualevu.sf') > 0.9, 'served');
assert.ok(Math.abs(ev('R.rev.wisp') - ev('R.wisp.vanualevu.d*R.wisp.vanualevu.sf*wispRate("vanualevu")')) < 1e-6);
assert.equal(ev("wispRate('vanualevu')"), ev('EYE_RATE*14'), 'island prices');
assert.ok(ev('R.revMo') >= ev('R.rev.eyeballs+R.rev.wisp') - 1e-6);
// Investors on a revenue share take their slice of island homes too.
ev("S.loans=[{id:'v',bank:'vult',share:0.1,bal:0}];compute()");
assert.ok(Math.abs(ev('R.cost.revshare') - 0.1 * ev('R.rev.eyeballs+R.rev.business+R.rev.ix+(R.rev.orbit||0)+R.rev.wisp')) < 1e-6);
assert.deepEqual(errors, []);
});
test('take-up grows to the link\'s cap and no further; a small circuit fills, and growing it lets homes in', (t) => {
const { ev, errors } = game(t, SUV + "ACT.wispSat({z:'vanualevu',bird:'kac1',g:5});");
ev(ready);
const K = ev(`wispK('vanualevu',${Z})`);
assert.ok(Math.abs(K - ev("wispPool('vanualevu')*SAT_ORB.geo.wisp")) < 1e-9, 'about 35% over GEO');
let top = 0;
for (let i = 0; i < 40; i++) { days(ev, 10); top = Math.max(top, ev(`${Z}.d`)); }
assert.ok(top <= K + 1e-9, `never past the cap: ${top} of ${K}`);
assert.ok(ev(`${Z}.d`) > 0.9 * K, 'close to it after a year');
// A 1G circuit: homes hover where it serves 90% of them.
ev("ACT.wispSatSize({z:'vanualevu',g:1})");
days(ev, 200);
const d1 = ev(`${Z}.d`);
assert.ok(d1 > 0.95 && d1 < 1.25, `about 1/0.9 G: ${d1}`);
ev("selectCity('suv');UI.tab='cust';UI.wz='vanualevu';renderPanel()");
assert.match(ev("document.getElementById('panel').textContent"), /The link is full: homes are waiting/);
const c0 = ev('S.cash');
ev("ACT.wispSatSize({z:'vanualevu',g:5})");
assert.equal(c0 - ev('S.cash'), ev("wispSatMo('kac1',5)"), 'a bigger one pays its month up front');
days(ev, 100);
assert.ok(ev(`${Z}.d`) > 1.5, 'more homes come in');
assert.deepEqual(errors, []);
});
test('moving to MEO: tracking antennas first, then the old circuit carries until the new one is up', (t) => {
const { ev, errors } = game(t, SUV + VL);
ev(ready);
const c0 = ev('S.cash');
ev("ACT.wispSat({z:'vanualevu',bird:'o3b',g:5})");
assert.equal(ev('S.cash'), c0, 'nothing charged');
assert.match(ev("wispSatWhy('vanualevu','o3b',5)"), /tracking antennas/);
ev("ACT.teleTrk({city:'suv'});ACT.wispSat({z:'vanualevu',bird:'o3b',g:5})");
assert.equal(ev(`${Z}.nxt.bird`), 'o3b');
assert.equal(ev(`${Z}.sat.bird`), 'kac1');
assert.match(ev("wispSatWhy('vanualevu','is18',2)"), /move to another satellite is under way/);
ev('compute()');
assert.equal(ev(`wispLink('vanualevu',${Z})===${Z}.sat`), true, 'the old circuit carries meanwhile');
assert.ok(ev('R.wisp.vanualevu.car') > 0);
assert.equal(ev('R.cost.sat'), ev("TPORT_MO+TRK_MO+wispSatMo('kac1',2)+wispSatMo('o3b',5)"), 'both rents while it moves');
ev(`S.day=${Z}.nxt.ready-1;dayTick()`);
assert.equal(ev(`${Z}.sat.bird`), 'o3b');
assert.equal(ev(`${Z}.nxt`), undefined);
assert.ok(Math.abs(ev(`wispK('vanualevu',${Z})`) - ev("wispPool('vanualevu')*SAT_ORB.meo.wisp")) < 1e-9, 'about 75% over MEO');
assert.match(ev("JSON.stringify(S.log.slice(0,8).map(e=>e.t))"), /Vanua Levu & Taveuni now rides O3bservant/);
assert.deepEqual(errors, []);
});
test('the spur: level 3, never where one cannot be laid, the price of the day; lit, everyone signs up and the satellite stands by', (t) => {
const { ev, errors } = game(t, SUV + VL + "ACT.buildPop({city:'yfb'});");
ev('S.lvl=2');
assert.match(ev("wispSpurWhy('vanualevu')"), /level 3/);
ev('S.lvl=3');
assert.match(ev("wispSpurWhy('nunavut')"), /sea ice/);
const c0 = ev('S.cash');
ev("ACT.wispSpur({z:'nunavut'})");
assert.equal(ev('S.cash'), c0, 'refused');
ev("ACT.wispSpur({z:'vanualevu'})");
assert.equal(c0 - ev('S.cash'), ev("wispSpurCost('vanualevu')"));
assert.equal(ev("wispSpurCost('vanualevu')"), Math.round((150000 + 600 * 220) / 1000) * 1000, 'today\'s price, no market under Change Freeze');
assert.match(ev("wispSpurWhy('vanualevu')"), /laid already/);
ev(ready);
assert.ok(Math.abs(ev(`wispK('vanualevu',${Z})`) - ev("wispPool('vanualevu')")) < 1e-9, 'everyone may sign up');
assert.equal(ev(`wispLink('vanualevu',${Z}).sp`), true, 'the spur carries');
ev(`${Z}.d=5;compute()`);
assert.ok(ev('R.wisp.vanualevu.car') > 2 + 1e-6, 'more than the 2G circuit could');
assert.equal(ev('R.cost.sat'), ev("TPORT_MO+wispSatMo('kac1',2)"), 'the circuit standing by is still rented');
assert.equal(ev('R.cost.wisp'), ev("wispUpMo('vanualevu')+wispSpurMo('vanualevu')"));
ev("UI.sel={type:'city',id:'suv'};UI.tab='links';renderAll()");
assert.match(ev("document.getElementById('panel').textContent"), /Vanua Levu & Taveuni[^]*Standby/);
assert.deepEqual(errors, []);
});
test('the single-spur trap: a cut takes weeks; a satellite beside it carries the islands, without one they go dark and leave', (t) => {
const { ev, errors } = game(t, SUV + VL + "ACT.wispSpur({z:'vanualevu'});");
ev(ready + `;${Z}.d=5;compute()`);
// A spur that is lit and whole is something a failure can find; nothing else gives it a weight.
const opts = "(()=>{window.__opts=null;runNow(eval('('+failureRun.toString().replace('if(!opts.length)return;','window.__opts=opts.map(o=>o.join(\":\"));return;')+')')());return __opts;})()";
assert.ok(J(ev, opts).includes('wspur:1.5'));
ev('fireFailure("wspur")');
const inc = J(ev, "S.inc.find(i=>i.type==='wspur')");
assert.ok(inc && inc.z === 'vanualevu' && inc.ref === 'suv' && inc.cost === 250000);
assert.ok(inc.until - ev('S.day') >= 14, 'weeks for the repair ship');
assert.match(inc.msg, /The satellite circuit carries the islands meanwhile/);
assert.equal(ev("incTitle('wspur')"), 'Spur cut');
assert.ok(!J(ev, opts).some((o) => o.startsWith('wspur')), 'a cut spur is not cut again');
ev('compute()');
assert.ok(Math.abs(ev('R.wisp.vanualevu.car') - 2) < 1e-9, 'the 2G circuit carries what it can');
// The rush button charges the ship and mends it.
const c0 = ev('S.cash');
ev(`ACT.fixInc({id:${JSON.stringify(inc.id)}})`);
assert.equal(c0 - ev('S.cash'), 250000);
assert.equal(ev("wispCut('vanualevu')"), 0);
assert.ok(ev('R.wisp.vanualevu.car') > 2 + 1e-6, 'the spur carries again');
// Without a satellite: dark, and homes leave toward the floor.
ev("ACT.wispSatRm({z:'vanualevu'});ACT.wispSatRm({z:'vanualevu'});fireFailure('wspur')");
assert.match(J(ev, "S.inc.find(i=>i.type==='wspur')").msg, /offline until it is mended/);
ev('compute()');
assert.equal(ev('R.wisp.vanualevu.car'), 0);
assert.equal(ev('R.wisp.vanualevu.sf'), 0);
const d0 = ev(`${Z}.d`);
days(ev, 5);
assert.ok(ev(`${Z}.d`) < d0, 'homes leave');
assert.ok(ev(`${Z}.d`) >= ev("wispStart('vanualevu')") - 1e-9, 'never below the floor');
// The intern's repair order rushes it, once its budget is raised past the ship.
ev("ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();S.ops.on.repair=true;S.ops.cap.repair=1e6;");
ev('opsDay(S.day)');
assert.equal(ev("S.inc.some(i=>i.type==='wspur')"), false, 'rushed');
// No spur at all: the failure has nothing to find.
ev("S.inc=[];ACT.wispRm({z:'vanualevu'});ACT.wispRm({z:'vanualevu'})");
assert.ok(!J(ev, opts).some((o) => o.startsWith('wspur')));
const n = ev('S.inc.length');
ev("fireFailure('wspur')");
assert.equal(ev('S.inc.length'), n, 'nothing to cut');
assert.deepEqual(errors, []);
});
test('IPv4: island homes are IPv6-only from day one, in the NAT64 pool, never behind CGNAT', (t) => {
const { ev, errors } = game(t, "S.rules=makeRules('oncall');" + SUV);
assert.equal(ev('ip4On()'), true);
const u0 = J(ev, 'ip4Use()');
ev(VL + `${Z}.d=3;compute()`);
const u1 = J(ev, 'ip4Use()');
assert.ok(Math.abs(u1.H6 - u0.H6 - 30) <= 1, `H6 grows by d×${ev('IP4_BB')}: ${u0.H6} → ${u1.H6}`);
assert.equal(u1.cg, u0.cg, 'no home behind CGNAT for it');
ev("selectCity('suv');UI.tab='cust';UI.wz='vanualevu';renderPanel()");
assert.match(ev("document.getElementById('panel').textContent"), /IPv6-only \(464XLAT\) from day one/);
assert.deepEqual(errors, []);
});
test('saves: zones and circuits survive a reload, broken ones are repaired, and the state stays canonical', (t) => {
const { ev, errors } = game(t, SUV + VL + "ACT.wispSpur({z:'vanualevu'});ACT.buildPop({city:'tbu'});ACT.buildPop({city:'yfb'});");
ev(ready + ";fireFailure('wspur');compute()");
const s0 = ev('JSON.stringify(S)'), s1 = ev('JSON.stringify(migrate(JSON.parse(JSON.stringify(S))))');
assert.ok(s0 === s1, 'a reload changes nothing: ' + firstDiff(s0, s1).join(', '));
// Broken saves.
const fix = (code) => J(ev, `(()=>{const s=JSON.parse(JSON.stringify(S));${code};return migrate(s);})()`);
let s = fix("s.pops.suv.wisp.bogus={day:0,d:1};s.pops.suv.wisp.vavau={day:0,d:1};s.pops.suv.wisp.constructor={day:0,d:1}");
assert.deepEqual(Object.keys(s.pops.suv.wisp), ['vanualevu'], 'unknown and misplaced zones go');
s = fix("s.pops.suv.wisp.vanualevu.sat.bird='is37'");
assert.equal(s.pops.suv.wisp.vanualevu.sat, undefined, 'a bird that does not see the islands');
s = fix("s.pops.suv.wisp.vanualevu.sat.bird='o3b'");
assert.equal(s.pops.suv.wisp.vanualevu.sat, undefined, 'MEO without tracking antennas');
s = fix("s.pops.suv.wisp.vanualevu.nxt=s.pops.suv.wisp.vanualevu.sat;delete s.pops.suv.wisp.vanualevu.sat");
assert.equal(s.pops.suv.wisp.vanualevu.sat.bird, 'kac1', 'a move without a circuit is the circuit');
assert.equal(s.pops.suv.wisp.vanualevu.nxt, undefined);
s = fix("s.pops.suv.wisp.vanualevu.sat.g=3;s.pops.suv.wisp.vanualevu.d='x'");
assert.equal(s.pops.suv.wisp.vanualevu.sat.g, 2, 'a size the orbit sells');
assert.equal(s.pops.suv.wisp.vanualevu.d, 0);
s = fix("s.pops.yfb.wisp={nunavut:{day:0,d:1,sp:{day:0,ready:5}}}");
assert.deepEqual(s.pops.yfb.wisp.nunavut, { day: 0, d: 1 }, 'no spur where none can be laid');
s = fix("delete s.pops.suv.wisp.vanualevu.sp");
assert.equal(s.inc.some((i) => i.type === 'wspur'), false, 'a cut without its spur goes');
s = fix("delete s.pops.suv.tele");
assert.equal(s.pops.suv.wisp.vanualevu.sat, undefined, 'no teleport, no circuit');
s = fix("s.pops.suv.wisp=[1]");
assert.equal(s.pops.suv.wisp, undefined);
// The gate flipping (below level 2) leaves the homes as they were, and nothing in the money.
const d0 = ev(`${Z}.d`);
ev('S.lvl=1;compute();dayTick()');
assert.equal(ev(`${Z}.d`), d0);
assert.ok(Number.isFinite(ev(`${Z}.d`)));
assert.equal(ev("'wisp' in R.rev||'wisp' in R.cost"), false);
assert.deepEqual(J(ev, 'R.cityWisp'), {});
// An old save has no zones and runs as it did.
ev(`S=migrate(JSON.parse(${JSON.stringify(SAVE)}));compute()`);
assert.equal(ev("Object.values(S.pops).some(p=>'wisp' in p)"), false);
assert.equal(ev("'wisp' in R.cost||'wisp' in R.rev"), false);
assert.ok(ev('R.served') > 0);
assert.deepEqual(errors, []);
});
test('the teleport stays while a zone rides it; decommissioning the city closes its zones and their cuts at once', (t) => {
const { ev, errors } = game(t, SUV + VL + "ACT.wispSpur({z:'vanualevu'});ACT.buildPop({city:'syd'});");
ev(ready + ";fireFailure('wspur')");
ev("ACT.teleRm({city:'suv'})");
assert.equal(ev('teleOf("suv")'), 1, 'refused');
assert.match(ev("JSON.stringify(S.log.slice(0,3).map(e=>e.t))"), /Cancel its satellite circuit first/);
ev("UI.sel={type:'city',id:'suv'};UI.tab='links';renderAll()");
assert.ok(!J(ev, "[...document.querySelectorAll('#panel [data-act]')].map(b=>b.dataset.act)").includes('teleRm'), 'no close button');
ev("ACT.decomOpen({city:'suv'})");
assert.match(ev("document.getElementById('modalCard').textContent"), /Island Wi-Fi closes with it: Vanua Levu & Taveuni/);
ev('ACT.decomGo()');
assert.equal(ev('!!S.pops.suv'), false);
assert.equal(ev("S.inc.some(i=>i.type==='wspur')"), false, 'the cut goes with it');
assert.equal(ev('wispAll().length'), 0);
assert.equal(ev('R.cost.sat||0'), 0);
assert.deepEqual(errors, []);
});
test('gates: never in puzzles, the Architect or scenarios, and not below level 2', (t) => {
const { ev, errors } = game(t, SUV + VL);
ev(ready);
assert.equal(ev('wispOn()'), true);
ev("S.lvl=1;compute();UI.sel={type:'city',id:'suv'};UI.tab='cust';renderAll()");
assert.equal(ev('wispOn()'), false);
assert.doesNotMatch(ev("document.getElementById('panel').textContent"), /Island Wi-Fi/);
assert.equal(ev("wispFact('suv')+wispHtml('suv')"), '');
assert.equal(ev('R.wispL.length'), 0, 'its homes are no demand');
assert.match(ev("wispSatWhy('vanualevu','kac1',2)"), /level 2/);
ev("ACT.startScn({id:SCN[0].id})");
assert.equal(ev('!!S.scn&&wispOn()'), false, 'scenarios');
ev("ACT.pzStart({id:PZ[0].id})");
assert.equal(ev("S.mode==='puzzle'&&wispOn()"), false, 'puzzles');
ev("ACT.pzArStart({id:'euro'})");
assert.equal(ev('!!S.ar&&wispOn()'), false, 'the Architect');
ev("ACT.pzLeave();ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip()");
assert.equal(ev("S.mode==='sandbox'&&wispOn()"), true, 'sandbox has them');
assert.deepEqual(errors, []);
});
test('Starblink: a gateway on your fiber in the zone\'s own city brings 90% of the islands online at about 30 ms', (t) => {
const { ev, errors } = game(t, 'S.lvl=5;' + SUV + "ACT.buildPop({city:'yfb'});ACT.teleBuild({city:'yfb'});");
assert.match(ev("wispSatWhy('vanualevu','sb53',5)"), /gateway/);
ev("ACT.wispSat({z:'vanualevu',bird:'sb53',g:5})");
assert.equal(ev(Z), null, 'refused without a gateway');
ev("ACT.teleLeo({city:'suv'})");
assert.equal(ev("wispSatWhy('vanualevu','sb53',5)"), '');
assert.equal(ev(`leoReachLL('suv',WISP.vanualevu.lat,WISP.vanualevu.lon)`), true);
const rtt = ev("Math.round(2*wispMs('vanualevu','sb53'))");
assert.ok(rtt >= 25 && rtt <= 45, `about 30 ms round trip, got ${rtt}`);
// Nunavut is past the shell: GEO only, whatever you build.
assert.ok(!J(ev, "wispBirds('nunavut')").includes('sb53'));
assert.match(ev("wispSatWhy('nunavut','sb53',5)"), /does not see both/);
const c0 = ev('S.cash');
ev("ACT.wispSat({z:'vanualevu',bird:'sb53',g:5})");
assert.equal(c0 - ev('S.cash'), ev("wispKit('vanualevu')+wispSatMo('sb53',5)"));
assert.equal(ev("wispSatMo('sb53',5)"), Math.round(ev("satMo('sb53',5)") * 0.6 / 10) * 10, 'a contended share of Starblink\'s own price');
ev(ready);
assert.ok(Math.abs(ev(`wispK('vanualevu',${Z})`) - ev("wispPool('vanualevu')*SAT_ORB.leo.wisp")) < 1e-9, 'about 90% over LEO');
ev(`${Z}.d=4;compute()`);
assert.ok(Math.abs(ev('R.wisp.vanualevu.car') - 4) < 1e-9);
assert.equal(ev('R.cost.sat'), ev("TPORT_MO*2+LEO_GW_MO+wispSatMo('sb53',5)"));
// The gateway's readout counts the islands landing there; it stays while they ride it.
ev("UI.sel={type:'city',id:'suv'};UI.tab='links';renderAll()");
const infra = ev("document.getElementById('panel').textContent");
assert.match(infra, /Landing here from orbit4\.0 Gbps/);
assert.ok(!J(ev, "[...document.querySelectorAll('#panel [data-act]')].map(b=>b.dataset.act)").includes('teleLeoRm'));
ev("ACT.teleLeoRm({city:'suv'});ACT.teleLeoRm({city:'suv'})");
assert.equal(ev("leoGw('suv')"), true, 'not while a zone rides it');
// A storm puts it in safe mode too, and a zone alone is enough for one to come.
assert.equal(ev('leoLive()'), true, 'a zone over LEO is in the sky');
ev('fireFailure("leostorm");compute()');
assert.ok(ev('S.ev.sky') > ev('S.day'));
assert.equal(ev('R.wisp.vanualevu.car'), 0, 'safe mode');
ev("UI.sel={type:'city',id:'suv'};UI.tab='cust';UI.wz='vanualevu';renderAll()");
assert.match(ev("document.getElementById('panel').textContent"), /Safe mode through a solar storm/);
ev('S.day=S.ev.sky;compute()');
assert.ok(ev('R.wisp.vanualevu.car') > 0, 'back after the storm');
// Once your own constellation carries, Starblink sells nothing new: no growth, no new zone; the circuit keeps running.
ev("S.pieV=1;pieInit();S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full,day:S.day,las:false}];compute()");
assert.equal(ev('leoRival()'), true);
ev("ACT.wispSatSize({z:'vanualevu',g:10})");
assert.equal(ev(`${Z}.sat.g`), 5, 'no growth');
assert.match(ev("wispSatWhy('santo','sb53',5)"), /rival constellation|POP in/);
assert.ok(ev('R.wisp.vanualevu.car') > 0, 'the circuit already rented keeps carrying');
ev("ACT.wispSatSize({z:'vanualevu',g:5})");
// A reload without the gateway drops the LEO circuit; a GEO one stays.
const s = J(ev, "(()=>{const s=JSON.parse(JSON.stringify(S));delete s.pops.suv.leo;return migrate(s);})()");
assert.equal(s.pops.suv.wisp.vanualevu.sat, undefined);
assert.deepEqual(errors, []);
});
test('on a phone: the zones in the Customers tab, the order rows, the spur and the teleport rows, at 360 px', (t) => {
const { ev, errors } = game(t, SUV);
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)`);
// A city with zones and no POP: the chip and the teaser.
ev("UI.sel={type:'city',id:'tbu'};renderAll()");
assert.match(text('#panel'), /1 island zone/);
assert.match(text('#panel'), /Open a POP here to bring Wi-Fi to the islands around it: Vava’u & Ha’apai \(3\.\d Gbps of homes\)/);
// With a POP and no teleport yet, the teleport's reach counts the islands too.
ev("ACT.buildPop({city:'tbu'});UI.sel={type:'city',id:'tbu'};UI.tab='links';renderAll()");
assert.match(text('#panel'), /in reach at your level\.\s*Island Wi-Fi from this teleport: 1 island zone/);
// The zone, opened, before anything is bought: the birds, the kit, the spur.
ev("UI.sel={type:'city',id:'suv'};UI.tab='cust';renderAll();ACT.wispOpen({z:'vanualevu'})");
assert.equal(ev('UI.wz'), 'vanualevu');
assert.match(text('#panel'), /Island Wi-Fi[^]*No link yet[^]*Backhaul[^]*island kit[^]*Spur cable[^]*Lay the spur/);
assert.ok(acts('#panel').filter((a) => a === 'wispSat').length >= 4, 'sizes as buttons');
assert.ok(acts('#panel').includes('teleTrk'), 'MEO: the tracking antennas first');
ev(VL + ready + ';renderAll()');
assert.match(text('#panel'), /Homes online[^]*Served on the islands[^]*Towers, solar and crews/);
assert.ok(acts('#panel').includes('wispSatSize') && acts('#panel').includes('wispSatRm') && acts('#panel').includes('wispRm'));
// The same button folds it.
ev("ACT.wispOpen({z:'vanualevu'})");
assert.equal(ev('UI.wz'), null);
ev("ACT.wispOpen({z:'vanualevu'})");
const h = ev("[...document.querySelectorAll('#panel section')].filter(s=>/Island Wi-Fi/.test(s.querySelector('h3').textContent)).map(s=>s.innerHTML).join('')");
assert.match(h, /Homes online/);
assert.doesNotMatch(h, /width:\s*\d+px|min-width|color:var\(--bad\)/, 'no fixed widths, no red that dark mode cannot read');
for (const s of ['#panel', '#toasts']) assert.doesNotMatch(text(s), /wisp\.|satellites\.|undefined|NaN/, s);
// The teleport lists the zone's circuit, which opens the zone.
ev("UI.tab='links';renderAll()");
assert.match(text('#panel'), /Island Wi-Fi from this teleport:[^]*Vanua Levu & Taveuni/);
assert.ok(acts('#panel').includes('wispOpen'));
// The dashboard's cost row.
ev("ACT.wispSpur({z:'vanualevu'});" + ready + ";ACT.dash&&ACT.dash();renderDash&&renderDash()");
assert.equal(ev("tr('wisp.costs_row')"), 'Island Wi-Fi: towers and spurs');
assert.deepEqual(errors, []);
});