Files
Investidor-V2/outputs/investmoz-editorial-QA-20261018/finalize.py
T
nala cf003c8623
tests / ci (push) Canceled after 0s
versao nrgocios 4
2026-10-18 15:57:06 +02:00

36 lines
3.7 KiB
Python

from pathlib import Path
import json,hashlib,difflib,subprocess,zipfile,datetime
r=Path.cwd();o=Path(__file__).resolve().parent;q=Path('C:/Users/macbook/.config/investmoz/editorial-QA-20261018/source')
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
before=json.loads((o/'ATIVO-ANTES.json').read_text('utf8'))
assert all((r/n).exists() and sha(r/n)==v for n,v in before.items()),'Active source/build changed'
folders=['app','config','routes','database','resources']
delta=[];patch=[]
for folder in folders:
for p in sorted((q/folder).rglob('*')):
if not p.is_file():continue
n=p.relative_to(q).as_posix();old=before.get(n)
if old==sha(p):continue
# Generated TS routes/actions are artifacts of the same declared controllers, not separate feature edits.
delta.append({'path':n,'before':old,'after':sha(p),'new':old is None,'generated':n.startswith(('resources/js/actions/','resources/js/routes/'))})
if p.suffix in ['.php','.tsx','.ts']:
a=(r/n).read_text('utf8').splitlines(True) if old else []
patch.extend(difflib.unified_diff(a,p.read_text('utf8').splitlines(True),fromfile='a/'+n,tofile='b/'+n))
build={p.relative_to(q).as_posix():sha(p) for p in sorted((q/'public/build').rglob('*')) if p.is_file()}
revision=hashlib.sha256(json.dumps({'source':delta,'build':build},sort_keys=True).encode()).hexdigest();candidate='editorial-QA-'+revision[:12]
syntax=[]
for d in delta:
if d['path'].endswith('.php'):
x=subprocess.run(['C:/Users/macbook/.config/investmoz/php-8.5.11/php.exe','-l',str(q/d['path'])],capture_output=True,text=True);assert x.returncode==0,x.stdout+x.stderr;syntax.append(d['path'])
proofs={}
for name in ['PROVAS-HTTP-QA.json','PROVAS-DELTA-QA.json','PROVAS-PREENCHIMENTO-QA.json']:
data=json.loads((o/name).read_text('utf8'));assert all(c['resultado']=='observado' for c in data['checks']),name;proofs[name]={'checks':len(data['checks']),'sha256':sha(o/name)}
legacy=o/'PROVA-LEITOR-LEGADO-QA.json';blob=legacy.read_bytes();data=json.loads(blob.decode('utf16' if blob.startswith(b'\xff\xfe') else 'utf-8-sig'));assert data['result']=='observado';legacy.write_text(json.dumps(data,ensure_ascii=False,indent=2),'utf8')
manifest={'candidate':candidate,'revision_sha256':revision,'target':'QA only editorial_20261018_test:55441 / http://127.0.0.1:18548','sources':delta,'build':build,'migration':'2026_10_18_160000_add_portal_editorial_content','active_changes':0,'accepted_tests_repeated':False,'guarded_QA':True,'syntax_files_checked':syntax,'functional_proofs':proofs,'visual_upload':'not observed: extension requires Allow access to file URLs; no bypass','rollback':'Do not drop used JSONB or history; old UI hides editorial bodies. Preserve compatible public/editorial readers after use; no active deployment proposed by this QA receipt.'}
(o/'MANIFESTO-QA.json').write_text(json.dumps(manifest,ensure_ascii=False,indent=2),'utf8');(o/'DELTA.patch').write_text(''.join(patch),'utf8')
with zipfile.ZipFile(o/(candidate+'.zip'),'w',zipfile.ZIP_DEFLATED) as z:
for d in delta:z.write(q/d['path'],d['path'])
for n in build:z.write(q/n,n)
(o/'PRESERVACAO-ATIVO.json').write_text(json.dumps({'checked_at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'all_preexisting_sources_and_build_equal':True,'files_checked':len(before),'no_active_DB_connection_in_QA_boot':True,'no_active_migration_or_SQL':True,'active_changes':0,'scope':'source/build checks against before; QA bootstrap exact DB guard. No active DB functional audit or accepted tests replayed.'},indent=2),'utf8')
print(json.dumps({'candidate':candidate,'source_files':len(delta),'build_files':len(build),'new_source_files':sum(d['new'] for d in delta),'checks':sum(x['checks'] for x in proofs.values()),'active_preserved':True,'paths':[d['path'] for d in delta if not d['generated']]},ensure_ascii=True,indent=2))