Merge review fixes: Tier 1 cone, badges, merged-PR polish
This commit is contained in:
commit
f13b0d40af
28 changed files with 275 additions and 35 deletions
|
|
@ -135,3 +135,37 @@ test('the share card rings the variant badges', () => {
|
|||
assert.ok(fiery > plain, `the ring and the tally are drawn (${fiery} > ${plain} calls)`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a variant named after an Object prototype key is not a variant', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev);
|
||||
for (const k of ['constructor', 'toString', '__proto__', 'hasOwnProperty']) {
|
||||
ev(`const o=JSON.parse(JSON.stringify(S));o.ach={hello:3};o.achP={hello:${JSON.stringify(k)}};S=migrate(o)`);
|
||||
assert.equal(ev('S.achP.hello'), 'oncall', k);
|
||||
assert.equal(ev(`bvar(${JSON.stringify(k)}).k`), 'oncall', `bvar(${k})`);
|
||||
ev(`S.rules={preset:${JSON.stringify(k)}}`);
|
||||
assert.equal(ev('badgeVar()'), 'oncall', `badgeVar() under preset ${k}`);
|
||||
}
|
||||
ev("S.rules={preset:'oncall'};S.achP.hello='constructor';shareCanvas()");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('"Badge upgraded" means the collection on this device got a better variant', () => {
|
||||
const { ev, errors } = load();
|
||||
const spy = () => ev("window.__t=[];if(!window.__sp){window.__sp=1;const _t=toast;toast=(h,...a)=>{window.__t.push(h);return _t(h,...a);};}");
|
||||
// a new game, but this device already holds the frosted badge: the standard one upgrades it
|
||||
start(ev, 'oncall');
|
||||
ev("localStorage.setItem('sot-badges',JSON.stringify({hello:{d:'2026-01-01',n:'Old',vs:{freeze:'2026-01-01'}}}))");
|
||||
spy(); earnHello(ev);
|
||||
assert.match(ev("window.__t.join(' ')"), /Badge upgraded/);
|
||||
assert.equal(hof(ev).hello.v, 'oncall');
|
||||
// another new game, the device already holds the fiery one: earning the frosted one is a plain unlock
|
||||
start(ev, 'freeze');
|
||||
ev("localStorage.setItem('sot-badges',JSON.stringify({hello:{d:'2026-01-01',n:'Old',vs:{bgp:'2026-01-01'}}}))");
|
||||
spy(); earnHello(ev);
|
||||
const t = ev("window.__t.join(' ')");
|
||||
assert.match(t, /Badge unlocked/);
|
||||
assert.doesNotMatch(t, /Badge upgraded/);
|
||||
assert.equal(hof(ev).hello.v, 'bgp', 'the best variant stays on the shelf');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
24
tests/link-trial.test.js
Normal file
24
tests/link-trial.test.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// #62 on a big network: a redundancy check routes once (the failed link), and uses the live routing as "before".
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
test('#62 a redundancy check computes only the trial, and matches comparing two fresh routings', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});S.cash=1e8;ACT.buildPop({city:'bde'});ACT.buildPop({city:'ams'});S.biz=[{id:'circuit',name:'Test Circuit',type:'l2vpn',city:'fra',city2:'bde',bw:80,rate:1,reqs:[]}]");
|
||||
ev("S.links=[{id:'main',a:'fra',b:'bde',kind:'wave',tier:1,km:100,mo:100,cut:0},{id:'a',a:'fra',b:'ams',kind:'wave',tier:0,km:100,mo:100,cut:0},{id:'b',a:'ams',b:'bde',kind:'wave',tier:0,km:100,mo:100,cut:0}];compute()");
|
||||
ev("window.__n=0;window.__c=compute;compute=function(){window.__n++;return window.__c.apply(this,arguments);}");
|
||||
const t = JSON.parse(ev("JSON.stringify(linkTrial('main'))"));
|
||||
assert.equal(ev('window.__n'), 1, 'one routing pass per check');
|
||||
assert.equal(t.split, false);
|
||||
assert.equal(t.loss, 70);
|
||||
assert.equal(ev("linkTrial('nope')"), null);
|
||||
assert.equal(ev('window.__n'), 1, 'an unknown link costs nothing');
|
||||
ev('compute=window.__c');
|
||||
// the old way: route the copy twice, before and after the cut
|
||||
const old = ev(`(()=>{const save=S,live=R;try{S=JSON.parse(JSON.stringify(save));compute();const b=R;S.links[0].cut=S.day+1;compute();
|
||||
const g=c=>Math.max(0,(b.citySrv[c]||0)-(R.citySrv[c]||0)),l2=Math.max(0,(b.l2.circuit||0)-(R.l2.circuit||0));
|
||||
return Object.keys(S.pops).reduce((a,c)=>a+(g(c)>.01?g(c):0),0)+(l2>.01?l2:0);}finally{S=save;R=live;}})()`);
|
||||
assert.equal(t.loss, old);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
40
tests/metric-panel.test.js
Normal file
40
tests/metric-panel.test.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// #131 on Safari: the custom metric field keeps focus through a button tap, and the panel skips re-rendering a
|
||||
// focused field, so switching between multiplier and cost (or to a preset) left the old panel on screen.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const setup = (ev) => {
|
||||
ev("ACT.start({});S.cash=1e9;S.lvl=4;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});ACT.buildPop({city:'ams'});UI.via=null;openLinkModal('fra','ams');ACT.buildLink({tier:1});closeModal()");
|
||||
ev("window.L=S.links[0].id;ACT.selLink({id:L});renderAll();ACT.setMetric({id:L,v:'custom'});renderAll()");
|
||||
};
|
||||
|
||||
test('#131 switching the custom metric mode re-renders even while the field has focus', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const d = dom.window.document;
|
||||
setup(ev);
|
||||
d.getElementById('metIn').focus();
|
||||
assert.equal(d.activeElement.id, 'metIn');
|
||||
ev("ACT.metricMode({id:L,k:'w'})");
|
||||
assert.equal(d.getElementById('metIn').getAttribute('step'), '1', 'the field is now the exact cost');
|
||||
assert.equal(+d.getElementById('metIn').value, ev("S.pairMet[edgeKey(S.links[0])].v"));
|
||||
d.getElementById('metIn').focus();
|
||||
ev("ACT.metricMode({id:L,k:'f'})");
|
||||
assert.equal(d.getElementById('metIn').getAttribute('step'), '0.1', 'and back to a multiplier');
|
||||
d.getElementById('metIn').focus();
|
||||
ev("ACT.setMetric({id:L,v:'normal'})");
|
||||
assert.equal(d.getElementById('metIn'), null, 'a preset hides the field');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#131 the daily re-render still keeps a half-typed value', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const d = dom.window.document;
|
||||
setup(ev);
|
||||
const t = d.getElementById('metIn');
|
||||
t.focus(); t.value = '3.5';
|
||||
ev("S.day++;renderPanel()");
|
||||
assert.equal(d.getElementById('metIn').value, '3.5');
|
||||
assert.equal(d.activeElement.id, 'metIn');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -409,8 +409,8 @@ test('#114 Only Spätzle-IX can be won by peering alone', () => {
|
|||
const { ev, errors } = load();
|
||||
ev("ACT.startScn({id:'stg',sure:1})");
|
||||
assert.equal(ev("scnRule('local')&&scnRule('noTransit')"), true);
|
||||
assert.match(ev("SCN.find(x=>x.id==='stg').goal"), /45%.*300 Gbps/);
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(scnProg().items.map(x=>x.max))")), [0.45, 300]);
|
||||
assert.match(ev("SCN.find(x=>x.id==='stg').goal"), /50%.*300 Gbps/);
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(scnProg().items.map(x=>x.max))")), [0.5, 300]);
|
||||
// a game saved before the fix picks the rule up on load
|
||||
ev("const o=JSON.parse(JSON.stringify(S));delete o.scn.rules.local;migrate(o);window.__mig=o.scn.rules.local");
|
||||
assert.equal(ev('window.__mig'), true);
|
||||
|
|
|
|||
|
|
@ -1076,7 +1076,12 @@ test('prices follow real connectivity: thin markets cost more, hubs stay put', (
|
|||
const { ev, errors } = load();
|
||||
start(ev);
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(Object.keys(CITY_PDB).filter(c=>!CITY[c]))')), [], 'every entry is a city on the map');
|
||||
assert.ok(ev('Object.keys(CITY_PDB).length') >= 190, 'real-world data for most cities');
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(CITIES.filter(c=>!CITY_PDB[c.id]).map(c=>c.id))')), [], 'every city has data, so none keeps the plain price by accident');
|
||||
assert.ok(ev('Object.values(CITY_PDB).every(q=>Array.isArray(q)&&q.length===3&&q.every(x=>Number.isInteger(x)&&x>=0)&&q[1]>=0)'), '[facilities, presences, ASNs], whole numbers');
|
||||
// The cities that used to have none: thin markets cost more than Frankfurt, and the Arctic has no neutral data center.
|
||||
for (const c of ['dus', 'rix', 'mct', 'mle', 'fuk', 'sju', 'kin', 'anc', 'tik']) assert.ok(ev(`txComp('${c}')`) > 1, `${c} is no hub`);
|
||||
for (const c of ['brw', 'tik', 'pvs', 'hav']) assert.equal(ev(`colo('${c}')`), 1.5, `${c}: no carrier-neutral data center`);
|
||||
assert.ok(ev("txComp('dus')") < ev("txComp('rix')") && ev("txComp('rix')") < ev("txComp('mle')"), 'Düsseldorf, Riga, Malé: ever thinner');
|
||||
// A city without data keeps the plain regional price.
|
||||
assert.equal(ev("(()=>{const q=CITY_PDB.fra;delete CITY_PDB.fra;const r=[txComp('fra'),colo('fra'),popMo('fra')];CITY_PDB.fra=q;return r.join()})()"), `1,1,${ev('POP_MO')}`);
|
||||
assert.equal(ev("regionMult('syd')"), ev('AU_TRANSIT'), 'Australia keeps its hand-set transit price');
|
||||
|
|
|
|||
|
|
@ -23,8 +23,12 @@ test('cones are built once at load and hold customers of customers', () => {
|
|||
assert.equal(ev("NETS.filter(n=>n.tail).every(n=>ANC[n.id].some(u=>NET[u].type==='t1'))"), true, 'from a Tier 1, directly or through a carrier');
|
||||
assert.equal(ev("NET.tail45.up.join()"), 'mag', 'Auckland has no Tier 1: Hobbit Hole buys from a carrier that is there');
|
||||
assert.equal(ev("NETS.filter(n=>n.tail).map(n=>n.up.join('+')).join()"), ev("NETS.filter(n=>n.tail).map(n=>tailUp(n.name,n.pops).join('+')).join()"), 'stable: picked by name');
|
||||
// Australians buy only from Australian carriers, so a Tier 1 PNI is still no back door into Australia.
|
||||
assert.equal(ev("['opt','tpr','abb','npt','lpt','lnt','pnt','stb','blg'].some(id=>t1Need().some(t=>CONE_S[t.id].has(id)))"), false);
|
||||
// Australia's big ISPs buy only from Australian carriers, so a Tier 1 PNI is no back door to them.
|
||||
assert.equal(ev("['opt','tpr','abb','npt','lpt','lnt','pnt','stb','blg','inp'].some(id=>t1Need().some(t=>CONE_S[t.id].has(id)))"), false);
|
||||
// The smaller ones that buy from a Tier 1 or a carrier of one do come along, and these are exactly the ones.
|
||||
const au = "NETS.filter(n=>n.type==='eye'&&n.pops.length&&n.pops.every(c=>CITY[c].au)&&t1Need().some(t=>CONE_S[t.id].has(n.id))).map(n=>n.id).sort().join()";
|
||||
assert.equal(ev(au), 'ddo,ext,spn,tail44', 'Doodoo, Lintel, Spin2wintel, Kangaroo Courier');
|
||||
assert.equal(ev("[NET.tail44.name,NET.tail44.up.join(),NET.ddo.up.join(),NET.spn.up.join(),NET.ext.up.join(),NET.voc.up.join(),NET.spl.up.join()].join('|')"), 'Kangaroo Courier|cog|voc|voc|spl|ntt,tly|tly');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
|
|
@ -146,3 +150,48 @@ test('routing with cones costs about what it did: exits are asked once, cones ar
|
|||
assert.ok(t < plain * 2 + 20, `compute() with cones ${t.toFixed(1)} ms vs without ${plain.toFixed(1)} ms`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the panel names the peer that really carries a network, not the first Tier 1 it buys from', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=50");
|
||||
// a long-tail network that buys from Cogentle first and Level Tree second; peer only with Level Tree
|
||||
const t = ev("NETS.find(n=>n.tail&&n.up.length===2&&n.up[0]==='cog'&&n.up[1]==='lvl').id");
|
||||
ev("S.transit=[];S.ixp={};S.peers={};S.grace=null;S.pni=[{id:'pl',net:'lvl',city:'fra',tier:2}];compute()");
|
||||
assert.equal(ev(`R.cone.${t}`), 'lvl');
|
||||
ev(`UI.left='goals';UI.leftOpen=true;ACT.netFocus({id:'${t}'})`);
|
||||
const txt = dom.window.document.getElementById('leftBody').textContent;
|
||||
assert.match(txt, /Reached through the customer cone of Level Tree/);
|
||||
assert.doesNotMatch(txt, /customer cone of Cogentle/);
|
||||
// over an exchange: the member you have a session with
|
||||
ev("S.pni=[];compute()");
|
||||
assert.equal(ev(`!!R.cone.${t}`), false);
|
||||
assert.match(ev(`(ACT.netFocus({id:'${t}'}),document.getElementById('leftBody').textContent)`), /Buys transit from Cogentle/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a traceroute down a two-level cone shows every network on the way', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=50");
|
||||
// Doodoo buys from Hocus Pocus, which buys from Not That Telecom; a PNI with Not That Telecom only
|
||||
ev("S.transit=[];S.ixp={};S.peers={};S.grace=null;S.pni=[{id:'pn',net:'ntt',city:'fra',tier:2}];compute()");
|
||||
const tr = JSON.parse(ev("JSON.stringify(traceroute('fra',{net:'ddo'}))"));
|
||||
assert.deepEqual(tr.asPath, [ev('S.asn'), ev('NET.ntt.asn'), ev('NET.voc.asn'), ev('NET.ddo.asn')]);
|
||||
assert.match(tr.text, /Not That Telecom hands it to its customer Hocus Pocus/);
|
||||
assert.match(tr.text, /Hocus Pocus hands it to its customer Doodoo/);
|
||||
assert.equal(ev("coneChain('ntt','ddo').join()"), 'ntt,voc,ddo');
|
||||
assert.equal(ev("R.cone.ddo"), 'ntt');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#114 Only Spätzle-IX still takes more than the exchange and two Tier 1 PNIs, now that cones count', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("UI.pitched=true;beginGame('T','stg',{scn:SCN.find(x=>x.id==='stg')});S.cash=1e9;S.lvl=10;S.pops.stg.bb={d:400};S.ixp.stg=0;for(const id of ixMembers('stg'))S.peers[id+'@stg']=1;compute()");
|
||||
const reach = (ts) => ev(`S.pni=[];for(const t of ${JSON.stringify(ts)})S.pni.push({id:'p'+t,net:t,city:'stg',tier:2});compute();R.reach`);
|
||||
const T = ['lvl', 'ntt', 'tly', 'cog', 'tat'];
|
||||
const goal = ev("SCN.find(x=>x.id==='stg').ok.toString()");
|
||||
assert.match(goal, /R\.reach>=0\.5/);
|
||||
for (let i = 0; i < T.length; i++) for (let j = i + 1; j < T.length; j++)
|
||||
assert.ok(reach([T[i], T[j]]) < 0.5, `${T[i]}+${T[j]} is not enough`);
|
||||
assert.ok(reach(['lvl', 'ntt', 'tly']) >= 0.5, 'three Tier 1 PNIs and the exchange can be');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -136,3 +136,24 @@ test('route-server batch leaves peering policy and player-owned exchanges alone'
|
|||
assert.equal(ev('S.rs.fra'), false, 'owned exchange has no join-route-server control');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#192 the Infra tab shows the kit as one line, without repeating its rows', t => {
|
||||
for (const w of [1280, 360]) {
|
||||
const { ev, dom, errors } = setup(t);
|
||||
ev(`window.innerWidth=${w}`);
|
||||
ev("S.caches=[{id:'c1',city:'fra',net:'cfl'},{id:'c2',city:'fra',net:'cfl'}];compute();selectCity('fra');ACT.tab({t:'links'})");
|
||||
const body = dom.window.document.getElementById('panelBody');
|
||||
const txt = body.textContent;
|
||||
assert.match(txt, /PoP redundancy kit · One-off: /);
|
||||
assert.doesNotMatch(txt, /Second site(None|Installed)/, 'no second copy of the second-site row');
|
||||
assert.doesNotMatch(txt, /At least two routers/, 'no second copy of the routers row');
|
||||
assert.doesNotMatch(txt, /Request missing caches/, 'caches are in the Peering tab and Utilities');
|
||||
assert.equal(body.querySelectorAll('section h3').length, [...body.querySelectorAll('section h3')].filter(h => h.textContent !== 'PoP redundancy kit').length);
|
||||
assert.equal(txt.split('Backup generator').length - 1, 1, 'the generator shows once, in Power');
|
||||
assert.ok(body.querySelector('[data-act="utilityKit"]'), 'the kit is one tap away');
|
||||
body.querySelector('[data-act="utilities"]').click();
|
||||
assert.match(dom.window.document.getElementById('modalCard').textContent, /At least two routers/, 'the full kit is in Utilities');
|
||||
assert.equal(dom.window.document.querySelector('#utilityCity').value, 'fra');
|
||||
assert.deepEqual(errors, [], `${w}px`);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue