Files
Investidor-V2/outputs/investmoz-audit-current-20261012/align-existing-qa.py
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

42 lines
3.5 KiB
Python

"""Align only the existing, complete HTTPS QA with the active code/build."""
from pathlib import Path
from datetime import datetime,timezone
import hashlib,json,os,subprocess,zipfile
ROOT=Path(__file__).resolve().parents[2];OUT=Path(__file__).resolve().parent
PRIVATE=ROOT/'storage/app/private/investmoz-v2/portal-audit'
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
state=json.loads((OUT/'runtime-qa18445.json').read_text())
assert state['identity']=={'database':'stability_consumers_20261011_084534_test','port':55441} and state['table_count']==295
plan=json.loads((PRIVATE/'portal-stability-latest.json').read_text());QA=Path(plan['source'])
assert QA.resolve().is_relative_to(PRIVATE.resolve()) and QA.name=='portal-stability-source-20261011_083742'
assert not (OUT/'qa-code-alignment.json').exists(),'Inspect existing alignment instead of repeating'
inventory=json.loads((OUT/'environment-differences.json').read_text())['environments']['qa18445']
paths=inventory['source_differences_from_active']
assert len(paths)==25
manifest=json.loads((ROOT/'outputs/investmoz-staff-preparation-20261012/abertura-workflow-2e2f16c83483/manifesto-final.json').read_text())
build=[r['path'] for r in manifest['compiled_resources']]
env=QA/'.env.stability-consumers';env_sha=sha(env)
active_baseline={str(p.relative_to(ROOT)):sha(p) for folder in ['app','config','routes','resources'] for p in (ROOT/folder).rglob('*') if p.is_file()}
recovery=PRIVATE/('audit-qa-code-recovery-'+datetime.now(timezone.utc).strftime('%Y%m%d_%H%M%S'));recovery.mkdir()
before={}
with zipfile.ZipFile(recovery/'source-build-before.zip','w',compression=zipfile.ZIP_STORED) as archive:
for relative in set(paths+[p.relative_to(QA).as_posix() for p in (QA/'public/build').rglob('*') if p.is_file()]):
p=QA/relative
if p.is_file():before[relative]=sha(p);archive.write(p,relative)
with zipfile.ZipFile(recovery/'source-build-before.zip') as archive:
for name,digest in before.items():assert hashlib.sha256(archive.read(name)).hexdigest()==digest
ordered=[p for p in build if p!='public/build/manifest.json']+paths+['public/build/manifest.json']
changed=[]
for relative in ordered:
src=ROOT/relative;dest=QA/relative
assert dest.resolve().is_relative_to(QA.resolve()) and src.is_file()
if dest.is_file() and sha(dest)==sha(src):continue
dest.parent.mkdir(parents=True,exist_ok=True);tmp=dest.with_name(dest.name+'.audit-code-new');assert not tmp.exists()
tmp.write_bytes(src.read_bytes());os.replace(tmp,dest);changed.append(relative)
for relative in paths+build:assert sha(QA/relative)==sha(ROOT/relative)
assert sha(env)==env_sha
for path,digest in active_baseline.items():assert sha(ROOT/path)==digest
proof={'at':datetime.now(timezone.utc).isoformat(),'result':'QA_aligned','source':str(QA),'target':state['identity'],'URL':'https://portal-investidor.test:18445','source_paths_aligned':paths,'compiled_resources':len(build),'changed_files':changed,'previous_QA_source_and_build_preserved':str(recovery),'configuration_key_cookie_data_unchanged':True,'active_files_unchanged':True,'new_product_implementation':False,'database_writes':0,'interface_coverage':'Connector unavailable; previous valid proofs reused, current criteria pending browser where affected'}
(OUT/'qa-code-alignment.json').write_text(json.dumps(proof,indent=2),encoding='utf-8')
print(json.dumps({k:proof[k] for k in ['result','target','URL','compiled_resources','active_files_unchanged','new_product_implementation','database_writes']}))