tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

cold-load-probe.mjs (1461B)


      1 export async function run(control){
      2  const delay=ms=>new Promise(r=>setTimeout(r,ms));
      3  for(let i=0;document.getElementById('status').textContent!=='Ready';i++){if(i>4500)throw Error('Homepage failed to become Ready');await delay(20);}
      4  const transfers=(await(await fetch(control+'/transfers')).json()).filter(r=>r.path.startsWith('/nested/site/')||r.path.startsWith('/_arboricx/'));
      5  const base=new URL('../',document.querySelector('script[type=module][src]').src);
      6  const compiler=(await(await fetch(new URL('compiler.json',base))).json()).hash;
      7  if(transfers.some(r=>r.path==='/_arboricx/bundle/hash/'+compiler))throw Error('Homepage fetched the compiler bundle');
      8  const manifest=await(await fetch(new URL('assets.json',location.href))).json();
      9  const bundled=manifest.files.filter(r=>/\.(?:m?js)$/.test(r.path)).length===7;
     10  const js=transfers.filter(r=>/\.(?:m?js)(?:\?|$)/.test(r.path));
     11  if(bundled&&js.length!==4)throw Error('Bundled homepage must load four JS entrypoints');
     12  if(transfers.some(r=>/compiler\.(?:json|dag)|environment\.tsv|runtime\/zig|local-module-worker|reference\//.test(r.path)))throw Error('Homepage fetched a lazy asset');
     13  return {userAgent:navigator.userAgent,checks:['cold homepage ready; compiler, Zig, local validation and library references stay lazy'],requests:transfers.length,jsRequests:js.length,bytes:transfers.reduce((n,r)=>n+r.bytes,0),jsBytes:js.reduce((n,r)=>n+r.bytes,0),readyMs:globalThis.__readyMs,transfers};
     14 }