Files
Investidor-V2/tools/portal-stability-extra-browser.py
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

35 lines
7.8 KiB
Python
Raw Permalink 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.
from pathlib import Path
ROOT=Path(__file__).resolve().parent.parent
prefix=(ROOT/'tools/portal-stability-consumers-chromium.cjs').read_text(encoding='utf-8').split('try{\nif(remaining)')[0]
prefix=prefix.replace('portal-stability-consumers-chromium.json','portal-stability-extra-chromium.json')
body=r'''try{
const resumeExtra=process.argv.includes('--resume-extra');
if(resumeExtra){const prior=JSON.parse(fs.readFileSync(receipt));assert.equal(prior.checks.length,2);Object.assign(proof,prior);delete proof.failure;delete proof.result;}
if(!resumeExtra){
await actor('geo');await open('/management/territory-geometry-import?level=1');
assert(await page.getByText(/Scan: limpo e atual/).isVisible());await page.getByLabel('Fundamento da aplicação ou reversão').fill('Synthetic isolated QA stability: replay and reversal preserve retained geometries');await page.getByLabel('Confirmei as correspondências.').check();
const apply=page.getByRole('button',{name:'Aplicar correspondências',exact:true});await apply.click();await page.getByRole('status').filter({hasText:'Criadas 0; reutilizadas 11; pendentes 0.'}).waitFor();await apply.click();await page.getByRole('status').filter({hasText:'Criadas 0; reutilizadas 11; pendentes 0.'}).waitFor();
assert.equal(proof.operations.at(-1).key_sha256,proof.operations.at(-2).key_sha256);await page.getByRole('button',{name:'Reverter apenas geometrias criadas pelo lote',exact:true}).click();await page.getByRole('status').filter({hasText:'Revertidas 0; preservadas 11'}).waitFor();
proof.checks.push({component:'territory-geometry-import',criterion:'preview/apply/replay/reverse preserves all eleven existing province geometries; publication separate',passed:true});save();
await page.getByLabel('Nível',{exact:true}).selectOption('2');await page.getByText(/Esperado: 159/).waitFor();await page.getByRole('button',{name:'Atualizar pré-visualização',exact:true}).click();await page.getByText(/Esperado: 159/).waitFor();proof.checks.push({criterion:'level switch and preview refresh without randomUUID',passed:true});save();
}
await actor('promoter');await open('/minhas-oportunidades/53/resources');
let resourceKeys=[];page.on('request',r=>{if(r.method()==='POST'&&new URL(r.url()).pathname.includes('/53/resources/')){const key=r.postData()?.match(/name="creation_key"\r\n\r\n([0-9a-f-]+)/)?.[1];if(key){assert.match(key,/^[0-9a-f-]{36}$/);resourceKeys.push(crypto.createHash('sha256').update(key).digest('hex'));}}});
let interrupted=false;await page.route('**/53/resources/locations',async r=>{if(r.request().method()==='POST'&&!interrupted){interrupted=true;await r.abort('failed');}else await r.continue();});
await page.getByLabel('Título',{exact:true}).fill('Synthetic stability recoverable location');await page.getByLabel('Motivo (20–1000 caracteres)').fill('Synthetic QA UUID location save: no territorial classification inferred');await page.getByRole('button',{name:'Guardar recurso',exact:true}).click();await page.getByRole('status').filter({hasText:/Failed to fetch/}).waitFor();
await page.getByRole('button',{name:'Guardar recurso',exact:true}).click();await page.getByText('Synthetic stability recoverable location · v1 · rascunho',{exact:true}).waitFor();assert.equal(resourceKeys[0],resourceKeys[1]);
await recover('/minhas-oportunidades/53/resources','incomplete location preserved after validation/retry and refresh');proof.checks.push({component:'opportunity-resources',key_preserved_on_retry:true,passed:true});save();
await page.getByRole('button',{name:'Ver / editar / restaurar',exact:true}).last().click();await page.getByLabel('Título',{exact:true}).fill('Synthetic stability recoverable location edited');await page.getByRole('button',{name:'Guardar recurso',exact:true}).click();await page.getByText('Synthetic stability recoverable location edited · v2 · rascunho',{exact:true}).waitFor();proof.checks.push({criterion:'resource selection rotates key and edited version visible',passed:true});save();
await open('/balcao-virtual/painel');await page.getByText('Preparar acompanhamento de um projecto',{exact:true}).click();await page.getByLabel('Título do projecto',{exact:true}).fill('Synthetic UUID direct Balcao dossier');await page.getByLabel('Autorizo reutilizar os dados seleccionados').check();await page.locator('form').getByRole('button').first().click();await page.waitForURL(/\/balcao-virtual\/dossiers\/[a-f0-9-]+$/);const directCase=new URL(page.url()).pathname;proof.new_direct_case=directCase;
await page.getByRole('button',{name:'Preparar rascunho de pedido',exact:true}).click();await page.waitForURL(/\/balcao-virtual\/pedidos\/[a-f0-9-]+$/);proof.new_direct_request=new URL(page.url()).pathname;proof.checks.push({component:'desk-panel + desk-case',criterion:'both direct creation actions saved and retrieved',passed:true});await recover(proof.new_direct_request,'direct desk request refreshed');
await open('/parcerias/salas/1');page.on('response',r=>{const u=new URL(r.url());if(u.pathname==='/parcerias/salas/1/mensagens'){proof.room_responses??=[];proof.room_responses.push({status:r.status()});save();}});
for(let n=1;n<=2;n++){const text='Independent UUID stability room message '+n;await page.getByLabel('Mensagem privada',{exact:true}).fill(text);const response=page.waitForResponse(r=>new URL(r.url()).pathname==='/parcerias/salas/1/mensagens'&&r.request().method()==='POST');await page.getByRole('button',{name:'Enviar mensagem',exact:true}).click();const r=await response;assert(r.status()<400,'Room POST failed: '+r.status());await page.getByText(text,{exact:true}).waitFor();await page.getByLabel('Mensagem privada',{exact:true}).toBeEmpty?.();await page.waitForFunction(()=>document.querySelector('textarea')?.value==='');}
await recover('/parcerias/salas/1','two independently keyed room messages persisted');proof.checks.push({component:'partnership-room',passed:true});save();
await actor('outsider');for(const route of [directCase,proof.new_direct_request,'/investimentos/d8ac9133-65b6-4ed4-964e-e230bc656a02','/management/territory-geometry-import','/management/profile-install']){const r=await open(route);assert([403,404].includes(r.status()));proof.checks.push({criterion:'other account cannot access private or privileged consumer',role,route,status:r.status(),passed:true});save();}
if(ctx)await ctx.close();ctx=await browser.newContext({ignoreHTTPSErrors:false});await ctx.addInitScript(()=>Object.defineProperty(Crypto.prototype,'randomUUID',{value:undefined,configurable:true}));page=await ctx.newPage();page.setDefaultTimeout(35000);await open('/simulador-fiscal');
const post=page.waitForResponse(r=>new URL(r.url()).pathname==='/api/v1/simulation-drafts'&&r.request().method()==='POST');await page.getByLabel('Nível de detalhe (obrigatório)',{exact:true}).selectOption('simple');const response=await post;assert(response.status()<300,'Anonymous autosave failed: '+response.status());const json=await response.json();proof.anonymous_draft_id=json.data.id;const k=response.request().headers()['idempotency-key'];assert.match(k,/^[0-9a-f-]{36}$/);proof.checks.push({component:'simulation-form',criterion:'anonymous autosave generates compatible header key and recovers own draft',key_sha256:crypto.createHash('sha256').update(k).digest('hex'),passed:true});await page.reload({waitUntil:'networkidle'});assert.equal(await page.getByLabel('Nível de detalhe (obrigatório)',{exact:true}).inputValue(),'simple');save();
assert.equal(proof.errors.length,0);proof.result='passed';save();console.log(JSON.stringify({result:proof.result,checks:proof.checks.length,operations:proof.operations.length,active_writes:0}));
}catch(e){proof.result='failed';proof.failure=redact(e);save();console.log(JSON.stringify({result:'failed',failure:proof.failure,checks:proof.checks.length,active_writes:0}));process.exitCode=1;}finally{if(ctx)await ctx.close();await browser.close();}})();
'''
(ROOT/'tools/portal-stability-extra-chromium.cjs').write_text(prefix+body,encoding='utf-8')