88 lines
5.9 KiB
Python
88 lines
5.9 KiB
Python
from pathlib import Path
|
|
from datetime import datetime, timezone
|
|
from zipfile import ZipFile, ZIP_DEFLATED
|
|
from urllib.request import urlopen
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import shutil
|
|
import ssl
|
|
import subprocess
|
|
import sys
|
|
|
|
OUT = Path(__file__).resolve().parent
|
|
ROOT = OUT.parents[1]
|
|
QA = ROOT / 'storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742'
|
|
sha = lambda p: hashlib.sha256(p.read_bytes()).hexdigest()
|
|
reauth_build = '--reauth-20261014' in sys.argv
|
|
schema_build = '--schema-feedback-20261014' in sys.argv
|
|
condition_build = '--condition-state-20261014' in sys.argv
|
|
build_label = 'case32-schema-feedback-20261014' if schema_build else ('case32-reauth-20261014' if reauth_build else 'case32-feedback-20261013')
|
|
receipt_path = OUT / ('case32-schema-feedback-build-QA-20261014.json' if schema_build else ('case32-reauth-build-QA-20261014.json' if reauth_build else 'case32-feedback-build-QA-20261013.json'))
|
|
if condition_build:
|
|
build_label = 'case32-condition-state-20261014'
|
|
receipt_path = OUT / 'case32-C148-condition-state-build-QA-20261014.json'
|
|
assert not receipt_path.exists()
|
|
with urlopen('https://portal-investidor.test:18445/_qa/runtime', context=ssl.create_default_context(), timeout=20) as response:
|
|
runtime = json.load(response)
|
|
assert runtime['target']['database'] == 'stability_consumers_20261011_084534_test' and int(runtime['target']['port']) == 55441
|
|
source_files = ['app/Services/OpportunityCanonicalContract.php', 'resources/js/components/opportunity-canonical-fields.tsx', 'resources/js/components/opportunity-profile-actions.tsx'] if schema_build else ['resources/js/components/opportunity-profile-actions.tsx', 'resources/js/pages/management/opportunity-draft.tsx', 'resources/js/lib/profile-json.ts',
|
|
'app/Services/OpportunityProfileWorkflow.php', 'app/Http/Controllers/OpportunityManagementController.php'] if reauth_build else ['resources/js/components/opportunity-profile-actions.tsx', 'app/Http/Middleware/AuditProfileDecision.php']
|
|
if condition_build:
|
|
source_files = ['resources/js/components/opportunity-profile-actions.tsx']
|
|
active_before = {name: sha(ROOT / name) for name in source_files + ['public/build/manifest.json']}
|
|
base_zip = OUT / 'investmoz-B-posicoes-tecnicas-QA-revisao-20261013.zip'
|
|
assert sha(base_zip) == '5b3676a25555e140b783350eb9379a6911dcf1ef62bf0d67271ded5244d288dc'
|
|
build = QA / 'public/build'
|
|
prepared = QA / ('public/build-case32-schema-feedback-prepared-20261014' if schema_build else ('public/build-case32-reauth-prepared-20261014' if reauth_build else 'public/build-case32-feedback-prepared-20261013'))
|
|
if condition_build:
|
|
prepared = QA / 'public/build-case32-condition-state-prepared-20261014'
|
|
assert not prepared.exists()
|
|
backup = QA / ('storage/app/private/case32-schema-feedback-build-before-20261014.zip' if schema_build else ('storage/app/private/case32-reauth-build-before-20261014.zip' if reauth_build else 'storage/app/private/case32-feedback-build-before-20261013.zip'))
|
|
if condition_build:
|
|
backup = QA / 'storage/app/private/case32-condition-state-build-before-20261014.zip'
|
|
assert not backup.exists()
|
|
old_manifest = sha(build / 'manifest.json')
|
|
with ZipFile(backup, 'w', ZIP_DEFLATED) as archive:
|
|
for p in build.rglob('*'):
|
|
if p.is_file(): archive.write(p, p.relative_to(build).as_posix())
|
|
proof = {'at': datetime.now(timezone.utc).isoformat(), 'base_review': '396c691930bc',
|
|
'target': runtime['target'], 'scope': 'Observed workflow feedback failure only, QA',
|
|
'old_QA_manifest': old_manifest, 'private_backup_sha256': sha(backup),
|
|
'commands': [], 'active_changes': 0, 'visual_acceptance_complete': False,
|
|
'source_files': {name: sha(QA / name) for name in source_files},
|
|
'base_ZIP_preserved': True}
|
|
env = os.environ.copy()
|
|
env['STABILITY_QA_MODE'] = 'consumers'
|
|
env['INVESTMOZ_QA_BUILD'] = '0'
|
|
env['PATH'] = 'C:/laragon/bin/php/php-8.5.11-Win32-vs17-x64;C:/Program Files/nodejs;' + env.get('PATH', '')
|
|
try:
|
|
for name, args in [('types', ['types:check']), ('build', ['build', '--', '--outDir', str(prepared.relative_to(QA))])]:
|
|
print(json.dumps({'stage': name, 'QA_only': True}), flush=True)
|
|
result = subprocess.run(['C:/Program Files/nodejs/npm.cmd', 'run', *args], cwd=QA, env=env,
|
|
capture_output=True, text=True, encoding='utf-8', errors='replace')
|
|
(OUT / f'{build_label}-{name}-QA.log').write_text(result.stdout + result.stderr, encoding='utf-8')
|
|
proof['commands'].append({'script': name, 'exit_code': result.returncode})
|
|
assert result.returncode == 0, f'{name} failed; see restricted local log'
|
|
assert (prepared / 'manifest.json').exists() and sha(build / 'manifest.json') == old_manifest
|
|
for p in prepared.rglob('*'):
|
|
if not p.is_file() or p.name == 'manifest.json': continue
|
|
destination = build / p.relative_to(prepared)
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
if destination.exists(): assert sha(destination) == sha(p), 'Immutable chunk conflict'
|
|
else: shutil.copyfile(p, destination)
|
|
temporary = build / 'manifest.case32-feedback.pending'
|
|
shutil.copyfile(prepared / 'manifest.json', temporary)
|
|
os.replace(temporary, build / 'manifest.json')
|
|
assert active_before == {name: sha(ROOT / name) for name in active_before}
|
|
proof.update(result='passed', new_QA_manifest=sha(build / 'manifest.json'),
|
|
prepared_assets=sum(p.is_file() for p in prepared.rglob('*')),
|
|
old_assets_preserved=True, atomic_QA_manifest_switch=True,
|
|
active_source_and_manifest_unchanged=True,
|
|
prepared_build=prepared.relative_to(QA).as_posix())
|
|
except Exception as error:
|
|
proof.update(result='stopped', error_type=type(error).__name__)
|
|
receipt_path.write_text(json.dumps(proof, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
print(json.dumps(proof, ensure_ascii=False), flush=True)
|
|
raise SystemExit(0 if proof['result'] == 'passed' else 1)
|