Files
Investidor-V2/outputs/investmoz-parques-L1-ativacao-20261018/matrix-observation/update.mjs
T
nala 6bc0cc6f52
tests / ci (push) Canceled after 0s
versao nrgocios 3
2026-10-18 11:17:35 +02:00

22 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from 'node:fs/promises';
import crypto from 'node:crypto';
import { Workbook } from '@oai/artifact-tool';
const input=JSON.parse(await fs.readFile(new URL('./input.json',import.meta.url),'utf8'));
const hash=x=>crypto.createHash('sha256').update(x).digest('hex');
const raw=await fs.readFile(input.matrix);if(hash(raw)!==input.sha256_before)throw Error('Concurrent matrix edit');
const workbook=await Workbook.fromCSV(input.csv_subset,{sheetName:'Matriz'});const sheet=workbook.worksheets.getItem('Matriz');
const before=sheet.getRangeByIndexes(0,0,6,46).values;if(JSON.stringify(before.slice(1))!==JSON.stringify(input.selected.map(x=>x.row)))throw Error('CSV import changed values');
sheet.getRange('A1:A6').format.columnWidthPx=240;
if(process.argv.includes('--preview')){const blob=await workbook.render({sheetName:'Matriz',range:'A1:A6',scale:1});await fs.writeFile(new URL('./before.png',import.meta.url),new Uint8Array(await blob.arrayBuffer()));process.exit(0);}
const additions={"Evidências atuais verificadas": "18/10/2026, L1: observado diretamente pelo Codex no editor Balama, URL HTTPS confirmado, conta2/Osmane Nala pelo DOM. Quatro grupos L1 presentes; público v3/preparação não guardada. Sem alterar campos, guardar, publicar ou repetir140000. Evidência EDITOR-OBSERVADO-20261018.txt e OBSERVACAO-OPERACIONAL-FINAL.json no diretório da ativação.", "Critérios restantes atuais": "Pendência operacional de abertura/observação do editor L1 resolvida: observado. Ficha integral permanece aberta nos restantes critérios anteriores. Não há novo teste QA ou outro lote.", "Limites das provas agrupadas": "Rectificação expressa: ChatGPT conferiu documentos DOC02 QA; não está confirmada a conferência pelo utilizador do relatório local da ativação. Esta nota corrige atribuições anteriores. Relatório/recibo finais preparados para anexar à página privada existente. Sessão autorizada existente; sem novo desafio MFA ou observação de gravação/publicação.", "Esforço e pressupostos atuais": "Observação operacional restante L1 concluída, resultado observado; saldo operacional deste recorte zero. 2–4h e24–36h continuam estimativas históricas, não horas consumidas; ficha integral aberta."};
for(const [name,note]of Object.entries(additions)){const col=input.headers.indexOf(name);if(col<0)throw Error('Column absent');sheet.getRangeByIndexes(1,col,5,1).values=input.selected.map((x,i)=>[before[i+1][col]+' | '+note]);}
workbook.recalculate();const after=sheet.getRangeByIndexes(0,0,6,46).values;const allowed=Object.keys(additions).map(x=>input.headers.indexOf(x));
for(let i=1;i<6;i++)for(let j=0;j<46;j++)if(!allowed.includes(j)&&before[i][j]!==after[i][j])throw Error('Unrelated cell changed');
const quote=s=>/[",\r\n]/.test(s)?'"'+s.replaceAll('"','""')+'"':s;
let text=raw.toString('utf8');for(let i=0;i<5;i++){const old=input.selected[i].raw;if(text.split(old).length!==2)throw Error('Nonunique row');const ending=old.endsWith('\r\n')?'\r\n':old.endsWith('\n')?'\n':'';text=text.replace(old,after[i+1].map(quote).join(',')+ending);}
const inspect=await workbook.inspect({kind:'table',range:'Matriz!A1:B6',tableMaxRows:6,tableMaxCols:2,maxChars:1400});await fs.writeFile(new URL('./inspection.json',import.meta.url),inspect.ndjson);
const image=await workbook.render({sheetName:'Matriz',range:'A1:A6',scale:1});await fs.writeFile(new URL('./after.png',import.meta.url),new Uint8Array(await image.arrayBuffer()));
await fs.writeFile(input.matrix,text);
await fs.writeFile(new URL('../MATRIZ-OBSERVACAO-ATUALIZACAO.json',import.meta.url),JSON.stringify({rows:3402,rows_updated:input.selected.map(x=>x.id),columns_updated:Object.keys(additions),other_raw_rows_preserved:3397,states_and_original_criteria_preserved:true,sha256_before:input.sha256_before,sha256_after:hash(Buffer.from(text)),authoring:'artifact-tool; only selected cells appended; unrelated raw rows preserved'},null,2));
console.log(JSON.stringify({updated_rows:5,states_preserved:true,other_raw_rows_preserved:3397}));