import fs from 'node:fs/promises'; import path from 'node:path'; import assert from 'node:assert/strict'; import {createRequire} from 'node:module'; import {pathToFileURL,fileURLToPath} from 'node:url'; import {createHash} from 'node:crypto'; const root=path.dirname(path.dirname(path.dirname(fileURLToPath(import.meta.url)))); const out=path.join(root,'outputs/investmoz-workflow-opening-20261012'); const baseline=JSON.parse(await fs.readFile(path.join(out,'matrix-deployment-baseline.json'),'utf8')); const file=path.join(root,'docs/investmoz/v2/auditoria-portal/matriz-requisitos.csv'); const bytes=await fs.readFile(file,'utf8'); assert.equal(createHash('sha256').update(bytes).digest('hex'),baseline.sha256); const req=createRequire(path.join(root,'storage/app/private/investmoz-v2/portal-audit/legacy-sector-reconciliation-20261010/package.json')); const {Workbook}=await import(pathToFileURL(req.resolve('@oai/artifact-tool')).href); const workbook=await Workbook.fromCSV(bytes.replace(/^\ufeff/,''),{sheetName:'Requisitos'}); const sheet=workbook.worksheets.getItem('Requisitos'); const final=baseline.rows.map(r=>[...r]); const headers=final[0],column=headers.indexOf('Consolidação'),changes=[]; const same=(v,s)=>(v instanceof Date?new Date(v).getTime()===Date.parse(s):(v==null?'':String(v))===s); assert(sheet.getRangeByIndexes(0,0,final.length,headers.length).values.every((r,i)=>r.every((v,c)=>same(v,final[i][c])))); for(let i=1;ir.every((v,c)=>same(v,final[i][c])))); const quote=v=>/[",\r\n]/.test(v)?'"'+v.replaceAll('"','""')+'"':v; const result='\ufeff'+final.map(row=>row.map(quote).join(',')).join('\r\n')+'\r\n'; await fs.writeFile(path.join(out,'matrix-before-deployment.csv'),bytes,'utf8'); await fs.writeFile(file,result,'utf8'); const proof={result:'passed',requirements:final.length-1,source_occurrences:final.slice(1).reduce((n,r)=>n+Number(r[headers.indexOf('Quantidade de linhas de origem')]),0),changes,new_ids:0,states_unchanged:true,all_other_cells_and_references_preserved:true,sha256:createHash('sha256').update(result).digest('hex')}; await fs.writeFile(path.join(out,'matrix-deployment-proof.json'),JSON.stringify(proof,null,2)); console.log(JSON.stringify(proof));