seriesoftubes/tests/intern-optical-upgrade.test.js
jvanvik 286ae48207 Build standard: never take a fiber dark under a customer's wave; the intern no longer skips leased pairs and IRUs
The build standard's Apply could swap the line system on a fiber that carries a
sold alien wave or a Lambda Bazaar managed wave, taking those customers dark for
a day with no warning. The intern refused any fiber with any customer on it,
leased pairs and IRUs included, though a line-system swap cannot touch them.

One helper next to fiberOk(), dfWaveCust(), says whether a customer rides the
fiber's line system (every fiber type but glass: dfpair, pairs, capfib), and both
bstdDarkOk() and opsDarkPre() use it. bstdPlan() holds such a fiber (J.held) and
lists it in J.wv; the sheet and the MCP quote give that reason. The link
panel's own upgrade button (ACT.upSys) still swaps with a warning toast.
2026-11-09 23:02:02 +01:00

143 lines
8.9 KiB
JavaScript
Raw Permalink 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.

// The intern upgrades optical transport: line systems up a size (only where the traffic gets around the day-long swap and
// no customer rides the fiber), optics traded for bigger ones on full, hot fiber, or every fiber up to the build standard's
// line system.
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
// Frankfurt (transit) and Amsterdam (broadband) joined by a full Rainbow-in-a-Box fiber of 16×400G, and the long way
// round through Paris on two waves. Level 6: every line system and optic unlocked. Change Freeze: no fat fingers.
// Annie runs the shift: Kevin would swap two line systems a night (tests/intern-personas.test.js).
const BASE = "ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;S.lvl=6;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');" +
"for(const c of ['ams','par'])ACT.buildPop({city:c});for(const c of ['fra','ams','par']){S.pops[c].rgen=mainRG(3);S.pops[c].routers=2;}ACT.launchBB({city:'ams'});" +
"S.transit=[];ACT.buyTransit({city:'fra',net:'cog',tier:2});" +
"S.links=[{id:'f',a:'fra',b:'ams',kind:'df',own:true,sys:'lite',ch:Array(16).fill('zr4'),km:450,trench:'t1',ready:0,cut:0,mo:1,pairs:1}," +
"{id:'w1',a:'fra',b:'par',kind:'wave',tier:4,km:480,cut:0,mo:1},{id:'w2',a:'par',b:'ams',kind:'wave',tier:4,km:430,cut:0,mo:1}];compute();" +
"ACT.opsHire({id:'annie'});S.ops.floor=0;S.ops.cap.optup=0;closeModal()";
function game(t, extra) {
const h = load();
t.after(() => h.dom.window.close());
h.ev(BASE);
if (extra) h.ev(extra);
return h;
}
const order = (ev, p) => ev(`S.ops.on.optup=true;S.ops.p.optup=${JSON.stringify(p)}`);
// The line system every fiber should have: the build standard's.
const goal = (ev, sys) => ev(`S.popStd=bstdPut({...bstd(),sys:${JSON.stringify(sys)}})`);
// The fiber runs at 90% of what it carries.
const heat = ev => ev("R.load.f=dfCap(S.links[0])*0.9");
const fiber = ev => JSON.parse(ev("JSON.stringify({sys:S.links[0].sys,ch:S.links[0].ch.join(),down:S.links[0].eqDown>S.day})"));
test('a full, hot fiber gets the next line system where the traffic gets around it, at the price of the click', t => {
const { ev, errors } = game(t);
order(ev, { at: 80 });
const want = ev('sysUpCost(S.links[0])'), served = ev('R.served'), c0 = ev('S.cash');
heat(ev);
ev('opsDay(S.day)');
assert.equal(fiber(ev).sys, 'roadm', 'up to the ROADMaster');
assert.equal(c0 - ev('S.cash'), want, 'the shift paid exactly what Upgrade costs');
assert.equal(fiber(ev).down, true, 'the swap takes the fiber down for the day, as by hand');
assert.ok(ev('R.served') >= served - 1e-6, 'and every gigabit still gets through, the long way round');
assert.match(ev('opsLine(S.ops.log[0])'), /upgraded the line system on Frankfurt–Amsterdam ⇧ROADM/);
// Not hot enough, or not full: nothing.
const { ev: ev2 } = game(t);
order(ev2, { at: 80 });
ev2('R.load.f=dfCap(S.links[0])*0.5;opsDay(S.day)');
ev2('S.links[0].ch.pop();R.load.f=dfCap(S.links[0])*0.95;S.day++;opsDay(S.day)');
assert.equal(fiber(ev2).sys, 'lite', 'a fiber with a free channel gets more optics from Light more fiber, not a new line system');
assert.deepEqual(errors, []);
});
test('no way around, or a customer on the fiber: no swap; bigger optics instead, one channel at a time', t => {
// Without the waves through Paris, Amsterdam would be cut off for the day.
const { ev, errors } = game(t, "S.links=S.links.filter(l=>l.kind==='df');compute()");
order(ev, { at: 80 });
heat(ev);
const c0 = ev('dfCap(S.links[0])'), cash0 = ev('S.cash');
ev('opsDay(S.day)');
assert.equal(fiber(ev).sys, 'lite', 'no outage');
assert.equal(fiber(ev).down, false);
assert.ok(ev('dfCap(S.links[0])') > c0, 'more capacity from bigger optics');
assert.match(fiber(ev).ch, /zr8/, 'Sizzle 800ZR+ in place of some 400ZR+');
assert.equal(ev("S.links[0].ch.length"), 16, 'still sixteen channels');
assert.ok(ev("S.spares.zr4") > 0, 'the old optics went on the shelf');
assert.ok(cash0 - ev('S.cash') > 0);
assert.match(ev('opsLine(S.ops.log[0])'), /swapped \d+ optics for bigger ones \(Frankfurt–Amsterdam 400G→800G\)/);
// A customer's wave on the fiber: the intern never swaps its line system, even with a way around.
const { ev: ev2 } = game(t, "S.links[0].ch.length=15;S.biz.push({id:'cw',name:'Wave',city:'fra',city2:'ams',type:'wwave',link:'f',slots:1,bw:400,rate:1})");
order(ev2, { at: 80, swap: false });
heat(ev2);
ev2('opsDay(S.day)');
assert.equal(fiber(ev2).sys, 'lite');
// A managed wave too. Leased pairs and IRUs are glass: the swap never touches them, so it goes ahead.
for (const [type, sys] of [['mwave', 'lite'], ['dfpair', 'roadm'], ['pairs', 'roadm']]) {
const { ev: ev3, errors: e3 } = game(t, `S.biz.push({id:'cx',name:'Customer',city:'fra',city2:'ams',type:'${type}',link:'f',slots:1,g:100,bw:1,rate:1})`);
order(ev3, { at: 80, swap: false });
heat(ev3);
ev3('opsDay(S.day)');
assert.equal(fiber(ev3).sys, sys, type);
assert.deepEqual(e3, []);
}
assert.deepEqual(errors, []);
});
test("the build standard's line system: every fiber below it is moved up, two steps in one night if need be, one fiber a night", t => {
const { ev, errors } = game(t, "S.links[0].ch=['zr4'];" +
"for(const [i,a,b] of [[2,'fra','par'],[3,'par','ams']])S.links.push({id:'g'+i,a,b,kind:'df',own:true,sys:'lite',ch:['zr4'],km:450,trench:'t'+i,ready:0,cut:0,mo:1,pairs:1});compute()");
order(ev, { at: 90 });
goal(ev, 'cl');
const want = ev("sysCost('roadm')+sysCost('cl')");
const sys = () => JSON.parse(ev("JSON.stringify(S.links.filter(l=>l.kind==='df').map(l=>l.sys))"));
const c0 = ev('S.cash');
ev('opsDay(S.day)');
assert.equal(sys().filter(s => s === 'cl').length, 1, 'one fiber a night, cold or not');
assert.equal(c0 - ev('S.cash'), want, 'both steps in one night: one outage, not two');
for (let n = 0; n < 6 && sys().some(s => s !== 'cl'); n++) ev('S.day+=2;compute();opsDay(S.day)');
assert.deepEqual(sys(), ['cl', 'cl', 'cl', 'cl'].slice(0, sys().length), 'the rest on the nights after');
// Nothing is ever moved down.
goal(ev, 'roadm');
ev('S.day+=2;compute();opsDay(S.day)');
assert.ok(sys().every(s => s === 'cl'));
// A fiber with no way around is tested once, then left alone for a week: no routing every night for nothing.
goal(ev, 'cl');
ev("S.links=S.links.filter(l=>l.id==='f');S.links[0].sys='lite';S.day+=2;compute()");
const runs = () => ev('window.__runs||0');
ev("window.__runs=0;const c0=compute;compute=function(){window.__runs++;return c0.apply(this,arguments);};opsDay(S.day)");
assert.equal(sys()[0], 'lite');
assert.equal(runs(), 0, 'no other path at all: not even one routing to find out');
ev("S.links.push({id:'w9',a:'fra',b:'ams',kind:'wave',tier:0,km:450,cut:0,mo:1});S.day+=OPTUP_WAIT;window.__runs=0;opsDay(S.day)");
assert.equal(runs(), 1, 'a path, too thin: one routing to find out');
assert.equal(sys()[0], 'lite');
ev('S.day++;window.__runs=0;opsDay(S.day)');
assert.equal(runs(), 0, 'and not again the next night');
assert.deepEqual(errors, []);
});
test("the budget holds, the settings are saved, and the sheet shows them as lists and the line system as the standard's", t => {
const { ev, dom, errors } = game(t);
order(ev, { at: 80 });
ev('S.ops.cap.optup=10000');
heat(ev);
ev('opsDay(S.day)');
assert.equal(fiber(ev).sys, 'lite', 'a $10k budget does not buy a line system');
assert.ok(ev("S.ops.log[0].r.some(x=>x[0]==='broke')"));
const back = v => ev(`(()=>{const s=JSON.parse(JSON.stringify(S));s.ops.p.optup=${v};sanitize(s);return JSON.stringify(s.ops.p.optup);})()`);
assert.deepEqual(JSON.parse(back("{swap:false,at:70}")), { at: 70, swap: false });
assert.deepEqual(JSON.parse(back("{at:55,swap:'yes'}")), {});
assert.deepEqual(JSON.parse(back('undefined')), {}, 'an old save without the order');
ev("const s=JSON.parse(JSON.stringify(S));delete s.ops.on.optup;sanitize(s);window.__off=s.ops.on.optup");
assert.equal(ev('__off'), false, 'off in an old save');
dom.window.innerWidth = 360;
ev("ACT.phoneTab({t:'noc'})");
dom.window.document.querySelector('#leftBody [data-act="opsOpen"]').click();
const doc = dom.window.document, card = () => [...doc.querySelectorAll('#modalCard .ops-o.on')].find(o => o.querySelector('.nm').textContent === 'Upgrade optical transport');
assert.deepEqual([...card().querySelectorAll('select[data-chg="opsParam"]')].map(s => JSON.parse(s.dataset.args).p), ['at', 'swap'], 'no line system list of its own');
// The line system is the build standard's: what it says, and the way to the sheet.
assert.match(card().querySelector('.ops-from').textContent, /^Line systemFrom the build standard: Next one, when full/);
goal(ev, 'cl');
ev('ACT.opsOpen()');
assert.equal(card().querySelector('.ops-from b').textContent, 'From the build standard: ROADMaster 9000 C+L');
card().querySelector('.ops-from [data-act="bstdOpen"]').click();
assert.ok(ev('bstdShown()'), 'the button opens the build standard');
assert.deepEqual(errors, []);
});