// 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'); const { createSession, TOOLS } = require('../scripts/lib/mcp-game'); // 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('a regen site added later under an express needs a regen card for its channels too: the fiber panel and the MCP quote say so', (t) => { const { ev, errors } = game(t, SPANS + "ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;window.s3=df('fra','ams');compute();"); ev(BUILD + "ACT.xpCh({id:x,o:'zr4',d:1});L(s1).ch=['zr4'];compute()"); assert.equal(ev('L(x).ch.length'), 2); const card = ev("Math.round(optCost('zr4')*REGEN_CH)"), two = ev("Math.round(optCost('zr4')*2*REGEN_CH)"), three = ev("Math.round(optCost('zr4')*3*REGEN_CH)"); assert.equal(ev('regenAddCost(L(s3))'), ev('REGEN_COST'), 'a dark fiber with nothing in it: the hut alone'); assert.equal(ev('regenAddCost(L(s2))'), ev('REGEN_COST') + two, 'two express channels and nothing of its own'); assert.equal(ev('regenAddCost(L(s1))'), ev('REGEN_COST') + three, 'its own channel and the two expresses'); // The fiber panel's button shows that price, and adding the site charges it. ev('selectLink(s2)'); assert.ok(ev("$('panel').textContent").includes('Regen site ' + ev('fmt$(REGEN_COST+' + two + ')')), "the price on the fiber's regen button"); let cash = ev('S.cash'); ev('ACT.regen({id:s2,d:1})'); assert.equal(ev('L(s2).regen'), 1); assert.equal(cash - ev('S.cash'), ev('REGEN_COST') + two); cash = ev('S.cash'); ev('ACT.regen({id:s3,d:1})'); assert.equal(cash - ev('S.cash'), ev('REGEN_COST'), 'no express on it: no card'); // Lighting another channel afterwards pays its card at the new site, as before. cash = ev('S.cash'); ev("ACT.xpCh({id:x,o:'zr4',d:1})"); assert.equal(cash - ev('S.cash'), ev("optCost('zr4')") + card); assert.deepEqual(errors, []); }); test('a dirty connector in the glass under an express dims it too; an MTU mismatch, microbursts or a marginal optic there do not', (t) => { const { ev, errors } = game(t); ev(BUILD + "L(s1).ch=['zr4'];compute()"); const cap = (id) => Math.round(ev(`capOf(L(${id}))`)); assert.equal(cap('x'), 400); // The fiber's own routers and optics: the fiber suffers, the express riding past them does not. for (const [set, name] of [['L(s1).deg=S.day+3', 'an MTU mismatch'], ['L(s1).loss={until:S.day+3,f:0.8}', 'microbursts'], ['L(s1).loss={until:S.day+3,f:0.7}', 'a marginal optic']]) { ev(`L(s1).deg=0;L(s1).loss=null;${set};compute()`); assert.ok(cap('s1') < 400, name + ' slows the fiber'); assert.equal(cap('x'), 400, name + ' leaves the express alone'); } // A dirty connector is in the glass: every wave there, the express too. ev('L(s1).deg=0;L(s1).loss=null;L(s2).loss={until:S.day+3,f:0.6,glass:true};compute()'); assert.equal(cap('x'), 240, 'Brussels–Paris lets 60% through'); assert.equal(ev('linkDown(L(x))'), false, 'dimmed, not dark'); assert.ok(ev('R.load[x]') > 1, 'it still carries traffic'); ev('selectLink(x)'); assert.match(ev("$('panel').textContent"), /Brussels ⇄ Paris has a dirty connector: every wave in that fiber, this express too, runs at 60%/); ev('L(s1).loss={until:S.day+3,f:0.6,glass:true};compute()'); assert.equal(cap('x'), 144, 'two dirty fibers: both bite'); ev('L(s1).loss.until=S.day;L(s2).loss.until=S.day;compute();selectLink(x)'); assert.equal(cap('x'), 400, 'cleaned: full rate again'); assert.doesNotMatch(ev("$('panel').textContent"), /dirty connector/); // Dealt by the dice: on a fiber with channels of its own, only the dirty connector (the first of the three) is in the glass. for (const v of [0, 1, 2]) { ev(`L(s1).loss=null;L(s2).loss=null;S.inc=[];compute();{const q=[0.5,0.1,${(v + 0.5) / 3},0];const r0=Math.random;Math.random=()=>q.length?q.shift():r0();fireFailure('loss');Math.random=r0;}compute()`); assert.equal(ev('!!L(s2).loss'), false, 'the dice picked the fiber with its own channel'); if (v !== 1) assert.ok(cap('s1') < 400, 'the fiber itself slows, variant ' + v); assert.equal(ev('!!(L(s1).loss&&L(s1).loss.glass)'), v === 0, 'variant ' + v); assert.equal(cap('x'), v === 0 ? 240 : 400, 'variant ' + v); } // A fiber that only carries expresses has nothing but glass to go wrong: the dice find it, and it is always the connector. ev("L(s1).ch=[];L(s1).loss=null;S.inc=[];compute();fireFailure('loss');compute()"); assert.equal(ev('S.inc.at(-1).type'), 'loss'); assert.ok(ev('[s1,s2].includes(S.inc.at(-1).ref)')); assert.equal(ev('L(S.inc.at(-1).ref).loss.glass'), true); assert.equal(cap('x'), 240); // Fixed: the express is back. ev('clearInc(S.inc.at(-1));compute()'); assert.equal(cap('x'), 400); assert.deepEqual(errors, []); }); test('saves: a dirty connector keeps dimming the express after a reload; an old save\'s loss stays on its own fiber', (t) => { const { ev, errors } = game(t); ev(BUILD + "L(s2).loss={until:S.day+3,f:0.6,glass:true};compute()"); ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()'); assert.equal(ev('JSON.stringify(L(s2).loss)'), ev('JSON.stringify({until:S.day+3,f:0.6,glass:true})')); assert.equal(Math.round(ev('capOf(L(x))')), 240); // A loss from before the connector was told apart, or a hand-edited flag that is not true: router-side, as it was. for (const loss of ['{until:S.day+3,f:0.6}', '{until:S.day+3,f:0.6,glass:"yes"}']) { ev(`{const o=JSON.parse(JSON.stringify(S));o.links.find(l=>l.id===s2).loss=${loss};S=migrate(o);compute();}`); assert.equal(ev('JSON.stringify(L(s2).loss)'), ev('JSON.stringify({until:S.day+3,f:0.6})'), loss); assert.equal(Math.round(ev('capOf(L(x))')), 400, loss); } assert.deepEqual(errors, []); }); test('MCP: the dry run of a regen site under an express quotes what the game then charges', () => { 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: 'fra', preset: 'sandbox', seed: 7, name: 'Probe' }); ev(BASE.replace(/^ACT\.start\(\{\}\);if\(UI\.pendGame\)ACT\.pitchSkip\(\);/, '') + SPANS + BUILD); assert.equal(ev("S.links.filter(l=>l.kind==='xp').length"), 1); const q = T('act', { action: 'regen', args: { id: ev('s1'), d: 1 }, dryRun: true }).quote; assert.deepEqual(q.blocked, []); assert.equal(q.setup, ev("REGEN_COST+Math.round(optCost('zr4')*REGEN_CH)"), 'the hut and a card for the express channel'); const c0 = ev('S.cash'); T('act', { action: 'regen', args: { id: ev('s1'), d: 1 } }); assert.equal(q.setup, c0 - ev('S.cash'), 'quote equals charge'); assert.deepEqual(s.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('