${b.i} ${up?tr('badges.badge_upgraded_name',{name:esc(b.t)}):tr('badges.badge_unlocked_name',{name:esc(b.t)})}
${R0.n}${v==='oncall'?'':` · ${V.i} ${tr(V.n)}`} · ${esc(b.d)}`,'goal',[],{a:'tab',v:'goals'});sfx('coin');track('badge_'+b.id+(v==='oncall'?'':'_'+v));}
if(h)try{localStorage.setItem('sot-badges',JSON.stringify(h));}catch(e){}}
// How many badges this device has ever earned in each variant: the collection.
function badgeShelf(h){const o={freeze:0,oncall:0,bgp:0};for(const b of BADGES){const x=h[b.id];if(x)for(const v of BVAR_IDS)if(x.vs[v]!==undefined)o[v]++;}return o;}
diff --git a/src/game/90-actions/60-links.js b/src/game/90-actions/60-links.js
index d9b1000..7c046d0 100644
--- a/src/game/90-actions/60-links.js
+++ b/src/game/90-actions/60-links.js
@@ -30,10 +30,10 @@ Object.assign(ACT,{
setPref:({kind,id,v})=>{if(!own(PREF,v))return;if(kind!=='t'&&kind!=='p'&&!(isIx(id)&&S.ixp[id]!==undefined))return;if(kind==='t'){const t=S.transit.find(x=>x.id===id);if(t)t.pref=v;}else if(kind==='p'){const x=S.pni.find(y=>y.id===id);if(x)x.pref=v;}else{S.ixPref=S.ixPref||{};S.ixPref[id]=v;}sfx('click');after();},
setMetric:({id,v})=>{if(v!=='custom'&&!own(MET,v))return;const l=S.links.find(x=>x.id===id);if(!l)return;const m=S.pairMet||(S.pairMet={}),k=edgeKey(l);
// Switching to custom starts from the current preset's factor, so nothing moves until the player edits it.
- if(v==='custom'){if(!pairCm(k))m[k]={k:'f',v:MET[pairMet(k)].f};}else if(v==='normal')delete m[k];else m[k]=v;sfx('click');after();},
+ if(v==='custom'){if(!pairCm(k))m[k]={k:'f',v:MET[pairMet(k)].f};}else if(v==='normal')delete m[k];else m[k]=v;metBlur();sfx('click');after();},
metricMode:({id,k})=>{if(k!=='f'&&k!=='w')return;const l=S.links.find(x=>x.id===id);if(!l)return;const key=edgeKey(l),c=pairCm(key);if(!c||c.k===k)return;
// The cost stays what it was on this link, written the other way.
- const w=pairW(key,l.km);S.pairMet[key]={k,v:clampM(k,k==='w'?w:w/(l.km+60))};sfx('click');after();},
+ const w=pairW(key,l.km);S.pairMet[key]={k,v:clampM(k,k==='w'?w:w/(l.km+60))};metBlur();sfx('click');after();},
metricSet:({id})=>{const l=S.links.find(x=>x.id===id),t=$('metIn');if(!l||!t)return;const key=edgeKey(l),c=pairCm(key);if(!c)return;const v=parseFloat(String(t.value).replace(',','.'));if(!Number.isFinite(v)){sfx('err');return;}
t.blur();S.pairMet[key]={k:c.k,v:clampM(c.k,v)};sfx('click');after();},
setStandby:({id,on})=>{const l=S.links.find(x=>x.id===id);if(!l)return;if(on)l.standby=true;else delete l.standby;sfx('click');after();},
diff --git a/src/game/93-ui/40-hud-and-panels.js b/src/game/93-ui/40-hud-and-panels.js
index b1e0470..90ccb82 100644
--- a/src/game/93-ui/40-hud-and-panels.js
+++ b/src/game/93-ui/40-hud-and-panels.js
@@ -80,7 +80,7 @@ function renderLeft(){checkLayer();
h+=`${btn(tr('common.all_networks'),'netFilter',{f:'all'},!foc&&!out?'sm':'ghost sm')}${btn(tr('hud_and_panels.out_of_reach_without_transit_n',{n:lostN}),'netFilter',{f:'out'},out?'sm':'ghost sm')}
`;
if(out&&!lostN)h+=`${tr('hud_and_panels.nothing_every_network_is_reachable')}
`;
for(const n of foc?[foc]:out?ntLost():NETS){if(n.tail&&!UI.tailOpen&&!foc&&!out)continue;
- h+=`${logo(n)}
${esc(n.name)} AS${n.asn}
${TYPE_L[n.type]} ${n.pol} · ${tr('hud_and_panels.p_of_traffic',{p:(NSH[n.id]*100).toFixed(1)})}${n.price?` · ${tr('hud_and_panels.transit_price_gbps',{price:(n.price*S.priceMul).toFixed(2)})}`:''}
${esc(n.blurb)}
${netWhere(n,where)}${(foc||out)&&!R.nt[n.id]?`
${esc(offTransitHint(n.id))}
`:''}${(foc||out)&&coneVia(n.id)&&(R.cone[n.id]||!R.nt[n.id])?`
${R.cone[n.id]?tr('hud_and_panels.reached_through_the_customer_cone_of',{net:esc(coneVia(n.id).name)}):tr('hud_and_panels.buys_transit_from_net_peer_with',{net:esc(coneVia(n.id).name)})}
`:''}${foc||out&&!R.nt[n.id]?meetLine(n,foc?24:4):''}
`;}
+ h+=`${logo(n)}
${esc(n.name)} AS${n.asn}
${TYPE_L[n.type]} ${n.pol} · ${tr('hud_and_panels.p_of_traffic',{p:(NSH[n.id]*100).toFixed(1)})}${n.price?` · ${tr('hud_and_panels.transit_price_gbps',{price:(n.price*S.priceMul).toFixed(2)})}`:''}
${esc(n.blurb)}
${netWhere(n,where)}${(foc||out)&&!R.nt[n.id]?`
${esc(offTransitHint(n.id))}
`:''}${(foc||out)&&coneVia(n.id)&&(R.cone[n.id]||!R.nt[n.id])?`
${R.cone[n.id]?tr('hud_and_panels.reached_through_the_customer_cone_of',{net:esc((NET[R.cone[n.id]]||coneVia(n.id)).name)}):tr('hud_and_panels.buys_transit_from_net_peer_with',{net:esc(coneVia(n.id).name)})}
`:''}${foc||out&&!R.nt[n.id]?meetLine(n,foc?24:4):''}
`;}
if(!foc&&!out)h+=`${tr('hud_and_panels.the_long_tail')} ${tr('hud_and_panels.n_small_networks',{n:tl.length})}
${tr('hud_and_panels.p_of_traffic_between_them_scattered',{p:(tl.reduce((a,n)=>a+NSH[n.id],0)*100).toFixed(1),n:tlOn})}
${btn(UI.tailOpen?tr('common.hide'):tr('common.show'),'tailTog',{},'ghost sm')}
`;
}
if(h!==UI._lh){UI._lh=h;morph($('leftBody'),h);}
diff --git a/src/game/93-ui/50-city-panel.js b/src/game/93-ui/50-city-panel.js
index 4c068b7..b816232 100644
--- a/src/game/93-ui/50-city-panel.js
+++ b/src/game/93-ui/50-city-panel.js
@@ -67,7 +67,7 @@ function cityPanel(c){
${have.length?btn(tr('common.remove'),'rmCache',{id:(have.find(x=>x.site==='b')||have[0]).id},'ghost sm'):''}${btn(have.length?tr('common.box'):tr('common.request'),'cache',{city:c,net:n.id},'sm',!ok)}${S.pops[c].site2&&have.length?(()=>{const nb=have.filter(x=>x.site==='b').length,na=have.length-nb;return `${tr('city_panel.boxes_a_in_a_b_in',{a:na,b:nb})}${na?btn(tr('city_panel.move_one_to_b'),'cacheSite',{city:c,net:n.id,s:'b'},'ghost sm'):''}${nb?btn(tr('city_panel.move_one_to_a'),'cacheSite',{city:c,net:n.id,s:'a'},'ghost sm'):''}
`;})():''}`;}
h+=``;
}else{
- h+=utilityKitHtml(c);
+ h+=utilityKitLine(c);
const ls=S.links.filter(l=>l.a===c||l.b===c);
const rt=p.routers||1,g=p.rgen||0,G=RG[g],nl=R.nodeLoad[c]||0,nc=R.nodeCap[c]||nodeCap(c),Ni=g===mainRG(G.cls)?mainRG(G.cls+1):-1,N=Ni>=0?RG[Ni]:null,pu=portsUsed(c),pm=portsMax(c);
h+=`${tr('common.routers')}
${tr('city_panel.the_model_sets_your_fastest')}
diff --git a/src/game/93-ui/55-utilities.js b/src/game/93-ui/55-utilities.js
index 2d50105..3398392 100644
--- a/src/game/93-ui/55-utilities.js
+++ b/src/game/93-ui/55-utilities.js
@@ -5,6 +5,11 @@ function utilityKitHtml(city,modal=false){const q=utilityKit(city);if(!q)return
${tr('utilities.cache_moves',{n:q.moves.length})}
${q.cost||q.moves.length?`${tr('utilities.kit_cost',{cost:fmt$(q.cost),mo:fmt$(q.mo)})}
${btn(tr('utilities.apply_kit'),'utilityKit',{city,cost:q.cost,modal},'pink',q.cost>0&&S.cash
`:`${tr('utilities.kit_balanced')}
`}
${tr('utilities.redundancy_note')}
${utilityCachesHtml(city,modal)}`;}
+// In the Infra tab (#192): one line and the button, since the generator, second site, routers and caches each have
+// their own rows below; the full kit with its caches is in Utilities.
+function utilityKitLine(city){const q=utilityKit(city);if(!q)return '';const todo=q.cost||q.moves.length;
+ return `${tr('utilities.redundancy_kit')} · ${todo?tr('utilities.kit_cost',{cost:fmt$(q.cost),mo:fmt$(q.mo)})+(q.moves.length?' · '+tr('utilities.cache_moves',{n:q.moves.length}):''):tr('utilities.kit_balanced')}
+ ${todo?btn(tr('utilities.apply_kit'),'utilityKit',{city,cost:q.cost},'pink sm',q.cost>0&&S.cash
`;}
function utilityCachesHtml(city,modal=false){const q=utilityCaches(city);if(!q)return '';
return `${tr('common.embedded_caches')}
${tr('utilities.cache_note')}
${tr('utilities.cache_quote',{n:q.add.length,mo:fmt$(q.mo)})}
diff --git a/src/game/93-ui/70-link-panels.js b/src/game/93-ui/70-link-panels.js
index 4633d68..9167cb4 100644
--- a/src/game/93-ui/70-link-panels.js
+++ b/src/game/93-ui/70-link-panels.js
@@ -34,10 +34,11 @@ function vxcPanel(l){
return h;
}
function prefCtl(kind,id,cur){cur=cur||'normal';return `${tr('common.egress')}${Object.keys(PREF).map(v=>btn(PREF[v],'setPref',{kind,id,v},cur===v?'pink sm':'ghost sm')).join('')}
`;}
-// Trial routing is isolated from the live save, counters and scenic-route memory.
+// Trial routing is isolated from the live save, counters and scenic-route memory. "Before" is the live routing, which
+// after() keeps current, so a check costs one compute() on a big network, not two.
function linkTrial(id){const save=S,live=R,hot=UI.hotMap,cache=TE_CACHE;
- try{S=JSON.parse(JSON.stringify(save));const l=S.links.find(x=>x.id===id);if(!l||linkDown(l))return null;
- compute();const before=R;l.cut=S.day+1;compute();
+ try{const l0=save.links.find(x=>x.id===id);if(!l0||linkDown(l0))return null;
+ S=JSON.parse(JSON.stringify(save));const l=S.links.find(x=>x.id===id),before=live;l.cut=S.day+1;compute();
const allowed=new Set(Object.keys(S.pops).filter(popUp).concat(remoteCities())),adj={};
for(const x of S.links)if(!linkDown(x)&&allowed.has(x.a)&&allowed.has(x.b)){(adj[x.a]=adj[x.a]||[]).push(x.b);(adj[x.b]=adj[x.b]||[]).push(x.a);}
const seen=new Set([l.a]),q=[l.a];for(let i=0;i=0.8&&egs.length){const d=R.egDesc[egs[0][0]];h+=`${tr('link_panels.biggest_feeder_egress_in_city_set',{egress:esc(d.lab),city:CITY[d.city].name})}
`;}
return h+``;
}
+// Safari keeps the number field focused through a button tap, and renderPanel() skips a focused field: let go first (#131).
+const metBlur=()=>{const t=$('metIn');if(t&&document.activeElement===t)t.blur();};
function metricSection(l){const key=edgeKey(l),cur=pairMet(key),pl=pairLinks(l.a,l.b),sb=!!l.standby,base=l.km+60,sel=k=>cur===k?'pink sm':'ghost sm';
let h=`${tr('common.routing_metric')}
${tr('link_panels.your_routers_pick_the_lowest_cost_0160')}
${Object.keys(MET).map(k=>btn(MET[k].l,'setMetric',{id:l.id,v:k},sel(k))).join('')}${btn(tr('common.custom'),'setMetric',{id:l.id,v:'custom'},sel('custom'))}
`;
const cm=pairCm(key);
diff --git a/src/game/94-dashboard/10-progress.js b/src/game/94-dashboard/10-progress.js
index be14c3a..111df9b 100644
--- a/src/game/94-dashboard/10-progress.js
+++ b/src/game/94-dashboard/10-progress.js
@@ -4,7 +4,7 @@ const RS_G=80,RS_DAYS=30,asiaG=()=>S.links.reduce((a,l)=>a+((CITY[l.a].reg==='AS
const pSrv=g=>({l:tr('common.traffic_served'),v:R.served,max:g,txt:`${fmtG(R.served)} / ${fmtG(g)}`});
const pReach=()=>({l:tr('common.reach'),v:R.reach,max:0.99,txt:`${pct(R.reach)} / 99%`});
const pChk=(l,ok)=>({l,v:ok?1:0,max:1,txt:ok?'✓':'—'});
-const SCN_PROG={stg:()=>[{l:tr('common.reach'),v:R.reach,max:0.45,txt:`${pct(R.reach)} / 45%`},pSrv(300)],redsea:()=>{const g=asiaG(),n=S.stats.asiaRun||0;return [pChk(tr('progress.a_path_from_marseille_to_singapore'),pathExists('mrs','sin')),{l:tr('progress.your_traffic_to_and_from_asia'),v:Math.min(g,RS_G),max:RS_G,txt:`${fmtG(g)} / ${fmtG(RS_G)}`},{l:tr('progress.days_in_a_row_at_g',{g:fmtG(RS_G)}),v:n,max:RS_DAYS,txt:`${n} / ${RS_DAYS}`}];},spat:()=>[pReach(),pSrv(150)],
+const SCN_PROG={stg:()=>[{l:tr('common.reach'),v:R.reach,max:0.5,txt:`${pct(R.reach)} / 50%`},pSrv(300)],redsea:()=>{const g=asiaG(),n=S.stats.asiaRun||0;return [pChk(tr('progress.a_path_from_marseille_to_singapore'),pathExists('mrs','sin')),{l:tr('progress.your_traffic_to_and_from_asia'),v:Math.min(g,RS_G),max:RS_G,txt:`${fmtG(g)} / ${fmtG(RS_G)}`},{l:tr('progress.days_in_a_row_at_g',{g:fmtG(RS_G)}),v:n,max:RS_DAYS,txt:`${n} / ${RS_DAYS}`}];},spat:()=>[pReach(),pSrv(150)],
carnaval:()=>[pChk(tr('progress.carnaval_delivered_in_full'),(S.stats.evFull||0)>=1)],ixbr:()=>{const n=brIxN();return [{l:tr('progress.ix_brrr_ports'),v:n,max:15,txt:`${n} / 15`},pChk(tr('progress.a_port_on_ix_brrr_manaus'),S.ixp.mao!==undefined),pSrv(200)];},
c2c:()=>[pChk(tr('progress.a_path_from_cape_town_to'),pathExists('cpt','cai')),...['lag','nbo'].map(c=>pChk(tr('progress.pop_in_city',{city:CITY[c].name}),!!S.pops[c])),pSrv(150)],
pac:()=>[pChk(tr('progress.1_6t_on_every_hop_from'),fastPath('lax','syd',1600)),pChk(tr('progress.a_path_from_los_angeles_to'),pathExists('lax','tok')),pSrv(150)],
diff --git a/src/i18n/en.js b/src/i18n/en.js
index 9e5308b..d13d34c 100644
--- a/src/i18n/en.js
+++ b/src/i18n/en.js
@@ -3204,7 +3204,7 @@
"scenarios.ponta_delgada_in_the_azores_halfway":"Ponta Delgada, in the Azores, halfway across the Atlantic. Florida to Spain and Lisbon to Lagos are just too long for a 1.6T wave: straight across, each carries 1.2T. Land on the islands in between, start the light fresh, and every hop runs at 1.6T or better. You start with 1.6T gear unlocked.",
"scenarios.pops_in_bogota_lima_santiago_and":"POPs in Bogotá, Lima, Santiago and São Paulo, and 150 Gbps served",
"scenarios.ports_on_15_ix_brrr_exchanges":"Ports on 15 IX.brrr exchanges, one of them in Manaus, and 200 Gbps served",
-"scenarios.reach_45_of_the_internet_and":"Reach 45% of the internet and serve 300 Gbps",
+"scenarios.reach_50_of_the_internet_and":"Reach 50% of the internet and serve 300 Gbps",
"scenarios.red_sea_crisis":"Red Sea Crisis",
"scenarios.rio_from_scratch_carnaval_starts_in":"Rio from scratch. Carnaval starts in 90 days and wants 400 Gbps for five days straight. The whole world is watching.",
"scenarios.sandbox_mode_a_billion_dollars_chaos":"Sandbox mode
A billion dollars and every unlock. Chaos: {chaos}. Build the internet you always wanted, and keep a spare backhoe handy.",
diff --git a/tests/badges-variants.test.js b/tests/badges-variants.test.js
index 648aaed..9f1b6a2 100644
--- a/tests/badges-variants.test.js
+++ b/tests/badges-variants.test.js
@@ -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, []);
+});
diff --git a/tests/link-trial.test.js b/tests/link-trial.test.js
new file mode 100644
index 0000000..ae39a32
--- /dev/null
+++ b/tests/link-trial.test.js
@@ -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, []);
+});
diff --git a/tests/metric-panel.test.js b/tests/metric-panel.test.js
new file mode 100644
index 0000000..fdf2d5a
--- /dev/null
+++ b/tests/metric-panel.test.js
@@ -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, []);
+});
diff --git a/tests/modes.test.js b/tests/modes.test.js
index 622de40..95ef1bd 100644
--- a/tests/modes.test.js
+++ b/tests/modes.test.js
@@ -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);
diff --git a/tests/regions.test.js b/tests/regions.test.js
index 139c27f..875f3a1 100644
--- a/tests/regions.test.js
+++ b/tests/regions.test.js
@@ -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');
diff --git a/tests/tier1-cone.test.js b/tests/tier1-cone.test.js
index bc79518..55b5372 100644
--- a/tests/tier1-cone.test.js
+++ b/tests/tier1-cone.test.js
@@ -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, []);
+});
diff --git a/tests/utilities.test.js b/tests/utilities.test.js
index d096951..feba9a5 100644
--- a/tests/utilities.test.js
+++ b/tests/utilities.test.js
@@ -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`);
+ }
+});