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,4 +1,5 @@
// The intern standardizes routers on a chosen model within the budget, and every setting in the Ops sheet is a list.
// 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');
@ -17,12 +18,15 @@ function game(t) {
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('a chosen model: every POP on a smaller one is swapped to it, at the price of the swap, never as an outage', t => {
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');
ev(`S.ops.on.routers=true;S.ops.p.routers={at:90,how:'auto',model:${m}};S.ops.cap.routers=0;compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0`);
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');
@ -32,18 +36,19 @@ test('a chosen model: every POP on a smaller one is swapped to it, at the price
// 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 chosen model get more routers, never a swap to another one.
// 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 chosen model');
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', t => {
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);
ev(`S.ops.on.routers=true;S.ops.p.routers={at:90,how:'auto',model:${m}};compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0;R.nodeLoad.par=R.nodeCap.par*0.5`);
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]`);
@ -54,24 +59,70 @@ test('the budget decides how far it gets, the busiest POP first; a smaller model
// 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]);
// Choosing a smaller model swaps nothing back.
ev("S.ops.cap.routers=0;S.ops.p.routers.model=RG.findIndex(r=>r.n==='Edge Lord 400');S.day++;compute();opsDay(S.day)");
// 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<RG[${big}].cap`), 'up, but no further than what is unlocked');
assert.deepEqual(errors, []);
});
test('the setting is saved; an unknown model falls back to the next generation', t => {
test('saves: an old model or line system setting moves into the standard when it names none; its own wins; neither stays neither', t => {
const { ev, errors } = game(t);
const back = v => ev(`(()=>{const s=JSON.parse(JSON.stringify(S));s.ops.p.routers=${v};sanitize(s);return JSON.stringify(s.ops.p.routers);})()`);
assert.deepEqual(JSON.parse(back(`{model:${ev(MODEL)}}`)), { model: ev(MODEL) });
assert.deepEqual(JSON.parse(back('{model:999}')), {});
assert.deepEqual(JSON.parse(back("{model:'7'}")), {});
assert.deepEqual(JSON.parse(back('undefined')), {}, 'an old save without it');
assert.equal(ev("opsP('routers','model')"), 'next');
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('every setting in the Ops sheet is a list to pick from, on a phone too', t => {
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;
@ -88,24 +139,29 @@ test('every setting in the Ops sheet is a list to pick from, on a phone too', t
// 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);
// The model list: the next generation, then the models you can buy, smallest first.
const model = sel('opsParam', { k: 'routers', p: 'model' });
assert.ok(model, 'the routers order has a model list');
assert.equal(model.options[0].textContent, 'Next generation, when busy');
assert.ok([...model.options].some(o => o.textContent === 'Arrrhipster 7800R'));
assert.ok(![...model.options].some(o => o.textContent === 'Absolute Unit 3.2T'), 'only models unlocked at your level');
pick(model, 'Arrrhipster 7800R');
assert.equal(ev("opsP('routers','model')"), ev(MODEL));
assert.equal(doc.activeElement && doc.activeElement.dataset.args, JSON.stringify({ k: 'routers', p: 'model' }), 'the keyboard stays on the list');
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 MCP tools still step without a value.
ev("ACT.opsParam({k:'routers',p:'model',v:'99'});ACT.opsCap({k:'routers',v:'-1'});ACT.opsFloor({v:'x'})");
assert.deepEqual([ev("opsP('routers','model')"), ev("opsCap('routers')"), ev('S.ops.floor')], [ev(MODEL), 0, 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, []);