// Actual client forwarded to actual8085 HTTP; confirmation prohibited. import fs from 'node:fs';import assert from 'node:assert/strict';import {parsePage,installDom} from './purchasing-workspace-dom.mjs';import {session} from './sgf-single-http.mjs'; const nativeFetch=globalThis.fetch,s=await session('sgf:finance_prepare','accounting');const r=await s.get('/fiscal/rules',{headers:{Accept:'text/html'}});assert.equal(r.status,200);const document=parsePage(await r.text());installDom(document);document.getElementById=id=>document.querySelector('#'+id);globalThis.window={addEventListener(){}};const $=id=>document.getElementById(id);let previews=0,confirms=0;const checks=[],calls=[];const ok=(v,n)=>{assert(v,n);checks.push(n);};globalThis.fetch=async(url,options={})=>{if(url.startsWith('http:'))return nativeFetch(url,options);calls.push(url);if(options.method==='POST'){if(url.endsWith('/confirm')){confirms++;throw Error('No confirmations in UI proof');}assert(url.endsWith('/preview'));previews++;const a=await s.command(url,JSON.parse(options.body),options.headers['Idempotency-Key']);return{status:a.status,json:async()=>a.value};}const a=await s.get(url);return{status:a.status,json:()=>a.json()};};await import('../public/sgf-fiscal-rules.mjs?document-dom-http');const wait=async f=>{const end=Date.now()+15000;while(!f()&&Date.now()setTimeout(r,25));assert(f(),$('message').textContent);};await wait(()=>$('events').children.length===2);ok($('selection').textContent.includes('Nenhuma versão'),'no rule selected automatically');const row=[...$('events').children].find(row=>row.textContent.includes('2026-11-30'));assert(row);await row.querySelector('button').onclick();ok($('selection').textContent.includes('v1'),'explicit existing version1');$('action').value='calculate_document';$('action').onchange();ok($('documentLines').children.length===1&&$('documentMode').value==='','blank line and explicit mode');$('documentMode').value='gross_included';$('documentOn').value='2026-11-10';$('documentCurrency').value='MZN';$('doc-reference-1').value='G100';$('doc-quantity-1').value='1';$('doc-price-1').value='100';$('reason').value='Conferência QA de modalidade incluída e diferenças exactas, sem confirmar.';$('operation').oninput();await $('operation').onsubmit({preventDefault(){}});ok(previews===1&&confirms===0,'one real rollback preview zero confirmations');ok($('impact').textContent.includes('86.21')&&$('impact').textContent.includes('13.79')&&$('impact').textContent.includes('100.00'),'documentary amounts shown before confirmation');ok($('impact').textContent.includes('2500/29')&&$('impact').textContent.includes('400/29')&&$('impact').textContent.includes('9/2900'),'exact fractions and differences shown');ok($('fields').disabled&&$('filters').disabled,'preview locks form and catalogue');$('cancel').onclick();ok(!$('fields').disabled&&$('doc-price-1').value==='100','cancel preserves line');$('addDocumentLine').onclick();ok($('documentLines').children.length===2,'add second line');$('documentLines').children[1].querySelector('button').onclick();ok($('documentLines').children.length===1&&$('doc-price-1').value==='100','remove explicit line preserves other input');$('size').value='100';$('apply').onclick();await wait(()=>$('filters').disabled===false&&calls.some(c=>c.includes('per_page=100')));ok($('doc-price-1').value==='100'&&$('documentMode').value==='gross_included','pagination preserves unsubmitted lines and mode');$('view').value='calculations';$('apply').onclick();await wait(()=>$('events').children.length===5);await $('events').children[0].querySelector('button').onclick();ok($('detail').textContent.includes('9/2900')&&$('detail').textContent.includes('current_evaluation'),'frozen result and current evaluation readable');ok($('documentDownload').textContent.includes('Descarregar mapa interno'),'historical line report link');ok($('inputs').textContent.includes('Sem regra escolhida'),'historical record does not automatically choose its rule');const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),root=run.root+'/private/receipt-composition-cc50a276c10c',p=JSON.parse(fs.readFileSync(root+'/document-math-http-20261110.json'));$('referenceKey').value=p.operations.included100.key;await $('recovery').onsubmit({preventDefault(){}});ok($('receipt').textContent.includes('Nenhuma operação repetida'),'own receipt recovered via GET');const after=await s.get('/api/fiscal-rules?view=calculations');ok((await after.json()).records.total===5&&confirms===0,'five saved calculations preserved');const file=root+'/document-math-dom-http-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks,preview_posts:previews,confirmation_posts:confirms,real_http_forwarded:true,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof:file}));