// The intern standardizes routers on the build standard's model within the budget; the Ops sheet says where the model // comes from and leads to the sheet that sets it, and every other setting there is a list. const test = require('node:test'); const assert = require('node:assert/strict'); const { load } = require('./harness'); // Frankfurt (one router, broadband), Amsterdam (two routers, broadband) and Paris (one router, nothing on it yet), // all on the Edge Lord 400. Change Freeze: no fat fingers. const BASE = "ACT.start({});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');" + "ACT.launchBB({city:'fra'});S.pops.fra.rgen=1;ACT.buyTransit({city:'fra',net:'cog',tier:1});" + "for(const c of ['ams','par'])ACT.buildPop({city:c});ACT.launchBB({city:'ams'});S.pops.ams.rgen=1;S.pops.ams.routers=2;S.pops.par.rgen=1;compute();" + "ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal()"; const MODEL = "RG.findIndex(r=>r.n==='Arrrhipster 7800R')"; function game(t) { const h = load(); t.after(() => h.dom.window.close()); h.ev(BASE); return h; } const gens = ev => JSON.parse(ev("JSON.stringify(['fra','ams','par'].map(c=>S.pops[c].rgen))")); // The build standard's router model (the standard's other targets stay as they are). const model = (ev, g) => ev(`S.popStd=bstdPut({...bstd(),g:${g}})`); test("the build standard's model: every POP on a smaller one is swapped to it, at the price of the swap, never as an outage", t => { const { ev, errors } = game(t); const m = ev(MODEL); assert.ok(m > 0 && ev(`rgOpen(${m})`), 'the model is unlocked at level 3'); model(ev, m); ev("S.ops.on.routers=true;S.ops.p.routers={at:90,how:'auto'};S.ops.cap.routers=0;compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0"); const want = ev(`swapCost('ams',${m})+swapCost('par',${m})`), c0 = ev('S.cash'); ev('opsDay(S.day)'); assert.deepEqual(gens(ev), [1, m, m], 'Amsterdam (a second router) and Paris (no traffic yet) are swapped; Frankfurt has one busy router, so no'); assert.equal(c0 - ev('S.cash'), want, 'the shift paid exactly what the two swaps cost'); assert.equal(ev("S.inc.some(i=>i.type==='maint')"), false, 'no outage'); assert.match(ev('opsLine(S.ops.log[0])'), /Amsterdam ⇧800G/); // Frankfurt gets its turn once it has a second router. ev('S.pops.fra.routers=2;S.day++;compute();opsDay(S.day)'); assert.deepEqual(gens(ev), [m, m, m]); // Busy POPs on the standard's model get more routers, never a swap to another one. ev("S.ops.p.routers.how='swap';S.day++;compute();R.nodeLoad.ams=R.nodeCap.ams*0.95;opsDay(S.day)"); assert.equal(ev('S.pops.ams.rgen'), m, 'no swap away from the standard\'s model'); ev("S.ops.p.routers.how='add';S.day++;compute();R.nodeLoad.ams=R.nodeCap.ams*0.95;opsDay(S.day)"); assert.equal(ev('S.pops.ams.routers'), 3, 'a busy POP gets a third router'); assert.deepEqual(errors, []); }); test('the budget decides how far it gets, the busiest POP first; a smaller model is never a downgrade; a locked one means the best unlocked below it', t => { const { ev, errors } = game(t); const m = ev(MODEL); model(ev, m); ev("S.ops.on.routers=true;S.ops.p.routers={at:90,how:'auto'};compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0;R.nodeLoad.par=R.nodeCap.par*0.5"); // A budget for one swap: Paris is the busier, so it goes first and Amsterdam waits for next month. const one = ev(`swapCost('par',${m})`); ev(`S.ops.cap.routers=OPS_CAPS.filter(c=>c>=${one}).sort((a,b)=>a-b)[0]`); assert.ok(ev('S.ops.cap.routers') < one + ev(`swapCost('ams',${m})`), 'the budget is too small for both'); ev('opsDay(S.day)'); assert.deepEqual(gens(ev), [1, 1, m], 'Paris first'); assert.ok(ev("S.ops.log[0].r.some(x=>x[0]==='broke')"), 'the log says the budget ran out'); // Next month, a new budget: Amsterdam. ev('{const m0=monthIdx(S.day);while(monthIdx(S.day)===m0)S.day++;}compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0;opsDay(S.day)'); assert.deepEqual(gens(ev), [1, m, m]); // A smaller model in the standard swaps nothing back. ev("S.ops.cap.routers=0;S.day++;compute()"); model(ev, "RG.findIndex(r=>r.n==='Edge Lord 400')"); ev('opsDay(S.day)'); assert.deepEqual(gens(ev), [1, m, m]); // A model above the level: the best main-line model unlocked below it, as the standard means for a new POP. const big = ev("RG.findIndex(r=>r.n==='Arrrhipster 7800R5')"); assert.equal(ev(`rgOpen(${big})`), false); model(ev, big); ev('S.pops.fra.routers=2'); const best = ev(`bstdModel(${big},'fra')`); ev('S.day++;compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0;opsDay(S.day)'); assert.equal(ev('S.pops.fra.rgen'), best); assert.ok(ev('S.pops.fra.rgen') > 1 && ev(`RG[S.pops.fra.rgen].cap { const { ev, errors } = game(t); const m = ev(MODEL), el = ev("RG.findIndex(r=>r.n==='Edge Lord 400')"); // An old save: the routers order's model and the optical order's line system, with or without a standard. x: what // else the save says (by default both orders ran, with Kevin hired). const ON = 's.ops.on.routers=true;s.ops.on.optup=true'; const back = (p, std, x = ON) => JSON.parse(ev(`(()=>{const s=JSON.parse(JSON.stringify(S));s.ops.p=${p};s.popStd=${std};${x};sanitize(s);return JSON.stringify({p:s.ops.p,std:s.popStd});})()`)); let r = back(`{routers:{model:${m},at:70},optup:{sys:'cl',swap:false}}`, 'null'); assert.deepEqual(r.std, { g: m, rt: 1, sys: 'cl' }, 'no standard: both move into a new one'); assert.deepEqual(r.p.routers, { at: 70 }, 'the old setting is gone, the others stay'); assert.deepEqual(r.p.optup, { swap: false }); // Only what an order that ran used: a paused order's setting, or one with nobody hired, did nothing, and goes. r = back(`{routers:{model:${m},at:70},optup:{sys:'cl'}}`, 'null', 's.ops.on.routers=false'); assert.deepEqual([r.std, r.p.routers, r.p.optup], [null, { at: 70 }, {}], 'both paused: no standard'); r = back(`{routers:{model:${m}},optup:{sys:'cl'}}`, 'null', 's.ops.on.routers=true'); assert.deepEqual(r.std, { g: m, rt: 1 }, 'the routers order ran, the optical order was paused'); r = back(`{routers:{model:${m}},optup:{sys:'cl'}}`, '{rt:2}', ON + ';s.ops.intern=null'); assert.deepEqual([r.std, r.p.routers, r.p.optup], [{ rt: 2 }, {}, {}], 'nobody hired: the standard stays as it was'); r = back(`{routers:{model:${m}},optup:{sys:'roadm'}}`, `{g:${el},rt:2,sys:'cl',gen:true}`); assert.deepEqual(r.std, { g: el, rt: 2, gen: true, sys: 'cl' }, 'a standard that names its own keeps them'); assert.deepEqual([r.p.routers, r.p.optup], [{}, {}]); r = back(`{routers:{model:${m}},optup:{sys:'roadm'}}`, '{rt:3,lag:2}'); assert.deepEqual(r.std, { g: m, rt: 3, lag: 2, sys: 'roadm' }, 'one without them takes them and keeps the rest'); r = back("{routers:{model:'next'},optup:{sys:'next'}}", 'null'); assert.deepEqual([r.std, r.p.routers, r.p.optup], [null, {}, {}], "'next' was no choice: nothing moves"); r = back("{routers:{model:999},optup:{sys:'warp'}}", 'null'); assert.deepEqual([r.std, r.p.routers, r.p.optup], [null, {}, {}], 'junk moves nowhere'); r = back("{routers:{model:'7'}}", `{g:${el}}`); assert.deepEqual(r.std, { g: el, rt: 1 }); r = back('undefined', 'undefined'); assert.deepEqual([r.std, r.p.routers, r.p.optup], [null, {}, {}], 'an old save with neither'); // The order reads the standard: none set, it is the next generation when busy. assert.equal(ev('bstd().g'), 'keep'); // A loaded save whose model sat in a paused order, the intern since fired: new POPs cost what they did. const lon = ev("popCost('lon')"); ev(`S.ops.p.routers={model:${m}};S.ops.on.routers=false;S.ops.intern=null;S=migrate(JSON.parse(JSON.stringify(S)))`); assert.deepEqual([ev('S.popStd'), ev("newPopCost('lon')"), ev("JSON.stringify(S.ops.p.routers)")], [null, lon, '{}']); ev("ACT.buildPop({city:'lon'})"); assert.equal(ev('S.pops.lon.rgen||0'), 0, 'and get the basic router'); // A loaded save that had a model in a running order plays with it: the shift swaps to it. ev(`ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();S.ops.p.routers={model:${m}};S.ops.on.routers=true;S=migrate(JSON.parse(JSON.stringify(S)));compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0;opsDay(S.day)`); assert.equal(ev('S.popStd.g'), m); assert.equal(ev('S.pops.ams.rgen'), m); assert.deepEqual(errors, []); }); test('the Ops sheet: the model comes from the build standard, one line and a way there; every other setting is a list, on a phone too', t => { const { ev, dom, errors } = game(t); dom.window.innerWidth = 360; const doc = dom.window.document; ev("for(const k in S.ops.on)S.ops.on[k]=true;ACT.phoneTab({t:'noc'})"); doc.querySelector('#leftBody [data-act="opsOpen"]').click(); assert.equal(doc.querySelectorAll('#modalCard [data-act="opsParam"],#modalCard [data-act="opsCap"],#modalCard [data-act="opsFloor"]').length, 0, 'no buttons that step through values'); const sel = (act, args) => [...doc.querySelectorAll(`#modalCard select[data-chg="${act}"]`)].find(s => s.dataset.args === JSON.stringify(args)); const pick = (s, text) => { const o = [...s.options].find(o => o.textContent === text); assert.ok(o, `${text} is on the list`); s.value = o.value; s.dispatchEvent(new dom.window.Event('change', { bubbles: true })); }; // Every setting of every order, every budget and the floor. const n = ev('OPS.reduce((a,d)=>a+Object.keys(d.p).length+(d.cap?1:0),0)+1'); assert.equal(doc.querySelectorAll('#modalCard .ops-p select').length, n); assert.equal(sel('opsParam', { k: 'routers', p: 'model' }), undefined, 'no model list of its own'); // The routers order: where its model comes from, and the button to the sheet that sets it. const routers = [...doc.querySelectorAll('#modalCard .ops-o.on')].find(o => o.querySelector('.nm').textContent === 'Keep routers ahead'); assert.ok(routers.querySelector('.ops-from'), 'a line in the routers order'); assert.match(routers.querySelector('.ops-from').textContent, /^ModelFrom the build standard: Next generation, when busy/); routers.querySelector('.ops-from [data-act="bstdOpen"]').click(); assert.ok(ev('bstdShown()'), 'the button opens the build standard'); // Set there, it is what the line says. pick([...doc.querySelectorAll('#modalCard select[data-chg="bstdSet"]')].find(s => JSON.parse(s.dataset.args).k === 'g'), 'Arrrhipster 7800R'); assert.equal(ev('bstd().g'), ev(MODEL)); ev('ACT.opsOpen()'); const r2 = [...doc.querySelectorAll('#modalCard .ops-o.on')].find(o => o.querySelector('.nm').textContent === 'Keep routers ahead'); assert.match(r2.querySelector('.ops-from b').textContent, /^From the build standard: Arrrhipster 7800R$/); // The rest are still lists. pick(sel('opsParam', { k: 'transit', p: 'prov' }), 'Already connected'); assert.equal(ev("opsP('transit','prov')"), 'have'); pick(sel('opsCap', { k: 'routers' }), 'no limit'); assert.equal(ev("opsCap('routers')"), 0); pick(sel('opsFloor', {}), ev('fmt$(1e6)')); assert.equal(ev('S.ops.floor'), 1e6); // A value from nowhere changes nothing; the retired setting is nothing either; the MCP tools still step without a value. ev("ACT.opsParam({k:'routers',p:'model',v:'1'});ACT.opsCap({k:'routers',v:'-1'});ACT.opsFloor({v:'x'})"); assert.deepEqual([ev('bstd().g'), ev("opsCap('routers')"), ev('S.ops.floor'), ev("JSON.stringify(S.ops.p.routers||{})")], [ev(MODEL), 0, 1e6, '{}']); ev("ACT.opsParam({k:'routers',p:'how'})"); assert.equal(ev("opsP('routers','how')"), 'add'); assert.deepEqual(errors, []); });