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

16 lines
2.9 KiB
JavaScript

const {start,assert,DIR,path,fs,sanitized,TARGET}=require('./portal-service-followup-browser-lib.cjs');
const cp=require('node:child_process'),crypto=require('node:crypto'),PHP='C:/laragon/bin/php/php-8.5.11-Win32-vs17-x64/php.exe';
void(async()=>{const q=await start('service-followup-20mib-recovery-qa');let ctx;try{
const original=JSON.parse(fs.readFileSync(path.join(DIR,'service-followup-20mib-boundary-qa.json'),'utf8'));assert.equal(original.target,TARGET);assert.equal(original.upload_status,201);assert.equal(original.worker_exit,255);
const a=await q.context('promoter');ctx=a.ctx;const page=a.page;await q.login(page,'promoter');
function inspect(){return JSON.parse(cp.execFileSync(PHP,['-d','memory_limit=256M',path.join(__dirname,'portal-service-followup-inspect.php'),String(original.opportunity_id)],{encoding:'utf8',timeout:60000}));}
const before=inspect(),row=before.rows.find(r=>r.resource_id===original.resource_id);assert(row);q.proof.resource_id=original.resource_id;q.proof.opportunity_id=original.opportunity_id;q.proof.before=before;q.save();
let state=inspect(),end=Date.now()+300000;
while(state.rows.find(r=>r.resource_id===original.resource_id).malware_scan_status!=='clean'&&Date.now()<end){await page.waitForTimeout(5000);state=inspect();}
const recovered=state.rows.find(r=>r.resource_id===original.resource_id);assert.equal(recovered.malware_scan_status,'clean');assert.equal(recovered.original_cipher_sha256,row.original_cipher_sha256);assert(recovered.plaintext_hash_matches);assert.equal(state.rows.filter(r=>r.kind==='documents').length,1);assert.equal(state.jobs.length,0);assert.equal(state.failed_jobs,0);
const response=await page.evaluate(async url=>{const r=await fetch(url),b=await r.arrayBuffer(),h=await crypto.subtle.digest('SHA-256',b);return {status:r.status,bytes:b.byteLength,hash:[...new Uint8Array(h)].map(v=>v.toString(16).padStart(2,'0')).join('')};},'/minhas-oportunidades/'+original.opportunity_id+'/resources/documents/'+original.resource_id+'/download');
assert.equal(response.status,200);assert.equal(response.bytes,20*1048576);assert.equal(response.hash,original.sha256);
await q.open(page,'/minhas-oportunidades/'+original.opportunity_id+'/resources');await page.getByRole('button',{name:'Documentos',exact:true}).click();await q.shot(page,'20mib-recovered-after-cli-memory-interruption',false);
q.proof.after=state;q.proof.download=response;q.proof.checks.web_20mib_saved_scanned_recovered_after_128m_interruption_without_resubmission=true;q.proof.checks.planned_256m_scheduled_worker_recovery=true;q.proof.result='passed';q.save();console.log(JSON.stringify({result:'passed',checks:q.proof.checks,target:TARGET,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();}})();