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

27 lines
4.5 KiB
Python

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("BASE=plan.consumer_environment.base,TARGET=plan.consumer_environment.target.database+':55441'", "BASE=plan.qa_environment.base,TARGET=JSON.parse(fs.readFileSync(path.join(plan.source,'stability-qa.json'))).target.database+':55441'")
prefix=prefix.replace("const actors=JSON.parse(fs.readFileSync(path.join(DIR,'profiles-v1-actors-private.json')));", "const actors=JSON.parse(fs.readFileSync(path.join(plan.source,'storage/app/private/stability-cold-actors.json')));")
prefix=prefix.replace('portal-stability-consumers-chromium.json','portal-stability-cold-chromium.json')
body=r'''try{
await actor('approver');await observed('profile-installation','/management/profile-install');
const bootstrapOnly=process.argv.includes('--bootstrap-only');
if(bootstrapOnly){const prior=JSON.parse(fs.readFileSync(receipt));fs.writeFileSync(receipt.replace('.json','-before-normal-enrollment-fix.json'),JSON.stringify(prior,null,2));proof.previous_bootstrap_status=prior.bootstrap_status;}
if(!bootstrapOnly){
const before=await page.evaluate(async()=>await (await fetch('/management/profile-install',{headers:{Accept:'application/json'}})).json());assert(before.ready&&before.consistent);proof.before={installed:before.installed,dependencies:before.dependencies,bootstrap:before.bootstrap};save();
let lost=false,payload;
await page.route('**/management/profile-install',async route=>{if(route.request().method()==='POST'&&!lost){payload=route.request().postDataJSON();lost=true;proof.initial_connection_interrupted_before_commit=true;save();await route.abort('failed');}else await route.continue();});
await page.getByLabel('Fundamento',{exact:true}).fill('Synthetic QA cold installer: recover committed operation after lost response');await page.getByLabel('Confirmo exclusivamente a ação indicada nesta base').check();
const install=page.getByRole('button',{name:'Instalar schema 040000',exact:true});await install.click();await page.getByRole('status').filter({hasText:/Failed to fetch|ligação|resposta|fetch/i}).waitFor();await install.click();
await page.getByRole('status').filter({hasText:'Schema instalado.'}).waitFor();assert.equal(proof.operations.at(-1).key_sha256,proof.operations.at(-2).key_sha256);
const repeat=await page.evaluate(async body=>{const cookie=document.cookie.split('; ').find(v=>v.startsWith('XSRF-TOKEN='))?.slice(11);const r=await fetch('/management/profile-install',{method:'POST',headers:{Accept:'application/json','Content-Type':'application/json','X-XSRF-TOKEN':decodeURIComponent(cookie??'')},body:JSON.stringify(body)});return {status:r.status,json:await r.json()};},payload);assert.equal(repeat.status,200);assert(repeat.json.installed);proof.checks.push({criterion:'cold040 interrupted attempt/retry preserves key; replay returns same receipt',passed:true});
}
if(bootstrapOnly)await page.getByLabel('Fundamento',{exact:true}).fill('Synthetic QA normal Fortify MFA bootstrap after compatibility correction');
await page.getByLabel('ID da primeira conta explicitamente designada').fill(String(actors.first.id));await page.getByLabel('ID da segunda conta explicitamente designada').fill(String(actors.second.id));await page.getByLabel('Confirmo exclusivamente a ação indicada nesta base').check();
const answer=page.waitForResponse(r=>new URL(r.url()).pathname==='/management/profile-install/bootstrap'&&r.request().method()==='POST');await page.getByRole('button',{name:'Inicializar apenas estas duas contas',exact:true}).click();const r=await answer;proof.bootstrap_status=r.status();proof.bootstrap_message=(await r.json()).message??null;save();assert.equal(r.status(),200);
await page.getByRole('status').filter({hasText:'Dupla inicializada.'}).waitFor();await actor('first');await recover('/management/profile-install','explicit synthetic pair initialization recovered as designated holder in new session');proof.result='passed';save();console.log(JSON.stringify({result:proof.result,checks:proof.checks.length,active_writes:0}));
}catch(e){proof.result='failed';proof.failure=redact(e);save();console.log(JSON.stringify({result:'failed',failure:proof.failure,bootstrap_status:proof.bootstrap_status,bootstrap_message:proof.bootstrap_message,active_writes:0}));process.exitCode=1;}finally{if(ctx)await ctx.close();await browser.close();}})();
'''
(ROOT/'tools/portal-stability-cold-chromium.cjs').write_text(prefix+body,encoding='utf-8')