io-v2-protocol-probe.mjs (2474B)
1 // Real WASM engines, inert header inspection only, no source compiler substitute. 2 export async function run(_control,backend){ 3 const base=new URL('../',document.querySelector('script[type=module][src]').src); 4 const fixtures=await(await fetch('/zig-negative.json')).json(),checks=[]; 5 let inspect,dispose; 6 if(backend==='haskell-wasm'){ 7 const {CompilerWorker}=await import(new URL('runtime/haskell/client.mjs',base)); 8 const client=new CompilerWorker();dispose=()=>client.dispose(); 9 await client.request({type:'init',compiler:false}); 10 inspect=async fixture=>{await client.request({type:'load',bytes:new Uint8Array(fixture.bytes).buffer,hash:fixture.hash});return JSON.parse((await client.request({type:'io-v2-header',name:'root',arguments:[]})).text);}; 11 }else{ 12 const {WasmRuntime}=await import('/io-v2-runtime.mjs'); 13 const {ioV2Protocol}=await import(new URL('dist/zig-helpers.js',base)); 14 const graph=await WasmRuntime.create(new Uint8Array(await(await fetch(new URL('runtime/zig/arboricx.wasm',base))).arrayBuffer())); 15 dispose=()=>graph.dispose(); 16 inspect=async fixture=>graph.scope(()=>ioV2Protocol.header(graph,graph.load(new Uint8Array(fixture.bytes),'root'))); 17 } 18 const equal=(got,want)=>{if(JSON.stringify(got)!==JSON.stringify(want))throw Error('Header mismatch: '+JSON.stringify(got));}; 19 try{ 20 for(let code=0;code<10;code++)equal(await inspect(fixtures['v2-header-core-'+code]),{kind:'core',code}); 21 checks.push('all ten core headers without expanding shared payloads'); 22 equal(await inspect(fixtures['v2-header-future']),{kind:'request',group:'future-9',revision:65535,operation:'unknown'}); 23 equal(await inspect(fixtures['v2-header-long-name']),{kind:'request',group:'a'.repeat(64),revision:1,operation:'read'}); 24 checks.push('future named request and exact name/revision bounds'); 25 for(const [name,message] of [['bad-tag','unknown computation constructor'],['bad-name','invalid facility header'],['bad-revision','invalid facility header'],['zero-revision','invalid facility header'],['bad-shape','invalid computation shape']]){ 26 let rejected=false;try{await inspect(fixtures['v2-header-'+name]);}catch(error){if(!error.message.includes(message))throw error;rejected=true;} 27 if(!rejected)throw Error('Accepted '+name); 28 equal(await inspect(fixtures['v2-header-core-0']),{kind:'core',code:0}); 29 } 30 checks.push('five malformed headers reject; runtime remains usable after each'); 31 }finally{dispose();} 32 return {backend,checks}; 33 }