import fs from 'node:fs'; import assert from 'node:assert/strict'; // Directed regression of the shared runtime change. Only role/context selection // and reads; no business workflow is executed again. const cookies=new Map(),checks=[]; async function send(path,options={}){ const response=await fetch('http://127.0.0.1:8085'+path,{redirect:'manual',...options,headers:{Cookie:[...cookies].map(([k,v])=>k+'='+v).join('; '),Accept:'application/json',...options.headers}}); for(const raw of response.headers.getSetCookie()){const [name,value]=raw.split(';')[0].split('=');cookies.set(name,value);} return response; } function ok(v,name){assert(v,name);checks.push(name);} async function enter(role,stage){const entry=await send('/compras',{headers:{Accept:'text/html'}}),html=await entry.text();const csrf=/name="_token" value="([^"]+)"/.exec(html)?.[1];assert(csrf);const response=await send('/compras/entrar',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:new URLSearchParams({_token:csrf,role,stage})});assert.equal(response.status,302);const session=await send('/api/session');return (await session.json());} let session=await enter('issuer','obligations'); const obligation=await send('/api/purchasing-obligations/2',{headers:{'X-SGF-Context':session.context.token}});const book=await obligation.json(); ok(obligation.status===200&&book.obligations[0].principal_minor===10000&&book.obligations[0].balance_minor===10000,'existing obligation remains 100MZN with no new settlement'); session=await enter('validator','receipts'); const receipt=await send('/api/purchasing-receipts/orders/1',{headers:{'X-SGF-Context':session.context.token}}); ok(receipt.status===200,'accepted purchase receipt remains readable after shared runtime update'); const context=await send('/api/context',{method:'POST',headers:{'Content-Type':'application/json','X-CSRF-TOKEN':session.csrf,'X-SGF-Context':session.context.token},body:JSON.stringify({tenant_id:1,company_id:2,unit_id:2,module_id:'stock'})}); ok(context.status===200,'explicit transition to authorized Stock module is preserved');session=await context.json(); ok(session.context.stock.operations===false,'new Stock operations remain disabled without granting new rights'); const disabled=await send('/stock/operations');ok(disabled.status===404,'installed workspace is blocked until explicit activation'); const asset=await send('/stock-operations-workspace.mjs');ok(asset.status===200&&(await asset.text()).includes('stock-workspace'),'same server delivers the installed workspace asset'); const result={passed:true,checks,real_http:true,business_commands:0,existing_role_selection:true,visual_review:false};if(process.argv[2])fs.writeFileSync(process.argv[2],JSON.stringify(result,null,2));console.log(JSON.stringify({passed:true,checks:checks.length,business_commands:0}));