backend-probe.mjs (4100B)
1 import {inspect,input,change,status,wait,pause,el,description} from './source-probe-helpers.mjs'; 2 const assert=(condition,message)=>{if(!condition)throw Error(message);}; 3 export async function run(control,backend='haskell-wasm'){ 4 await status('Ready'); 5 const requests=async()=>await(await fetch(control+'/requests')).json(); 6 const fault=async values=>{const response=await fetch(control+'/fault',{method:'POST',body:JSON.stringify(values)});assert(response.ok,'Fault control');}; 7 const select=async name=>{change('program-picker','demo:'+name);await status('Ready');}; 8 assert(!el('runtime-backend'),'Runtime is fixed without a selector'); 9 assert(await inspect('greeting')==='Hello, world!','Default real Haskell inspection'); 10 assert((await requests()).some(path=>path.endsWith('/runtime/haskell/reactor.wasm')),'Haskell is really loaded'); 11 await fault({runtime:true});change('program-picker','demo:arithmetic');await status('Stopped'); 12 assert(/WASM fetch failed|HTTP|fetch/i.test(el('operation-diagnostic').textContent),'Runtime artifact failure is visible, no JS fallback'); 13 change('program-picker','demo:arithmetic');await status('Stopped'); 14 await fault({runtime:false});el('reload-package').click();await status('Ready'); 15 assert(!el('source-editor').hidden&&!globalThis.__sourceEditor.isReadOnly,'Retry after a fresh load failure restores editable demo source'); 16 await select('language-reference'); 17 assert(await inspect('leaf','tricu')==='t','Published stored binding'); 18 assert(!(await requests()).some(path=>path.endsWith('/compiler.json')),'Published inspection does not initialize compiler'); 19 for(const name of ['rgb','microscope','shipping','events','registration','migration'])await select(name); 20 await select('language-reference'); 21 input('source-editor',globalThis.__sourceEditor.getSource().replace('first 42 7','first 43 7'));await status('Compiled'); 22 assert(await inspect('answer','number')==='43','Edited source compiles'); 23 assert(/MiB WASM linear memory/.test(el('compiler-stats').textContent),'Native runtime statistics'); 24 await inspect('answer','string');assert(description().includes('Cannot interpret'),'Decoder errors are visible'); 25 assert(await inspect('answer','number')==='43','Decoder errors preserve compiled definitions'); 26 input('source-editor',globalThis.__sourceEditor.getSource()+'\n-- revision');await status('Compiled');assert(await inspect('answer','number')==='43','New revision'); 27 el('restore-source').click();await status('Ready'); 28 await fault({compilerPin:true});document.querySelector('[data-compiler-example=contracts]').click();await status('Compilation failed'); 29 assert(/Runtime compiler pin mismatch|HTTP|fetch/i.test(el('compile-diagnostic').textContent),'Compiler pin failure has no fallback'); 30 await fault({compilerPin:false}); 31 await select('names-values'); 32 const report=await(await import('/inline-io-probe.mjs')).run(control,backend); 33 await select('shipping');input('source-editor',globalThis.__sourceEditor.getSource()+'\n-- native imports');await status('Compiled'); 34 document.querySelector('[data-compiler-example=identity]').click();input('source-editor','answer = 42\nloop = (x : x x) (x : x x)');await status('Compiled'); 35 document.querySelector('[aria-label="Inspect compiled definition loop"]').click();await wait(()=>el('status').textContent==='Inspecting loop','CPU-bound observation');await pause(100);el('stop').click(); 36 assert(!el('compile').disabled,'Stop discards runtime and permits recompile'); 37 const source=globalThis.__sourceEditor.getSource();el('compile').click();await status('Compiled');assert(globalThis.__sourceEditor.getSource()===source,'Runtime restart preserves source'); 38 assert(await inspect('answer','number')==='42','Runtime restart rebuilds independent definitions'); 39 await(await import('/backend-resume-probe.mjs')).probeResume(backend); 40 return {...report,checks:[...report.checks,'real Haskell default; package/practical compilation; native statistics; decoder recovery; artifact/pin failures without fallback; CPU-bound Stop; backend isolation; stale/malformed resume rejection']}; 41 }