import fs from 'node:fs';import assert from 'node:assert/strict';import {Element,walk,parsePage,installDom} from './purchasing-workspace-dom.mjs'; Element.prototype.contains=function(el){return walk(this).includes(el);};Element.prototype.hasAttribute=function(name){return Object.hasOwn(this.attributes,name);};Object.defineProperty(Element.prototype,'tagName',{get(){return this.tag.toUpperCase();}}); const checks=[];for(const kind of ['finance','ledger']){ const finance=kind==='finance',attribute=finance?'data-action':'data-ledger-action';const inputs=finance?'':''; const document=parsePage(`

${inputs}
`);installDom(document);const listeners={};globalThis.window={addEventListener:(key,fn)=>listeners[key]=fn};let reloads=0;globalThis.location={reload:()=>reloads++}; const calls=[];let lose=true;globalThis.fetch=async(path,options)=>{calls.push({path,...options});if(lose){lose=false;throw Error('Response lost after commit');}return {ok:true,status:200,json:async()=>({replayed:true})};}; await import('../public/sgf-'+(finance?'finance-payables':'composed-ledger')+'.mjs?client-proof');const [form,other]=document.querySelectorAll('form');await form.onsubmit({preventDefault(){}});assert.equal(calls.length,1);assert.equal(reloads,0);checks.push(kind+' uncertain response does not imply success'); assert(document.querySelectorAll('input').every(e=>e.disabled));assert.equal(form.querySelector('button').disabled,false);checks.push(kind+' uncertain fields frozen and only recovery button enabled'); const body=JSON.parse(calls[0].body);if(finance){assert.deepEqual(body.allocations,[{obligation_id:2,source_revision:'revision',amount:'20.00'}]);assert.equal(body.amount,undefined);}else{assert.equal(calls[0].path,'/api/general-ledger/effect-prepare');assert.equal(body.source_id,4);assert.equal(body.effect_type,'sales.invoice');}checks.push(kind+' visible selection maps to exact original command'); await other.onsubmit({preventDefault(){}});assert.equal(calls.length,1);checks.push(kind+' unrelated decision blocked during recovery');let protectedExit=false;listeners.beforeunload({preventDefault(){protectedExit=true;}});assert(protectedExit);checks.push(kind+' uncertain operation protects navigation'); await form.onsubmit({preventDefault(){}});assert.equal(calls.length,2);assert.equal(calls[1].body,calls[0].body);assert.equal(calls[1].headers['Idempotency-Key'],calls[0].headers['Idempotency-Key']);assert.equal(reloads,1);checks.push(kind+' recovery sends identical normalized body and key after disabled fields'); } const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'));const proof=run.root+'/private/receipt-composition-cc50a276c10c/single-finance-ledger-client-20261110.json';fs.writeFileSync(proof,JSON.stringify({passed:true,checks,dom_simulation:true,visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof}));