3 lines
2.7 KiB
JavaScript
3 lines
2.7 KiB
JavaScript
import fs from 'node:fs';import path from 'node:path';import assert from 'node:assert/strict';import vm from 'node:vm';import crypto from 'node:crypto';
|
|
const state=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json','utf8')),tag=process.argv[2];if(state.port!==55439||!/^[a-f0-9]{12}$/.test(tag??''))throw Error('Owned HTTP fixture required');const root=path.join(state.root,'private/ledger-'+tag),out=path.join(root,'industrial-form-check.json');if(fs.existsSync(out))throw Error('Valid form proof preserved');const html=fs.readFileSync(path.join(root,'industrial-preparer.html'),'utf8'),script=[...html.matchAll(/<script>([\s\S]*?)<\/script>/g)].at(-1)?.[1];if(!script)throw Error('Rendered industrial script missing');let checks=0;const ok=(v,m)=>{checks++;assert(v,m);},form={dataset:{action:'effect-prepare'},fields:{effect_type:'industry.cost.validated',source_id:'1',journal_on:'2026-10-29',period_key:'QA-2026-10',rule_key:'QA-INDUSTRIAL',reason:'Exact industrial result capture.'},button:{},querySelector(){return this.button;}},error={textContent:''},calls=[],mock={fail:false},sandbox={document:{querySelectorAll:()=>[form],querySelector:()=>error},FormData:class{constructor(f){return new Map(Object.entries(f.fields));}},crypto:{randomUUID:crypto.randomUUID},location:{reload(){}},fetch:async(url,options)=>{calls.push({url,options,body:JSON.parse(options.body)});return{ok:!mock.fail,json:async()=>mock.fail?{message:'Expected industrial version refusal.'}:{journal_id:1}};}};vm.createContext(sandbox);vm.runInContext(script,sandbox);const submit=()=>form.onsubmit({preventDefault(){}});await submit();ok(calls[0].body.source_id===1&&calls[0].body.period_key==='QA-2026-10'&&calls[0].body.journal_on==='2026-10-29','Numeric source ID with explicit date and period');await submit();ok(calls[1].options.headers['Idempotency-Key']===calls[0].options.headers['Idempotency-Key'],'Unchanged retry stable key');form.fields.reason='Different deliberate industrial basis.';await submit();ok(calls[2].options.headers['Idempotency-Key']!==calls[1].options.headers['Idempotency-Key'],'Changed basis new key');form.dataset.action='post';form.fields={proposal_id:'7',revision:'a'.repeat(64),reason:'Apply exact reviewed industrial impact.'};await submit();ok(calls.at(-1).body.proposal_id===7&&calls.at(-1).body.revision==='a'.repeat(64),'Proposal numeric and revision string');mock.fail=true;await submit();ok(error.textContent.includes('Expected industrial version refusal.')&&form.button.disabled===false,'Refusal visible and retry control restored');fs.writeFileSync(out,JSON.stringify({passed:true,checks,rendered_javascript:true,node_vm_only:true,no_business_commands:true,actual_browser:false},null,2)+'\n');console.log(JSON.stringify({passed:true,checks}));
|