seriesoftubes/tests/express-fiber.test.js
jvanvik 61e31c53d3
Some checks are pending
CI / plan (push) Waiting to run
CI / part (push) Blocked by required conditions
CI / build (push) Waiting to run
CI / translations (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / timings (push) Blocked by required conditions
Container image / gate (push) Waiting to run
Container image / test (push) Blocked by required conditions
Container image / publish (push) Blocked by required conditions
Merge upstream: Lambda Bazaar, traffic badges, moving customers and faster routing (3.3.0)
CHANGELOG.md: upstream's released sections as they are; main's 11 Unreleased bullets kept under Unreleased.
scripts/lib/route-fuzz.js: upstream's skip of dashboard tabs the base lacks, plus main's trimming of args the base's buttons lack.
src/game/10-catalog/40-ports.js: upstream's one-pass portsAt(); an express still takes ports per channel at its ends.
src/game/10-catalog/60-reach-and-subsea.js: upstream's dfLit/dfCap0/dfOn (managed waves carved out); capOf() keeps xp and sat.
src/game/60-features/80-new-game.js: upstream's vol and cm in a new game, with main's ip4, rgen, mp and saved-shape fields.
src/game/60-features/95-standing-orders.js: upstream's portsAt, cachePlan and promiseCheck, inside main's build-standard routers order, optup marks, opsDarkPre and decom gone list; opsPairs still leaves satellites out.
src/game/80-simulation/30-compute.js: upstream's routing core; main's satellite edges (SATN) pass into it, express risks and sat/ip4 money stay.
src/game/80-simulation/29-route-core.js: main's satellite latency note moved into the core, where upstream moved the flow loop.
src/game/80-simulation/40-billing.js: main's linkCut() and xp/sat in linkDown(), with upstream's dfOn().
src/game/80-simulation/50-sanitize.js: upstream's cmClean listings and cmFix/volFix; main keeps the xp/sat kinds, mpSanitize, ip4Fix and satSanitize.
src/game/80-simulation/60-requirements.js: upstream's shared diversity graph; an express link carries the list of trenches it rides.
src/game/91-save.js: upstream's saves in the worker, except a multiplayer session network, whose text is made on the page (mpSave) so the server gets the very save the slot holds; bootNotes() kept.
src/game/91-slots.js: upstream's slot text and day, with main's mp badge on a slot.
src/game/93-ui/70-link-panels.js: a fiber says both its managed waves and the expresses it carries.
src/game/94-dashboard/60-dashboard.js: upstream's carried tile, main's themed demand line.
src/game/95-modals/70-link-modal.js: main's Express tab, then upstream's hint for a coast no cable lands on (#321).

After the merge:
- Moving a circuit: a path over an express shares the trenches of the fibers it rides, so it is never called fully diverse from a path along them (test in express-fiber).
- The capacity market and moving customers leave the slots expresses hold (test in express-fiber; no code change needed).
- The NOC log keeps only the kinds a reload keeps: the market's info/warn news is a plain line, live as after a reload.
- New acts classified for server-run play: market and path moves sent, marketOpen and pathOpen local; pathPin's path may be longer than 64 characters.
- Server-play fixtures written again (new cm and vol fields); the dark-mode test reads mapStill()'s three states.
- A big multiplayer network that moved on still pushes its save to the server (test in multiplayer).
- The full suite ran on jsdom 31.0.0 and playwright-core 1.65.0, the versions the merged lockfile pins.
2026-11-09 19:04:21 +01:00

423 lines
27 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Express lightpaths (#58): a wave from Frankfurt to Paris over your own dark fibers Frankfurt–Brussels and
// Brussels–Paris that passes Brussels as light, through its ROADM. Routing sees a Frankfurt–Paris edge; Brussels'
// router never sees the traffic. Change Freeze, no random failures: nothing here depends on luck.
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
// Three POPs on routers that take 400G optics, broadband in Paris, transit in Frankfurt, and two ROADM fibers
// (s1 Frankfurt–Brussels, s2 Brussels–Paris), finished and dark. df(a,b,extra) lays another one.
const BASE = "ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;S.lvl=8;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');closeModal();" +
"for(const c of ['bru','par'])ACT.buildPop({city:c});for(const c of ['fra','bru','par'])S.pops[c].rgen=1;ACT.launchBB({city:'par'});ACT.buyTransit({city:'fra',net:'cog',tier:2});" +
"window.df=(a,b,o={})=>{const id=uid();S.links.push(Object.assign({id,a,b,kind:'df',own:true,sys:'roadm',ch:[],km:kmBetween(a,b),sub:false,cable:null,mo:100,trench:id,cut:0,day:S.day,ready:S.day,spares:false,pairs:1},o));return id;};" +
"window.L=id=>S.links.find(l=>l.id===id);";
const SPANS = "window.s1=df('fra','bru');window.s2=df('bru','par');compute();";
const BUILD = "ACT.xpBuild({a:'fra',b:'par',via:s1+','+s2,o:'zr4'});window.x=(S.links.find(l=>l.kind==='xp')||{}).id;compute();";
function game(t, extra = SPANS, opts = {}) {
const h = load(opts);
t.after(() => h.dom.window.close());
h.ev(BASE + extra);
return h;
}
const xps = (ev) => ev("S.links.filter(l=>l.kind==='xp').length");
test('an express is a Frankfurt–Paris edge: traffic rides it, ports at both ends, and Brussels never sees it', (t) => {
const { ev, errors } = game(t);
assert.equal(ev("JSON.stringify(xpPaths('fra','par').map(p=>p.sp.map(s=>s.id)))"), ev('JSON.stringify([[s1,s2]])'), 'the two fibers chain');
const ports = () => JSON.parse(ev("JSON.stringify(['fra','bru','par'].map(c=>portsUsed(c)))"));
const p0 = ports(), cash = ev('S.cash');
ev(BUILD);
assert.equal(xps(ev), 1);
assert.deepEqual(JSON.parse(ev('JSON.stringify(L(x))')), { id: ev('x'), a: 'fra', b: 'par', kind: 'xp', via: [ev('s1'), ev('s2')], ch: ['zr4'], km: ev('L(s1).km+L(s2).km'), mo: 0, cut: 0, day: ev('S.day') });
assert.equal(cash - ev('S.cash'), ev("optCost('zr4')+XP_PASS"), 'the optic, and patching it through Brussels');
const p1 = ports();
assert.equal(p1[0] - p0[0], ev("chPorts('zr4','fra')"), 'a port in Frankfurt');
assert.equal(p1[2] - p0[2], ev("chPorts('zr4','par')"), 'a port in Paris');
assert.equal(p1[1], p0[1], 'none in Brussels');
assert.equal(ev('capOf(L(x))'), 400);
assert.ok(ev('R.load[x]') > 1, 'Paris reaches its transit over the express');
assert.ok(!ev('R.nodeLoad.bru'), "Brussels' router carries nothing");
assert.equal(ev('linkLat(L(x))'), ev('linkLat(L(s1))+linkLat(L(s2))'), 'the latency of the fibers it rides, with no router in between');
// With channels of their own on both fibers there is a path through Brussels too: the express is one hop shorter.
ev("L(s1).ch=['zr4'];L(s2).ch=['zr4'];compute()");
assert.ok(ev('R.load[x]') > 1);
assert.equal(ev('(R.load[s1]||0)+(R.load[s2]||0)'), 0, 'the hop through Brussels stays idle');
assert.ok(!ev('R.nodeLoad.bru'));
// Without the express the same traffic goes through Brussels' router.
ev('L(x).standby=true;S.pairMet[edgeKey(L(x))]="backup";compute()');
assert.ok(ev('R.nodeLoad.bru') > 1, 'the router in Brussels works when the light does not pass it');
assert.deepEqual(errors, []);
});
test('a cut, a build or a line system swap on any fiber darkens the express; a fiber under one stays', (t) => {
const { ev, errors } = game(t);
ev(BUILD);
assert.equal(ev('linkDown(L(x))'), false);
ev('L(s2).cut=S.day+5;compute()');
assert.equal(ev('linkDown(L(x))'), true, 'a cut fiber');
assert.equal(ev('R.load[x]||0'), 0);
assert.match(ev("xpDarkWhy(L(x)).join(' ')"), /Brussels ⇄ Paris is cut/);
assert.equal(ev('(o=>o.dark&&!o.cut&&o.dash===8)(linkLook([L(x)],S.day))'), true, 'drawn dark, no backhoe of its own');
ev('L(s2).cut=0;L(s2).ready=S.day+10;compute()');
assert.equal(ev('linkDown(L(x))'), true, 'a fiber still being built');
assert.match(ev("xpDarkWhy(L(x)).join(' ')"), /Brussels ⇄ Paris is still being built: 10 days left\./);
ev('L(s2).ready=S.day+1');
assert.match(ev("xpDarkWhy(L(x)).join(' ')"), /still being built: 1 day left\./, 'one day, not one days');
ev('L(s2).ready=S.day;compute()');
assert.equal(ev('linkDown(L(x))'), false);
ev('ACT.upSys({id:s1})');
assert.equal(ev("L(s1).sys"), 'cl');
assert.equal(ev('linkDown(L(x))'), true, 'the line system swap takes the express down for the day');
ev('S.day++;compute()');
assert.equal(ev('linkDown(L(x))'), false, 'and it is back the next day, on the new line system');
// A fiber under an express cannot be given up; the express can, and its optic goes on the shelf.
ev('ACT.rmLink({id:s1});ACT.rmLink({id:s1})');
assert.ok(ev('!!L(s1)'), 'the fiber is still there');
assert.match(ev('S.log[0].t'), /express lightpath rides this fiber/);
const sp = ev("spareN('zr4')");
ev('ACT.rmLink({id:x});ACT.rmLink({id:x})');
assert.equal(xps(ev), 0);
assert.equal(ev("spareN('zr4')"), sp + 1);
ev('ACT.rmLink({id:s1});ACT.rmLink({id:s1})');
assert.ok(!ev('L(s1)'), 'then the fiber goes');
assert.deepEqual(errors, []);
});
test('a backhoe or the chaos monkey still finds a fiber that only carries expresses, never the express itself', (t) => {
const { ev, errors } = game(t);
ev(BUILD);
assert.equal(ev('linkDown(L(s1))&&linkDown(L(s2))'), true, 'dark as links of their own: no channels of their own');
assert.equal(ev('xpBare(L(s1))&&xpBare(L(s2))'), true);
ev("fireFailure('cut');compute()");
assert.equal(ev("S.links.filter(l=>l.cut>S.day).map(l=>l.kind).join()"), 'df', 'one fiber cut, not the express');
assert.equal(ev('linkDown(L(x))'), true);
assert.equal(ev("S.inc.filter(i=>i.type==='cut').length"), 1);
ev("for(const l of S.links)l.cut=0;S.inc=[];compute();mkSnip()");
assert.equal(ev("S.links.filter(l=>l.cut>S.day).map(l=>l.kind).join()"), 'df', 'the monkey snips a fiber too');
assert.deepEqual(errors, []);
});
test("the intern's decom order counts an express as a link between its cities, and never hands one back", (t) => {
const { ev, errors } = game(t);
ev(BUILD + "UI.pending={a:'fra',b:'par'};UI.route='diverse';ACT.buildLink({tier:1});compute()");
ev("ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();for(const k in S.ops.on)S.ops.on[k]=false;S.ops.on.decom=true;S.ops.cap.decom=0;compute();opsDay(S.day)");
assert.equal(ev("S.links.filter(l=>l.kind==='wave').length"), 1, 'kept as the spare: its trench is not one the express runs in');
ev("S.ops.p.decom={keep:false};S.day++;compute();opsDay(S.day)");
assert.equal(ev("S.links.map(l=>l.kind).join()"), 'df,df,xp', 'the express carries the pair with room to spare: the wave goes back');
assert.deepEqual(errors, []);
});
test('decommissioning the city in the middle takes its fibers and the expresses riding them', (t) => {
const { ev, errors } = game(t);
ev(BUILD);
assert.equal(ev("decomImpact(['bru']).links.length"), 3, 'both fibers and the express');
const sp = ev("spareN('zr4')");
ev("decommission(['bru']);compute()");
assert.equal(ev('S.links.length'), 0);
assert.equal(ev("spareN('zr4')"), sp + 1, 'the express optic is on the shelf');
assert.deepEqual(errors, []);
});
test('reach: the light must make the whole run between regen sites, through Brussels too', (t) => {
const { ev, errors } = game(t, "window.s1=df('fra','bru',{km:2000});window.s2=df('bru','par',{km:2000});compute();");
assert.equal(ev('xpRunKm([L(s1),L(s2)])'), 4000, 'no regen anywhere: one 4,000 km run');
assert.match(ev("xpWhy('fra','par',[L(s1),L(s2)],'zr4')"), /Too far: the light runs 4,000 km/);
ev(BUILD);
assert.equal(xps(ev), 0, 'refused');
ev('ACT.regen({id:s1,d:1})');
assert.equal(ev('xpRunKm([L(s1),L(s2)])'), 3000, 'the last 1,000 km of the first fiber and all of the second');
const cash = ev('S.cash');
ev(BUILD);
assert.equal(xps(ev), 1);
assert.equal(cash - ev('S.cash'), ev("Math.round(optCost('zr4')*1.5)+XP_PASS"), 'a regen card at the one regen site');
assert.equal(ev('capOf(L(x))'), 200, 'a 400ZR+ at 3,000 km runs its slow setting');
ev('ACT.regen({id:s1,d:-1})');
assert.equal(ev('L(s1).regen'), 1, 'the express needs that regen site: it stays');
ev('L(s1).regen=2;L(s2).regen=2;compute()');
assert.equal(ev('xpRunKm([L(s1),L(s2)])'), 1334);
assert.equal(ev('capOf(L(x))'), 400, 'short runs everywhere: full rate');
assert.deepEqual(errors, []);
});
test('slots: lit channels, sold alien waves and express channels share every line system', (t) => {
const { ev, errors } = game(t);
ev("L(s1).ch=Array(10).fill('zr4');S.biz.push({id:uid(),city:'fra',city2:'bru',link:s1,slots:53,type:'wwave',name:'Alien Co',bw:1,rate:1000,reqs:[],mood:100,since:S.day});for(const c of ['fra','bru','par'])S.pops[c].routers=4;compute()");
assert.equal(ev('freeCh(L(s1))'), 1);
ev(BUILD);
assert.equal(xps(ev), 1);
assert.equal(ev('xpSlots(L(s1))'), 1);
assert.equal(ev('xpSlots(L(s2))'), 1);
assert.equal(ev('freeCh(L(s1))'), 0, 'the sold waves and the express take the last slots');
assert.equal(ev('freeCh(L(s2))'), 63);
assert.match(ev("chWhy(L(s1),'zr4')"), /is full/, 'no more channels of its own either');
assert.match(ev("xpWhy('fra','par',[L(s1),L(s2)],'zr4')"), /Frankfurt ⇄ Brussels has no free channel slot/);
ev("ACT.xpCh({id:x,o:'zr4',d:1})");
assert.equal(ev('L(x).ch.length'), 1, 'refused');
// A full pair lets you light the next one, and the express grows into it.
ev('ACT.addPair({id:s1})');
assert.equal(ev('L(s1).pairs'), 2);
ev("ACT.xpCh({id:x,o:'zr4',d:1})");
assert.equal(ev('L(x).ch.length'), 2);
assert.equal(ev('xpSlots(L(s2))'), 2);
assert.equal(ev('capOf(L(x))'), 800);
// The intern lights optics on hot fibers: never into the slots expresses and alien waves hold.
ev("ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();S.ops.on.optics=true;S.ops.cap.optics=0;compute();for(const l of S.links)if(l.kind==='df')R.load[l.id]=1e6;opsDay(S.day)");
assert.equal(ev("S.links.filter(l=>l.kind==='df').every(l=>(l.ch||[]).length+soldSlots(l)+xpSlots(l)<=chMax(l))"), true);
assert.ok(ev('L(s1).ch.length') > 10, 'the intern did light the hot fiber with room');
assert.equal(ev('L(s2).ch.length'), 0, 'a fiber that only carries the express is not new fiber: it stays bare');
// Unplugging: never the last channel.
ev("ACT.xpCh({id:x,o:'zr4',d:-1})");
assert.equal(ev('L(x).ch.length'), 1);
ev("ACT.xpCh({id:x,o:'zr4',d:-1})");
assert.equal(ev('L(x).ch.length'), 1, 'the last channel stays');
ev("ACT.rmCh({id:x,o:'zr4'})");
assert.equal(ev('L(x).ch.length'), 1, "a fiber's unplug button does not work on an express");
assert.deepEqual(errors, []);
});
test('the capacity market and moving customers leave the slots expresses hold; a path over an express shares its fibers\' trenches', (t) => {
const { ev, errors } = game(t);
ev("L(s1).ch=Array(61).fill('zr4');for(const c of ['fra','bru','par'])S.pops[c].routers=4;compute()");
ev(BUILD);
assert.equal(ev('xpSlots(L(s1))'), 1);
assert.equal(ev('freeCh(L(s1))'), 2, '64 slots: 61 lit, 1 express');
// Spectrum the broker can sell (Lambda Bazaar) is what is free after the express, never the express's own slot.
assert.equal(ev("cmCan(L(s1),'spec')"), 2);
assert.equal(ev("cmSpare(L(s1),'spec',0)"), 2);
ev("ACT.listFiber({id:s1,w:3})");
assert.equal(ev('(L(s1).list||{}).w||0'), 2, 'a listing stops at the free slots');
// A carrier with three alien waves on a parallel fiber cannot move onto s1: the express holds the slot it would need.
ev("window.s3=df('fra','bru');S.biz.push({id:'aw',city:'fra',city2:'bru',link:s3,slots:3,type:'wwave',name:'Alien Co',bw:1,rate:1000,reqs:[],mood:100,since:S.day,day:S.day,route:'normal',what:'x'});compute()");
assert.match(ev("(fiberTargets(S.biz.find(b=>b.id==='aw')).find(o=>o.l.id===s1)||{}).no||''"), /2/, 'only 2 free channels there');
ev("ACT.pathMove({id:'aw',link:s1})");
assert.equal(ev("S.biz.find(b=>b.id==='aw').link"), ev('s3'), 'refused');
// A circuit pinned through Brussels' router rides s1 and s2; the express to Paris runs in those very trenches.
ev("L(s2).ch=['zr4'];compute();S.biz.push({id:'k',type:'l2vpn',name:'Big Circuit',city:'fra',city2:'par',bw:1,rate:10,reqs:[],mood:80,since:0,day:0,route:'normal',pin:['fra','bru','par']});compute()");
const alts = JSON.parse(ev("JSON.stringify(circuitTargets(S.biz.find(b=>b.id==='k')).alts.map(a=>[a.p.join('>'),a.shared]))"));
assert.deepEqual(alts, [['fra>par', 1]], 'the express is offered, sharing its one span with the path through Brussels');
ev("ACT.pathOpen({id:'k'})");
assert.doesNotMatch(ev("document.getElementById('modal').textContent"), /Fully diverse/);
assert.deepEqual(errors, []);
});
test('saves: an express survives a round trip; one whose fibers are gone is dropped and its optics go on the shelf', (t) => {
const { ev, errors } = game(t);
// A save from before expresses existed loads as it always did.
const old = ev('JSON.stringify(S)');
ev(`S=migrate(JSON.parse(${JSON.stringify(old)}));compute()`);
assert.equal(ev('S.links.length'), 2);
assert.equal(ev('freeCh(L(s1))'), 64);
ev(BUILD);
ev('S=sanitize(JSON.parse(JSON.stringify(S)));compute()');
assert.equal(ev("L(x).kind"), 'xp', 'still an express, not a wave');
assert.equal(ev("L(x).via.join(',')"), ev("s1+','+s2"));
assert.ok(ev('R.load[x]') > 1);
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
assert.equal(xps(ev), 1);
const sp = ev("spareN('zr4')");
// Its second fiber gone (a hand-edited file): dropped, the optic back on the shelf.
ev('{const o=JSON.parse(JSON.stringify(S));o.links=o.links.filter(l=>l.id!==s2);S=sanitize(o);compute();}');
assert.equal(xps(ev), 0);
assert.equal(ev("spareN('zr4')"), sp + 1);
// Fibers that do not chain from a, a fiber without a ROADM, no optic: all dropped.
for (const bad of ["x.via=[s2,s1]", "o.links.find(l=>l.id===s1).sys='lite'", "x.ch=['nope']", "x.via=[s1]", "x.b='ams'"]) {
ev(`{S=migrate(JSON.parse(${JSON.stringify(old)}));${BUILD}const o=JSON.parse(JSON.stringify(S)),x=o.links.find(l=>l.kind==='xp');${bad};S=sanitize(o);compute();}`);
assert.equal(xps(ev), 0, bad);
}
assert.deepEqual(errors, []);
});
test('the route worker routes an express as the page does; traceroute skips Brussels; diverse paths count its trenches', (t) => {
const h = game(t);
const { ev, errors } = h;
h.dom.window.structuredClone = globalThis.structuredClone;
ev(BUILD + "L(s1).ch=['zr4'];L(s2).ch=['zr4'];compute()");
const SIG = "JSON.stringify({load:R.load,served:R.served,node:R.nodeLoad,ef:Object.keys(R.ef).sort().map(k=>[k,R.ef[k]])})";
ev('window.__got=null;window.postMessage=(m)=>{window.__got=m;};');
ev('{window.__R0=R;const prev={load:R.load,l2route:R.l2route,efg:rwEfgOut(R.efg)};const keep=S;window.__S0=JSON.stringify(S);rwServe(structuredClone({seq:1,S,...prev}));S=keep;}');
ev('R=rwUnpack(structuredClone(__got.R),__got.ef)');
const fromWorker = ev(SIG);
assert.ok(ev('R.load[x]') > 1, 'the worker routed over the express');
ev('R=__R0;S=JSON.parse(__S0);compute()');
assert.equal(ev(SIG), fromWorker);
const tr = ev("traceroute('par',{city:'fra'}).text");
assert.match(tr, /express lightpath, optically past Brussels/);
assert.doesNotMatch(tr, /cr1\.bru\./, 'no hop in Brussels');
// The express runs in the trenches of the fibers it rides: with them it is no second path.
assert.equal(ev("diversePaths('fra','par')"), false);
ev("S.biz.push({id:'div1',city:'fra',city2:'par',type:'ai',name:'Skynot Compute',bw:400,rate:10,reqs:['diverse'],mood:100,since:S.day});compute()");
assert.equal(ev("R.div['div1']"), false, 'compute() agrees');
ev("UI.pending={a:'fra',b:'par'};UI.route='diverse';ACT.buildLink({tier:1});compute()");
assert.equal(ev("diversePaths('fra','par')"), true, 'a wave in a trench of its own is');
assert.equal(ev("R.div['div1']"), true);
assert.deepEqual(errors, []);
});
test('on a phone: the fiber offers an express, the link window has an Express tab, the express has its panel, the map draws it', (t) => {
const h = load();
t.after(() => h.dom.window.close());
const { ev, errors } = h;
ev('window.innerWidth=360;window.innerHeight=740;' + BASE + SPANS);
assert.equal(ev('isPhone()'), true);
ev('selectLink(s1)');
const panel = ev("$('panel').innerHTML");
assert.match(panel, /Express lightpaths/);
assert.match(panel, /data-act="xpOpen"/);
ev("ACT.xpOpen({a:'fra',b:'par'})");
const modal = ev("$('modal').innerHTML"), text = ev("$('modal').textContent");
assert.match(modal, /data-act="xpBuild"/);
assert.match(text, /via Brussels · 581 km/);
// Optic names are long ('Sienna WaveMagic 1.6T'): never in the 70px column a wave's '400G' fits in.
assert.equal(ev(`[...$('modal').querySelectorAll('[data-act="xpBuild"]')].filter(b=>b.querySelector('.sz')||!b.querySelector('.grow .onm+.meta')).length`), 0);
assert.equal(ev(`$('modal').querySelector('[data-act="xpBuild"] .onm').textContent`), ev('OPT.zr4.n'));
assert.doesNotMatch(text, /express\.[a-z_]{3,}|undefined|NaN/);
// The other tabs are one tap away, and the Express tab only shows where fibers chain.
ev("ACT.dfMode({m:'wave'})");
assert.match(ev("$('modal').innerHTML"), /data-act="xpOpen"/);
ev("closeModal();UI.lmode='xp';openLinkModal('fra','ams')");
assert.doesNotMatch(ev("$('modal').innerHTML"), /data-act="xpOpen"|data-act="xpBuild"/);
ev('closeModal();' + BUILD + 'selectLink(s1)');
assert.match(ev("$('panel').textContent"), /0 of 64 channels lit · 1 carries an express/, 'the slot the express takes, next to the lit ones');
// Without a ROADMaster the hint points at the Line system section, which comes before it.
ev("L(s1).sys='lite';selectLink(s1)");
const lp = ev("$('panel').innerHTML"), hint = lp.indexOf('upgrade it under Line system above');
assert.ok(hint > 0 && lp.indexOf('<h3>Line system</h3>') < hint, 'the upgrade is above the hint');
ev("L(s1).sys='roadm';selectLink(x)");
const xp = ev("$('panel').textContent");
assert.match(xp, /Express lightpath · 581 km/);
assert.match(xp, /Tear down the express/);
assert.doesNotMatch(xp, /express\.[a-z_]{3,}|undefined|NaN/);
assert.match(ev('capName(L(x))'), /400G express/);
// Drawn along its fibers, a little to one side: it passes Brussels without landing there.
const g = JSON.parse(ev("JSON.stringify(linkGeom(L(x)).pts)")), B = JSON.parse(ev("JSON.stringify([CITY.bru.x,CITY.bru.y])"));
const near = Math.min(...g.map(([x, y]) => Math.hypot(x - B[0], y - B[1])));
assert.ok(near > 1 && near < 12, 'beside Brussels: ' + near);
ev('UI.started=true;UI.pitched=true;for(const z of [0.6,1.5,3]){cam.z=z;draw(performance.now());}');
assert.deepEqual(errors, []);
});
test('in German, every express screen is translated', (t) => {
const h = load({ lang: 'de' });
t.after(() => h.dom.window.close());
const { ev, errors } = h;
ev('window.innerWidth=360;' + BASE + SPANS + BUILD + 'selectLink(s1)');
assert.match(ev("$('panel').textContent"), /Express-Lightpaths/);
ev("ACT.xpOpen({a:'fra',b:'par'})");
assert.doesNotMatch(ev("$('modal').textContent"), /express\.[a-z_]{3,}|undefined|NaN/);
ev('closeModal();selectLink(x)');
assert.match(ev("$('panel').textContent"), /Express abbauen/);
assert.deepEqual(errors, []);
});
test('amp huts, ROADM slips and backhoes find fibers that only carry expresses, forced or at random', (t) => {
const { ev, errors } = game(t);
ev(BUILD);
ev("fireFailure('amp');compute()");
assert.equal(ev('[s1,s2].filter(id=>L(id).eqDown>S.day).length'), 1, 'an amp hut on one of the fibers goes');
assert.equal(ev('linkDown(L(x))'), true, 'and the express with it');
assert.equal(ev('S.inc.at(-1).type'), 'amp');
assert.equal(ev('S.inc.at(-1).cost'), ev('AMP_COST'), 'no spares kit: a truck and a new amp');
ev("for(const l of S.links)l.eqDown=0;S.inc=[];compute();fireFailure('roadmff');compute()");
assert.equal(ev('[s1,s2].filter(id=>L(id).eqDown>S.day).length'), 1, 'a fat-fingered channel plan too');
// The glass under the express is the only glass here: the dice still find it (seeded, so always the same draws).
ev(`window.__n={};for(let i=0;i<400;i++){for(const l of S.links){l.cut=0;l.eqDown=0;}for(const p of Object.values(S.pops)){p.down=0;p.rdown=0;}for(const x of S.transit)x.down=0;S.inc=[];compute();
fireFailure();for(const c of S.inc)if([s1,s2].includes(c.ref))__n[c.type]=(__n[c.type]||0)+1;if(S.links.some(l=>l.kind==='xp'&&(l.cut>S.day||l.eqDown>S.day)))__n.xp=(__n.xp||0)+1;}`);
const n = JSON.parse(ev('JSON.stringify(__n)'));
assert.ok(n.cut > 0, 'a backhoe: ' + JSON.stringify(n));
assert.ok(n.amp > 0, 'an amp hut: ' + JSON.stringify(n));
assert.ok(!n.xp, 'never the express itself');
assert.deepEqual(errors, []);
});
test('the chaos monkey counts fibers that only carry expresses when it decides whether to visit', (t) => {
const { ev, errors } = game(t, "ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;window.s1=df('fra','bru');window.s2=df('bru','par');window.s3=df('bru','ams');compute();");
ev(BUILD + "ACT.xpBuild({a:'fra',b:'ams',via:s1+','+s3,o:'zr4'});compute()");
assert.equal(ev('xps=S.links.filter(l=>l.kind==="xp").length'), 2);
assert.equal(ev('[s1,s2,s3].every(id=>xpBare(L(id)))'), true);
ev("S.rules=makeRules('oncall');S.monkey={next:S.day};mkTick(S.day)");
assert.equal(ev('!!S.monkey.on'), true, 'three fibers in the ground: enough network for a visit');
assert.deepEqual(errors, []);
});
test("the intern's optics order leaves fibers that only carry expresses bare: no ports in the city they bypass", (t) => {
const { ev, errors } = game(t, SPANS + "ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;window.s3=df('fra','ams');compute();");
ev(BUILD);
const ports = () => JSON.parse(ev("JSON.stringify(['bru','par'].map(c=>portsUsed(c)))"));
const p0 = ports();
ev("ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();for(const k in S.ops.on)S.ops.on[k]=false;S.ops.on.optics=true;S.ops.cap.optics=0;compute();opsDay(S.day)");
assert.equal(ev('L(s1).ch.length+L(s2).ch.length'), 0, 'both fibers under the express stay bare');
assert.deepEqual(ports(), p0, 'no router port in Brussels, none more in Paris');
assert.ok(ev('L(s3).ch.length') > 0, 'new fiber with nothing on it still gets its first channel');
ev('S.day++;compute();opsDay(S.day)');
assert.equal(ev('L(s1).ch.length+L(s2).ch.length'), 0, 'and on the next shift');
assert.deepEqual(errors, []);
});
test('an express is no link between its ends for a new wave: the first one pays the usual price and gets no route question', (t) => {
const wave = (extra) => {
const { ev, errors } = game(t, SPANS + extra, { agent: true });
const quote = ev("API_CMD.buildLink.quote({a:'fra',b:'par',tier:1}).monthly");
ev("UI.lmode='wave';openLinkModal('fra','par')");
const modal = ev("$('modal').innerHTML");
ev("UI.route='same';ACT.buildLink({tier:1});compute()");
const w = JSON.parse(ev("JSON.stringify(S.links.find(l=>l.kind==='wave'))"));
assert.deepEqual(errors, []);
return { quote, modal, mo: w.mo, mult: w.mult };
};
const plain = wave(''), xp = wave(BUILD);
assert.ok(plain.mo > 0);
assert.equal(xp.mo, plain.mo, 'the same monthly price as without the express');
assert.equal(xp.mult, plain.mult);
assert.equal(xp.quote, plain.quote, 'and the same quote for tools');
assert.doesNotMatch(xp.modal, /data-act="route"/, 'no same-trench or diverse choice: there is no wave here yet');
});
test("a fiber's 'Express to…' opens the window on the path it offered, even with shorter ones elsewhere", (t) => {
// Frankfurt to Paris: via Bettembourg, via Brussels, via Düsseldorf and Brussels are all shorter than via Amsterdam.
const { ev, errors } = game(t, SPANS + "ACT.buildPop({city:'ams'});for(const c of ['bet','dus']){ACT.buildPop({city:c});S.pops[c].rgen=1;}S.pops.ams.rgen=1;" +
"df('fra','bet');df('bet','par');df('fra','dus');df('dus','bru');window.fa=df('fra','ams');df('ams','par');compute();");
ev('selectLink(fa)');
const plans = JSON.parse(ev(`JSON.stringify([...$('panel').querySelectorAll('[data-act="xpOpen"]')].map(b=>JSON.parse(b.dataset.args)))`));
const offer = plans.find((p) => p.a === 'fra' && p.b === 'par');
assert.ok(offer, 'the fiber offers Frankfurt → Paris: ' + JSON.stringify(plans));
assert.equal(offer.via.split(',')[0], ev('fa'), 'starting on this fiber');
assert.equal(ev(`xpPaths('fra','par').some(r=>r.sp[0].id===fa)`), false, 'not among the three shortest');
ev(`ACT.xpOpen(${JSON.stringify(offer)})`);
const heads = () => JSON.parse(ev(`JSON.stringify([...$('modal').querySelectorAll('h4')].map(h=>h.textContent))`));
assert.match(heads()[0], /^via Amsterdam · /, 'the offered path comes first: ' + heads().join(' | '));
assert.ok(ev(`[...$('modal').querySelectorAll('[data-act="xpBuild"]')].some(b=>JSON.parse(b.dataset.args).via===${JSON.stringify(offer.via)}&&!b.disabled)`), 'and it can be lit from here');
// Switching tabs and back keeps it; the Express tab of a fresh window shows the shortest three.
ev("ACT.dfMode({m:'wave'})");
ev(`ACT.xpOpen(JSON.parse($('modal').querySelector('[data-act="xpOpen"]').dataset.args))`);
assert.match(heads()[0], /^via Amsterdam · /);
ev("closeModal();ACT.xpOpen({a:'fra',b:'par'})");
assert.ok(!heads().some((h) => /Amsterdam/.test(h)), heads().join(' | '));
ev(`ACT.xpBuild({a:'fra',b:'par',via:${JSON.stringify(offer.via)},o:'zr4'});compute()`);
assert.equal(ev("S.links.filter(l=>l.kind==='xp').map(l=>l.via[0]).join()"), ev('fa'));
assert.deepEqual(errors, []);
});
test('the build standard keeps a fiber lit while an express on it carries traffic, and swaps it once the express is idle', (t) => {
const { ev, errors } = game(t);
ev(BUILD);
assert.ok(ev('R.load[x]') > 1, 'Paris rides the express');
assert.equal(ev('(R.load[s1]||0)+(R.load[s2]||0)'), 0, 'the fibers carry nothing of their own');
ev("S.popStd=bstdPut(Object.assign(bstd(),{sys:'cl'}));compute()");
assert.deepEqual(JSON.parse(ev('JSON.stringify(bstdQuote(false).held)')).sort(), ['bru|par', 'fra|bru'], 'both fibers wait');
ev('ACT.bstdApply()');
assert.equal(ev("L(s1).sys+','+L(s2).sys"), 'roadm,roadm', 'no line system swap under a busy express');
assert.equal(ev('xpDown(L(x))'), false, 'the express stays up');
// Idle (Paris has no users left), the express no longer holds its fibers back.
ev('S.pops.par.bb=null;compute()');
assert.equal(ev('R.load[x]||0'), 0);
ev('ACT.bstdApply()');
assert.equal(ev("L(s1).sys+','+L(s2).sys"), 'cl,cl', 'both fibers move up to C+L');
assert.deepEqual(errors, []);
});
test('in Spanish, every express label says exprés', () => {
const es = require('fs').readFileSync(require('path').join(__dirname, '..', 'site', 'i18n', 'es.js'), 'utf8');
const lines = es.split('\n').filter((l) => l.startsWith('"express.'));
assert.ok(lines.length > 30);
assert.deepEqual(lines.filter((l) => /\bexpress\b/i.test(l.slice(l.indexOf(':')))), []);
});