from pathlib import Path from hashlib import sha256 from datetime import datetime,timezone import json,re ROOT=Path(__file__).resolve().parents[2] OUT=Path(__file__).resolve().parent QA=ROOT/'storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742' scope=json.loads((OUT/'option-B-scope-frozen.json').read_text(encoding='utf-8')) proof=json.loads((OUT/'option-B-preflight.json').read_text(encoding='utf-8')) assert proof['target']=={'database':'stability_consumers_20261011_084534_test','port':55441} assert proof['scope_sha256']==scope['acceptance_scope_sha256'] assert proof['desk_installed'] and proof['path_columns_present']==[True,True] assert '2026_10_09_190000_prepare_investor_path' in proof['installed_migrations'] assert not proof['gates']['notifications'] and not proof['gates']['external_CRM'] assert not proof['path_enabled_config'], 'Already enabled: inspect rather than repeat preparation.' path=QA/'.env.stability-consumers' assert path.resolve().parent==QA.resolve() original=path.read_bytes() matches=list(re.finditer(rb'^INVESTOR_PATH_ENABLED=([^\r\n]*)\r?$',original,re.M)) assert len(matches)<=1 if matches: m=matches[0] assert m.group(1).strip().lower() in [b'false',b'0',b'"false"',b"'false'"] updated=original[:m.start()]+b'INVESTOR_PATH_ENABLED=true'+original[m.end():] else: updated=original+(b'' if original.endswith(b'\n') else b'\r\n')+b'INVESTOR_PATH_ENABLED=true\r\n' backup=QA/'storage/app/private/option-B-env-before-20261013.bin' assert not backup.exists() backup.write_bytes(original) active_env=ROOT/'.env' active_before=sha256(active_env.read_bytes()).hexdigest() with path.open('r+b') as handle: handle.write(updated);handle.truncate() assert active_before==sha256(active_env.read_bytes()).hexdigest() assert path.read_bytes()==updated result={'at':datetime.now(timezone.utc).isoformat(),'scope':'B','target':proof['target'], 'QA_source':str(QA),'changed_configuration_keys':['INVESTOR_PATH_ENABLED'], 'old_effective_value':False,'new_value':True,'repeated_installs':0, 'active_configuration_unchanged':True,'active_writes':0,'QA_schema_or_business_writes':0, 'notifications_CRM_AI_remain_disabled':True,'private_backup_preserved':True, 'before_configuration_sha256':sha256(original).hexdigest(),'after_configuration_sha256':sha256(updated).hexdigest(), 'reason':'190000 already installed with five-phase/nineteen-stage definition; QA flag was OFF.'} (OUT/'option-B-enable-path-QA.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n',encoding='utf-8') print(json.dumps({k:v for k,v in result.items() if k!='QA_source'}))