The build standard owns the router model and the line system; one owner per fiber

The routers order reads its model from the build standard (bstd().g, 'keep'
is the old next-model-up rule) and the optical upgrade order its line system
(bstd().sys). The Ops sheet shows "From the build standard: X" with a button
to the sheet. Old saves move a model or line system from an order that was
running into the standard when it has none of its own; a paused order's or
an unhired intern's setting is dropped. opsParam refuses model/sys and points
at bstdSet.

The build standard's order is a generator now: every first job that takes a
fiber dark goes through the optical order's routing test (opsDark, in the
route worker in play), under one shared budget of dark swaps a night (two for
Kevin) and the week-long memory for a failed fiber. A fiber one order worked
on is the other's no more that shift, and decom keeps waves the standard just
upgraded. The plan is checked at every job, since the shift rests between
them: a POP gone or changed by hand meanwhile is skipped. The button still
runs the whole plan at once on the page.
This commit is contained in:
jvanvik 2026-11-07 06:55:01 +01:00
parent 032470f486
commit fbae6fc3ed
22 changed files with 573 additions and 138 deletions

View file

@ -1,5 +1,6 @@
// 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 a chosen line system.
// 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');
@ -21,6 +22,8 @@ function game(t, 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})"));
@ -69,10 +72,11 @@ test('no way around, or a customer on the fiber: no swap; bigger optics instead,
assert.deepEqual(errors, []);
});
test('a chosen line system: every fiber below it is moved up, two steps in one night if need be, one fiber a night', t => {
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, { sys: 'cl', at: 90 });
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');
@ -82,10 +86,12 @@ test('a chosen line system: every fiber below it is moved up, two steps in one n
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.
ev("S.ops.p.optup.sys='roadm';S.day+=2;compute();opsDay(S.day)");
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.
ev("S.links=S.links.filter(l=>l.id==='f');S.links[0].sys='lite';S.ops.p.optup.sys='cl';S.day+=2;compute()");
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');
@ -98,7 +104,7 @@ test('a chosen line system: every fiber below it is moved up, two steps in one n
assert.deepEqual(errors, []);
});
test('the budget holds, the setting is saved, and the sheet shows it as lists', t => {
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');
@ -107,16 +113,22 @@ test('the budget holds, the setting is saved, and the sheet shows it as lists',
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("{sys:'cl',swap:false,at:70}")), { at: 70, sys: 'cl', swap: false });
assert.deepEqual(JSON.parse(back("{sys:'lite',swap:'yes'}")), {});
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 sel = [...dom.window.document.querySelectorAll('#modalCard select[data-chg="opsParam"]')].find(s => s.dataset.args === '{"k":"optup","p":"sys"}');
assert.deepEqual([...sel.options].map(o => o.textContent), ['Next one, when full', 'ROADMaster 9000', 'ROADMaster 9000 C+L']);
assert.match(dom.window.document.getElementById('modalCard').textContent, /Upgrade optical transport/);
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, []);
});