52 lines
6.3 KiB
Python
52 lines
6.3 KiB
Python
from pathlib import Path
|
|
import json,hashlib,zipfile,datetime
|
|
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
|
|
load=lambda n:json.loads((out/n).read_text('utf-8'))
|
|
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
|
write=lambda n,d:(out/n).write_text(json.dumps(d,ensure_ascii=False,indent=2)+'\n','utf-8')
|
|
baseline=load('BASELINE-FICHEIROS.json');changes=[]
|
|
for f in baseline['files']:
|
|
p=root/f['path']
|
|
if not p.is_file() or sha(p)!=f['sha256']:changes.append(f['path'])
|
|
assert not changes
|
|
write('PRESERVACAO-FICHEIROS.json',{'date':'2026-10-16','protected_files':len(baseline['files']),'changed':changes,'active_database_connections':0,'active_sources_and_build_unchanged':True,'deployed_source_count':11,'deployed_build_count':161,'baseline_sha256':sha(out/'BASELINE-FICHEIROS.json'),'scope':'File comparison only; no active DB inspected; QA reference preservation is separate','functional_tests_repeated':0,'implementation_started':False})
|
|
qa=load('ESTADO-QA-READONLY.json')['targets']['restored_destination']['tables'];bysector={r['sector_id']:r for r in qa['economic_activities']['rows']}
|
|
correspondences=[]
|
|
for s in sorted(qa['sectors']['rows'],key=lambda r:r['id']):
|
|
a=bysector.get(s['id'])
|
|
correspondences.append({'sector_id':s['id'],'slug':s['slug'],'original_name':s['name'],'existing_activity_id':a['id'] if a else None,'existing_activity_code':a['code'] if a else None,'basis':'existing explicit sector_id FK' if a else 'no explicit economic_activities sector_id relation in restored clone','official_CAE_equivalence':None,'updates_executed':False})
|
|
write('CORRESPONDENCIAS.json',{'status':'existing links inventoried, proposed bounded branch not yet implemented','sectors':correspondences,'proposed_CAE_branch':load('LOTE-PROPOSTO.json')['activities'],'inferences_by_name':0,'master_merges':0,'new_real_classifications':0})
|
|
inventory=load('INVENTARIO-ACERVO.json')
|
|
write('INVENTARIO-RESUMO.json',{'date':'2026-10-16','corpus_inventory_reused':inventory['corpus_inventory_reused'],'current_instruction_attachments_count':len(inventory['current_instruction_attachments']),'prior_inventories':inventory['historical_inventories_including_embedded_resources'],'selected_exemplars':inventory['sources_selected'],'embedded_in_selected_DOCX':inventory['selected_DOCX_embedded'],'full_inventory_local_sha256':sha(out/'INVENTARIO-ACERVO.json'),'selected_sources_extraction_sha256':sha(out/'FONTES-EXTRAIDAS.json'),'note':'Originals and full local inventory remain private; package contains only the bounded planning/proof records.'})
|
|
sources=load('FONTES-EXTRAIDAS.json')['selection'];citations=[]
|
|
for s in sources:
|
|
item={'source_name':Path(s['path']).name,'source_path':s['path'],'sha256':s['sha256'],'bytes':s['bytes'],'provenance_revalidation':False,'new_publication_authorization_inferred':False}
|
|
if 'sheets' in s:item['cited_cells']='CAE: header A1:F1; A39:F39, A57:F57, A124:F124, A238:F238, A1122:F1122'
|
|
elif 'Implementação da CAE' in item['source_name']:item['paragraphs']=[p for p in s['paragraphs'] if p['paragraph'] in [3,4,5,6,7,8,9,10,11,12]]
|
|
elif 'upgrade do portal' in item['source_name']:item['paragraphs']=[p for p in s['paragraphs'] if p['paragraph'] in [534,535,538,539,542,543,631]]
|
|
elif item['source_name']=='agronegócio 1.docx':item['paragraphs']=[p for p in s['paragraphs'] if p['paragraph']==1]
|
|
elif 'Corredores de Desenvolvimento' in item['source_name']:item['paragraphs']=[p for p in s['paragraphs'] if p['paragraph'] in [4,10,23,29,39]]
|
|
else:item['use']='Context read, not selected as legal rule or source of automatic business relations'
|
|
citations.append(item)
|
|
write('CITACOES-LOTE.json',citations)
|
|
lot=load('LOTE-PROPOSTO.json');assert len(lot['activities'])+len(lot['chain_stages'])+len(lot['chain_links'])+1==15
|
|
assert lot['estimate_hours']['total']==[sum(v[i] for k,v in lot['estimate_hours'].items() if k!='total') for i in [0,1]]
|
|
assert all(x['after_sha256'] is None for x in lot['prospective_files'])
|
|
assert not any((root/x['path']).exists() for x in lot['prospective_files'] if not x['exists'])
|
|
maptext=(out/'MAPA-LOTE-MINIMO.md').read_text('utf-8')
|
|
assert '\ufffd' not in maptext and 'Ã' not in maptext and 'â‚' not in maptext
|
|
names=['MAPA-LOTE-MINIMO.md','LOTE-PROPOSTO.json','FONTES-E-DELTA-PREVISTO.json','CORRESPONDENCIAS.json','CAE-RESUMO.json','CITACOES-LOTE.json','INVENTARIO-RESUMO.json','ESTADO-QA-READONLY.json','DEPENDENCIAS-QA-READONLY.json','PRESERVACAO-REFERENCIAS-QA.json','PRESERVACAO-FICHEIROS.json','ATUALIZACAO-MESMA-MATRIZ.json']
|
|
items=[{'path':n,'bytes':(out/n).stat().st_size,'sha256':sha(out/n)} for n in names]
|
|
write('INTEGRIDADE-CONTEUDO.json',{'package_type':'planning only, no deployable sources/migrations/imports','date':'2026-10-16','files':items,'all_accepted_statuses_preserved':True})
|
|
archive=root/'outputs/investmoz-referencias-economicas-mapa-20261016.zip'
|
|
assert not archive.exists()
|
|
with zipfile.ZipFile(archive,'w',compression=zipfile.ZIP_DEFLATED) as z:
|
|
for n in names+['INTEGRIDADE-CONTEUDO.json']:z.write(out/n,n)
|
|
with zipfile.ZipFile(archive) as z:
|
|
assert z.testzip() is None
|
|
assert sorted(z.namelist())==sorted(names+['INTEGRIDADE-CONTEUDO.json'])
|
|
for item in items:assert hashlib.sha256(z.read(item['path'])).hexdigest()==item['sha256']
|
|
receipt={'date':'2026-10-16','scope':'Pre-implementation map, QA only; not an activation proposal or completed QA acceptance','map':items[0],'files':items,'zip':{'path':archive.relative_to(root).as_posix(),'bytes':archive.stat().st_size,'sha256':sha(archive),'entries':len(names)+1,'all_entry_hashes_verified':True,'CRC_verified':True},'preservation':{'protected_active_files':len(baseline['files']),'changed_active_files':0,'active_DB_connections':0,'QA_reference_tables_unchanged':True,'accepted_functional_tests_repeated':0,'same_matrix_rows':3402,'same_matrix_updated_rows':7,'unrelated_raw_rows_preserved':3395,'all_states_preserved':True},'pending':['Tempo editorial scope/convention decisions detailed in map','Implementation and all new directed proofs','Positive chain cases in both consumers'],'verification':'Local archive opened; all entries compared to SHA256 inventory. No claim of Tempo ZIP inspection.'}
|
|
write('RECIBO-INTEGRIDADE.json',receipt)
|
|
print(json.dumps({'zip':receipt['zip'],'map':receipt['map'],'receipt_sha256':sha(out/'RECIBO-INTEGRIDADE.json'),'protected_files':len(baseline['files']),'same_matrix':7},ensure_ascii=True))
|