The intern standardizes routers on a chosen model; Ops settings are lists
Some checks are pending
CI / test 1/4 (push) Waiting to run
CI / test 2/4 (push) Waiting to run
CI / test 3/4 (push) Waiting to run
CI / test 4/4 (push) Waiting to run
CI / build (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / translations (push) Waiting to run
Some checks are pending
CI / test 1/4 (push) Waiting to run
CI / test 2/4 (push) Waiting to run
CI / test 3/4 (push) Waiting to run
CI / test 4/4 (push) Waiting to run
CI / build (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / translations (push) Waiting to run
Keep routers ahead gets a Model setting: the next generation when busy (as before), or a model to standardize on. With a model, every POP on a smaller one is swapped to it, the busiest first, within the monthly budget, through the same upRouter click: never a step down, only unlocked models that fit, and only where a second router carries the traffic or nothing runs yet. Busy POPs on it only get more routers. Every setting in the Standing orders sheet (each order's dials, budgets, the cash floor) is a dropdown instead of a button that steps through the values. The change handler passes a select's data-args, the actions take the picked position (v) and still step without one for the MCP tools, which now declare v as optional.
This commit is contained in:
parent
9d64aa0144
commit
1e7638c4b9
16 changed files with 188 additions and 33 deletions
|
|
@ -51,10 +51,12 @@ test('#262 the setting is saved, an unknown value falls back, and it shows on th
|
|||
dom.window.innerWidth = 360;
|
||||
ev("ACT.phoneTab({t:'noc'})");
|
||||
dom.window.document.querySelector('#leftBody [data-act="opsOpen"]').click();
|
||||
const btn = [...dom.window.document.querySelectorAll('#modalCard [data-act="opsParam"]')].find((b) => b.dataset.args.includes('pick'));
|
||||
assert.ok(btn, 'the Optics button is in the sheet');
|
||||
assert.match(btn.textContent, /Optics: biggest on new fiber/);
|
||||
btn.click();
|
||||
const sel = [...dom.window.document.querySelectorAll('#modalCard select[data-chg="opsParam"]')].find((s) => s.dataset.args.includes('pick'));
|
||||
assert.ok(sel, 'the Optics list is in the sheet');
|
||||
assert.match(sel.closest('label').textContent, /Optics/);
|
||||
assert.equal(sel.options[sel.selectedIndex].textContent, 'biggest on new fiber');
|
||||
sel.value = [...sel.options].find((o) => o.textContent !== 'biggest on new fiber').value;
|
||||
sel.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
||||
assert.equal(ev("opsP('optics','pick')"), 'cheap');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
112
tests/intern-router-model.test.js
Normal file
112
tests/intern-router-model.test.js
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
// The intern standardizes routers on a chosen model within the budget, and every setting in the Ops sheet 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))"));
|
||||
|
||||
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 => {
|
||||
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`);
|
||||
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 chosen 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');
|
||||
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 => {
|
||||
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`);
|
||||
// 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]);
|
||||
// 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)");
|
||||
assert.deepEqual(gens(ev), [1, m, m]);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the setting is saved; an unknown model falls back to the next generation', 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');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('every setting in the Ops sheet is a list to pick from, 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);
|
||||
// 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');
|
||||
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]);
|
||||
ev("ACT.opsParam({k:'routers',p:'how'})");
|
||||
assert.equal(ev("opsP('routers','how')"), 'add');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -356,7 +356,9 @@ test('the Ops sheet works at 360 px in every language, from the NOC tab and the
|
|||
assert.ok(ev('opsHired()'), lang);
|
||||
doc.querySelector('#modalCard [data-act="opsToggle"]').click();
|
||||
assert.equal(doc.querySelector('#modalCard [data-act="opsToggle"]').getAttribute('aria-pressed'), 'true', lang);
|
||||
doc.querySelector('#modalCard [data-act="opsParam"]').click();
|
||||
const sel = doc.querySelector('#modalCard select[data-chg="opsParam"]');
|
||||
sel.value = String((sel.selectedIndex + 1) % sel.options.length);
|
||||
sel.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
||||
const txt = doc.getElementById('modalCard').textContent;
|
||||
assert.doesNotMatch(txt, /\bops\.[a-z_]+/, lang);
|
||||
assert.ok(doc.querySelector('#modalCard select[data-chg="opsCity"]'), lang);
|
||||
|
|
@ -495,7 +497,7 @@ test('the fat-fingered LAG member respects a paused transit order and per-POP ex
|
|||
});
|
||||
|
||||
test('caches: the cash floor and a running-cost budget hold; the panel and the log show what a month costs', t => {
|
||||
const { ev, errors } = game(t);
|
||||
const { ev, dom, errors } = game(t);
|
||||
hire(ev); on(ev, 'caches', { g: 1 });
|
||||
ev('S.pops.fra.rgen=0;compute()'); // 100G ports: 100G boxes at $400/mo
|
||||
const add = () => ev("utilityCaches('fra').add.filter(x=>(R.cityDem.fra||0)*NSH[x.net]>=1).length");
|
||||
|
|
@ -515,7 +517,8 @@ test('caches: the cash floor and a running-cost budget hold; the panel and the l
|
|||
ev('opsModal()');
|
||||
const txt = ev("document.getElementById('modalCard').textContent");
|
||||
assert.match(txt, /each box costs \$400\/mo/);
|
||||
assert.match(txt, /Adds at most: \+\$1\.0k\/mo/);
|
||||
const capSel = [...dom.window.document.querySelectorAll('#modalCard select[data-chg="opsCap"]')].find(x => x.dataset.args === '{"k":"caches"}');
|
||||
assert.equal(capSel.closest('label').firstChild.textContent + ': ' + capSel.options[capSel.selectedIndex].textContent, 'Adds at most: +$1.0k/mo');
|
||||
assert.match(txt, /This month: \$0 up front, \+\$800\/mo on the bill/);
|
||||
ev('S.day+=monLen(S.day);S.ops.cap.caches=0'); shift(ev);
|
||||
assert.equal(ev('S.ops.addMo.caches'), (ev('S.caches.length') - 2) * 400, 'a new month counts from zero');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue