Files
Investidor-V2/outputs/investmoz-audit-current-20261012/manual-396c-workbook.mjs
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

20 lines
1.3 KiB
JavaScript

import fs from 'node:fs/promises';
import { Workbook } from '@oai/artifact-tool';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
const dir=path.dirname(fileURLToPath(import.meta.url));
const plan=JSON.parse(await fs.readFile(path.join(dir,process.argv[2] ?? '20261013_manual_auth_p3-plan.json'),'utf8'));
for(const p of plan){
const wb=await Workbook.fromCSV(await fs.readFile(path.join(dir,p.source_file),'utf8'),{sheetName:'ExistingRows'});
const sheet=wb.worksheets.getItem('ExistingRows');
const range=sheet.getRangeByIndexes(0,0,p.source_rows.length+1,p.fields.length);
const original=range.values;
if(JSON.stringify(original)!==JSON.stringify([p.fields,...p.source_rows]))throw Error('CSV source preservation failed');
for(const c of p.changes){const cell=sheet.getCell(c.row,c.column);if(cell.values[0][0]!==c.old)throw Error('Value conflict');cell.values=[[c.value]];}
wb.recalculate();
const result=range.values;
for(const c of p.changes)if(result[c.row][c.column]!==c.value)throw Error('Cell readback mismatch');
await fs.writeFile(path.join(dir,p.output_json),JSON.stringify(result));
console.log(JSON.stringify({kind:p.kind,editedRows:p.source_rows.length,editedCells:p.changes.length,newIds:0,format:'CSV preserving unrelated records'}));
}