Files
Investidor-V2/tools/portal-workflow-upgrade-office-qa.cjs
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

12 lines
3.4 KiB
JavaScript

const {start,assert,DIR,path,fs,sanitized}=require('./portal-workflow-upgrade-browser-lib.cjs');const cp=require('node:child_process');
void(async()=>{const q=await start('workflow-upgrade-office-chromium-20261011');let ctx,page;try{
({ctx,page}=await q.context('promoter'));await q.login(page,'promoter');const previous=JSON.parse(fs.readFileSync(path.join(DIR,'workflow-upgrade-document-pipeline-chromium-20261011.json'),'utf8')),id=previous.opportunity_id;
const files=JSON.parse(fs.readFileSync(path.join(DIR,'workflow-upgrade-office-fixtures.json'),'utf8'));q.proof.documents=[];
for(const f of files){const response=await q.open(page,`/minhas-oportunidades/${id}/resources`);const html=await response.text(),encoded=html.match(/data-page="([^"]+)"/);const body=encoded&&encoded[1].startsWith('{')?JSON.parse(encoded[1].replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&#039;/g,"'")):JSON.parse(html.match(/<script[^>]*type="application\/json"[^>]*>([\s\S]*?)<\/script>/)[1]);
const r=await page.evaluate(async({id,etag,extension,bytes})=>{const form=new FormData();form.set('etag',etag);form.set('creation_key',crypto.randomUUID());form.set('reason','Original Office explicitamente sintético QA: testar fila, análise real, cifra e recuperação sem efeitos jurídicos.');form.set('payload',JSON.stringify({title:'SIMULAÇÃO QA '+extension,classification:'restricted',visibility:'internal'}));form.set('file',new File([Uint8Array.from(atob(bytes),c=>c.charCodeAt(0))],'SIMULACAO-QA.'+extension));const token=decodeURIComponent(document.cookie.split('; ').find(v=>v.startsWith('XSRF-TOKEN='))?.slice(11)||'');const r=await fetch(`/minhas-oportunidades/${id}/resources/documents`,{method:'POST',headers:{Accept:'application/json','X-XSRF-TOKEN':token},body:form});return {status:r.status,data:await r.json()};},{id,etag:body.props.etag,extension:f.extension,bytes:fs.readFileSync(f.path).toString('base64')});assert.equal(r.status,201);q.proof.documents.push({extension:f.extension,resource_id:r.data.id,sha256:f.sha256});q.save();}
cp.execFileSync('C:/laragon/bin/php/php-8.5.11-Win32-vs17-x64/php.exe',[path.join(__dirname,'portal-workflow-upgrade-worker.php')],{timeout:90000,stdio:['ignore','pipe','pipe']});
for(const d of q.proof.documents){const result=await page.evaluate(async url=>{const r=await fetch(url,{headers:{Accept:'application/json'}}),b=await r.arrayBuffer(),h=await crypto.subtle.digest('SHA-256',b);return {status:r.status,sha256:[...new Uint8Array(h)].map(v=>v.toString(16).padStart(2,'0')).join(''),type:r.headers.get('content-type')};},`/minhas-oportunidades/${id}/resources/documents/${d.resource_id}/download`);assert.equal(result.status,200);assert.equal(result.sha256,d.sha256);d.media_type=result.type;d.recovered=true;}
await q.open(page,`/minhas-oportunidades/${id}/resources`);await page.getByRole('button',{name:'Documentos',exact:true}).click();await page.getByText('SIMULACAO-QA.docx',{exact:false}).first().waitFor();await q.shot(page,'office-originals-clean-and-recoverable',false);
q.proof.checks={DOCX_real_scan_and_exact_recovery:true,XLSX_real_scan_and_exact_recovery:true,original_office_no_conversion_or_publication:true};q.proof.result='passed';q.save();console.log(JSON.stringify({result:'passed',checks:q.proof.checks,active_writes:0}));
}catch(e){q.proof.result='failed';q.proof.failure=sanitized(e);q.save();console.log(JSON.stringify({result:'failed',failure:q.proof.failure}));process.exitCode=1;}finally{if(ctx)await ctx.close();await q.browser.close();}})();