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

36 lines
3.6 KiB
Python

"""Adapt the existing completed criteria to the changed Apache/production environment."""
from pathlib import Path
import json, subprocess
ROOT=Path(__file__).resolve().parent.parent
PRIVATE=ROOT/'storage/app/private/investmoz-v2/portal-audit'
read=lambda p:json.loads(Path(p).read_text(encoding='utf-8-sig'))
plan=read(PRIVATE/'portal-stability-latest.json');source=Path(plan['source']);settings=plan['qa_environment']
js=(ROOT/'tools/portal-country-https-chromium.cjs').read_text(encoding='utf-8')
start=js.index("const meta=JSON.parse")
end=js.index("const BASE=meta.base",start)
js=js[:start]+'''const plan=JSON.parse(fs.readFileSync(path.join(DIR,'portal-stability-latest.json'))),source=plan.source;
const settings=JSON.parse(fs.readFileSync(path.join(source,'stability-qa.json')));
const meta={base:settings.base,http_redirect:settings.http_base};
const target={target:settings.target,base:settings.base,credentials_path:settings.credentials_path,code_hash:'162daff6ce08117582dd7d796639d02b156d1b940cd85ef3587ff88a65747edd'};
const actor=JSON.parse(fs.readFileSync(target.credentials_path));
const build=JSON.parse(fs.readFileSync(path.join(DIR,'portal-stability-production.json')));
const stage={assets:build.assets,build_manifest_sha256:build.build_manifest_sha256};
'''+js[end:]
js=js.replace('country-https-chromium-20261011.json','portal-stability-country-chromium-20261011.json')
js=js.replace('MAP country02-qa.test 127.0.0.1','MAP portal-investidor.test 127.0.0.1')
js=js.replace("!u.port.includes('18105')", "u.origin!==meta.http_redirect")
js=js.replace("assets:prior?.assets??{}", "assets:{},previous_assets:prior?.assets??{}")
js=js.replace("await page.locator('input[name=\"code\"]').fill(otp());", "await page.waitForTimeout(30500-(Date.now()%30000));await page.locator('input[name=\"code\"]').fill(otp());")
js=js.replace("assert.equal((await response).status(),302);", "const appliedResponse=await response;assert.equal(appliedResponse.status(),302);const appliedPayload=appliedResponse.request().postDataJSON();")
marker="proof.checks.cold_installation_visible=true;"
assert js.count(marker)==1
js=js.replace(marker,marker+'''\n const replay=await page.evaluate(async ({endpoint,body})=>{const csrf=document.cookie.split('; ').find(v=>v.startsWith('XSRF-TOKEN='))?.slice(11);const r=await fetch(endpoint,{method:'POST',headers:{Accept:'application/json','Content-Type':'application/json','X-XSRF-TOKEN':decodeURIComponent(csrf??'')},body:JSON.stringify(body)});return {status:r.status(),data:await r.json()};},{endpoint:INSTALL,body:appliedPayload});assert.equal(replay.status,200);proof.installation_replay=replay.data;proof.checks.authenticated_replay_same_operation=true;\n'''.replace('r.status()','r.status'))
js=js.replace('C:/Users/macbook/.config/investmoz/php-8.5.11/php.exe','C:/laragon/bin/php/php-8.5.11-Win32-vs17-x64/php.exe')
js=js.replace("c.name==='country_https_18443_qa'","c.name==='investmoz_stability_18444_qa'")
js=js.replace("session.domain==='country02-qa.test'","session.domain==='portal-investidor.test'")
js=js.replace("portal-country-https-qa.php","portal-stability-runtime.php").replace("),'seed']", "),'seed-organization']")
js=js.replace('Synthetic COUNTRY02 production bundle organization','Synthetic integrated stability QA organization')
js=js.replace("proof.result='passed';save();", "proof.runtime.php=target.php;proof.environment='Standalone destination Apache/mod_php, no development TLS proxy';proof.result='passed';save();")
(ROOT/'tools/portal-stability-country-chromium.cjs').write_text(js,encoding='utf-8')
print(json.dumps({'result':'existing_COUNTRY_criteria_bound_to_new_Apache_QA','source':str(source),'origin':settings['base'],'active_writes':0}))