seriesoftubes/tests/pop-kinds-build-standard.test.js
jvanvik 08eb349d87
Some checks are pending
CI / plan (push) Waiting to run
CI / part (push) Blocked by required conditions
CI / build (push) Waiting to run
CI / translations (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / timings (push) Blocked by required conditions
Container image / gate (push) Waiting to run
Container image / test (push) Blocked by required conditions
Container image / publish (push) Blocked by required conditions
Merge upstream: POP standards, latency contracts, device transfer, typed links and NOC downgrades (3.4.0, 3.5.0)
Conflicts, file by file:
- CHANGELOG.md: the fork's Unreleased bullets on top; 3.5.0 and 3.4.0 exactly as upstream has them.
- src/i18n/en.js, site/i18n/{de,es,fr,it,pt}.js: merged label by label, sorted; the labels each side dropped stay dropped.
- src/agent/10-domains.js, 30-docs.js, 40-read.js: both sides' enums, state docs and tables (popStd as the build standard, popTiers, ip4, mp).
- src/agent/20-commands.js: the fork's wording on accept and upRouter, upstream's acceptFix, utilityKitAll/New and pt*; theme, session and transfer acts in the local table.
- src/game/60-features/80-new-game.js: ip4, rgen and mp next to popTiers.
- src/game/80-simulation/29-route-core.js, 30-compute.js: the route core takes both SATN and the spill tiers (TT).
- src/game/80-simulation/40-billing.js: upstream's gulfPair and borderShut; linkCut() is built on borderShut, linkDown() keeps express and satellite.
- src/game/80-simulation/50-sanitize.js: PNI bundles up to PNI_LAG_MAX next to the fork's link kinds; popStdSanitize then ptSanitize; mpSanitize then lcSanitize.
- src/game/80-simulation/75-customer-lifecycle.js: clGrow() stops at a type's most (#137) and at an IPv4 block that is not free (#150).
- src/game/90-actions/60-links.js: rmLink keeps the express guard and moves on to the next parallel link (#119).
- src/game/90-actions/85-routing-and-routers.js: rmRouter checks the PNIs on its routers (#323), upRouter keeps own().
- src/game/90-actions/89-game-and-settings.js: the menu keeps the build standard and session tiles and gains Send to another device.
- src/game/93-ui/40-hud-and-panels.js, 70-link-panels.js: offers show both the IPv4 note and Buy and sign; link headers name their cities, the closed-border section reads in dark mode; the express count stays.
- src/game/93-ui/50-city-panel.js: the teleport section and Link to a city.
- src/game/94-dashboard/40-connections.js: upstream's per-table next port size replaces the fork's own 400G guard.
- src/game/94-dashboard/90-noc-window.js, 96-map/95-clicks.js, 99-loop.js: both sides' acts and boot steps.
- src/styles/40-modal.css: the dark-mode tag tokens and the transfer textarea.
- tests/mcp-commands.test.js: both sides' sample args.

Interaction fixes:
- POP standards and the build standard: a POP marked as a kind keeps its kind's routers (ptKind). The build
  standard's router jobs and the intern's model swaps leave it alone; every other target still applies. Both sheets say so.
- Spill tiers: pathMs() fills a path's ground latency and satellite edges too, so a tier's detour costs users its
  latency (it went uncharged before).
- Send to another device: a session network goes by the session's own #mp= link; its save file is called a copy.
- Buy and sign (#241) does not buy for an offer whose IPv4 block does not fit.
- Dark mode: the closed-border title and the renewal ticks use the dark-aware red (upstream's #292 test follows).
- Server-run tables: the new acts classified (pt*, acceptFix and utilityKitAll quote their cost); mp-sim fixtures
  written again with tests/lib/mp-sim-fixtures.js.

Review fixes:
- POP standards: ptSave, ptApply, ptPlan, ptAll and popStdSet find a POP with own(), so 'toString' is no POP (also
  decomToggle, decomGo, dkStay).
- Server-run envelope: an arg value that names anything on Object.prototype is refused, in args, drafts and
  ctx.win.ui.
- Decommissioning a POP drops its POP-standard mark, so live state stays what a reload makes of it (the T2 gate
  refused later pt* acts).
- acceptFix, ptApply, ptAll and utilityKitAll take a quote within 1% (quoteNear), like utilityKit and bstdApply:
  router prices drift daily.
- The transfer paste box reads in dark mode (--text, as input.t).
- A session's #mp= link pasted under From another device opens it (saved, then loaded again with it), in MP builds.
- The express and satellite circuit panels name their cities as links (#196); a circuit shows the closed-border
  section (#329).
- CHANGELOG: the fork's 400G connections bullet goes (3.5.0 ships it); bullets for POP kinds, the session link and Buy
  and sign's IPv4 check.
2026-11-12 00:52:42 +01:00

109 lines
7.5 KiB
JavaScript

// POP standards by kind (#315: micro, medium, regional hub) next to the build standard (96-pop-standard.js): a POP the
// player marked as a kind keeps that kind's routers, so the build standard's router row, its button and the intern never
// pull its routers another way. Every other target of the build standard still applies to it, and every unmarked POP
// follows the build standard's routers as before. Both only ever add or swap up: neither takes a router out.
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
// Frankfurt (busy, broadband, two routers), Amsterdam and Paris (empty), all on the Edge Lord, level 7, Change Freeze.
const BASE = "ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;S.lvl=7;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');" +
"ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});for(const c of ['ams','par'])ACT.buildPop({city:c});" +
"for(const c of ['fra','ams','par']){S.pops[c].rgen=1;S.pops[c].routers=2;}compute()";
const AU = "RG.findIndex(r=>r.n==='Absolute Unit 3.2T')";
function game(t) {
const h = load();
t.after(() => h.dom.window.close());
h.ev(BASE);
return h;
}
const J = (ev, x) => JSON.parse(ev(`JSON.stringify(${x})`));
const routers = (ev) => J(ev, "['fra','ams','par'].map(c=>[S.pops[c].rgen,S.pops[c].routers])");
const jobs = (ev, c) => J(ev, `bstdPlan(false).filter(j=>j.c==='${c}').map(j=>j.k)`);
test('a POP marked as a kind keeps its kind\'s routers: the build standard\'s plan, button and intern leave them alone', t => {
const { ev, errors } = game(t);
const au = ev(AU);
// Amsterdam is a micro POP: two Edge Lords. The build standard wants four Absolute Units and a generator everywhere.
ev("ACT.ptSave({city:'ams',k:'micro'})");
assert.deepEqual(J(ev, 'S.popTiers.def.micro'), { g: 1, rt: 2 });
assert.equal(ev("ptKind('ams')"), 'micro');
assert.equal(ev("ptKind('par')"), null, 'an unmarked POP has no kind');
ev(`S.popStd=bstdPut({...bstd(),g:${au},rt:4,gen:true});compute()`);
assert.deepEqual(jobs(ev, 'ams'), ['gen'], 'only the generator: its routers are the micro standard\'s');
assert.ok(jobs(ev, 'par').includes('g') && jobs(ev, 'par').filter((k) => k === 'rt').length === 2, 'an unmarked POP gets the model and two more routers');
// The button brings the rest up and leaves Amsterdam's routers as they are.
const q = J(ev, 'bstdQuote(false)');
ev(`ACT.bstdApply({quote:bstdPlanKey(bstdPlan(false)),q:${q.cost}})`);
assert.deepEqual(routers(ev), [[au, 4], [1, 2], [au, 4]]);
assert.equal(ev('S.pops.ams.gen'), true, 'the build standard\'s other targets still apply to it');
assert.deepEqual(jobs(ev, 'ams'), [], 'nothing left below the standard there');
// The intern's routers order, standardizing on the build standard's model: Amsterdam is not swapped either.
ev("S.pops.par.rgen=1;S.pops.par.rupDay=-1;ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();S.ops.on.routers=true;S.ops.p.routers={at:90,how:'auto'};S.ops.cap.routers=0;S.day++;compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0;opsDay(S.day)");
assert.deepEqual(routers(ev).map((r) => r[0]), [au, 1, au], 'Paris is swapped back up to the standard\'s model, Amsterdam keeps the micro model');
// The kind's own button still works: a medium standard of three Absolute Units, Amsterdam marked as medium.
ev(`S.popTiers.def.medium={g:${au},rt:3};S.day++;compute()`);
const pq = J(ev, "ptPlan('ams','medium')");
assert.deepEqual(pq.steps, ['swap', 'add'], 'swap up, then one more router');
ev(`ACT.ptApply({city:'ams',k:'medium',cost:${pq.cost}})`);
assert.deepEqual(routers(ev)[1], [au, 3]);
assert.equal(ev("ptKind('ams')"), 'medium');
assert.deepEqual(jobs(ev, 'ams'), [], 'three routers is not below the build standard\'s four there: the kind owns them');
// Neither ever steps down: a kind below the build standard leaves an unmarked POP that has more as it is.
ev("S.popTiers.def.micro={g:1,rt:1};S.popTiers.at.par='micro'");
assert.equal(ev("ptPlan('par','micro')"), null, 'a smaller kind is no plan at all');
assert.deepEqual(errors, []);
});
test('the build standard sheet and a POP\'s panel say who owns the routers, at 360 px', t => {
const { ev, dom, errors } = game(t);
const au = ev(AU);
ev(`ACT.ptSave({city:'ams',k:'hub'});S.popStd=bstdPut({...bstd(),g:${au}});compute()`);
ev('innerWidth=360;ACT.bstdOpen({})');
assert.match(dom.window.document.getElementById('modalCard').textContent, /A POP marked as a kind in POP standards keeps that kind's routers/);
ev("closeModal();selectCity('ams');UI.tab='infra';renderPanel()");
const body = dom.window.document.getElementById('panelBody').textContent;
assert.match(body, /This POP: Regional hub/);
assert.match(body, /keeps that kind's routers/);
// No build standard routers: no note in the panel.
ev("S.popStd=null;renderPanel()");
assert.doesNotMatch(dom.window.document.getElementById('panelBody').textContent, /keeps that kind's routers/);
// Old saves: no popTiers at all, or junk in it, load as no kinds.
ev('S=migrate(JSON.parse(JSON.stringify({...S,popTiers:undefined})));compute()');
assert.deepEqual(J(ev, 'S.popTiers'), { def: { micro: null, medium: null, hub: null }, at: {} });
ev("S=migrate(JSON.parse(JSON.stringify({...S,popTiers:{def:{hub:{g:'x'}},at:{ams:'hub',nowhere:'micro',par:'giant'}}})));compute()");
assert.equal(ev("ptKind('ams')"), null, 'a kind without a valid standard owns nothing');
assert.deepEqual(errors, []);
});
test('a decommissioned POP loses its mark, as a reload would: a POP built there again has no kind', t => {
const { ev, errors } = game(t);
const au = ev(AU);
ev("ACT.ptSave({city:'ams',k:'micro'});ACT.ptApply({city:'par',k:'micro',cost:0})");
assert.deepEqual(J(ev, 'S.popTiers.at'), { ams: 'micro', par: 'micro' });
ev("UI.decom=['ams'];ACT.decomGo()");
assert.equal(ev('!!S.pops.ams'), false);
assert.deepEqual(J(ev, 'S.popTiers.at'), { par: 'micro' }, 'the mark goes with the POP');
// The live state is what a reload makes of it (the server-run gate refuses every later act that touches it otherwise).
assert.equal(ev('JSON.stringify(migrate(JSON.parse(JSON.stringify(packSave(S)))).popTiers)'), ev('JSON.stringify(S.popTiers)'));
// Built again in the same session: an unmarked POP, which the build standard's routers reach.
ev(`ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;S.pops.ams.routers=1;S.popStd=bstdPut({...bstd(),g:${au},rt:4});compute()`);
assert.equal(ev("ptKind('ams')"), null);
assert.ok(jobs(ev, 'ams').includes('g'), 'the build standard swaps its model');
assert.deepEqual(errors, []);
});
test('a name every object has (toString, valueOf) is no POP: the kinds and the build standard stay as they were', t => {
const { ev, errors } = game(t);
const au = ev(AU);
ev(`ACT.ptSave({city:'ams',k:'micro'});S.pops.par.gen=true;ACT.popStdSet({city:'par'});S.popStd=bstdPut({...bstd(),g:${au},rt:3});compute()`);
const tiers = ev('JSON.stringify(S.popTiers)'), std = ev('JSON.stringify(S.popStd)'), cash = ev('S.cash');
for (const c of ['toString', 'valueOf', 'hasOwnProperty', 'constructor']) {
ev(`ACT.ptSave({city:'${c}',k:'micro'});ACT.ptApply({city:'${c}',k:'micro',cost:0});ACT.popStdSet({city:'${c}'});closeModal()`);
assert.equal(ev('JSON.stringify(S.popTiers)'), tiers, `ptSave and ptApply on '${c}'`);
assert.equal(ev('JSON.stringify(S.popStd)'), std, `popStdSet on '${c}'`);
assert.equal(ev(`ptPlan('${c}','micro')`), null);
}
assert.equal(ev('S.cash'), cash);
assert.deepEqual(errors, []);
});