Build standard: a Broadband: IPv6-only row, rolled out by the button and the intern (#150)
The owed follow-up to IPv6-only broadband (next-session item 4). A new POP target, v6, shown and planned only while IPv4 is scarce (rule ip4): bstdPlan() makes a job per broadband city still on dual stack (ip6Todo()), the most dual-stack homes first (the most behind CGNAT, the most addresses freed), each calling ACT.ip6Go(). Its price is the whole swap (ip6Cost(), the city panel's own figure); its mo is the IPv4 bill's change, counted one city after another on a copy so the sum is all of them done. ip6Go() pays nothing at the start (the routers are paid day by day), so these jobs are marked later: the button and the std order start one only with the whole swap in hand on top of what the swaps under way still owe (ip6Owed(), X.can's new owed argument for the floor), and the order counts the whole swap against its month's budget (not in what the shift paid up front). The button's toast counts started swaps whole, as the quote did. The sheet shows the row and a note only while ip4On(); bstdLine() counts it; the MCP docs (bstdSet, bstdApply, popStd) name it. Strings in all six dictionaries. Tests: tests/bstd-ipv6-only.test.js (order and price, the button, budget and floor, rule off, saves, the sheet at 360 px portrait and landscape in every language).
This commit is contained in:
parent
02b6c24d7b
commit
417160f383
16 changed files with 215 additions and 18 deletions
155
tests/bstd-ipv6-only.test.js
Normal file
155
tests/bstd-ipv6-only.test.js
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
// The build standard's "Broadband: IPv6-only" row (96-pop-standard.js, the swap itself in 34-ipv6-only.js): every
|
||||
// broadband city still on dual stack starts its home-router swap, the most dual-stack homes first, priced as the city
|
||||
// panel prices it (the whole swap, paid as the routers go in), from the sheet's button or the intern's standing order,
|
||||
// within the order's budget and the cash floor. Only while IPv4 is scarce (rule ip4).
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
const { lit } = require('../scripts/lib/js-literal');
|
||||
|
||||
// On-call (IPv4 is scarce), plenty of cash, nothing breaking. Broadband in Amsterdam (3,000 homes), Frankfurt (1,300) and
|
||||
// Paris (500): their swaps cost $12k, $5.2k and $2k.
|
||||
const BASE = "ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.rules=makeRules('oncall');S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;S.lvl=9;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.offers=[];S.biz=[];" +
|
||||
"ACT.launchBB({city:'fra'});S.pops.fra.rgen=3;ACT.buyTransit({city:'fra',net:'lvl',tier:3});for(const c of ['ams','par']){ACT.buildPop({city:c});ACT.launchBB({city:c});}" +
|
||||
"S.pops.fra.bb.d=130;S.pops.ams.bb.d=300;S.pops.par.bb.d=50;compute()";
|
||||
function game(t, opts) {
|
||||
const h = load(opts);
|
||||
t.after(() => h.dom.window.close());
|
||||
h.ev(BASE);
|
||||
return h;
|
||||
}
|
||||
const J = (ev, x) => JSON.parse(ev(`JSON.stringify(${x})`));
|
||||
const std = (ev, d) => ev(`S.popStd=${lit(d)}`);
|
||||
const v6 = (ev, plan = 'bstdPlan(false)') => J(ev, `${plan}.filter(j=>j.k==='v6').map(j=>[j.c,j.cost])`);
|
||||
const swapping = ev => J(ev, "['ams','fra','par'].filter(c=>S.pops[c].bb.v6e)");
|
||||
const COST = { ams: 12000, fra: 5200, par: 2000 };
|
||||
|
||||
test('the row: every dual-stack broadband city, the most homes first, at the swap\'s own price and its IPv4 bill', (t) => {
|
||||
const h = game(t, { agent: true });
|
||||
const { ev, errors } = h;
|
||||
assert.equal(ev('ip4On()'), true);
|
||||
assert.deepEqual(J(ev, "['ams','fra','par'].map(ip6Cost)"), [COST.ams, COST.fra, COST.par]);
|
||||
assert.deepEqual(v6(ev), [], 'no standard, no jobs');
|
||||
std(ev, { v6: true });
|
||||
assert.deepEqual(v6(ev), [['ams', COST.ams], ['fra', COST.fra], ['par', COST.par]], 'Amsterdam first: the most homes behind CGNAT');
|
||||
assert.equal(ev('bstdLine(bstd())'), '1 more target');
|
||||
// The plan's running costs are the IPv4 bill with every city done, against today's.
|
||||
const want = ev("(()=>{const eye=(R.rev&&R.rev.eyeballs)||0,m=b=>b.box+b.box64+b.refund,s={ip4:S.ip4,biz:S.biz,pops:{...S.pops}};for(const c of ['ams','fra','par'])s.pops[c]={...S.pops[c],bb:{...S.pops[c].bb,v6:1}};return m(ip4Bill(eye,s))-m(ip4Bill(eye));})()");
|
||||
const q = J(ev, 'bstdQuote(false)');
|
||||
assert.deepEqual([q.pops, q.n, q.cost], [3, 3, COST.ams + COST.fra + COST.par]);
|
||||
assert.equal(q.mo, Math.round(want));
|
||||
// A city already swapping, one done, one with no homes yet: nothing to do there.
|
||||
ev("S.pops.ams.bb.v6e=S.day+40;S.pops.par.bb.v6=1;ACT.buildPop({city:'lon'});ACT.launchBB({city:'lon'});S.pops.lon.bb.d=0;compute()");
|
||||
assert.deepEqual(v6(ev), [['fra', COST.fra]]);
|
||||
// A POP the intern is told to leave alone keeps its routers as they are.
|
||||
ev("ACT.opsHire({id:'annie'});closeModal();S.ops.skip.fra=['std']");
|
||||
assert.deepEqual(v6(ev, 'bstdPlan(true)'), []);
|
||||
assert.deepEqual(v6(ev), [['fra', COST.fra]], 'the button is not the intern');
|
||||
// The MCP tools: the target and the quote.
|
||||
ev("S.popStd=null;apiRun('bstdSet',{k:'v6'})");
|
||||
assert.deepEqual(J(ev, 'S.popStd'), { rt: 1, v6: true });
|
||||
assert.equal(J(ev, "apiRun('bstdApply',{},{dryRun:true})").quote.setup, COST.fra);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the button starts every swap it can pay in full, on top of what the swaps under way still owe', (t) => {
|
||||
const { ev, dom, errors } = game(t);
|
||||
std(ev, { v6: true });
|
||||
// Enough for Amsterdam and Paris, not for Frankfurt as well: the busiest first, then whatever still fits.
|
||||
ev(`S.cash=${COST.ams + COST.fra - 1};ACT.bstdOpen()`);
|
||||
const btn = dom.window.document.querySelector('#modalCard [data-act="bstdApply"]');
|
||||
assert.equal(btn.textContent, `Bring everything up now · ${ev(`fmt$(${COST.ams + COST.fra + COST.par})`)}`);
|
||||
btn.click();
|
||||
assert.deepEqual(swapping(ev), ['ams', 'par']);
|
||||
assert.equal(ev('S.cash'), COST.ams + COST.fra - 1, 'nothing paid yet: the routers are paid as they go in');
|
||||
assert.equal(ev('ip6Owed()'), COST.ams + COST.par);
|
||||
const said = `2 jobs done for the build standard, ${ev(`fmt$(${COST.ams + COST.par})`)}.`;
|
||||
assert.ok(dom.window.document.getElementById('toasts').textContent.includes(said), 'the toast counts the swaps whole, as the quote did');
|
||||
// Day by day the swaps pay what the button counted, and Frankfurt waits for the money.
|
||||
ev('for(let i=0;i<60;i++){S.day++;ip4Day(S.day);}compute()');
|
||||
assert.deepEqual(J(ev, "['ams','par'].map(c=>S.pops[c].bb.v6)"), [1, 1]);
|
||||
assert.ok(Math.abs(ev('S.cash') - (COST.fra - 1 - COST.par)) < 1e-6, 'the swaps cost what the button counted: ' + ev('S.cash'));
|
||||
assert.deepEqual(v6(ev), [['fra', COST.fra]]);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test("the intern rolls it out within the order's budget and the cash floor, and the shift log names the cities", (t) => {
|
||||
const { ev, errors } = game(t);
|
||||
std(ev, { v6: true });
|
||||
ev("ACT.opsHire({id:'annie'});closeModal();S.ops.on.std=true;S.ops.floor=0;S.ops.cap.std=OPS_CAPS[0]");
|
||||
// A $10k month: Amsterdam's $12k swap never fits it; Frankfurt and Paris do.
|
||||
const c0 = ev('S.cash');
|
||||
ev('opsDay(S.day)');
|
||||
assert.deepEqual(swapping(ev), ['fra', 'par']);
|
||||
assert.equal(ev('S.ops.spent.std'), COST.fra + COST.par, 'the whole swaps count against the month');
|
||||
assert.equal(ev('S.cash'), c0, 'and are paid as the routers go in');
|
||||
const e = J(ev, 'S.ops.log[0]');
|
||||
assert.equal(e.up, undefined, 'nothing paid up front');
|
||||
assert.ok(e.r.some(x => x[0] === 'broke'), 'Amsterdam waits for the budget');
|
||||
assert.match(ev('opsLine(S.ops.log[0])'), /did 2 jobs for the build standard \(Frankfurt IPv6, Paris IPv6\)/);
|
||||
assert.equal(ev('S.ops.log[0].r.find(x=>x[0]===\'std\')[2].every(opsWhereOk)'), true, 'the log survives a save');
|
||||
// No budget, a $50k floor and $15k above it: Amsterdam starts; Frankfurt does not fit on top of what Amsterdam owes,
|
||||
// Paris does.
|
||||
ev("for(const c of ['fra','par']){delete S.pops[c].bb.v6e;delete S.pops[c].bb.v6;}S.ops.cap.std=0;S.ops.floor=50000;S.cash=50000+15000;S.day++;compute();opsDay(S.day)");
|
||||
assert.deepEqual(swapping(ev), ['ams', 'par']);
|
||||
assert.equal(ev('S.cash'), 65000);
|
||||
// Paid down, the next shift starts Frankfurt.
|
||||
ev('for(let i=0;i<60;i++){S.day++;ip4Day(S.day);}S.cash=1e6;compute();opsDay(S.day)');
|
||||
assert.deepEqual(swapping(ev), ['fra']);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('only while IPv4 is scarce: no row, no jobs and no count in the gentler rules; saves keep the target', (t) => {
|
||||
const { ev, dom, errors } = game(t);
|
||||
std(ev, { v6: true });
|
||||
ev("S.rules=makeRules('freeze');compute()");
|
||||
assert.equal(ev('ip4On()'), false);
|
||||
assert.deepEqual(v6(ev), []);
|
||||
assert.equal(ev('bstdLine(bstd())'), 'None');
|
||||
ev('ACT.bstdOpen()');
|
||||
const sel = [...dom.window.document.querySelectorAll('#modalCard select[data-chg="bstdSet"]')].map(s => JSON.parse(s.dataset.args).k);
|
||||
assert.ok(sel.length > 0 && !sel.includes('v6'), 'no IPv6-only list');
|
||||
assert.doesNotMatch(dom.window.document.getElementById('modalCard').textContent, /IPv6/);
|
||||
// The target stays in the standard: back on scarce IPv4 it is there again.
|
||||
ev("closeModal();S.rules=makeRules('oncall');compute()");
|
||||
assert.deepEqual(v6(ev).map(x => x[0]), ['ams', 'fra', 'par']);
|
||||
// Saves: the target round-trips; an old standard has none; junk is no target.
|
||||
const rt = d => J(ev, `(()=>{const s={popStd:${lit(d)}};popStdSanitize(s);return s.popStd;})()`);
|
||||
assert.deepEqual(rt({ rt: 1, v6: true }), { rt: 1, v6: true });
|
||||
assert.deepEqual(rt({ g: 1, rt: 2 }), { g: 1, rt: 2 });
|
||||
assert.equal(rt({ rt: 1, v6: 'yes' }), null);
|
||||
assert.deepEqual(J(ev, 'migrate(JSON.parse(JSON.stringify(S))).popStd'), { rt: 1, v6: true });
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the sheet at 360 px, portrait and landscape, in every language: the row, its note and what is below it', () => {
|
||||
for (const lang of ['en', 'de', 'es', 'fr', 'it', 'pt']) {
|
||||
const { ev, dom, errors } = load(lang === 'en' ? {} : { lang });
|
||||
ev(BASE);
|
||||
const doc = dom.window.document;
|
||||
for (const [w, hgt] of [[360, 740], [740, 360]]) {
|
||||
ev(`window.innerWidth=${w};window.innerHeight=${hgt};S.popStd=null;closeModal();ACT.bstdOpen()`);
|
||||
assert.equal(ev('isPhone()'), true, lang);
|
||||
const sel = () => [...doc.querySelectorAll('#modalCard select[data-chg="bstdSet"]')].find(s => JSON.parse(s.dataset.args).k === 'v6');
|
||||
let s = sel();
|
||||
assert.ok(s && s.closest('.ops-sel'), lang + ': two to a row with the other POP targets');
|
||||
s.value = String(s.options.length - 1);
|
||||
s.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
||||
assert.equal(ev('bstd().v6'), true, lang);
|
||||
assert.ok(ev('bstdShown()'), lang);
|
||||
s = sel();
|
||||
assert.equal(s.options[s.selectedIndex].textContent, ev("tr('bstd.every_bb_city')"), lang);
|
||||
const txt = doc.getElementById('modalCard').textContent;
|
||||
assert.ok(txt.includes(ev("tr('bstd.v6_note')")), lang + ': the note');
|
||||
assert.ok(txt.includes(ev(`fmt$(${COST.ams + COST.fra + COST.par})`)), lang + ': the bill');
|
||||
assert.doesNotMatch(txt, /\b(bstd|ops|pop_std|common|ip6)\.[a-z_0-9]+/, lang + ': a raw label');
|
||||
assert.doesNotMatch(txt, /\{[a-z]\w*\}|undefined|NaN/, lang);
|
||||
for (const b of doc.querySelectorAll('#modalCard button.b')) assert.ok(b.closest('.btns') || b.closest('.ops-h'), lang + ': ' + b.textContent);
|
||||
}
|
||||
// The city panel's line counts it.
|
||||
ev("closeModal();selectCity('fra');ACT.tab({t:'links'})");
|
||||
assert.ok(doc.getElementById('panelBody').textContent.includes(ev("trn('bstd.n_more_targets',1)")), lang);
|
||||
assert.deepEqual(errors, [], lang);
|
||||
dom.window.close();
|
||||
}
|
||||
});
|
||||
|
|
@ -480,8 +480,9 @@ test('the sheet at 360 px in every language: every list works by changing it, fr
|
|||
doc.querySelector('#modalCard [data-act="bstdOpen"]').click();
|
||||
assert.ok(ev('bstdShown()'), lang + ': from the menu');
|
||||
leaks();
|
||||
// Every target is a list; pick its last value and the standard follows, the sheet stays open and in focus.
|
||||
const keys = JSON.parse(ev('JSON.stringify(BSTD.map(x=>x.k))'));
|
||||
// Every target is a list; pick its last value and the standard follows, the sheet stays open and in focus. (IPv6-only
|
||||
// broadband is a target only while IPv4 is scarce, not in Change Freeze: tests/bstd-ipv6-only.test.js.)
|
||||
const keys = JSON.parse(ev('JSON.stringify(BSTD.filter(bstdOn).map(x=>x.k))'));
|
||||
assert.equal(doc.querySelectorAll('#modalCard select[data-chg="bstdSet"]').length, keys.length);
|
||||
for (const k of keys) {
|
||||
const s = [...doc.querySelectorAll('#modalCard select[data-chg="bstdSet"]')].find(x => JSON.parse(x.dataset.args).k === k);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue