Files
Investidor-V2/outputs/investmoz-negocios-classificacao-QA-20261016/prepare.py
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

30 lines
3.4 KiB
Python

from pathlib import Path
import json,hashlib,shutil,subprocess
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
private=Path('C:/Users/macbook/.config/investmoz/negocios-classificacao-QA-20261016');qa=private/'source'
assert not private.exists(),'Inspect existing work before resuming'
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
baseline={p.relative_to(root).as_posix():sha(p) for folder in ['app','config','routes','database','resources','public/build'] for p in (root/folder).rglob('*') if p.is_file()}
protected={n:sha(root/n) for n in ['.env','composer.lock','package-lock.json']}
private.mkdir(parents=True);qa.mkdir()
(out/'ATIVO-ANTES.json').write_text(json.dumps({'files':baseline,'protected':protected},indent=2),'utf-8')
for folder in ['app','config','routes','database','resources','bootstrap','public/build']:
shutil.copytree(root/folder,qa/folder)
for n in ['artisan','composer.json','composer.lock','package.json','package-lock.json','tsconfig.json','vite.config.ts']:
shutil.copy2(root/n,qa/n)
for folder in ['storage/framework/cache/data','storage/framework/views','storage/framework/sessions','storage/logs','storage/app/private','storage/app/public']:(qa/folder).mkdir(parents=True,exist_ok=True)
for name in ['vendor','node_modules']:
subprocess.run(['powershell','-NoProfile','-Command',f"New-Item -ItemType Junction -Path '{qa/name}' -Target '{root/name}' | Out-Null"],check=True,capture_output=True)
for n in ['config.php','routes-v7.php']:assert not (qa/'bootstrap/cache'/n).exists()
pg=Path('C:/Program Files/PostgreSQL/17/bin');common=['-h','127.0.0.1','-p','55441','-U','postgres'];db='business_classification_20261016_test'
dump=private/'reference-QA.dump'
subprocess.run([str(pg/'pg_dump.exe'),*common,'-d','stability_consumers_20261011_084534_test','-Fc','-f',str(dump)],check=True,capture_output=True)
subprocess.run([str(pg/'createdb.exe'),*common,db],check=True,capture_output=True)
subprocess.run([str(pg/'pg_restore.exe'),*common,'-d',db,'--exit-on-error','--no-owner','--no-privileges',str(dump)],check=True,capture_output=True)
# Retain only the synthetic reference QA key, never active application credentials.
reference=root/'storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742'
lines=(reference/'.env.stability-consumers').read_text('utf-8').splitlines();key=next(x for x in lines if x.startswith('APP_KEY='))
(qa/'.env').write_text('APP_NAME="InvesteMoz QA negocios classificacao"\nAPP_ENV=testing\n'+key+'\nAPP_DEBUG=false\nAPP_URL=http://127.0.0.1:18521\nDB_CONNECTION=pgsql\nDB_HOST=127.0.0.1\nDB_PORT=55441\nDB_DATABASE='+db+'\nDB_USERNAME=postgres\nDB_PASSWORD=\nSESSION_DRIVER=file\nSESSION_COOKIE=business_classification_qa\nCACHE_STORE=array\nQUEUE_CONNECTION=sync\nMAIL_MAILER=log\nINERTIA_SSR_ENABLED=false\nINVESTMOZ_MNE_ENABLED=true\nINVESTMOZ_MNE_COMPATIBILITY_SHADOW=false\nINVESTOR_PATH_ENABLED=true\nPORTAL_LEGACY_CONTENT_ENABLED=false\nPORTAL_LEGACY_CONTENT_QA_ENABLED=true\n','utf-8')
record={'source':str(qa),'database':db,'host':'127.0.0.1','port':55441,'url':'http://127.0.0.1:18521','reference_QA':'stability_consumers_20261011_084534_test:55441','reference_dump_sha256':sha(dump),'QA_key':'same isolated synthetic QA reference key; no active secrets','active_changes':0,'accepted_tests_repeated':False}
(out/'QA-ISOLAMENTO.json').write_text(json.dumps(record,indent=2)+'\n','utf-8');print(json.dumps(record))