Merge upstream: POP standards, latency contracts, device transfer, typed links and NOC downgrades (3.4.0, 3.5.0)
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
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
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.
This commit is contained in:
commit
08eb349d87
113 changed files with 2674 additions and 161 deletions
|
|
@ -1,12 +1,16 @@
|
|||
// A click's args name things the game looks up by key: S.pops[city], S.myIx[city]. A city that is '__proto__' or
|
||||
// 'constructor' (an MCP agent's, or a request to a server-run network) must find nothing there, never a prototype or a
|
||||
// built-in's statics: every action that takes one, with each such name in each usual arg, leaves the page's built-ins
|
||||
// as they were and spends nothing on them.
|
||||
// 'constructor', or any other name Object.prototype has ('toString': S.pops.toString is a function, so it reads as a
|
||||
// POP), from an MCP agent or a request to a server-run network, must find nothing there, never a prototype or a
|
||||
// built-in's statics: every action that takes one, with each such name in each usual arg, alone and next to the args
|
||||
// that get an action that far (a kind, a quoted price), leaves the page's built-ins as they were, spends nothing on
|
||||
// them, and writes no entry under that name anywhere in the game (S.popTiers.at.toString).
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const BAD = ['__proto__', 'constructor', 'prototype'];
|
||||
const BAD = ['__proto__', 'constructor', 'prototype', 'toString', 'hasOwnProperty', 'valueOf'];
|
||||
// The other args an action may need before it looks the name up: ptSave a kind, ptApply a kind and a price.
|
||||
const WITH = { k: 'micro', cost: 0 };
|
||||
const ARGS = ['city', 'id', 'net', 'k', 'c', 'v', 'a', 'b', 'to', 'from', 'link', 's'];
|
||||
|
||||
test('no action reaches a built-in through an arg that names one', (t) => {
|
||||
|
|
@ -19,19 +23,22 @@ test('no action reaches a built-in through an arg that names one', (t) => {
|
|||
// What the built-ins hold now: anything an action adds to them is found by name.
|
||||
ev(`window.__fp=()=>{const o={};for(const [n,x] of [['Object',Object],['Object.prototype',Object.prototype],['Array',Array],['Array.prototype',Array.prototype],['Function.prototype',Function.prototype],['String.prototype',String.prototype]])o[n]=Object.getOwnPropertyNames(x).sort().join(',');
|
||||
const e=[];for(const k in {})e.push(k);for(const k in [])e.push('[]'+k);o.enum=e.join(',');return o;};window.__fp0=__fp();
|
||||
window.__clean=()=>{for(const [n,x] of [['Object',Object],['Object.prototype',Object.prototype],['Array',Array],['Array.prototype',Array.prototype],['Function.prototype',Function.prototype],['String.prototype',String.prototype]]){const had=new Set(__fp0[n].split(','));for(const k of Object.getOwnPropertyNames(x))if(!had.has(k))delete x[k];}};`);
|
||||
window.__clean=()=>{for(const [n,x] of [['Object',Object],['Object.prototype',Object.prototype],['Array',Array],['Array.prototype',Array.prototype],['Function.prototype',Function.prototype],['String.prototype',String.prototype]]){const had=new Set(__fp0[n].split(','));for(const k of Object.getOwnPropertyNames(x))if(!had.has(k))delete x[k];}};
|
||||
window.__junk=(v)=>{const out=[],walk=(o,p,d)=>{if(!o||typeof o!=='object'||d>4)return;if(Object.prototype.hasOwnProperty.call(o,v)){out.push(p+'.'+v);delete o[v];}for(const k of Object.keys(o))walk(o[k],p+'.'+k,d+1);};walk(S,'S',0);return out;};`);
|
||||
const acts = JSON.parse(ev('JSON.stringify(Object.keys(API_CMD).filter(k=>typeof ACT[k]==="function"&&!/^pz[A-Z]/.test(k)))'));
|
||||
const hits = [];
|
||||
for (const act of acts) {
|
||||
for (const name of ARGS) {
|
||||
for (const v of BAD) {
|
||||
const r = JSON.parse(ev(`(()=>{const c0=S.cash;let err=null;try{ACT[${JSON.stringify(act)}]({[${JSON.stringify(name)}]:${JSON.stringify(v)}});}catch(e){err=String(e&&e.message||e);}
|
||||
try{closeModal();}catch(e){}UI.confirm=null;const f=__fp(),d=Object.keys(f).filter(k=>f[k]!==__fp0[k]);if(d.length)__clean();return JSON.stringify({d,spent:c0-S.cash,err});})()`));
|
||||
if (r.d.length) hits.push(`${act}({${name}:'${v}'}) changed ${r.d.join(', ')}${r.spent > 0 ? ` and spent ${r.spent}` : ''}`);
|
||||
for (const v of BAD) for (const extra of [{}, WITH]) {
|
||||
const args = { ...extra, [name]: v };
|
||||
const r = JSON.parse(ev(`(()=>{const c0=S.cash;let err=null;try{ACT[${JSON.stringify(act)}](${JSON.stringify(args)});}catch(e){err=String(e&&e.message||e);}
|
||||
try{closeModal();}catch(e){}UI.confirm=null;const f=__fp(),d=Object.keys(f).filter(k=>f[k]!==__fp0[k]);if(d.length)__clean();return JSON.stringify({d,spent:c0-S.cash,err,junk:__junk(${JSON.stringify(v)})});})()`));
|
||||
if (r.d.length) hits.push(`${act}(${JSON.stringify(args)}) changed ${r.d.join(', ')}${r.spent > 0 ? ` and spent ${r.spent}` : ''}`);
|
||||
if (r.junk.length) hits.push(`${act}(${JSON.stringify(args)}) wrote ${r.junk.join(', ')}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
t.diagnostic(`${acts.length} actions × ${ARGS.length} args × ${BAD.length} names`);
|
||||
t.diagnostic(`${acts.length} actions × ${ARGS.length} args × ${BAD.length} names × 2`);
|
||||
assert.deepEqual(hits, []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -474,3 +474,23 @@ test('no raw labels in the address space, in every language', (t) => {
|
|||
dom.window.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('buying what an offer asks for on signing (#241) buys nothing when its IPv4 block does not fit', (t) => {
|
||||
const { ev, errors } = game(t);
|
||||
homes(ev, 50);
|
||||
ev("S.pops.fra.gen=false;S.offers.push({id:'big',city:'fra',name:'Pixel Palace',type:'cgame',bw:3200,rate:45,reqs:['gen'],exp:S.day+30});compute()");
|
||||
assert.equal(ev("ip4Fits(S.offers[0])"), false);
|
||||
assert.equal(ev("reqFix(S.offers[0]).cost"), ev('GEN_COST'), 'the generator is what it lacks');
|
||||
assert.equal(ev("reqFixHtml(S.offers[0])"), '', 'no "Buy and sign" button for a deal that cannot be signed');
|
||||
const c0 = ev('S.cash');
|
||||
ev("ACT.acceptFix({id:'big',cost:GEN_COST})");
|
||||
assert.equal(ev('S.cash'), c0, 'nothing spent');
|
||||
assert.equal(ev('S.pops.fra.gen'), false, 'no generator bought for it');
|
||||
assert.equal(ev('S.biz.length'), 0);
|
||||
// A block that makes it fit brings the button back, and the click buys and signs.
|
||||
ev("ACT.ip4Buy({len:21});renderAll()");
|
||||
assert.notEqual(ev("reqFixHtml(S.offers[0])"), '');
|
||||
ev("ACT.acceptFix({id:'big',cost:GEN_COST})");
|
||||
assert.deepEqual([ev('S.pops.fra.gen'), ev('S.biz.length')], [true, 1]);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
53
tests/border-closed-links.test.js
Normal file
53
tests/border-closed-links.test.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// #329: a link a political event takes down (the Gulf spat, Russia's sovereign internet drill) is drawn broken on
|
||||
// the map, so its panel must say why and for how long, and the link modal must warn before you lease one.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const start = "ACT.start({});S.cash=1e9;S.lvl=13;S.nextFail=S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;";
|
||||
const panel = ev => ev("document.getElementById('panel').textContent");
|
||||
|
||||
test('#329 a link down for the Gulf spat says so in its panel, with the days left', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + "ACT.launchBB({city:'doh'});S.pops.auh={day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:3};compute()");
|
||||
ev("S.links.push({id:'w1',a:'doh',b:'auh',kind:'wave',tier:0,km:300,sub:false,mo:1,cut:0,day:0})");
|
||||
const id = 'w1';
|
||||
ev('S.ev.gulf=S.day+40;compute()');
|
||||
assert.equal(ev(`linkDown(S.links.find(l=>l.id==='${id}'))`), true, 'the spat takes it down');
|
||||
ev(`selectLink('${id}')`);
|
||||
assert.match(panel(ev), /Border closed/);
|
||||
assert.match(panel(ev), /Qatar/);
|
||||
assert.match(panel(ev), /Back in 40 days/);
|
||||
// Leasing another one now warns that it stays dark.
|
||||
ev("openLinkModal('doh','auh')");
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /stay dark/);
|
||||
assert.match(ev("dfModalBody('doh','auh',300,0)"), /stay dark/, 'dark fiber warns too');
|
||||
// On a phone the panel is a bottom sheet with the same note.
|
||||
ev(`closeModal();window.innerWidth=390;selectLink('${id}')`);
|
||||
assert.match(panel(ev), /Border closed/);
|
||||
ev('window.innerWidth=1280');
|
||||
// After the spat, nothing about it.
|
||||
ev('S.ev.gulf=0;compute();closeModal()');
|
||||
ev(`selectLink('${id}')`);
|
||||
assert.doesNotMatch(panel(ev), /Border closed/);
|
||||
ev("openLinkModal('doh','auh')");
|
||||
assert.doesNotMatch(ev("document.getElementById('modalCard').textContent"), /stay dark/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#329 dark fiber and virtual circuits into Qatar explain the spat too, and Russia\'s drill is named', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + "ACT.launchBB({city:'doh'});S.pops.auh={day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:3};compute()");
|
||||
ev("S.links.push({id:'dfx',a:'doh',b:'auh',kind:'df',own:false,sys:'lite',ch:[],km:300,sub:false,mo:1,ready:0,cut:0,day:0});S.ev.gulf=S.day+10");
|
||||
ev("selectLink('dfx')");
|
||||
assert.match(panel(ev), /Border closed/);
|
||||
ev("S.links.push({id:'vx1',a:'doh',b:'auh',kind:'vxc',prov:Object.keys(FAB)[0],vt:0,km:300,sub:false,mo:1,cut:0,day:0})");
|
||||
ev("selectLink('vx1')");
|
||||
assert.match(panel(ev), /Border closed/);
|
||||
assert.match(panel(ev), /Qatar/);
|
||||
ev("S.links.push({id:'ru1',a:'mos',b:'hel',kind:'wave',tier:0,km:900,sub:false,mo:1,cut:0,day:0});S.ev.gulf=0;S.ev.runet=S.day+1");
|
||||
ev("selectLink('ru1')");
|
||||
assert.match(panel(ev), /Border closed/);
|
||||
assert.match(panel(ev), /Russia/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
261
tests/bulk-actions.test.js
Normal file
261
tests/bulk-actions.test.js
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
// Late-game busywork: one policy or one button instead of many clicks, never a decision taken away.
|
||||
// #316 the intern can leave new fiber dark, #119 the link panel stays open on a sibling, #317 the kit at every POP,
|
||||
// #241 buy what a customer needs on signing, #315 POP standards by kind, #199 find a network at a POP.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
const { lit } = require('../scripts/lib/js-literal');
|
||||
|
||||
function setup(t, extra = '') {
|
||||
const h = load();
|
||||
t.after(() => h.dom.window.close());
|
||||
h.ev("ACT.start({});S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;S.nextFail=S.nextEvent=1e9;UI.speed=0;compute();" + extra);
|
||||
return h;
|
||||
}
|
||||
const doc = h => h.dom.window.document;
|
||||
const text = (h, sel) => [...doc(h).querySelectorAll(sel)].map(e => e.textContent).join('\n');
|
||||
const reload = ev => ev("save();S=migrate(JSON.parse(slotRaw(UI.slot)));compute()");
|
||||
|
||||
/* ---------- #316: new fiber stays dark when the player says so ---------- */
|
||||
const FIBER = "S.lvl=4;S.rules=makeRules('freeze');ACT.launchBB({city:'fra'});S.pops.fra.rgen=2;ACT.buildPop({city:'ams'});S.pops.ams.rgen=2;compute();" +
|
||||
"ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();" +
|
||||
"S.links.push({id:'f',a:'fra',b:'ams',kind:'df',sys:'roadm',ch:[],km:450,sub:false,ready:0,cut:0,mo:1,trench:'f'});compute();S.ops.on.optics=true;";
|
||||
const ch = ev => JSON.parse(ev("JSON.stringify(S.links.find(l=>l.id==='f').ch)"));
|
||||
|
||||
test('#316 by default the intern still lights new fiber, also in a save from before the switch', t => {
|
||||
const { ev, errors } = setup(t, FIBER);
|
||||
assert.equal(ev("opsP('optics','fresh')"), true);
|
||||
ev("S.ops.p.optics={}");
|
||||
reload(ev);
|
||||
assert.equal(ev("opsP('optics','fresh')"), true, 'an old save has no setting: the old behaviour');
|
||||
ev('opsDay(S.day)');
|
||||
assert.ok(ch(ev).length > 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#316 told not to, the intern leaves new fiber dark but still grows hot lit fiber', t => {
|
||||
const { ev, errors } = setup(t, FIBER);
|
||||
ev("ACT.opsOpen();ACT.opsParam({k:'optics',p:'fresh',v:1})");
|
||||
assert.equal(ev("opsP('optics','fresh')"), false);
|
||||
ev('opsDay(S.day)');
|
||||
assert.deepEqual(ch(ev), [], 'dark fiber stays dark');
|
||||
ev("S.links.find(l=>l.id==='f').ch=['zr8'];compute();R.load.f=dfCap(S.links.find(l=>l.id==='f'))*0.95;opsDay(S.day)");
|
||||
assert.ok(ch(ev).length > 1, 'a lit, hot fiber still gets more optics');
|
||||
reload(ev);
|
||||
assert.equal(ev("opsP('optics','fresh')"), false, 'the switch survives a reload');
|
||||
ev("S.ops.p.optics.fresh='maybe';S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
assert.equal(ev("opsP('optics','fresh')"), true, 'a bad value is repaired to the default');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#316 the switch is in the Ops sheet', t => {
|
||||
const h = setup(t, FIBER);
|
||||
h.ev('ACT.opsOpen()');
|
||||
assert.match(h.ev("document.getElementById('modalCard').textContent"), /Light new fiber/);
|
||||
assert.deepEqual(h.errors, []);
|
||||
});
|
||||
|
||||
/* ---------- #119: decommissioning one of several waves keeps the panel open ---------- */
|
||||
test('#119 the link panel moves on to the next parallel link, and closes after the last', t => {
|
||||
const h = setup(t, "ACT.buildPop({city:'ams'});" +
|
||||
"for(const id of ['w1','w2','w3'])S.links.push({id,a:'fra',b:'ams',kind:'wave',tier:0,km:450,sub:false,cut:0,mo:1000});compute();UI.sel={type:'link',id:'w1'};renderAll()");
|
||||
const { ev, errors } = h;
|
||||
ev("ACT.rmLink({id:'w1'});ACT.rmLink({id:'w1'})");
|
||||
assert.equal(ev("S.links.some(l=>l.id==='w1')"), false);
|
||||
assert.equal(ev('JSON.stringify(UI.sel)'), JSON.stringify({ type: 'link', id: 'w2' }));
|
||||
assert.equal(ev("document.getElementById('panel').hidden"), false, 'the panel is still open');
|
||||
ev("ACT.rmLink({id:'w2'});ACT.rmLink({id:'w2'})");
|
||||
assert.equal(ev('UI.sel.id'), 'w3');
|
||||
ev("ACT.rmLink({id:'w3'});ACT.rmLink({id:'w3'})");
|
||||
assert.equal(ev('UI.sel'), null, 'the last link closes it');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
/* ---------- #317: the redundancy kit at every POP ---------- */
|
||||
const POPS = "for(const c of ['ams','lon','par'])ACT.buildPop({city:c});compute();";
|
||||
test('#317 one button kits every POP, at the sum of the per-POP quotes', t => {
|
||||
const { ev, errors } = setup(t, POPS + 'S.lvl=2;');
|
||||
const q = JSON.parse(ev('JSON.stringify(utilityKitAll())'));
|
||||
assert.equal(q.cities.length, 4);
|
||||
assert.equal(q.cost, ev("Object.keys(S.pops).reduce((a,c)=>a+utilityKit(c).cost,0)"));
|
||||
ev("ACT.utilities({})");
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /Kit all 4 POPs/);
|
||||
const cash = ev('S.cash');
|
||||
ev(`ACT.utilityKitAll({cost:${Math.round(q.cost * 0.9)}})`);
|
||||
assert.equal(ev('S.cash'), cash, 'a stale quote buys nothing');
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /quote changed/);
|
||||
ev(`ACT.utilityKitAll({cost:${q.cost}})`);
|
||||
assert.equal(ev('S.cash'), cash - q.cost);
|
||||
assert.equal(ev("Object.values(S.pops).every(p=>p.gen&&p.site2&&p.routers>=2)"), true);
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /Every POP has the full kit/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#317 needs level 2, never spends what is not there, and can put the kit in the intern\'s template', t => {
|
||||
const { ev, errors } = setup(t, POPS);
|
||||
ev('S.lvl=1;ACT.utilities({})');
|
||||
assert.equal(ev('utilityKitAll()'), null);
|
||||
assert.doesNotMatch(ev("document.getElementById('modalCard').textContent"), /Redundancy kit everywhere/);
|
||||
ev('S.lvl=2;window.q=utilityKitAll().cost;S.cash=q-1;ACT.utilityKitAll({cost:q})');
|
||||
assert.equal(ev('S.cash'), ev('q-1'));
|
||||
assert.equal(ev("Object.values(S.pops).some(p=>p.gen)"), false);
|
||||
ev("S.cash=1e8;ACT.opsHire({id:'annie'});closeModal();S.ops.tpl.kit=false;ACT.utilities({})");
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /come without the kit/);
|
||||
ev('ACT.utilityKitNew({})');
|
||||
assert.equal(ev('S.ops.tpl.kit'), true);
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /get the kit too/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
/* ---------- #241: buy what the customer asks for, on signing ---------- */
|
||||
const OFFER = (reqs, extra = {}) => `ACT.buildPop({city:'ams'});S.offers.push(${lit({ id: 'o1', city: 'fra', city2: 'ams', name: 'Needy Corp', type: 'l2vpn', bw: 1, rate: 900, reqs, exp: 30, ...extra })});compute();`;
|
||||
test('#241 the offer shows what is missing with its price, and one button buys it and signs', t => {
|
||||
const h = setup(t, OFFER(['gen', 'routers']));
|
||||
const { ev, errors } = h;
|
||||
const q = JSON.parse(ev("JSON.stringify(reqFix(S.offers[0]))"));
|
||||
assert.deepEqual(q.items.map(x => x.k + '@' + x.city), ['gen@fra', 'gen@ams', 'routers@fra']);
|
||||
assert.equal(q.cost, ev("2*GEN_COST+routerCost(0,1)"));
|
||||
ev("UI.left='deals';UI.leftOpen=true;window.innerWidth=390;renderAll()");
|
||||
const card = text(h, '#left');
|
||||
assert.match(card, /Missing: a backup generator in Frankfurt, a backup generator in Amsterdam, a second router in Frankfurt/);
|
||||
assert.match(card, /Buy it and sign/);
|
||||
assert.ok(doc(h).querySelector('[data-act="acceptFix"]'), 'the button is there on a phone');
|
||||
const cash = ev('S.cash');
|
||||
ev(`ACT.acceptFix({id:'o1',cost:${q.cost}})`);
|
||||
assert.equal(ev('S.cash'), cash - q.cost);
|
||||
assert.equal(ev("S.pops.fra.gen&&S.pops.ams.gen&&S.pops.fra.routers===2"), true);
|
||||
assert.equal(ev("S.biz.some(b=>b.id==='o1')&&!S.offers.length"), true, 'signed');
|
||||
assert.equal(ev("reqOk(S.biz.find(b=>b.id==='o1'))"), true, 'and every requirement is met');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#241 never silent: a stale price, too little cash or a deal that cannot be signed buys nothing', t => {
|
||||
const { ev, errors } = setup(t, OFFER(['metro']));
|
||||
const cost = ev("reqFix(S.offers[0]).cost");
|
||||
assert.equal(cost, ev('2*SITE2_COST'));
|
||||
ev(`ACT.acceptFix({id:'o1',cost:${Math.round(cost * 0.9)}})`);
|
||||
assert.equal(ev("!!S.pops.fra.site2||S.biz.length>0"), false);
|
||||
ev(`S.cash=${cost - 1};ACT.acceptFix({id:'o1',cost:${cost}})`);
|
||||
assert.equal(ev("!!S.pops.fra.site2||S.biz.length>0"), false);
|
||||
ev(`S.cash=1e8;S.offers[0].city2='lon';ACT.acceptFix({id:'o1',cost:${cost}})`);
|
||||
assert.equal(ev("!!S.pops.fra.site2||S.biz.length>0"), false, 'no POP in London: nothing is bought');
|
||||
assert.equal(ev("reqFixHtml(S.offers[0])"), '');
|
||||
ev("S.offers[0].city2='ams';S.offers[0].reqs=['nocog']");
|
||||
assert.equal(ev("reqFix(S.offers[0])"), null, 'only hardware at a POP is offered');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
/* ---------- #315: POP standards by kind ---------- */
|
||||
test('#315 save a standard, bring a POP up to it, then every POP of that kind at once', t => {
|
||||
const h = setup(t, POPS + "S.lvl=4;S.pops.fra.routers=2;S.pops.fra.rgen=1;compute();");
|
||||
const { ev, errors } = h;
|
||||
ev("UI.sel={type:'city',id:'fra'};UI.tab='links';window.innerWidth=390;renderAll()");
|
||||
assert.match(text(h, '#panel'), /POP standards/);
|
||||
assert.match(text(h, '#panel'), /Regional hub/);
|
||||
ev("ACT.ptSave({city:'fra',k:'medium'})");
|
||||
assert.equal(ev("JSON.stringify(S.popTiers.def.medium)"), JSON.stringify({ g: 1, rt: 2 }));
|
||||
assert.equal(ev('S.popTiers.at.fra'), 'medium');
|
||||
const q = JSON.parse(ev("JSON.stringify(ptPlan('ams','medium'))"));
|
||||
assert.deepEqual(q.steps, ['swap', 'add'], 'an empty POP swaps first, then adds');
|
||||
const cash = ev('S.cash');
|
||||
ev(`ACT.ptApply({city:'ams',k:'medium',cost:${q.cost}})`);
|
||||
assert.equal(ev('S.cash'), cash - q.cost, 'charged exactly the quote');
|
||||
assert.equal(ev("S.pops.ams.routers===2&&S.pops.ams.rgen===1&&S.popTiers.at.ams==='medium'"), true);
|
||||
// The standard grows: one button brings both medium POPs up.
|
||||
ev("S.pops.fra.routers=3;S.pops.fra.rgen=2;S.pops.fra.rupDay=-1;ACT.ptSave({city:'fra',k:'medium'});S.pops.fra.routers=2;S.pops.fra.rgen=1;S.pops.ams.rupDay=-1;compute()");
|
||||
const A = JSON.parse(ev("JSON.stringify({n:ptAll('medium').todo.length,cost:ptAll('medium').cost})"));
|
||||
assert.equal(A.n, 2);
|
||||
ev('ACT.utilities({})');
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /Bring 2 POPs up/);
|
||||
ev(`ACT.ptAll({k:'medium',cost:${A.cost}})`);
|
||||
assert.equal(ev("['fra','ams'].every(c=>S.pops[c].routers===3&&S.pops[c].rgen===2)"), true);
|
||||
assert.equal(ev("ptAll('medium').todo.length"), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#315 a busy lone router gets its partner before the swap, and never a step down', t => {
|
||||
const { ev, errors } = setup(t, POPS + "S.lvl=4;ACT.launchBB({city:'ams'});S.popTiers.def.hub={g:2,rt:2};S.popTiers.def.micro={g:0,rt:1};compute();");
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(ptPlan('ams','hub').steps)")), ['add', 'swap']);
|
||||
ev("ACT.ptApply({city:'ams',k:'hub',cost:ptPlan('ams','hub').cost})");
|
||||
assert.equal(ev("S.pops.ams.routers===2&&S.pops.ams.rgen===2"), true);
|
||||
assert.equal(ev("S.inc.some(i=>i.type==='maint'&&i.ref==='ams')"), false, 'a rolling upgrade, no maintenance window');
|
||||
assert.equal(ev("ptPlan('ams','micro')"), null, 'a smaller standard asks for nothing');
|
||||
ev("ACT.ptApply({city:'ams',k:'micro',cost:0})");
|
||||
assert.equal(ev("S.pops.ams.rgen===2&&S.pops.ams.routers===2&&S.popTiers.at.ams==='micro'"), true, 'only marked');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#315 level 1 has no standards, and saves old and broken load', t => {
|
||||
const h = setup(t, POPS);
|
||||
const { ev, errors } = h;
|
||||
ev("UI.sel={type:'city',id:'fra'};UI.tab='links';renderAll()");
|
||||
assert.doesNotMatch(text(h, '#panel'), /POP standards/);
|
||||
ev("ACT.ptSave({city:'fra',k:'micro'})");
|
||||
assert.equal(ev('S.popTiers.def.micro'), null);
|
||||
ev('delete S.popTiers;S=migrate(JSON.parse(JSON.stringify(S)))');
|
||||
assert.equal(ev('JSON.stringify(S.popTiers)'), JSON.stringify({ def: { micro: null, medium: null, hub: null }, at: {} }));
|
||||
ev("S.popTiers={def:{micro:{g:999,rt:2},hub:{g:1,rt:99},bogus:{g:1,rt:1}},at:{fra:'hub',ams:'nope',xyz:'micro',ber:'hub'}};S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
assert.equal(ev('JSON.stringify(S.popTiers)'), JSON.stringify({ def: { micro: null, medium: null, hub: { g: 1, rt: ev('RMAX') } }, at: { fra: 'hub' } }));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
/* ---------- #199: find a network at a POP ---------- */
|
||||
test('#199 search and connected-only filter the transit, exchange and PNI lists, on a phone', t => {
|
||||
const h = setup(t, "S.lvl=4;ACT.buyTransit({city:'fra',net:'cog',tier:0});compute();window.innerWidth=390;UI.sel={type:'city',id:'fra'};UI.tab='up';renderAll()");
|
||||
const { ev, errors } = h;
|
||||
const rows = () => [...doc(h).querySelectorAll('#panel .row .nm')].map(e => e.textContent.trim());
|
||||
const all = rows().length;
|
||||
assert.ok(doc(h).getElementById('netQ'), 'the search box is there');
|
||||
ev("ACT.netOnly()");
|
||||
assert.equal(rows().length, 1);
|
||||
assert.match(rows()[0], /Cogentle/);
|
||||
ev("ACT.netClear()");
|
||||
assert.equal(rows().length, all);
|
||||
// Typing into the box filters as you go, and the box keeps focus and text.
|
||||
ev("const i=document.getElementById('netQ');i.focus();i.value='goggle';i.dispatchEvent(new window.Event('input',{bubbles:true}))");
|
||||
assert.equal(ev("document.activeElement.id"), 'netQ');
|
||||
assert.equal(ev("UI.netQ"), 'goggle');
|
||||
ev("UI.tab='peer';renderAll()");
|
||||
const peer = rows();
|
||||
assert.ok(peer.length > 0 && peer.every(r => /Goggle/.test(r)), peer.join(' | '));
|
||||
ev("ACT.netFind({q:'zzzz'})");
|
||||
assert.match(text(h, '#panel'), /No network here matches this filter/);
|
||||
ev("ACT.netFind({q:String(NET.ggl.asn)})");
|
||||
assert.match(text(h, '#panel'), /Goggle/, 'an AS number finds the network');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
/* ---------- a quote a day old: hardware prices drift, the plan does not ---------- */
|
||||
// Under the market rule router prices move a little every day. On a server-run network the days go on while a window is
|
||||
// open, so a price shown yesterday must still buy today when only that drift moved it (quoteNear: within 1%), as the
|
||||
// redundancy kit at one POP and the build standard already do. A price a whole part away is still refused (above).
|
||||
test('#315 #317 #241 a price shown the day before still buys, when only the day\'s hardware drift moved it', t => {
|
||||
const { ev, errors } = setup(t, "closeModal();S.rules=makeRules('oncall');S.cash=1e9;S.lvl=7;S.offers=[];ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});" +
|
||||
"for(const c of ['ams','par','ber','mad'])ACT.buildPop({city:c});for(const c of ['fra','ams','par','ber','mad']){S.pops[c].rgen=1;S.pops[c].routers=1;S.pops[c].gen=false;delete S.pops[c].site2;}" +
|
||||
"S.day=500;S.hw={};compute();");
|
||||
assert.equal(ev("rule('market')"), true);
|
||||
const day = (f) => { const shown = ev(f); ev('S.day++;compute()'); const now = ev(f); assert.notEqual(now, shown, `${f} drifted`); assert.ok(ev(`quoteNear(${shown},${now})`)); return shown; };
|
||||
// The redundancy kit everywhere (#317).
|
||||
let shown = day('utilityKitAll().cost'), c0 = ev('S.cash');
|
||||
ev(`ACT.utilityKitAll({cost:${shown},city:'ams'})`);
|
||||
assert.ok(c0 - ev('S.cash') > 0, 'the kit everywhere');
|
||||
assert.equal(ev("Object.values(S.pops).every(p=>p.gen&&p.site2&&p.routers>=2)"), true);
|
||||
ev('closeModal()');
|
||||
// A POP standard at one POP, then at every POP of the kind (#315).
|
||||
ev("S.popTiers.def.medium={g:2,rt:3};S.popTiers.at.mad='medium';S.popTiers.at.ber='medium';compute()");
|
||||
shown = day("ptPlan('par','medium').cost"); c0 = ev('S.cash');
|
||||
ev(`ACT.ptApply({city:'par',k:'medium',cost:${shown}})`);
|
||||
assert.ok(c0 - ev('S.cash') > 0 && ev('S.pops.par.rgen') === 2, 'one POP');
|
||||
ev('S.pops.par.rupDay=-1;');
|
||||
shown = day("ptAll('medium').cost"); c0 = ev('S.cash');
|
||||
ev(`ACT.ptAll({k:'medium',cost:${shown},city:'ber'})`);
|
||||
assert.ok(c0 - ev('S.cash') > 0, 'every POP of the kind');
|
||||
assert.equal(ev("ptAll('medium').todo.length"), 0);
|
||||
ev('closeModal()');
|
||||
// Buy what an offer asks for, and sign (#241): a second router.
|
||||
ev("S.pops.fra.routers=1;S.offers.push({id:'o1',city:'fra',name:'Pixel Palace',city2:'ams',type:'l2vpn',bw:1,rate:900,reqs:['routers'],exp:S.day+30});compute()");
|
||||
shown = day('reqFix(S.offers[0]).cost'); c0 = ev('S.cash');
|
||||
ev(`ACT.acceptFix({id:'o1',cost:${shown}})`);
|
||||
assert.ok(c0 - ev('S.cash') > 0 && ev("S.biz.some(b=>b.id==='o1')"), 'bought and signed');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
91
tests/city-picker.test.js
Normal file
91
tests/city-picker.test.js
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
// #343: on a crowded phone map, dragging from a POP to a city far away is fiddly. A POP's panel can open the city
|
||||
// finder in link mode: type the other end, pick it, and get the same link window the drag would have opened.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
const { lit } = require('../scripts/lib/js-literal');
|
||||
|
||||
const start = "ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.nextFail=1e9;S.nextEvent=1e9;S.cash=1e9";
|
||||
const home = ev => ev("Object.keys(S.pops)[0]");
|
||||
|
||||
test('#343 a POP panel has a Link to a city button that opens the finder in link mode', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start);
|
||||
const a = home(ev);
|
||||
ev(`UI.sel={type:'city',id:${lit(a)}};UI.tab='links';renderPanel()`);
|
||||
const doc = dom.window.document;
|
||||
const b = [...doc.querySelectorAll('#panelBody [data-act="findLink"]')];
|
||||
assert.equal(b.length, 1, 'one button in the fiber section');
|
||||
assert.match(b[0].textContent, /Link to a city/);
|
||||
b[0].click();
|
||||
assert.equal(ev("$('modal').hidden"), false);
|
||||
assert.equal(ev("$('modal').className"), 'find');
|
||||
assert.match(doc.getElementById('modalCard').textContent, new RegExp(`New link from ${ev(`CITY[${lit(a)}].name`)}`));
|
||||
// Rows open the link window, not the map jump.
|
||||
ev("$('findIn').value='sydney';$('findIn').dispatchEvent(new Event('input',{bubbles:true}))");
|
||||
const row = doc.querySelector('#findList .findrow');
|
||||
assert.equal(row.dataset.act, 'linkTo');
|
||||
assert.deepEqual(JSON.parse(row.dataset.args), { a, b: 'syd' });
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#343 picking a city opens the same link window as dragging there, and Enter picks the first match', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start);
|
||||
const a = home(ev), doc = dom.window.document;
|
||||
const b = a === 'syd' ? 'tyo' : 'syd';
|
||||
ev(`ACT.findLink({city:${lit(a)}})`);
|
||||
ev(`$('findIn').value=CITY[${lit(b)}].name;$('findIn').dispatchEvent(new Event('input',{bubbles:true}))`);
|
||||
doc.querySelector('#findList .findrow').click();
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(UI.pending)")), { a, b });
|
||||
const viaPicker = doc.getElementById('modalCard').textContent;
|
||||
assert.match(viaPicker, new RegExp(`${ev(`CITY[${lit(a)}].name`)} → ${ev(`CITY[${lit(b)}].name`)}`));
|
||||
ev(`closeModal();openLinkModal(${lit(a)},${lit(b)})`);
|
||||
assert.equal(doc.getElementById('modalCard').textContent, viaPicker, 'exactly what the drag opens');
|
||||
// Typing without accents and pressing Enter.
|
||||
ev(`closeModal();ACT.findLink({city:${lit(a)}});$('findIn').value='SAO PAULO'`);
|
||||
doc.getElementById('findIn').dispatchEvent(new dom.window.KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(UI.pending)")), { a, b: 'sao' });
|
||||
// The plain finder still jumps the map.
|
||||
ev("closeModal();ACT.findOpen()");
|
||||
assert.equal(ev("UI.findFrom"), null);
|
||||
ev("$('findIn').value='sydney';$('findIn').dispatchEvent(new Event('input',{bubbles:true}))");
|
||||
assert.equal(doc.querySelector('#findList .findrow').dataset.act, 'findGo');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#343 only cities a link could end in are offered: not the POP itself, not cities the map does not show', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
const a = home(ev);
|
||||
assert.equal(ev(`findCities(${lit(ev(`CITY[${lit(a)}].name`))},${lit(a)}).includes(${lit(a)})`), false, 'not itself');
|
||||
assert.equal(ev("cityOn('aju')"), false, 'Aracaju is off the map');
|
||||
assert.equal(ev(`findCities('aracaju',${lit(a)}).includes('aju')`), false);
|
||||
assert.equal(ev("findCities('aracaju').includes('aju')"), true, 'the plain finder still finds it');
|
||||
// An empty box lists your other POPs.
|
||||
ev("ACT.buildPop({city:'syd'})");
|
||||
assert.deepEqual(ev(`findCities('',${lit(a)}).join()`).split(',').filter(Boolean), ev(`Object.keys(S.pops).filter(c=>c!==${lit(a)}).sort((x,y)=>CITY[x].name.localeCompare(CITY[y].name)).join()`).split(',').filter(Boolean));
|
||||
// Typed orders that make no sense do nothing.
|
||||
ev(`ACT.linkTo({a:${lit(a)},b:${lit(a)}})`);
|
||||
assert.equal(ev("$('modal').hidden"), true);
|
||||
ev("ACT.linkTo({a:'atlantis',b:'syd'})");
|
||||
assert.equal(ev("$('modal').hidden"), true);
|
||||
ev(`ACT.linkTo({a:${lit(a)},b:'aju'})`);
|
||||
assert.equal(ev("$('modal').hidden"), true, 'a city off the map takes no link');
|
||||
ev("ACT.findLink({city:'aju'})");
|
||||
assert.equal(ev("$('modal').hidden"), true, 'no finder from a city without a POP');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#343 the link finder works on a phone, in German', () => {
|
||||
const { ev, dom, errors } = load({ lang: 'de' });
|
||||
ev(start + ";window.innerWidth=360");
|
||||
const a = home(ev);
|
||||
ev(`UI.sel={type:'city',id:${lit(a)}};UI.tab='links';renderPanel()`);
|
||||
const doc = dom.window.document;
|
||||
assert.match(doc.getElementById('panelBody').textContent, /Link zu einer Stadt/);
|
||||
ev(`ACT.findLink({city:${lit(a)}})`);
|
||||
assert.match(doc.getElementById('modalCard').textContent, /Neuer Link ab/);
|
||||
assert.ok(ev("findCities('deutschland'," + lit(a) + ").includes('fra')") || a === 'fra');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
45
tests/conference-quiet.test.js
Normal file
45
tests/conference-quiet.test.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// #101: once you have made Tier 1, conferences stop announcing themselves: no 30-day reminders, no report when one
|
||||
// happens, no note from the sales engineer who booked it. What they do is unchanged, and the Deals panel still lists them.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const setup = t1 => {
|
||||
const r = load();
|
||||
r.ev("ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'})");
|
||||
r.ev(t1 ? 'S.done.t1=1' : 'delete S.done.t1');
|
||||
// Record every notification the conference code raises (toasts land in the NOC log too, so this catches both).
|
||||
r.ev("window.__t=[];const __o=toast;toast=(h,...a)=>{__t.push(String(h));return __o(h,...a)}");
|
||||
return r;
|
||||
};
|
||||
// A non-capacity conference: the day 30 days before it, and the day itself.
|
||||
const CF = "CONFS.find(c=>!c.cap)";
|
||||
const run = (ev, reg) => ev(`(()=>{const cf=${CF},d=confDay(cf,0),k=confKey(cf,0);
|
||||
S.day=d-30;confTick(d-30);${reg ? "S.confReg[k]=true;" : ''}S.day=d;confTick(d);return JSON.stringify(window.__t)})()`);
|
||||
|
||||
test('#101 before Tier 1, conferences still remind you and report back', () => {
|
||||
const { ev, errors } = setup(false);
|
||||
const t = JSON.parse(run(ev, true));
|
||||
assert.ok(t.some(h => /comes to .* in 30 days/.test(h)), 'the 30-day reminder');
|
||||
assert.ok(t.some(h => /You shook a lot of hands/.test(h)), 'the report on the day');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#101 after Tier 1, conferences say nothing, but attending still works and the Deals panel still lists them', () => {
|
||||
const { ev, errors } = setup(true);
|
||||
const t = JSON.parse(run(ev, true));
|
||||
assert.deepEqual(t, [], 'no reminder and no report');
|
||||
assert.ok(ev('!!(S.conf&&S.conf.until>S.day)'), 'the conference still gave its glow');
|
||||
assert.ok(ev(`(()=>{S.day=confDay(${CF},1)-20;return /Attend/.test(confSection())})()`), 'still listed in Deals');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#101 after Tier 1, a sales engineer still books conferences, without telling you each time', () => {
|
||||
const { ev, errors } = setup(true);
|
||||
// Hand the desk an engineer and run the desk on the day 30 days before the next conference.
|
||||
const booked = ev(`(()=>{const cf=${CF},d=confDay(cf,1),k=confKey(cf,1);S.day=d-30;
|
||||
S.sales={p:'eng'};S.confReg={};salesDay(d-30);return !!S.confReg[k]})()`);
|
||||
assert.equal(booked, true, 'the booking still happens');
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(window.__t)')), []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -408,6 +408,25 @@ test('at night the market\'s Hot and Cool tags take the dark tints, and red text
|
|||
assert.equal(decl('.b.red', 'color'), '#fff');
|
||||
});
|
||||
|
||||
// --ink stays near-black at night: it is the outline and the text on bright fills (yellow buttons, warning tags). Text in
|
||||
// it on a card's own fill (--soft, --paper) all but vanishes in the dark look, as the transfer paste box's did (1.5:1):
|
||||
// such text takes --text, as input.t does.
|
||||
test('at night no text is --ink on a card\'s own fill: the transfer paste box reads (AA)', () => {
|
||||
const html = assemble().html, css = html.slice(html.indexOf('<style>'), html.indexOf('</style>')).replace(/\/\*[\s\S]*?\*\//g, '');
|
||||
const block = (sel) => { const i = css.indexOf(sel + '{'); return css.slice(i, css.indexOf('}', i)); };
|
||||
const dark = block(':root[data-theme="dark"]');
|
||||
const val = (b, k) => { const m = new RegExp(`--${k}:\\s*([^;\\n]+);`).exec(b); return m && m[1].trim(); };
|
||||
const rules = css.split('}').map((r) => { const i = r.indexOf('{'); return i < 0 ? null : { sel: r.slice(0, i).trim(), body: r.slice(i + 1) }; }).filter(Boolean);
|
||||
const prop = (b, p) => { const m = new RegExp(`(?:^|;)\\s*${p}\\s*:\\s*([^;]+)`).exec(b); return m && m[1].trim(); };
|
||||
const ink = rules.filter((r) => !r.sel.startsWith(':root') && /^var\(--(soft|paper)\)$/.test(prop(r.body, 'background') || '') && prop(r.body, 'color') === 'var(--ink)').map((r) => r.sel);
|
||||
assert.deepEqual(ink, [], '--ink text on --soft or --paper');
|
||||
const box = rules.find((r) => r.sel === 'textarea.xfer-in');
|
||||
assert.ok(box, 'the paste box has its rule');
|
||||
assert.equal(prop(box.body, 'color'), 'var(--text)');
|
||||
assert.equal(prop(box.body, '-webkit-text-fill-color'), 'var(--text)');
|
||||
assert.ok(cr(val(dark, 'text'), val(dark, 'soft')) >= 4.5, `--text on --soft: ${cr(val(dark, 'text'), val(dark, 'soft')).toFixed(2)}`);
|
||||
});
|
||||
|
||||
test('the dashboard\'s Demand key matches its dashed line, by night too', () => {
|
||||
const { dom, ev, errors } = load({ storage: { 'sot-theme': 'dark' } });
|
||||
ev(started + "for(let i=0;i<3;i++)dayTick();ACT.dash({});");
|
||||
|
|
|
|||
78
tests/dashboard-connections.test.js
Normal file
78
tests/dashboard-connections.test.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// #336: the NOC dashboard's connection list can shrink connections too (a smaller port, one LAG member fewer) and
|
||||
// chase a PNI that is on order, with the same buttons and rules as the POP panel.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// A transit LAG, a live PNI LAG, a PNI on order and an IX LAG, all in Frankfurt, set up directly so nothing is left to luck.
|
||||
const setup = () => {
|
||||
const r = load();
|
||||
r.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;S.offers=[];S.nextFail=S.nextEvent=1e6;if(!S.pops.fra)ACT.buildPop({city:'fra'})");
|
||||
r.ev(`(()=>{const free=NETS.filter(n=>n.type!=='t1'&&n.type!=='cdn'&&n.pops.includes('fra')&&!msfNope(n.id,'fra')).map(n=>n.id);
|
||||
S.transit=[{id:'t1',city:'fra',net:'cog',tier:2,n:2}];
|
||||
S.pni=[{id:'p1',city:'fra',net:free[0],tier:2,n:2,ready:0,site:'a',sacrif:false},{id:'p2',city:'fra',net:free[1],tier:1,n:1,ready:S.day+60,site:'a',sacrif:false}];
|
||||
const x=ixIdsIn('fra')[0];S.ixp={[x]:2};S.ixn={[x]:2};window.__ix=x;compute();})()`);
|
||||
return r;
|
||||
};
|
||||
const open = (ev, phone) => ev(`window.innerWidth=${phone ? 390 : 1280};UI.dtab='conn';ACT.connOpen()`);
|
||||
// Every button in the list as act + args, to compare with what the POP panel offers.
|
||||
const acts = (ev, sel) => JSON.parse(ev(`JSON.stringify([...document.querySelectorAll('${sel} [data-act]')].map(b=>b.dataset.act+' '+b.dataset.args))`));
|
||||
const has = (list, act, args) => list.includes(`${act} ${JSON.stringify(args)}`);
|
||||
|
||||
for (const phone of [false, true]) {
|
||||
test(`#336 the connection list offers downgrades and a chase (${phone ? 'phone' : 'desktop'})`, () => {
|
||||
const { ev, errors } = setup();
|
||||
open(ev, phone);
|
||||
const ix = ev('window.__ix'), a = acts(ev, '#connSec');
|
||||
assert.ok(has(a, 'downT', { id: 't1' }) && has(a, 'lagT', { id: 't1', d: -1 }), 'transit: smaller port, one member fewer');
|
||||
assert.ok(has(a, 'downP', { id: 'p1' }) && has(a, 'lagP', { id: 'p1', d: -1 }), 'PNI: smaller port, one member fewer');
|
||||
assert.ok(has(a, 'pniChase', { id: 'p2' }), 'a PNI on order can be chased');
|
||||
assert.ok(!has(a, 'pniChase', { id: 'p1' }) && !has(a, 'downP', { id: 'p2' }), 'no chase for a live PNI, no downgrade for one on order');
|
||||
assert.ok(has(a, 'downIx', { city: ix }) && has(a, 'lagIx', { city: ix, d: -1 }), 'IX: smaller port, one member fewer');
|
||||
assert.match(ev("document.getElementById('connSec').textContent"), /Downgrade 100G/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
test('#336 the buttons in the list do what the POP panel buttons do', () => {
|
||||
const { ev, errors } = setup();
|
||||
const ix = ev('window.__ix');
|
||||
open(ev, false);
|
||||
const click = (act, args) => {
|
||||
const ok = ev(`(()=>{const b=[...document.querySelectorAll('#connSec [data-act]')].find(b=>b.dataset.act===${JSON.stringify(act)}&&b.dataset.args===${JSON.stringify(JSON.stringify(args))});if(!b)return false;b.click();return true})()`);
|
||||
assert.ok(ok, `${act} ${JSON.stringify(args)} is in the list`);
|
||||
open(ev, false);
|
||||
};
|
||||
click('downT', { id: 't1' });
|
||||
assert.equal(ev("S.transit[0].tier"), 1);
|
||||
click('lagT', { id: 't1', d: -1 });
|
||||
assert.equal(ev("S.transit[0].n||1"), 1);
|
||||
click('downP', { id: 'p1' });
|
||||
assert.equal(ev("S.pni.find(p=>p.id==='p1').tier"), 1);
|
||||
click('lagP', { id: 'p1', d: -1 });
|
||||
assert.equal(ev("S.pni.find(p=>p.id==='p1').n||1"), 1);
|
||||
click('downIx', { city: ix });
|
||||
assert.equal(ev(`S.ixp['${ix}']`), 1);
|
||||
click('lagIx', { city: ix, d: -1 });
|
||||
assert.equal(ev(`(S.ixn||{})['${ix}']||1`), 1);
|
||||
// A chase that lands takes a month off the wait, as from the POP panel.
|
||||
const ready = ev("S.pni.find(p=>p.id==='p2').ready");
|
||||
ev("Math.random=()=>0");
|
||||
click('pniChase', { id: 'p2' });
|
||||
assert.equal(ev("S.pni.find(p=>p.id==='p2').ready"), Math.max(ev('S.day') + 1, ready - 30));
|
||||
// No more members to take away: those buttons go away.
|
||||
const a = acts(ev, '#connSec');
|
||||
assert.ok(!has(a, 'lagT', { id: 't1', d: -1 }) && !has(a, 'lagP', { id: 'p1', d: -1 }) && !has(a, 'lagIx', { city: ix, d: -1 }));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#336 the list offers the same downgrades as the POP panel', () => {
|
||||
const { ev, errors } = setup();
|
||||
open(ev, false);
|
||||
const dash = acts(ev, '#connSec').filter(x => /^(downT|lagT|downIx|lagIx) /.test(x) && !x.includes('"d":1'));
|
||||
ev("UI.sel={type:'city',id:'fra'};UI.tab='up';renderPanel()");
|
||||
const panel = acts(ev, '#panelBody').filter(x => /^(downT|lagT) /.test(x) && !x.includes('"d":1'));
|
||||
assert.ok(panel.length >= 2, `the POP panel shows the transit downgrades: ${panel}`);
|
||||
for (const x of panel) assert.ok(dash.includes(x), `${x} is in the list too`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -189,7 +189,9 @@ test('a customer dropped while a sales trial routes: the trial runs again on the
|
|||
p.ev(TICK_ERR);
|
||||
p.ev("window.__ot=0;const ot=offerTrial;offerTrial=(...a)=>{__ot++;return ot(...a);};");
|
||||
let found = false;
|
||||
for (let d = 0; d < 20 && !found; d++) {
|
||||
// Played until such a trial comes: on the big save that depends on the offers the seeded game draws and on where
|
||||
// each city's traffic goes (#48, #137).
|
||||
for (let d = 0; d < 60 && !found; d++) {
|
||||
p.ev('rwDay()');
|
||||
for (let k = 0; k < 400 && p.ev('!!RW.job'); k++) {
|
||||
if (p.ev('__later.length')) { p.ev('__later.shift()()'); continue; }
|
||||
|
|
|
|||
133
tests/device-transfer.test.js
Normal file
133
tests/device-transfer.test.js
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
// Moving a network to another device (#263): the save file through the share sheet, or a link to paste. No server.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
const { until } = require('./net');
|
||||
|
||||
const settle = async (ev, cond, what) => assert.ok(await until(() => ev(cond)), what || cond);
|
||||
const SNAP = "JSON.stringify({day:S.day,cash:S.cash,pops:Object.keys(S.pops),links:S.links.length,biz:S.biz.length,name:S.name,hist:S.hist.length})";
|
||||
/* A share sheet like Chromium's: no .json files, .txt yes. Calls are recorded; share() is called at once (a sheet only
|
||||
opens straight from the tap). window.__shareResult: 'ok', 'abort' or 'fail'. */
|
||||
const CHROMIUM_SHARE = `navigator.canShare=d=>!!d&&Array.isArray(d.files)&&d.files.every(f=>/\\.txt$/.test(f.name));
|
||||
window.__shared=[];window.__shareResult='ok';
|
||||
navigator.share=d=>{__shared.push(d);return __shareResult==='ok'?Promise.resolve():Promise.reject(new DOMException('x',__shareResult==='abort'?'AbortError':'NotAllowedError'));};`;
|
||||
|
||||
async function sender(opts = {}) {
|
||||
const a = load({ gzip: true, ...opts });
|
||||
if (opts.share) a.ev(CHROMIUM_SHARE);
|
||||
a.ev("$('nmIn').value='Tube Mover';ACT.start({});S.cash=4321987;for(let i=0;i<40;i++)dayTick();save(true)");
|
||||
a.ev('ACT.xfer({})');
|
||||
await settle(a.ev, '!!UI.xfer', 'the send screen opens');
|
||||
return a;
|
||||
}
|
||||
|
||||
test('the save file goes to the share sheet straight from the tap, as a .txt where .json cannot be shared, and loads on the other device', async () => {
|
||||
const a = await sender({ share: true });
|
||||
assert.match(a.ev("$('modalCard').textContent"), /Send the save file/);
|
||||
assert.equal(a.ev('UI.xfer.file.name'), 'series-of-tubes-tube-mover-' + a.ev('new Date().toISOString().slice(0,10)') + '.txt');
|
||||
a.ev(`document.querySelector('#modalCard [data-act="xferShare"]').click()`);
|
||||
assert.equal(a.ev('__shared.length'), 1, 'the sheet opens in the same tap, not after waiting for anything');
|
||||
assert.equal(a.ev('__shared[0].files[0]===UI.xfer.file'), true);
|
||||
|
||||
// The file arrives on the other device and opens with Import a save.
|
||||
const txt = await a.dom.window.eval('__shared[0].files[0].text()'), want = a.ev(SNAP);
|
||||
const b = load({ gzip: true });
|
||||
b.dom.window.__txt = txt;
|
||||
b.ev("importFile(new File([__txt],'series-of-tubes-tube-mover.txt',{type:'text/plain'}))");
|
||||
await settle(b.ev, '!!UI.importing', 'it asks before loading');
|
||||
b.ev('ACT.importGo()');
|
||||
assert.equal(b.ev(SNAP), want, 'the same network, charts and all');
|
||||
// The picker takes the .txt that Chromium shares as well as .json.
|
||||
b.ev("HTMLInputElement.prototype.click=function(){window.__accept=this.accept;};ACT.importPick()");
|
||||
assert.match(b.ev('__accept'), /\.txt/);
|
||||
assert.match(b.ev('__accept'), /\.json/);
|
||||
assert.deepEqual(a.errors, []);
|
||||
assert.deepEqual(b.errors, []);
|
||||
});
|
||||
|
||||
test('a browser that shares .json gets the .json; one that cannot share files gets a download button', async () => {
|
||||
const a = load({ gzip: true });
|
||||
a.ev("navigator.canShare=()=>true;navigator.share=()=>Promise.resolve();ACT.start({});save(true);ACT.xfer({})");
|
||||
await settle(a.ev, '!!UI.xfer');
|
||||
assert.match(a.ev('UI.xfer.file.name'), /\.json$/);
|
||||
assert.equal(a.ev('UI.xfer.file.type'), 'application/json');
|
||||
|
||||
const c = await sender();
|
||||
assert.equal(c.ev('UI.xfer.file'), null);
|
||||
assert.ok(c.ev(`!!document.querySelector('#modalCard [data-act="xferFile"]')`), 'Export save instead');
|
||||
assert.ok(!c.ev(`document.querySelector('#modalCard [data-act="xferShare"]')`));
|
||||
assert.match(c.ev("$('modalCard').textContent"), /Download the save file/);
|
||||
assert.deepEqual(a.errors, []);
|
||||
assert.deepEqual(c.errors, []);
|
||||
});
|
||||
|
||||
test('a share that fails falls back to the download; closing the sheet does nothing', async () => {
|
||||
const a = await sender({ share: true });
|
||||
a.ev("window.__dl=0;exportSlot=()=>{__dl++;}");
|
||||
a.ev("__shareResult='abort';ACT.xferShare()");
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
assert.equal(a.ev('__dl'), 0, 'the player closed the sheet: nothing else happens');
|
||||
a.ev("__shareResult='fail';ACT.xferShare()");
|
||||
await settle(a.ev, '__dl===1', 'a refused share downloads the file instead');
|
||||
assert.deepEqual(a.errors, []);
|
||||
});
|
||||
|
||||
test('one link carries the whole network: opened on another device it loads the same game, and leaves the address bar', async () => {
|
||||
const a = await sender();
|
||||
const link = a.ev('UI.xfer.link'), want = a.ev(SNAP);
|
||||
assert.ok(link.startsWith('https://tests.invalid/#sot1.'), link.slice(0, 40));
|
||||
const b = load({ gzip: true, url: link });
|
||||
assert.equal(b.ev('location.hash'), '', 'the network is taken out of the address bar at once');
|
||||
await settle(b.ev, '!!UI.importing', 'it asks before loading');
|
||||
assert.match(b.ev("$('modalCard').textContent"), /Tube Mover/);
|
||||
b.ev('ACT.importGo()');
|
||||
assert.equal(b.ev(SNAP), want);
|
||||
assert.equal(b.ev('slotIdx().length'), 1, 'it joins the networks on that device');
|
||||
|
||||
// Pasted on the title screen, with whatever whitespace a clipboard adds.
|
||||
const c = load({ gzip: true });
|
||||
c.ev('ACT.xferRecv()');
|
||||
assert.ok(c.ev(`!!document.querySelector('#modalCard [data-act="importPick"]')`), 'Import a save is right there for the file');
|
||||
c.ev(`$('xferIn').value=${JSON.stringify(' ' + link + '\n')};ACT.xferPaste()`);
|
||||
await settle(c.ev, '!!UI.importing');
|
||||
for (const x of [a, b, c]) assert.deepEqual(x.errors, []);
|
||||
});
|
||||
|
||||
test('bad or cut links say so and load nothing', async () => {
|
||||
const a = await sender();
|
||||
const link = a.ev('UI.xfer.link');
|
||||
const b = load({ gzip: true });
|
||||
b.ev("xferTake('https://example.com/nothing-here')");
|
||||
assert.match(b.ev('document.body.textContent'), /not a transfer link/);
|
||||
b.ev(`xferTake(${JSON.stringify(link.slice(0, -40))})`);
|
||||
await settle(b.ev, '/incomplete or damaged/.test(document.body.textContent)', 'a cut link is reported');
|
||||
assert.equal(b.ev('!!UI.importing'), false);
|
||||
assert.equal(b.ev('S'), null, 'nothing was loaded');
|
||||
assert.deepEqual(b.errors, []);
|
||||
});
|
||||
|
||||
test('any network on the title screen can be sent without loading it, and the screen fits a 360 px phone', async () => {
|
||||
const a = await sender({ share: true });
|
||||
a.ev('ACT.toTitle()');
|
||||
const id = a.ev('slotIdx()[0].id');
|
||||
a.ev(`ACT.slotMenu({id:'${id}'})`);
|
||||
a.ev('window.innerWidth=360;UI.xfer=null');
|
||||
a.ev(`document.querySelector('#modalCard [data-act="xfer"]').click()`);
|
||||
await settle(a.ev, '!!UI.xfer', 'sent from storage');
|
||||
assert.equal(a.ev('S'), null, 'not loaded');
|
||||
assert.equal(a.ev('UI.xfer.name'), 'Tube Mover');
|
||||
assert.match(await a.dom.window.eval('UI.xfer.file.text()'), /"name":"Tube Mover"/);
|
||||
assert.ok(a.ev(`!!document.querySelector('#modalCard [data-act="xferShare"]')`));
|
||||
assert.ok(a.ev(`!!document.querySelector('#modalCard [data-act="xferLink"]')`));
|
||||
assert.deepEqual(a.errors, []);
|
||||
});
|
||||
|
||||
test('without compression the file still goes, only the link is missing', async () => {
|
||||
const a = load();
|
||||
a.ev(CHROMIUM_SHARE + "ACT.start({});save(true);ACT.xfer({})");
|
||||
await settle(a.ev, '!!UI.xfer');
|
||||
assert.equal(a.ev('UI.xfer.link'), null);
|
||||
assert.ok(a.ev(`!!document.querySelector('#modalCard [data-act="xferShare"]')`));
|
||||
assert.ok(!a.ev(`document.querySelector('#modalCard [data-act="xferLink"]')`));
|
||||
assert.deepEqual(a.errors, []);
|
||||
});
|
||||
|
|
@ -27,7 +27,8 @@ function twoPops() {
|
|||
}
|
||||
|
||||
test('at its own POP a carrier\'s port takes the traffic bound for that carrier, not an even split', () => {
|
||||
const { ev, lvl, tly, errors } = newYork();
|
||||
// Both ports with room: New York's traffic to the US eyeballs in Level Tree's cone alone would fill its port (#48).
|
||||
const { ev, lvl, tly, errors } = newYork(1, 150);
|
||||
assert.ok(via(ev, lvl, 'lvl') > 1, 'Level Tree traffic goes out of the Level Tree port');
|
||||
assert.equal(via(ev, tly, 'lvl'), 0, 'and none of it out of Tell-Ya');
|
||||
assert.ok(via(ev, tly, 'tly') > 1 && via(ev, lvl, 'tly') === 0, 'the same for Tell-Ya');
|
||||
|
|
|
|||
134
tests/endgame-scale.test.js
Normal file
134
tests/endgame-scale.test.js
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
// The late game grows sideways, plus one expensive way up: eyeball traffic starts where the eyeballs are (#48), giant AI
|
||||
// circuits spread over many metros (#61), a PNI grows by eight members per router (#323), and Auto-TE spills early onto
|
||||
// detours within a latency budget (#136).
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
const { lit } = require('../scripts/lib/js-literal');
|
||||
|
||||
const US = ['nyc', 'ash', 'chi', 'atn', 'den', 'sea', 'sjc', 'mia'];
|
||||
|
||||
// POPs in the given cities with the same home demand, a thin backbone between neighbours and transit at every POP.
|
||||
function usNetwork(ev, cities, wave) {
|
||||
ev(`ACT.start({});S.cash=1e10;S.lvl=6;S.day=500;S.biz=[];S.offers=[];S.links=[];S.pops={};S.pni=[];S.caches=[];S.transit=[];S.ixp={};S.peers={};S.rs={};
|
||||
S.nextFail=1e9;S.nextEvent=1e9;const cs=${lit(cities)};
|
||||
for(const c of cs){S.pops[c]={routers:2,rgen:3,gen:true,bb:{d:400},down:0};S.transit.push({id:'t'+c,net:'cog',city:c,tier:3,n:4,down:0});}
|
||||
for(let i=0;i+1<cs.length;i++)S.links.push({id:'w'+i,a:cs[i],b:cs[i+1],kind:'wave',tier:${wave},km:kmBetween(cs[i],cs[i+1]),cut:0,mo:100});
|
||||
compute();`);
|
||||
}
|
||||
|
||||
test('#48: traffic to a network that sells to homes starts where its users live', () => {
|
||||
const { ev, errors } = load();
|
||||
usNetwork(ev, ['nyc'], 3);
|
||||
const us = ev('R.demTo.cmc/R.demand');
|
||||
usNetwork(ev, ['fra'], 3);
|
||||
const de = ev('R.demTo.cmc/R.demand'), deDtk = ev('R.demTo.dtk/R.demand');
|
||||
usNetwork(ev, ['nyc'], 3);
|
||||
const usDtk = ev('R.demTo.dtk/R.demand');
|
||||
assert.ok(us > ev('NSH.cmc') * 3, `a New York POP sends Comecast far more than its world share (${us})`);
|
||||
assert.ok(us > de * 8, `and much more than a Frankfurt POP does (${us} vs ${de})`);
|
||||
assert.ok(deDtk > usDtk * 8, `Doitsche Telekomm the other way round (${deDtk} vs ${usDtk})`);
|
||||
// Only the split between home networks moves: content keeps its share, and a city's total demand stays the same.
|
||||
assert.ok(Math.abs(ev("[...locSh(NSH,'nyc')].reduce((a,b)=>a+b,0)") - 1) < 1e-9, 'the shares still add up to one');
|
||||
assert.equal(ev("locSh(NSH,'nyc')[LOC_NIX.get('ggl')]"), ev('NSH.ggl'), 'content is everywhere');
|
||||
assert.ok(Math.abs(ev("cityNetSh('nyc','cmc')") - ev("locSh(NSH,'nyc')[LOC_NIX.get('cmc')]")) < 1e-12, 'box sizing reads the same split');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#48: peering with an eyeball in more of the cities its users live in carries more of its traffic', () => {
|
||||
const { ev, errors } = load();
|
||||
// A 10G backbone: hauling Comecast's traffic to two PNIs fills it, and the rest leaves over transit.
|
||||
usNetwork(ev, US, 0);
|
||||
const share = pnis => {
|
||||
ev(`S.pni=${lit(pnis)}.map(c=>({id:'cmc@'+c,city:c,net:'cmc',tier:3,n:4}));compute()`);
|
||||
return ev('(R.netEg.cmc.p||0)/R.demTo.cmc');
|
||||
};
|
||||
const two = share(['nyc', 'ash']), all = share(US);
|
||||
assert.ok(all > 0.95, `a PNI in every city takes nearly all of it (${all})`);
|
||||
assert.ok(two < 0.6, `two PNIs only take what the backbone can haul to them (${two})`);
|
||||
assert.ok(all - two > 0.35, `more PNI locations carry more (${two} → ${all})`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#61: giant AI circuits spread over many metros, busy ones a bit busier', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(`ACT.start({});S.cash=1e12;S.lvl=11;S.biz=[];S.offers=[];for(const m of MEGA)if(!S.pops[m.c])S.pops[m.c]={routers:1,rgen:3,gen:true,bb:null,down:0};
|
||||
for(const c of ['ash','nyc','chi','dal','mex','lax','hou','bos','was'])if(!S.pops[c])S.pops[c]={routers:1,rgen:3,gen:true,bb:null,down:0};`);
|
||||
ev('__reseed(61)');
|
||||
// Three hundred offers, each signed as it comes, the way a long game fills up.
|
||||
const out = JSON.parse(ev(`(()=>{const cnt={};let n=0;for(let i=0;i<300;i++){const before=S.offers.length;spawnSpecial(['aiwan','mtrain','agi'][i%3]);
|
||||
if(S.offers.length===before)continue;const o=S.offers.pop();S.biz.push(o);n++;for(const c of bCities(o))cnt[c]=(cnt[c]||0)+1;}return JSON.stringify({cnt,n});})()`));
|
||||
const tot = Object.values(out.cnt).reduce((a, b) => a + b, 0);
|
||||
const five = ['mex', 'chi', 'dal', 'ash', 'nyc'].reduce((a, c) => a + (out.cnt[c] || 0), 0);
|
||||
assert.ok(out.n > 200, `offers came (${out.n})`);
|
||||
assert.ok(Object.keys(out.cnt).length >= 25, `ends in many metros (${Object.keys(out.cnt).length})`);
|
||||
assert.ok(five / tot < 0.35, `the old five metros no longer get most of it (${(five / tot).toFixed(2)})`);
|
||||
const avg = tot / Object.keys(out.cnt).length;
|
||||
assert.ok(out.cnt.ash > avg, `Ashburn stays a bit busier than the average metro (${out.cnt.ash} vs ${avg.toFixed(1)})`);
|
||||
assert.ok(out.cnt.ash < tot * 0.15, `but never the only place (${out.cnt.ash} of ${tot})`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#323: a PNI grows by eight members per router at the POP, up to 32', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev("ACT.start({});S.cash=1e12;S.lvl=13;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});S.pops.fra.rgen=RG_TOP;S.pops.fra.routers=1;S.rules={...(S.rules||{}),pnis:'instant'};");
|
||||
ev("S.pni.push({id:'p1',city:'fra',net:'nfx',tier:3,n:8});compute()");
|
||||
const n = () => ev("S.pni.find(p=>p.id==='p1').n");
|
||||
assert.equal(ev("pniLagMax('fra')"), 8, 'one router: eight members, as before');
|
||||
ev("ACT.lagP({id:'p1',d:1})");
|
||||
assert.equal(n(), 8, 'a ninth member needs a second router');
|
||||
assert.match(dom.window.document.getElementById('toasts').textContent, /already bundles 8 ports/);
|
||||
ev("ACT.addRouter({city:'fra'})");
|
||||
assert.equal(ev("pniLagMax('fra')"), 16);
|
||||
ev("ACT.lagP({id:'p1',d:1})");
|
||||
assert.equal(n(), 9, 'the second router takes eight more');
|
||||
assert.ok(Math.abs(ev("R.nodeCap.fra") - ev("nodeCap('fra')")) < 1e-9);
|
||||
// Taking that router away again would leave the bundle with nowhere to land.
|
||||
ev("ACT.rmRouter({city:'fra'})");
|
||||
assert.equal(ev('S.pops.fra.routers'), 2, 'the router stays while the PNI needs it');
|
||||
assert.match(dom.window.document.getElementById('toasts').textContent, /Shrink a PNI first/);
|
||||
ev("S.pops.fra.routers=6;");
|
||||
assert.equal(ev("pniLagMax('fra')"), 32, 'never more than 32 members, however many routers');
|
||||
for (let i = 0; i < 30; i++) ev("ACT.lagP({id:'p1',d:1})");
|
||||
assert.equal(n(), 32);
|
||||
// The panel offers a member while there is room and says why when there is none.
|
||||
ev("S.pops.fra.routers=4;UI.sel={type:'city',id:'fra'};S.pni.find(p=>p.id==='p1').n=31;");
|
||||
ev('window.innerWidth=390;renderAll()');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#323: saves keep their LAGs, big ones included, and garbage is clamped', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});ACT.launchBB({city:'fra'});S.pops.fra.routers=3;");
|
||||
ev("S.pni.push({id:'old',city:'fra',net:'nfx',tier:2,n:8},{id:'big',city:'fra',net:'ggl',tier:2,n:24,up:{tier:3,n:24,ready:S.day+30}},{id:'bad',city:'fra',net:'akm',tier:1,n:999})");
|
||||
ev('const o=JSON.parse(JSON.stringify(S));sanitize(o);window.__o=o');
|
||||
assert.equal(ev("__o.pni.find(p=>p.id==='old').n"), 8, 'an old save with an 8-port LAG loads as it was');
|
||||
assert.equal(ev("__o.pni.find(p=>p.id==='big').n"), 24);
|
||||
assert.equal(ev("__o.pni.find(p=>p.id==='big').up.n"), 24);
|
||||
assert.equal(ev("__o.pni.find(p=>p.id==='bad').n"), 32, 'never past the biggest bundle');
|
||||
assert.equal(ev("migrate(JSON.parse(JSON.stringify(S)))&&1"), 1);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#136: spill tiers keep a hot link at its line while a detour within the latency budget has room', () => {
|
||||
const { ev, errors } = load();
|
||||
// New York reaches its upstream in Los Angeles over a direct 10G wave, or about 10 ms longer through Miami on 800G.
|
||||
ev(`ACT.start({});S.cash=1e12;S.lvl=13;for(const g of GOALS)S.done[g.id]=0;for(const c of ['nyc','lax','mia'])if(!S.pops[c])ACT.buildPop({city:c});
|
||||
for(const c of ['nyc','lax','mia']){S.pops[c].rgen=RG_TOP;S.pops[c].routers=RMAX;}if(!S.pops.nyc.bb)ACT.launchBB({city:'nyc'});S.pops.nyc.bb.d=400;
|
||||
const L=(a,b,t)=>{UI.via=null;UI.lmode='wave';UI.route='main';openLinkModal(a,b);ACT.buildLink({tier:t});closeModal();};
|
||||
L('nyc','lax',0);L('nyc','mia',3);L('mia','lax',3);S.links.forEach(l=>l.ready=0);
|
||||
S.transit=[];const t=NETS.find(n=>n.price&&n.pops.includes('lax')&&n.type==='t1');ACT.buyTransit({city:'lax',net:t.id,tier:3});
|
||||
S.ixp={};S.pni=[];S.caches=[];S.te={on:true,day:0};S.core={lv:2,run:2,legacy:true};S.nextFail=1e9;S.nextEvent=1e9;`);
|
||||
const direct = "R.load[S.links.find(l=>l.a==='nyc'&&l.b==='lax').id]";
|
||||
const run = s => { ev(`S.te.script=${lit(s)};compute()`); return { load: ev(direct), served: ev('R.served'), moved: ev('R.teMoved') }; };
|
||||
const none = run(''), short = run('spill at 80% within 5 ms'), long = run('spill at 80% within 15 ms'), two = run('spill at 80% within 15 ms\nspill at 90% within 30 ms');
|
||||
assert.ok(none.load > 9.99, 'without tiers the direct link fills up');
|
||||
assert.ok(short.load > 9.99, 'a detour 10 ms longer is outside a 5 ms budget: the link fills up as before');
|
||||
assert.ok(Math.abs(long.load - 8) < 1e-6, `within 15 ms the link stays at 80% (${long.load})`);
|
||||
assert.ok(Math.abs(two.load - 8) < 1e-6, 'the 90% tier only opens once the 80% detours are full');
|
||||
assert.ok(Math.abs(long.served - none.served) < 1e-6, 'and nothing is lost: the detour carries it');
|
||||
assert.ok(long.moved > none.moved, 'Auto-TE moved it');
|
||||
assert.equal(ev("teParse('spill at 80% within 500 ms').errors.length"), 1, 'a budget past 100 ms is refused');
|
||||
assert.equal(ev("JSON.stringify(teParse('spill at 90% within 20 ms\\nspill at 80% within 10 ms').tiers)"), '[{"at":0.8,"ms":10},{"at":0.9,"ms":20}]');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -43,7 +43,7 @@ test('a listing is kept in the save, checked, and can be taken off the market',
|
|||
fiber(ev, 'big', 'fra', 'ams', 450);
|
||||
ev("ACT.listFiber({id:'big',w:4})");
|
||||
ev("const t=JSON.stringify(packSave(S));S=migrate(JSON.parse(t))");
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links.find(l=>l.id==='big').list)")), { w: 4, p: 0 });
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links.find(l=>l.id==='big').list)")), { w: 4, p: 0, hw: 4 });
|
||||
ev("const o=JSON.parse(JSON.stringify(packSave(S)));o.links.find(l=>l.id==='big').list={w:'lots',p:-3};S=migrate(o)");
|
||||
assert.equal(ev("S.links.find(l=>l.id==='big').list===undefined"), true, 'junk is dropped');
|
||||
ev("ACT.listFiber({id:'big',w:2});ACT.unlistFiber({id:'big'})");
|
||||
|
|
|
|||
2
tests/fixtures/mp-sim/roster.json
vendored
2
tests/fixtures/mp-sim/roster.json
vendored
|
|
@ -1 +1 @@
|
|||
{"t":"roster","code":"K7Q2XD","title":"Friday","preset":"oncall","seed":424242,"created":1730913600000,"players":[{"pid":"abcd1234","name":"Packet Pals","asn":201234,"color":"#3a86ff","card":{"day":45,"name":"Packet Pals","asn":201234,"tier":"t3","t1":false,"lvl":2,"pops":["fra","ams"],"links":[["ams","fra",10]],"ix":[],"transit":["cog"],"ppol":"open","reach":1,"peak":47.3,"served":47.3,"cust":0,"rev":7099,"cashB":5,"score":47},"seen":1731000000000,"joined":1730913600000},{"pid":"efgh5678","name":"Tubular Bells","asn":207777,"color":"#ff4f9a","card":null,"seen":1730999940000,"joined":1730996400000}],"feed":[{"k":"join","pid":"abcd1234","name":"Packet Pals","at":1730913600000},{"k":"join","pid":"efgh5678","name":"Tubular Bells","at":1730996400000},{"k":"chat","pid":"efgh5678","name":"Tubular Bells","at":1730999940000,"text":"peer with me?"}],"on":["abcd1234","efgh5678"]}
|
||||
{"t":"roster","code":"K7Q2XD","title":"Friday","preset":"oncall","seed":424242,"created":1730913600000,"players":[{"pid":"abcd1234","name":"Packet Pals","asn":201234,"color":"#3a86ff","card":{"day":45,"name":"Packet Pals","asn":201234,"tier":"t3","t1":false,"lvl":2,"pops":["fra","ams"],"links":[["ams","fra",10]],"ix":[],"transit":["cog"],"ppol":"open","reach":1,"peak":47.5,"served":47.5,"cust":0,"rev":7126,"cashB":5,"score":48},"seen":1731000000000,"joined":1730913600000},{"pid":"efgh5678","name":"Tubular Bells","asn":207777,"color":"#ff4f9a","card":null,"seen":1730999940000,"joined":1730996400000}],"feed":[{"k":"join","pid":"abcd1234","name":"Packet Pals","at":1730913600000},{"k":"join","pid":"efgh5678","name":"Tubular Bells","at":1730996400000},{"k":"chat","pid":"efgh5678","name":"Tubular Bells","at":1730999940000,"text":"peer with me?"}],"on":["abcd1234","efgh5678"]}
|
||||
|
|
|
|||
2
tests/fixtures/mp-sim/snap.json
vendored
2
tests/fixtures/mp-sim/snap.json
vendored
File diff suppressed because one or more lines are too long
2
tests/fixtures/mp-sim/sub.json
vendored
2
tests/fixtures/mp-sim/sub.json
vendored
File diff suppressed because one or more lines are too long
2
tests/fixtures/mp-sim/upd-act.json
vendored
2
tests/fixtures/mp-sim/upd-act.json
vendored
File diff suppressed because one or more lines are too long
2
tests/fixtures/mp-sim/upd-day.json
vendored
2
tests/fixtures/mp-sim/upd-day.json
vendored
File diff suppressed because one or more lines are too long
|
|
@ -224,6 +224,16 @@ test('N7: presence is real: PoPs are cities, exchange ports only where the netwo
|
|||
fail('N7', bad, 'an exchange port needs an exchange in that city and a PoP there');
|
||||
});
|
||||
|
||||
test('N8: a POP\'s traffic to the networks that sell to homes goes mostly to those whose users live near it (#48)', () => {
|
||||
// Every city keeps its total and content keeps its share: only the split between home networks follows geography.
|
||||
const bad = J(`CITIES.filter(c=>{const a=locSh(NSH,c.id);let t=0;for(let j=0;j<NETS.length;j++){t+=a[j];if(!NETS[j].cc&&Math.abs(a[j]-(NSH[NETS[j].id]||0))>1e-12)return true;}return Math.abs(t-1)>1e-9;}).map(c=>c.id)`);
|
||||
fail('N8', bad, 'locSh() must keep a city\'s total and every share of a network without home markets');
|
||||
// At home a network's share is above its world share, far away below it.
|
||||
const far = J(`NETS.filter(n=>n.cc&&NSH[n.id]>0).flatMap(n=>{const cc=[].concat(n.cc),home=CITIES.find(c=>cc.includes(c.cc)),away=CITIES.find(c=>!locNets()[LOC_NIX.get(n.id)].reg.has(c.reg));
|
||||
const j=LOC_NIX.get(n.id),out=[];if(home&&!(locSh(NSH,home.id)[j]>NSH[n.id]))out.push(n.id+'@home');if(away&&!(locSh(NSH,away.id)[j]<NSH[n.id]))out.push(n.id+'@away');return out;})`);
|
||||
fail('N8', far, 'LOC_HOME > LOC_REG > LOC_FAR, and home markets (cc) are where the users are');
|
||||
});
|
||||
|
||||
// ---------- Modes and rules ----------
|
||||
|
||||
test('M1: On-call is the classic game: the default rules, and what old saves load as', () => {
|
||||
|
|
@ -506,9 +516,45 @@ test('F8: a managed wave costs your own capacity, rides one optic, and is priced
|
|||
assert.deepEqual(g.errors, []);
|
||||
});
|
||||
|
||||
test('F9: a latency contract is late, capped, achievable, paid for its latency and credited when over it (#137)', () => {
|
||||
const T = J('BIZ_T.lowlat');
|
||||
assert.ok(T.lv >= 7, `F9: from customer level 7, not ${T.lv}`);
|
||||
assert.ok(T.l2 && T.lat && T.sla, 'F9: a circuit with a latency limit and an SLA');
|
||||
assert.ok(Math.min(...T.opts) >= 1600 && Math.max(...T.opts) <= T.max && T.max <= 3200, 'F9: 1.6T and up, never past 3.2T');
|
||||
assert.equal(ev("(()=>{const x={type:'lowlat',bw:BIZ_T.lowlat.max};return clGrow(x)||x.bw!==BIZ_T.lowlat.max;})()"), false, 'F9: never grows past its most');
|
||||
// Per Gbps on the same route, the bare contract beats any other big circuit with every extra it can ask for.
|
||||
const best = ev("Math.max(...['hyper','ai','aiwan'].map(t=>BIZ_T[t].km))*(1+REQS.diverse.bonus+REQS.metro.bonus+REQS.sharks.bonus+REQS.gen.bonus)");
|
||||
assert.ok(T.km > best, `F9: ${T.km} per km-unit against the best other big circuit's ${best}`);
|
||||
const g = load();
|
||||
g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=BIZ_T.lowlat.lv-1;S.biz=[];S.offers=[];for(const c of ['nyc','chi','lon','fra','tok','sin'])if(!S.pops[c])ACT.buildPop({city:c});compute()");
|
||||
const spawn = (n) => g.ev(`(()=>{const out=[];for(let i=0;i<${n};i++){S.offers=[];spawnOffer();out.push(...S.offers.filter(o=>o.type==='lowlat'));}S.offers=[];return JSON.stringify(out);})()`);
|
||||
assert.deepEqual(JSON.parse(spawn(400)), [], 'F9: none below its level');
|
||||
g.ev('S.lvl=BIZ_T.lowlat.lv');
|
||||
const os = JSON.parse(spawn(400));
|
||||
assert.ok(os.length > 0, 'F9: offered at its level');
|
||||
for (const o of os) assert.ok(g.ev(`Math.min(latFloor('${o.city}','${o.city2}'),bestLat('${o.city}','${o.city2}'))<=${o.latMax}`), `F9: ${o.city}–${o.city2} in ${o.latMax} ms can be built`);
|
||||
g.ev("S.biz.push({id:'x',type:'lowlat',name:'X',city:'nyc',city2:'chi',bw:1600,rate:100,reqs:['lat'],latMax:0.1,mood:100,since:S.day-30});compute()");
|
||||
const cash = g.ev('S.cash');
|
||||
assert.equal(g.ev("lcBreach(S.biz.find(b=>b.id==='x'),S.day)"), g.ev('LC_MOOD'), 'F9: over its limit, it loses patience');
|
||||
assert.equal(Math.round(cash - g.ev('S.cash')), g.ev('Math.round(1600*100/monLen(S.day))'), "F9: and a day's fee comes back as a credit");
|
||||
assert.deepEqual(g.errors, []);
|
||||
});
|
||||
|
||||
// D1–D4: DDoS as networks see it (#242). tests/ddos-model.test.js plays each one in detail.
|
||||
const ddFra = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=40;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.pops.fra.rgen=RG.findIndex(r=>r.fsN===8);S.biz.push({id:'g',type:'game',name:'G',city:'fra',bw:10,rate:1,mood:80,since:0,reqs:[]},{id:'d',type:'dia',name:'D',city:'fra',bw:5,rate:1,mood:80,since:0,reqs:[]});compute()");
|
||||
const ddHit = (ev, g) => ev(`S.ev.ddos={id:'x',city:'fra',tgt:'g',vec:'dns',gbps:${g},start:S.day,until:S.day+2,bh:false};compute()`);
|
||||
test('F10: growth goes sideways, plus one paid way up (#61, #323)', () => {
|
||||
// A PNI bundles eight members per router at its POP, up to 32; every other LAG stays at eight.
|
||||
assert.equal(ev('LAG_MAX'), 8, 'F10: transit, exchange and fabric LAGs hold eight members');
|
||||
const lim = J("[1,2,3,4,5,16].map(r=>{const o=S.pops.fra;S.pops.fra={routers:r};const m=pniLagMax('fra');if(o)S.pops.fra=o;else delete S.pops.fra;return m;})");
|
||||
assert.deepEqual(lim, [8, 16, 24, 32, 32, 32], 'F10: a PNI grows by eight members per router, up to 32');
|
||||
// Giant AI circuits land at campuses spread over many metros, no city more than two.
|
||||
const per = J("MEGA.reduce((m,x)=>(m[x.c]=(m[x.c]||0)+1,m),{})");
|
||||
assert.ok(Object.keys(per).length >= 30, `F10: campuses in at least 30 metros (${Object.keys(per).length})`);
|
||||
fail('F10', Object.entries(per).filter(([, n]) => n > 2).map(([c]) => c), 'no metro holds more than two campuses');
|
||||
fail('F10', J("MEGA.filter(m=>!CITY[m.c]).map(m=>m.c)"), 'campuses sit in real cities');
|
||||
});
|
||||
|
||||
test('D1: attack sizes come from the world, never from your network', () => {
|
||||
const g = load();
|
||||
ddFra(g.ev);
|
||||
|
|
|
|||
|
|
@ -1283,7 +1283,7 @@ test('#51 a dark fiber shows what is rented out, and spare capacity can be liste
|
|||
assert.equal(ev("S.links[0].list?S.links[0].list.w:0"), 4 - b.slots, 'the listing shrinks by what sold');
|
||||
// when every channel is lit or sold, only the spare pair in your own trench can be listed; then nothing is left
|
||||
ev("const l=S.links[0];delete l.list;l.ch=Array(chMax(l)-soldSlots(l)).fill('tp16');after();ACT.listFiber({id:'df1',w:4,p:1})");
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links[0].list)")), { w: 0, p: 1 });
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links[0].list)")), { w: 0, p: 1, hp: 1 });
|
||||
ev("S.biz.push({id:'p1',type:'dfpair',link:'df1',city:'fra',city2:'ams',name:'X',bw:1,rate:1,reqs:[]},{id:'p2',type:'dfpair',link:'df1',city:'fra',city2:'ams',name:'Y',bw:1,rate:1,reqs:[]});delete S.links[0].list;S.offers=[];renderPanel()");
|
||||
assert.match(txt(), /Nothing spare to sell on this fiber right now/);
|
||||
ev("ACT.listFiber({id:'df1',w:1,p:1})"); assert.equal(ev("S.links[0].list===undefined"), true);
|
||||
|
|
|
|||
162
tests/latency-contracts.test.js
Normal file
162
tests/latency-contracts.test.js
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
const { lit } = require('../scripts/lib/js-literal');
|
||||
|
||||
// Strict latency contracts (#137): big customers who pay for a latency SLA on one route, late in the game.
|
||||
const start = "ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'nyc'})";
|
||||
const pop = (c) => `S.pops['${c}']=S.pops['${c}']||{day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};S.pops['${c}'].rgen=RG.length-1;`;
|
||||
const wave = (id, a, b) => `S.links.push({id:'${id}',a:'${a}',b:'${b}',kind:'wave',tier:6,n:1,km:kmBetween('${a}','${b}'),cut:0,mo:0,day:0,ready:0});`;
|
||||
const CITIES = ['nyc', 'chi', 'ash', 'mia', 'lon', 'fra'];
|
||||
const net = () => CITIES.map(pop).join('') + wave('nc', 'nyc', 'chi') + wave('na', 'nyc', 'ash') + wave('am', 'ash', 'mia') + wave('mc', 'mia', 'chi') + 'compute();';
|
||||
// Spawn n offers, each on its own, and keep them all.
|
||||
const spawnMany = (ev, n) => JSON.parse(ev(`(()=>{const out=[];for(let i=0;i<${n};i++){S.offers=[];spawnOffer();out.push(...S.offers);}S.offers=[];return JSON.stringify(out);})()`));
|
||||
// A latency contract on New York ⇄ Chicago, signed long enough ago that its provisioning grace is over.
|
||||
const sign = (bw = 1600) => `(()=>{const b={id:'lc1',city:'nyc',city2:'chi',name:'Shortest Path Securities',type:'lowlat',bw:${bw},rate:500,reqs:['lat'],latMax:latMaxOf('nyc','chi'),route:'fast',mood:100,since:S.day-30};S.biz.push(b);compute();return b.id;})()`;
|
||||
|
||||
test('#137 latency contracts are offered only from their customer level, sized and priced as promised', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
ev(net());
|
||||
ev('S.lvl=LC_LV-1');
|
||||
assert.ok(ev('LC_LV') >= 7, 'a late-game customer');
|
||||
const early = spawnMany(ev, 600);
|
||||
assert.equal(early.filter((o) => o.type === 'lowlat').length, 0, 'never below its level');
|
||||
ev('S.lvl=LC_LV');
|
||||
const late = spawnMany(ev, 600);
|
||||
const lc = late.filter((o) => o.type === 'lowlat');
|
||||
assert.ok(lc.length >= 5, `they call at their level (${lc.length})`);
|
||||
for (const o of lc) {
|
||||
assert.ok([1600, 3200].includes(o.bw), 'big: 1.6T or 3.2T');
|
||||
assert.equal(o.reqs[0], 'lat', 'always a latency limit');
|
||||
assert.equal(o.latMax, ev(`latMaxOf('${o.city}','${o.city2}')`), 'the limit every latency customer gets');
|
||||
assert.ok(ev(`Math.min(latFloor('${o.city}','${o.city2}'),bestLat('${o.city}','${o.city2}'))<=${o.latMax}`), 'and one something you can build meets');
|
||||
}
|
||||
// Pay: per Gbps on the same route, above any other high-volume circuit (hyperscaler DCI, AI interconnects), whatever they ask for.
|
||||
const per = (o) => o.rate / ev(`150+kmBetween('${o.city}','${o.city2}')*0.08`);
|
||||
const big = late.filter((o) => ['hyper', 'ai', 'aiwan'].includes(o.type));
|
||||
assert.ok(big.length >= 5, 'there are other big circuits to compare with');
|
||||
assert.ok(Math.min(...lc.map(per)) > Math.max(...big.map(per)), 'a latency contract pays more per Gbps than any other big circuit');
|
||||
// Same size, same route: a 1.6T latency contract against a 1.6T hyperscaler DCI with every extra a DCI can ask for.
|
||||
const o = lc[0], km = ev(`kmBetween('${o.city}','${o.city2}')`);
|
||||
const dciBest = (150 + km * 0.08) * ev('BIZ_T.hyper.km') * (1 + ev("REQS.diverse.bonus+REQS.metro.bonus+REQS.sharks.bonus+REQS.gen.bonus"));
|
||||
assert.ok(1600 * o.rate > 1600 * dciBest, 'beats a fully loaded DCI of the same size');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#137 the latency limit is the circuit latency the game already measures, and breaking it costs credits and the customer', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
ev(net());
|
||||
ev('S.lvl=LC_LV');
|
||||
ev(sign());
|
||||
const b = "S.biz.find(b=>b.id==='lc1')";
|
||||
assert.ok(ev(`R.l2lat['lc1']<=${b}.latMax`), 'the direct wave meets it');
|
||||
assert.ok(ev(`REQS.lat.ok(${b})`));
|
||||
assert.ok(ev(`bizSf(${b})>=0.95`), 'and carries all of it');
|
||||
// Cut the direct wave: the circuit reroutes the long way round, still carried in full but too slow.
|
||||
ev("S.links.find(l=>l.id==='nc').cut=S.day+400;compute()");
|
||||
assert.ok(ev(`bizSf(${b})>=0.95`), 'all the bandwidth still arrives');
|
||||
assert.ok(ev(`R.l2lat['lc1']>${b}.latMax`), 'over its limit');
|
||||
assert.ok(!ev(`REQS.lat.ok(${b})`), 'REQS.lat says so');
|
||||
assert.ok(ev(`bizWhy(${b}).some(w=>/latency/i.test(w))`), 'and the customer row says why');
|
||||
// A day over: a day's fee back as an SLA credit, and more patience lost than a plain latency customer (HFT) loses.
|
||||
const cash = ev('S.cash'), mo = ev(`bizMo(${b})`), days = ev('monLen(S.day)');
|
||||
const extra = ev(`lcBreach(${b},S.day)`);
|
||||
assert.equal(extra, ev('LC_MOOD'));
|
||||
assert.equal(Math.round(cash - ev('S.cash')), Math.round(mo / days), "a day's fee credited");
|
||||
assert.equal(ev(`${b}.lcCr`), Math.round(mo / days));
|
||||
assert.equal(ev("lcBreach({type:'hft',since:0,latMax:1,city:'nyc',city2:'chi',reqs:['lat'],id:'x'},S.day)"), 0, 'only latency contracts pay credits');
|
||||
// In the provisioning grace (rule F1) nothing is credited and nothing is lost.
|
||||
assert.equal(ev(`(()=>{const x={...${b},id:'lc2',since:S.day-3};return lcBreach(x,S.day);})()`), 0);
|
||||
// Day after day over the limit: unhappy, warned, and gone, with credits paid every day.
|
||||
const m0 = ev(`${b}.mood`);
|
||||
ev('dayTick()');
|
||||
const m1 = ev(`${b}.mood`);
|
||||
assert.ok(m0 - m1 >= 6 - 1e-9, `loses at least 6 a day over its SLA (${m0} → ${m1})`);
|
||||
let gone = false;
|
||||
for (let i = 0; i < 40 && !gone; i++) {
|
||||
ev("S.links.find(l=>l.id==='nc').cut=S.day+400;dayTick()");
|
||||
gone = !ev("S.biz.some(b=>b.id==='lc1')");
|
||||
}
|
||||
assert.ok(gone, 'a contract over its latency for weeks cancels');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#137 a latency contract within its limit stays happy and pays no credits', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
ev(net());
|
||||
ev(sign());
|
||||
ev("S.biz.find(b=>b.id==='lc1').mood=90");
|
||||
for (let i = 0; i < 5; i++) ev("S.links.forEach(l=>l.cut=0);dayTick()");
|
||||
const b = ev("JSON.stringify(S.biz.find(b=>b.id==='lc1')||null)");
|
||||
const o = JSON.parse(b);
|
||||
assert.ok(o, 'still a customer');
|
||||
assert.equal(o.lcCr, undefined, 'no credits');
|
||||
assert.equal(o.lcB, undefined, 'not in breach');
|
||||
assert.ok(o.mood > 90, `happier every day it is served (${o.mood})`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#137 the volume cap holds: renewals, a sales shark and an edited save never take one past 3.2T', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
ev(net());
|
||||
ev(sign(1600));
|
||||
const b = "S.biz.find(b=>b.id==='lc1')";
|
||||
assert.ok(ev('Math.max(...BIZ_T.lowlat.opts)<=BIZ_T.lowlat.max'), 'a shark bumps an offer one size up its list, never past the most');
|
||||
assert.equal(ev(`clGrow(${b})`), true, 'grows to the next size once');
|
||||
assert.equal(ev(`${b}.bw`), 3200);
|
||||
assert.equal(ev(`clGrow(${b})`), false, 'and never past it');
|
||||
assert.equal(ev(`${b}.bw`), 3200);
|
||||
assert.equal(ev("(()=>{const x={type:'hyper',bw:6400};clGrow(x);return x.bw;})()"), 12800, 'other customers still double past their top size');
|
||||
// An edited save asking for more is cut back to the most the type sells.
|
||||
ev(`${b}.bw=51200`);
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
|
||||
assert.equal(ev(`${b}.bw`), 3200);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#137 old saves load, and new fields from a save are checked', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
ev(net());
|
||||
// A save from before latency contracts: nothing of theirs in it.
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
|
||||
assert.ok(!ev("S.biz.some(b=>b.type==='lowlat')"));
|
||||
// A save with a contract whose fields were edited or lost.
|
||||
ev(sign());
|
||||
ev(`(()=>{const s=JSON.parse(JSON.stringify(S)),b=s.biz.find(b=>b.id==='lc1');b.lcCr='lots';b.lcB='yes';delete b.latMax;b.reqs=[];S=migrate(s);compute();})()`);
|
||||
const b = JSON.parse(ev("JSON.stringify(S.biz.find(b=>b.id==='lc1'))"));
|
||||
assert.equal(b.lcCr, undefined, 'junk credits dropped');
|
||||
assert.equal(b.lcB, 1, 'flag as a flag');
|
||||
assert.equal(b.latMax, ev("latMaxOf('nyc','chi')"), 'the latency limit comes back');
|
||||
assert.ok(b.reqs.includes('lat'), 'and its requirement');
|
||||
ev(`(()=>{const s=JSON.parse(JSON.stringify(S));s.biz.find(b=>b.id==='lc1').lcCr=${lit(1234.4)};S=migrate(s);})()`);
|
||||
assert.equal(ev("S.biz.find(b=>b.id==='lc1').lcCr"), 1234);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#137 offer and customer rows on a 390 px phone', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start);
|
||||
ev(net());
|
||||
ev('S.lvl=LC_LV');
|
||||
ev("S.offers.push({id:'o1',city:'nyc',city2:'chi',name:'Great Circle Clearing House',type:'lowlat',bw:3200,rate:900,reqs:['lat'],latMax:latMaxOf('nyc','chi'),exp:S.day+40})");
|
||||
dom.window.innerWidth = 390;
|
||||
ev("ACT.leftTab({t:'deals'});renderAll()");
|
||||
const html = dom.window.document.body.innerHTML;
|
||||
assert.match(html, /Great Circle Clearing House/);
|
||||
assert.match(html, /Low-latency wholesale route/);
|
||||
assert.match(html, /Latency SLA [\d.]+ ms: a day's fee back for every day over it · never more than 3\.20 Tbps/);
|
||||
ev("ACT.accept({id:'o1'})");
|
||||
const c = JSON.parse(ev("JSON.stringify(S.biz.find(b=>b.name==='Great Circle Clearing House'))"));
|
||||
assert.equal(c.route, 'fast', 'routed for latency');
|
||||
assert.equal(c.latMax, ev("latMaxOf('nyc','chi')"));
|
||||
ev(`S.biz.find(b=>b.id===${lit(c.id)}).lcCr=5000;renderAll()`);
|
||||
const cs = ev('custSection()');
|
||||
assert.match(cs, /Low-latency wholesale route/);
|
||||
assert.match(cs, /\$5\.0k paid in SLA credits/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
78
tests/link-panel-cities.test.js
Normal file
78
tests/link-panel-cities.test.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// #196: the two city names at the top of a link panel (wave, dark fiber, virtual circuit, express, satellite circuit) open
|
||||
// that city's panel.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const start = "ACT.start({});S.cash=1e9;S.lvl=13;S.nextFail=S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;";
|
||||
const ends = ev => JSON.parse(ev("JSON.stringify([...document.querySelectorAll('#panel .ph h2 button[data-act=\"popGo\"]')].map(b=>[b.textContent,JSON.parse(b.dataset.args).city]))"));
|
||||
const click = (ev, i) => ev(`document.querySelectorAll('#panel .ph h2 button[data-act="popGo"]')[${i}].click()`);
|
||||
|
||||
function setup(ev) {
|
||||
ev(start + "ACT.launchBB({city:'fra'});ACT.buildPop({city:'ams'});compute()");
|
||||
ev("S.links.push({id:'w1',a:'fra',b:'ams',kind:'wave',tier:0,km:360,sub:false,mo:1,cut:0,day:0})");
|
||||
ev("S.links.push({id:'df1',a:'fra',b:'ams',kind:'df',own:false,sys:'lite',ch:[],km:360,sub:false,mo:1,ready:0,cut:0,day:0})");
|
||||
ev("S.links.push({id:'vx1',a:'fra',b:'ams',kind:'vxc',prov:Object.keys(FAB)[0],vt:0,km:360,sub:false,mo:1,cut:0,day:0});compute()");
|
||||
}
|
||||
|
||||
for (const [id, kind] of [['w1', 'wave'], ['df1', 'dark fiber'], ['vx1', 'virtual circuit']]) {
|
||||
test(`#196 a ${kind} panel links both of its cities, and a click opens the city`, () => {
|
||||
const { ev, errors } = load();
|
||||
setup(ev);
|
||||
ev(`selectLink('${id}')`);
|
||||
assert.deepEqual(ends(ev), [['Frankfurt', 'fra'], ['Amsterdam', 'ams']]);
|
||||
assert.match(ev("document.querySelector('#panel .ph h2').textContent"), /Frankfurt ⇄ Amsterdam/);
|
||||
click(ev, 1);
|
||||
assert.equal(ev("UI.sel.type+':'+UI.sel.id"), 'city:ams', 'the far end is selected');
|
||||
assert.equal(ev("cam.x"), ev("CITY.ams.x"), 'and the map moves to it');
|
||||
assert.match(ev("document.querySelector('#panel .ph h2').textContent"), /Amsterdam/);
|
||||
ev(`selectLink('${id}')`);
|
||||
click(ev, 0);
|
||||
assert.equal(ev("UI.sel.id"), 'fra');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
test('#196 on a 390 px phone the city links sit in the bottom sheet header and still open the city', () => {
|
||||
const { ev, errors } = load();
|
||||
setup(ev);
|
||||
ev("window.innerWidth=390;renderAll();selectLink('w1')");
|
||||
assert.equal(ev("isPhone()"), true);
|
||||
assert.equal(ends(ev).length, 2);
|
||||
// The link styling: reads as heading text that wraps, not a button that pushes the header wider.
|
||||
assert.match(ev("document.querySelector('#panel .ph h2 button').className"), /\bclink\b/);
|
||||
click(ev, 0);
|
||||
assert.equal(ev("UI.sel.type+':'+UI.sel.id"), 'city:fra');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#196 a city the map does not show stays plain text', () => {
|
||||
const { ev, errors } = load();
|
||||
setup(ev);
|
||||
ev("selectLink('w1')");
|
||||
// cityOn() is false for an off-map city without a POP or IX port: no button to a panel that would not open.
|
||||
ev("CITY.ams.off=true;delete S.pops.ams;renderPanel()");
|
||||
assert.deepEqual(ends(ev), [['Frankfurt', 'fra']]);
|
||||
assert.match(ev("document.querySelector('#panel .ph h2').textContent"), /Frankfurt ⇄ Amsterdam/);
|
||||
ev("delete CITY.ams.off");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#196 #329 an express and a satellite circuit name their cities as links too, and a circuit says when a border closed it', () => {
|
||||
const { ev, errors } = load();
|
||||
const panel = () => ev("document.getElementById('panel').textContent");
|
||||
ev(start + "ACT.launchBB({city:'fra'});for(const c of ['bru','par','doh','auh'])ACT.buildPop({city:c});for(const c of ['fra','bru','par'])S.pops[c].rgen=1;compute()");
|
||||
ev("for(const [id,a,b] of [['s1','fra','bru'],['s2','bru','par']])S.links.push({id,a,b,kind:'df',own:true,sys:'roadm',ch:[],km:kmBetween(a,b),sub:false,cable:null,mo:100,trench:id,cut:0,day:0,ready:0,spares:false,pairs:1});compute()");
|
||||
ev("ACT.xpBuild({a:'fra',b:'par',via:'s1,s2',o:'zr4'});compute();selectLink(S.links.find(l=>l.kind==='xp').id)");
|
||||
assert.deepEqual(ends(ev), [['Frankfurt', 'fra'], ['Paris', 'par']], 'the express');
|
||||
click(ev, 1);
|
||||
assert.equal(ev("UI.sel.type+':'+UI.sel.id"), 'city:par');
|
||||
// A GEO circuit across the Gulf: fine today, dark with a reason once the border closes.
|
||||
ev("const id=Object.keys(SATS).find(k=>SATS[k].orb==='geo');S.links.push({id:'st1',a:'doh',b:'auh',kind:'sat',bird:id,g:SAT_ORB.geo.g[0],km:72000,mo:1000,cut:0,day:0,ready:0});compute();selectLink('st1')");
|
||||
assert.deepEqual(ends(ev), [[ev('CITY.doh.name'), 'doh'], [ev('CITY.auh.name'), 'auh']], 'the satellite circuit');
|
||||
assert.doesNotMatch(panel(), /Border closed/);
|
||||
ev('S.ev.gulf=S.day+10;compute();renderPanel()');
|
||||
assert.match(panel(), /Border closed/);
|
||||
assert.match(panel(), /Qatar/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
66
tests/manual-listing.test.js
Normal file
66
tests/manual-listing.test.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
// #340: alien waves you list by hand stay listed, whatever the capacity market's thresholds say. The broker's daily pass
|
||||
// used to overwrite the listing with what the thresholds allowed, so 128 listed waves came back as 96, or as nothing.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const setup = () => {
|
||||
const r = load();
|
||||
r.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;S.biz=[];S.offers=[];for(const c of ['lon','nyc'])if(!S.pops[c])ACT.buildPop({city:c})");
|
||||
r.ev("S.links.push({id:'f',a:'lon',b:'nyc',kind:'df',own:true,sys:'cl',ch:[],km:5570,ready:0,day:0,cut:0,mo:1,trench:'own:f',pairs:1});after()");
|
||||
return r;
|
||||
};
|
||||
// Objects from the page come from another realm: compare them as JSON.
|
||||
const J = (ev, x) => JSON.parse(ev(`JSON.stringify(${x})`));
|
||||
const L = ev => J(ev, "S.links.find(l=>l.id==='f').list||null");
|
||||
// A day of the market with no buyer (so nothing sells and only the listing logic runs).
|
||||
const quietDay = ev => ev("(()=>{const r=Math.random;Math.random=()=>0.99;try{cmDay(S.day)}finally{Math.random=r}})()");
|
||||
|
||||
test('#340 a hand-made listing survives the broker when demand is below your minimum or the price below your floor', () => {
|
||||
const { ev, errors } = setup();
|
||||
ev("S.cm.p.spec.on=true;S.cm.p.spec.min=8;S.cm.p.spec.floor=120");
|
||||
ev("ACT.listFiber({id:'f',w:128})");
|
||||
assert.equal(L(ev).w, 128);
|
||||
quietDay(ev);
|
||||
assert.equal(L(ev).w, 128, 'still listed the next day');
|
||||
// Changing a setting relists right away; it must not take the hand-made listing away either.
|
||||
ev("ACT.mktCfg({p:'spec',k:'floor',v:100})");
|
||||
assert.equal(L(ev).w, 128);
|
||||
ev("ACT.mktCfg({p:'spec',k:'on',v:0})");
|
||||
assert.equal(L(ev).w, 128, 'switching the product off keeps what you listed by hand');
|
||||
ev("ACT.mktCfg({p:'spec',k:'on',v:1});ACT.mktRoute({k:'lon|nyc'})");
|
||||
assert.equal(L(ev).w, 128, 'leaving the route alone keeps it too');
|
||||
ev("ACT.unlistFiber({id:'f'})");
|
||||
assert.equal(L(ev), null, 'unlisting still clears it');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#340 the broker adds its share on top of yours, and sales take from its share first', () => {
|
||||
const { ev, errors } = setup();
|
||||
ev("S.cm.p.spec.on=true;S.cm.p.spec.min=1;S.cm.p.spec.floor=60;S.cm.hold=25");
|
||||
quietDay(ev);
|
||||
const auto = L(ev).w;
|
||||
assert.equal(auto, 96, 'the broker lists what is spare after the 25% kept back');
|
||||
ev("ACT.listFiber({id:'f',w:4})");
|
||||
quietDay(ev);
|
||||
assert.equal(L(ev).w, 100, 'your 4 come out of what is kept back');
|
||||
// A buyer takes a wave: the broker's share shrinks, yours stays.
|
||||
ev("(()=>{const r=Math.random;Math.random=()=>0;try{cmDay(S.day)}finally{Math.random=r}})()");
|
||||
assert.equal(ev("S.biz.filter(b=>b.type==='wwave').reduce((a,b)=>a+b.slots,0)"), 1);
|
||||
assert.equal(L(ev).hw, 4);
|
||||
quietDay(ev);
|
||||
assert.equal(L(ev).w, 99, '95 spare after the reserve, plus your 4');
|
||||
assert.equal(L(ev).hw, 4);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#340 the hand-made part of a listing round-trips through a save, and old saves load as before', () => {
|
||||
const { ev, errors } = setup();
|
||||
ev("ACT.listFiber({id:'f',w:12})");
|
||||
const back = J(ev, "((()=>{const s=parseSave(JSON.stringify(S)).s;migrate(s);return s.links.find(l=>l.id==='f').list})())");
|
||||
assert.deepEqual(back, { w: 12, p: 0, hw: 12 });
|
||||
assert.deepEqual(J(ev, "(cmClean({w:5,p:0,hw:40}))"), { w: 5, p: 0, hw: 5 }, 'never more by hand than listed');
|
||||
assert.deepEqual(J(ev, "(cmClean({w:5,p:0}))"), { w: 5, p: 0 }, 'an old listing has nothing by hand');
|
||||
assert.equal(ev("cmClean({w:0,p:0,hw:3})"), null);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -226,7 +226,7 @@ test('a dry run prices every command that has a price, and changes nothing', ()
|
|||
setChCount: { id: df, o: 'zr4', n: 2 }, xpBuild: { a: 'fra', b: 'par', via: df + ',' + df, o: 'zr4' }, xpCh: { id: df, o: 'zr4', d: 1 }, repayLoan: { id: 'none' }, buildScrub: { city: 'ams', tier: 1 }, scrubUp: { city: 'fra', tier: 1 },
|
||||
fixInc: { id: 'none' }, confGo: { key: T('catalog', { name: 'conferences' })[0].key }, confSponsor: { key: T('catalog', { name: 'conferences' })[0].key },
|
||||
opsHire: { id: ev('Object.keys(INTERNS)[0]') }, opsNewPop: { city: 'nyc' }, pniAll: { net: 'cog', tier: 1 }, seatBuy: { n: 2 }, layShip: { id: df }, seaRush: { id: df },
|
||||
utilityKit: { city: 'fra' }, utilityCaches: { city: 'fra' }, teDeploy: { script: 'spill at 85%' }, upLinkX: {},
|
||||
utilityKit: { city: 'fra' }, utilityCaches: { city: 'fra' }, acceptFix: { id: 'none' }, ptApply: { city: 'fra', k: 'medium' }, ptAll: { k: 'medium' }, teDeploy: { script: 'spill at 85%' }, upLinkX: {},
|
||||
pieRd: { k: 'reuse' }, pieAnt: { id: 'none' }, ip4Buy: { len: 24 }, ip4Lease: { len: 22 }, ip6Go: { city: 'fra' },
|
||||
teleBuild: { city: 'fra' }, teleTrk: { city: 'fra' }, buySat: { a: 'fra', b: 'rek', bird: 'is37', g: 1 }, satSize: { id: wave, g: 2 },
|
||||
};
|
||||
|
|
|
|||
|
|
@ -377,7 +377,8 @@ test('Flood Season: attacks keep coming, grow, and only count when service held'
|
|||
|
||||
test('DKNOG in Copenhagen is on the conference calendar', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0");
|
||||
// Not Tier 1 yet: after that, conferences no longer report back (#101).
|
||||
ev("ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;delete S.done.t1");
|
||||
const cf = JSON.parse(ev("JSON.stringify(CONFS.find(c=>c.n==='DKNOG'))"));
|
||||
assert.equal(cf.c, 'cph');
|
||||
assert.equal(ev(`MONTHS[${cf.m}]`), 'Mar', 'held in March, like the real one');
|
||||
|
|
|
|||
|
|
@ -100,15 +100,20 @@ test('the envelope check refuses what section 10 refuses', () => {
|
|||
[env('launchBB', { city: '__proto__' }), '__proto__ as a city'], [env('addGen', { city: 'constructor' }), 'constructor as a city'], [env('buildPop', { city: 'prototype' }), 'prototype as a city'],
|
||||
[env('buildPop', { city: ['fra', '__proto__'] }), '__proto__ in an array'], [env('buildLink', { tier: 1 }, { ui: { pending: { a: '__proto__', b: 'ams' } } }), '__proto__ in a draft'],
|
||||
[env('decomGo', {}, { ui: { decom: ['fra', 'constructor'] } }), 'constructor among the cities to close'], [env('orderDf', {}, { ui: { dfSys: 'constructor' } }), 'constructor as a system'],
|
||||
// Any name Object.prototype has reads as something there (S.pops.toString is a function, so a POP).
|
||||
[env('ptSave', { city: 'toString', k: 'micro' }), 'toString as a city'], [env('popStdSet', { city: 'valueOf' }), 'valueOf as a city'],
|
||||
[env('buildPop', { city: ['fra', 'hasOwnProperty'] }), 'hasOwnProperty in an array'], [env('decomGo', {}, { ui: { decom: ['fra', 'toString'] } }), 'toString among the cities to close'],
|
||||
// The open window: one the server knows by name, with only its own view state.
|
||||
[env('opsTpl', { k: 'bb' }, { ctx: { modal: true, win: { k: 'nope' } } }), 'a window that is none'], [env('opsTpl', { k: 'bb' }, { ctx: { win: 'ops' } }), 'a window as text'],
|
||||
[env('opsTpl', { k: 'bb' }, { ctx: { win: { k: 'ops', ui: { pieTab: 'co' } } } }), 'another window\'s view state'], [env('opsTpl', { k: 'bb' }, { ctx: { win: { k: 'ops', x: 1 } } }), 'a window with more'],
|
||||
[env('opsTpl', { k: 'bb' }, { ctx: { win: { k: 'ops', ui: { opsCity: '__proto__' } } } }), '__proto__ as the intern\'s POP'], [env('opsTpl', { k: 'bb' }, { ctx: { win: { k: 'ops', ui: { opsCity: { a: 1 } } } } }), 'a POP as an object'],
|
||||
[env('opsTpl', { k: 'bb' }, { ctx: { win: { k: 'constructor' } } }), 'constructor as a window'],
|
||||
[env('opsTpl', { k: 'bb' }, { ctx: { win: { k: 'ops', ui: { opsCity: 'toString' } } } }), 'toString as the intern\'s POP'],
|
||||
]) no('act', b, why);
|
||||
assert.equal(ok('act', env('teDeploy', { script: 'x'.repeat(4000) })).ok, true, 'a long script within its cap');
|
||||
// Free text may say them: a network named for a word.
|
||||
assert.equal(ok('act', env('renameGo', { name: 'constructor' })).ok, true, 'a name is no key');
|
||||
assert.equal(ok('act', env('renameGo', { name: 'toString' })).ok, true, 'nor this one');
|
||||
// An express of six spans: six link ids as the game mints them (10 or 11 characters each), joined by commas.
|
||||
const ids = Array.from({ length: 6 }, (x, i) => 'i' + (2e7 + i).toString(36).slice(-5) + (12345 + i));
|
||||
assert.equal(ids.join(',').length > 64, true);
|
||||
|
|
|
|||
|
|
@ -816,3 +816,67 @@ test('multiplayer: with a charter to sign first, the session code and its Share
|
|||
assert.deepEqual(errors, []);
|
||||
dom.window.close();
|
||||
});
|
||||
|
||||
test('multiplayer: "Send to another device" moves a session network by the session\'s own link; its save file is a copy', async () => {
|
||||
const { dom, ev, errors, f } = await started();
|
||||
const doc = dom.window.document;
|
||||
ev('save(true);ACT.xfer({})');
|
||||
assert.ok(await until(() => ev('!!UI.xfer')), 'the send screen opens');
|
||||
assert.equal(ev('UI.xfer.mp'), CODE);
|
||||
assert.equal(ev('UI.xfer.link'), ev('mpLink(S.mp)'), 'the link is the session\'s, with the token, not the network itself');
|
||||
assert.match(ev('UI.xfer.link'), new RegExp(`#mp=${CODE}\\.${PID}\\.[0-9a-f]{64}$`));
|
||||
const txt = doc.getElementById('modalCard').textContent;
|
||||
assert.match(txt, /Open this link on your other phone or computer/);
|
||||
assert.match(txt, /Anyone with this link can play as you/);
|
||||
assert.match(txt, /The save file is a copy: on another device it plays on alone, outside session K7Q-2XD/);
|
||||
assert.doesNotMatch(txt, /under From another device/, 'not a transfer link to paste');
|
||||
// Copying it sends the session the latest save first, as the session panel's own button does.
|
||||
ev("window.__clip=[];Object.defineProperty(navigator,'clipboard',{configurable:true,value:{writeText:t=>{__clip.push(t);return Promise.resolve();}}})");
|
||||
await until(() => ev('!MP.busy'));
|
||||
const k = f.saves().length;
|
||||
ev("S.name='Packet Pals Two';document.querySelector('#modalCard [data-act=\"xferLink\"]').click()");
|
||||
assert.ok(await until(() => ev('__clip.length===1')));
|
||||
assert.equal(ev('__clip[0]'), ev('mpLink(S.mp)'));
|
||||
assert.ok(await until(() => f.saves().length === k + 1), 'the save goes to the session first');
|
||||
assert.equal(JSON.parse(f.saves().at(-1).body.data).name, 'Packet Pals Two');
|
||||
assert.ok(await until(() => /Open it on your other device/.test(ev("document.getElementById('toasts').textContent"))));
|
||||
// Without the token on this device: no link at all, only the copy.
|
||||
ev('mpTokSet(S.mp.code,S.mp.pid,null);ACT.xfer({})');
|
||||
assert.ok(await until(() => ev('UI.xfer.link===null')));
|
||||
assert.equal(doc.querySelector('#modalCard [data-act="xferLink"]'), null);
|
||||
assert.match(doc.getElementById('modalCard').textContent, /The save file is a copy/);
|
||||
assert.deepEqual(errors, []);
|
||||
dom.window.close();
|
||||
});
|
||||
|
||||
test('multiplayer: the session link pasted under "From another device" opens there as the link would; a plain page has no session links', async () => {
|
||||
const a = await started();
|
||||
a.ev("ACT.launchBB({city:'fra'});for(let i=0;i<4;i++)dayTick()");
|
||||
const data = a.ev('JSON.stringify(packSave(S))'), link = a.ev('mpLink(S.mp)');
|
||||
// On this device, in a game: the game is saved before the page loads again.
|
||||
a.ev(`S.name='Saved First';ACT.xferRecv();$('xferIn').value=${lit(link)};ACT.xferPaste()`);
|
||||
assert.equal(a.ev('location.hash'), `#mp=${CODE}.${PID}.${TOK}`);
|
||||
assert.equal(a.ev('slotIdx().find(e=>e.id===UI.slot).name'), 'Saved First');
|
||||
a.dom.window.close();
|
||||
// The other device's title screen: the link, with whatever a chat adds around it.
|
||||
const f = fake([[/^GET \/api\/mp\/sessions\/K7Q2XD\/save$/, { status: 200, json: { seq: 4, at: 1, data } }], [/^GET \/api\/mp\/sessions\/K7Q2XD$/, { status: 200, json: roster([me()]) }], okSave]);
|
||||
const b = load({ mp: MPA, fetch: f });
|
||||
b.ev(`ACT.xferRecv();$('xferIn').value=${lit('Here: ' + link + '\n')};ACT.xferPaste()`);
|
||||
assert.equal(b.ev('location.hash'), `#mp=${CODE}.${PID}.${TOK}`, 'the link goes into the address bar and the page loads again (mpBoot reads it at boot)');
|
||||
assert.doesNotMatch(b.ev("$('toasts').textContent"), /not a transfer link/);
|
||||
const href = b.ev('location.href');
|
||||
b.dom.window.close();
|
||||
// That page, loaded again with the link (jsdom does not reload): the network moves here.
|
||||
const c = load({ mp: MPA, fetch: f, url: href });
|
||||
assert.ok(await until(() => c.ev('!!(S&&UI.started)')), 'the network opened');
|
||||
assert.deepEqual([c.ev('S.mp.code'), c.ev('S.day'), c.ev('location.hash')], [CODE, 4, '']);
|
||||
assert.equal(c.ev(`localStorage.getItem('sot-mp:${CODE}:${PID}')`), TOK);
|
||||
// A plain page: not a link it can open.
|
||||
const p = load();
|
||||
p.ev(`ACT.xferRecv();$('xferIn').value=${lit(link)};ACT.xferPaste()`);
|
||||
assert.match(p.ev("$('toasts').textContent"), /not a transfer link/);
|
||||
assert.equal(p.ev('location.hash'), '');
|
||||
for (const x of [a, b, c, p]) assert.deepEqual(x.errors, []);
|
||||
c.dom.window.close();
|
||||
p.dom.window.close();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -136,3 +136,15 @@ test('saves: fabric ports that make no sense are dropped, LAGs are kept in bound
|
|||
assert.equal(ev('R.cost.nni'), 500, 'a 10G port from before costs what it did');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a 400G fabric port in the Connections list offers a LAG member and no faster port, whatever the sort', () => {
|
||||
const { ev, errors } = open();
|
||||
ev(`S.pops.fra.rgen=${fast(5)};ACT.buyNni({city:"fra",prov:FB,tier:2});compute()`);
|
||||
assert.ok(ev('portShown(3)'), 'an 800G port is on sale, so nothing stops the list from offering one');
|
||||
for (const [k, cf] of [['use', '{}'], ['k', "{k:'nni'}"]]) {
|
||||
const h = ev(`UI.connSort='${k}';UI.connDir=-1;UI.cf=${cf};connSection()`);
|
||||
assert.match(h, /data-act="lagNni"/, `sorted by ${k}`);
|
||||
assert.doesNotMatch(h, /data-act="buyNni"/, `sorted by ${k}: no 800G fabric port`);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ test('saves: PNIs on order survive, and garbage is repaired', () => {
|
|||
setup(ev);
|
||||
ev("S.pni.push({id:'x',city:'fra',net:'dtk',tier:0,g1:true,ready:S.day+30,up:{tier:'9',n:99,ready:'x'}},{id:'y',city:'fra',net:'nfx',tier:1,g1:true})");
|
||||
ev('const o=JSON.parse(JSON.stringify(S));sanitize(o);window.__o=o');
|
||||
assert.equal(ev("__o.pni.find(p=>p.id==='x').up.n"), ev('LAG_MAX'));
|
||||
assert.equal(ev("__o.pni.find(p=>p.id==='x').up.n"), ev('PNI_LAG_MAX'));
|
||||
assert.equal(ev("__o.pni.find(p=>p.id==='x').g1"), true);
|
||||
assert.equal(ev("__o.pni.find(p=>p.id==='y').g1"), undefined, 'only Doitsche Telekomm does 1G');
|
||||
assert.deepEqual(errors, []);
|
||||
|
|
|
|||
109
tests/pop-kinds-build-standard.test.js
Normal file
109
tests/pop-kinds-build-standard.test.js
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
// 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, []);
|
||||
});
|
||||
73
tests/renewal-details.test.js
Normal file
73
tests/renewal-details.test.js
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// #292: a renewal haggle in Deals shows what is at stake: traffic booked and served, the price per Gbps now and asked,
|
||||
// and the path terms the customer signed for, each ticked as it stands today. It fits on a phone.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const start = "ACT.start({});S.cash=1e9;S.lvl=6;S.nextFail=S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;";
|
||||
// Frankfurt, Paris and Amsterdam in a triangle, so Frankfurt-Amsterdam has a direct path and one round through Paris.
|
||||
function net(ev) {
|
||||
ev(start + "ACT.launchBB({city:'fra'});ACT.buildPop({city:'par'});ACT.buildPop({city:'ams'});for(const c in S.pops){S.pops[c].rgen=3;S.pops[c].routers=2}");
|
||||
for (const [a, b] of [['fra', 'par'], ['par', 'ams'], ['fra', 'ams']]) ev(`UI.via=null;openLinkModal('${a}','${b}');ACT.buildLink({tier:1});closeModal()`);
|
||||
}
|
||||
const deals = ev => { ev("UI.left='deals';renderLeft()"); return ev("document.getElementById('left').innerHTML"); };
|
||||
const row = (ev, name) => ev(`(()=>{const r=[...document.querySelectorAll('#left .row')].find(r=>r.querySelector('.nm')&&r.querySelector('.nm').textContent==='${name}');return r?r.textContent:''})()`);
|
||||
|
||||
test('#292 an IP customer\'s renewal shows booked and served traffic and the price per Gbps', () => {
|
||||
const { ev, errors } = load();
|
||||
net(ev);
|
||||
ev("S.biz.push({id:'h1',city:'ams',city2:null,name:'Haggle Hosting',type:'dia',bw:5,rate:600,reqs:[],mood:90,since:S.day-800,te:S.day+20,mk:1,hag:{rate:540,until:S.day+20}});compute()");
|
||||
deals(ev);
|
||||
const t = row(ev, 'Haggle Hosting');
|
||||
assert.match(t, /5\.0 Gbps booked, [\d.]+ Gbps served/);
|
||||
assert.ok(t.includes(ev("fmt$(600)") + ' → ' + ev("fmt$(540)") + ' per Gbps'), t);
|
||||
assert.match(t, /Pays .* wants .* to renew/, 'the monthly bills are still there');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#292 a circuit\'s renewal shows its latency limit and path terms, ticked as they stand today', () => {
|
||||
const { ev, errors } = load();
|
||||
net(ev);
|
||||
ev("S.biz.push({id:'c1',city:'fra',city2:'ams',name:'Tulip Bank',type:'l2vpn',bw:10,rate:300,reqs:['lat','diverse','sharks'],latMax:50,route:'fast',mood:90,since:S.day-800,te:S.day+20,mk:1,hag:{rate:250,until:S.day+20}});compute()");
|
||||
deals(ev);
|
||||
let t = row(ev, 'Tulip Bank');
|
||||
assert.match(t, /10\.0 Gbps booked, 10\.0 Gbps served/);
|
||||
assert.match(t, /✓ latency within 50 ms \(now [\d.]+ ms one-way\)/);
|
||||
assert.match(t, /✓ two diverse paths/, 'direct and round through Paris');
|
||||
assert.match(t, /✓ no subsea cable/);
|
||||
// A tight budget the network cannot meet is crossed out, with what it gets today.
|
||||
ev("S.biz.find(b=>b.id==='c1').latMax=0.5;compute()");
|
||||
deals(ev);
|
||||
t = row(ev, 'Tulip Bank');
|
||||
assert.match(t, /✗ latency within 0\.5 ms/);
|
||||
assert.doesNotMatch(t, /undefined|NaN/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#292 SD-WAN shows its sites, fiber deals show no Gbps, and served traffic below what is booked is red', () => {
|
||||
const { ev, errors } = load();
|
||||
net(ev);
|
||||
ev("S.biz.push({id:'s1',city:'fra',city2:null,sites:['fra','par','ams'],name:'Kebab Kingdom',type:'sdwan',bw:2,rate:400,reqs:[],mood:90,since:S.day-800,te:S.day+20,mk:1,hag:{rate:360,until:S.day+20}});compute()");
|
||||
deals(ev);
|
||||
assert.match(row(ev, 'Kebab Kingdom'), /3 sites × 2\.0 Gbps booked/);
|
||||
assert.doesNotMatch(row(ev, 'Kebab Kingdom'), /✓|✗/, 'no path terms when they asked for none');
|
||||
assert.equal(ev("clRenInfo({...S.biz.find(b=>b.id==='s1'),type:'dfpair'})"), '', 'a fiber pair is not sold by the Gbps');
|
||||
ev("R.l2['s1']=0.5");
|
||||
// Red text in the dark-aware red (#80): --bad by day.
|
||||
assert.match(ev("clRenInfo(S.biz.find(b=>b.id==='s1'))"), /color:var\(--tx-red,var\(--bad\)\)">0\.5 Gbps/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#292 the renewal row fits a 390 px phone', () => {
|
||||
const { ev, errors } = load();
|
||||
net(ev);
|
||||
ev("S.biz.push({id:'c1',city:'fra',city2:'ams',name:'Tulip Bank',type:'l2vpn',bw:10,rate:300,reqs:['lat','diverse'],latMax:50,route:'fast',mood:90,since:S.day-800,te:S.day+20,mk:1,hag:{rate:250,until:S.day+20}});compute()");
|
||||
ev("window.innerWidth=390;renderAll()");
|
||||
deals(ev);
|
||||
assert.match(row(ev, 'Tulip Bank'), /booked, .* served/);
|
||||
// Every new line is a wrapping meta line, never one wide nowrap element.
|
||||
const info = ev("clRenInfo(S.biz.find(b=>b.id==='c1'))");
|
||||
assert.match(info, /^<div class="meta">/);
|
||||
assert.doesNotMatch(info, /nowrap|width:\s*\d{3,}px/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -17,10 +17,10 @@ function pages() {
|
|||
let base = head;
|
||||
try { const b = path.join(os.tmpdir(), `tubes-fuzz-test-${process.pid}-base.html`); fs.writeFileSync(b, page.assembleRef('origin/main')); base = b; } catch (e) {}
|
||||
let P = { base: openPage(base, 'base'), head: openPage(head, 'head') };
|
||||
// A change to the world itself (cities, networks, cables) or to what links cost cannot route like main: there is no
|
||||
// same game to compare. Then the base is this checkout too, and the cache on/off check still runs; equivalence with
|
||||
// main resumes once it lands.
|
||||
const world = (p) => p.ev("JSON.stringify([CITIES.map(c=>[c.id,c.land,c.P]),NETS.map(n=>[n.id,n.pops,n.ix,n.share,n.price,n.up]),CABLES.map(c=>[c.id,c.pairs.map(q=>[q[0],q[1]])]),[1,300,3000].map(k=>[dfLeaseMo(k),waveMo(k,false,2),dfBuildCost(k)])])");
|
||||
// A change to the world itself (cities, networks, cables, AI campuses, the kinds of customers that call), to what links cost or to where each city's
|
||||
// traffic goes (locSh(), #48) cannot route like main: there is no same game to compare. Then the base is this checkout
|
||||
// too, and the cache on/off check still runs; equivalence with main resumes once it lands.
|
||||
const world = (p) => p.ev("JSON.stringify([CITIES.map(c=>[c.id,c.land,c.P]),NETS.map(n=>[n.id,n.pops,n.ix,n.share,n.price,n.up]),CABLES.map(c=>[c.id,c.pairs.map(q=>[q[0],q[1]])]),[1,300,3000].map(k=>[dfLeaseMo(k),waveMo(k,false,2),dfBuildCost(k)]),Object.keys(BIZ_T).map(t=>[t,BIZ_T[t].lv||1,BIZ_T[t].opts]),MEGA.map(m=>m.c),['nyc','fra','sin'].map(c=>typeof locSh==='function'?Array.from(locSh(NSH,c)):null)])");
|
||||
if (base !== head && world(P.base) !== world(P.head)) { console.log('# route fuzz: the world or its prices differ from main, so both pages are this checkout'); P = { base: openPage(head, 'base'), head: P.head }; }
|
||||
return P;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -511,3 +511,21 @@ test('on a phone: the teleport section, the order sheet, a circuit’s panel and
|
|||
assert.deepEqual(errors, []);
|
||||
assert.equal(dom.window.document.querySelectorAll('#panel').length, 1);
|
||||
});
|
||||
|
||||
// Spill tiers (#136) time a detour before they use it: that path's latency on the ground (the haul to transit) and its
|
||||
// satellite edges are filled in the same step, so what users notice on a detour is charged as on any path.
|
||||
test('a spill tier\'s detour costs users its latency, as the same traffic does without tiers', (t) => {
|
||||
const { ev, errors } = game(t);
|
||||
ev(`S.cash=1e12;S.lvl=13;for(const c of ['nyc','lax','mia'])if(!S.pops[c])ACT.buildPop({city:c});
|
||||
for(const c of ['nyc','lax','mia']){S.pops[c].rgen=RG_TOP;S.pops[c].routers=RMAX;}if(!S.pops.nyc.bb)ACT.launchBB({city:'nyc'});S.pops.nyc.bb.d=400;
|
||||
const L=(a,b,t)=>{UI.via=null;UI.lmode='wave';UI.route='main';openLinkModal(a,b);ACT.buildLink({tier:t});closeModal();};
|
||||
L('nyc','lax',0);L('nyc','mia',3);L('mia','lax',3);S.links.forEach(l=>l.ready=0);
|
||||
S.transit=[];const t=NETS.find(n=>n.price&&n.pops.includes('lax')&&n.type==='t1');ACT.buyTransit({city:'lax',net:t.id,tier:3});
|
||||
S.ixp={};S.pni=[];S.caches=[];S.te={on:true,day:0};S.core={lv:2,run:2,legacy:true};`);
|
||||
const run = (s) => { ev(`S.te.script=${JSON.stringify(s)};compute()`); return J(ev, '{f:R.latF.nyc,far:R.latFar.nyc}'); };
|
||||
const none = run(''), tier = run('spill at 80% within 15 ms');
|
||||
assert.ok(none.f < 0.6, `New York's exit in Los Angeles is far either way (${none.f})`);
|
||||
assert.ok(Math.abs(tier.f - none.f) < 1e-9, `and a tier's detour through Miami is charged too (${tier.f} vs ${none.f})`);
|
||||
assert.equal(tier.far.share, 1, 'every bit of it went far');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -367,7 +367,7 @@ test('Auto-TE routes around a full link exactly like the plain path', () => {
|
|||
S.transit=[];const t=NETS.find(n=>n.price&&n.pops.includes('ams')&&n.type==='t1');ACT.buyTransit({city:'ams',net:t.id,tier:3});
|
||||
S.ixp={};S.pni=[];S.caches=[];S.te={on:true,day:0};S.core={lv:2,run:2,legacy:true};S.nextFail=1e9;S.nextEvent=1e9;`);
|
||||
const sig = () => ev('JSON.stringify({served:R.served,teMoved:R.teMoved,egT:R.egT,load:S.links.map(l=>R.load[l.id]||0),node:R.nodeLoad,t:R.useT})');
|
||||
for (const script of ['', 'spill at 70%']) {
|
||||
for (const script of ['', 'spill at 70%', 'spill at 80% within 5 ms\nspill at 90% within 20 ms']) {
|
||||
ev(`S.te.script=${lit(script)}`);
|
||||
ev('compute()'); const fast = sig();
|
||||
ev('__plain()'); const ref = sig();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue