import fs from 'node:fs'; import assert from 'node:assert/strict'; import {noncivilCase} from '../tests/frontend/helpers/irpc-annual-noncivil-case.mjs'; import {annualAdvanceCashflow,annualAdvancePeriod,annualBook,annualCurrent,annualHtml,recordAnnual,saveAnnualBook} from '../resources/js/lib/irpc-annual-settlement.ts'; import {createProjectDossierReport} from '../resources/js/lib/project-dossier-report.ts'; const out=new URL('../outputs/irpc-noncivil-20261114/',import.meta.url); fs.mkdirSync(out,{recursive:true}); for(const name of ['three','single','missing','changed']){ if(process.argv[2]==='generate'){ const {d,b}=noncivilCase(); if(name==='single')Object.assign(b.pecObligation.plan,{mode:'single',singleMonth:'2026-01'}); if(name==='missing')b.advancePeriodDeclaration.previousReference=''; if(name==='changed')b.ppcObligation.previousTax='200000'; const prior=recordAnnual(d,{...b,ppcObligation:undefined,pecObligation:undefined,advancePeriodDeclaration:undefined},'2026-11-14T08:00:00Z'); d.modelo_a_snapshot=saveAnnualBook(d,recordAnnual(d,{...prior,ppcObligation:b.ppcObligation,pecObligation:b.pecObligation,advancePeriodDeclaration:b.advancePeriodDeclaration},'2026-11-14T08:01:00Z')); fs.writeFileSync(new URL(name+'.json',out),JSON.stringify(d)); }else{ const d=JSON.parse(fs.readFileSync(new URL('recovered-'+name+'.json',out),'utf8')),b=annualBook(d),period=annualAdvancePeriod(d,b),m=annualAdvanceCashflow(b,period); assert.equal(annualCurrent(d,b),true);assert.equal(b.history.length,1); assert.deepEqual(b.result.model.arithmeticBalance,b.history[0].model.arithmeticBalance); assert.deepEqual(b.result.model.advancePeriod,period); if(['three','single'].includes(name))assert.deepEqual(m.total,{numerator:'112000',denominator:'1'}); else assert.equal(m.total,null); if(name==='changed'){assert.equal(m.ppcKnown,false);assert.equal(m.pecKnown,true);} const html=annualHtml(d),report=createProjectDossierReport(d,{selectedSections:new Set(['finance']),generatedAt:'2026-11-14T08:02:00Z'}); assert.match(html,/Projecção mensal conjunta PPC\/PEC/);assert.match(JSON.stringify(report),/Projecção mensal conjunta PPC\/PEC/); if(['three','single'].includes(name)){assert.match(html,/2025-11/);assert.match(html,/2026-03/);assert.match(JSON.stringify(report),/112000/);} fs.writeFileSync(new URL(name+'-report.html',out),html); fs.writeFileSync(new URL(name+'-verification.json',out),JSON.stringify({synthetic:true,nativeApiRecovery:true,historyPreserved:true,independentAnnualCalculationUnchanged:true,period,model:m},null,2)); } } console.log(process.argv[2]==='generate'?'Generated four synthetic annual noncivil cases':'Verified four recovered annual noncivil cases and reports');