"""Sequential acceptance checks, reviewer cases, research and reproducible clean startup.""" import json import os import subprocess import sys import time from pathlib import Path from dotenv import dotenv_values ROOT=Path(__file__).resolve().parents[1] EVIDENCE=ROOT/'evidence' EVIDENCE.mkdir(exist_ok=True) python=sys.executable port=os.environ.get('APP_PORT') or dotenv_values(ROOT/'.env').get('APP_PORT') or '8080' base_url=os.environ.get('BASE_URL') or 'http://127.0.0.1:'+str(port) api=subprocess.check_output(['docker','compose','ps','-q','api'],cwd=ROOT,text=True).split()[0] checks=[ ('course-files',[python,'scripts/check-course-files.py'],None), ('quality',[python,'-m','ruff','check','src'],None), ('format',[python,'-m','ruff','format','--check','src'],None), ('structure',[python,'scripts/check_contract.py'],None), ('openapi',[python,'scripts/validate_openapi.py'],None), ('request-deadline',['docker','exec','-i',api,'python'],'tests/request_deadline.py'), ('readiness-budget',['docker','exec','-i',api,'python'],'tests/readiness.py'), ('public-smoke',[python,'tests/smoke.py'],None), ('attachments',[python,'tests/attachments.py'],None), ('idempotency',[python,'tests/idempotency.py'],None), ('reviewer-cases',[python,'tests/lab4_review.py'],None), ('reconciliation',['scripts/test-reconciliation.sh'],None), ('upload-memory',['scripts/test-upload-memory.sh'],None), ('uploader-failover',[python,'tests/attachment_failover.py'],None), ('persistence-proof',[python,'scripts/test-persistence.py','--action-script','scripts/restart.sh','--base-url',base_url],None), ('clean-start',[python,'scripts/test-clean-lab4.py'],None), ] summary=[] for name,command,input_file in checks: print('Проверка: '+name,flush=True) started=time.perf_counter() source=open(ROOT/input_file,'rb') if input_file else None try: with (EVIDENCE/('lab4-final-'+name+'.txt')).open('wb') as output: result=subprocess.run(command,cwd=ROOT,env={**os.environ,'PYTHON':python,'BASE_URL':base_url},stdin=source, stdout=output,stderr=subprocess.STDOUT,timeout=1000 if name=='clean-start' else 180) summary.append({'check':name,'exit_code':result.returncode,'seconds':round(time.perf_counter()-started,3), 'evidence':'evidence/lab4-final-'+name+'.txt'}) if result.returncode: raise RuntimeError('Не прошла проверка '+name+'; см. '+summary[-1]['evidence']) finally: if source:source.close() (EVIDENCE/'lab4-final-summary.json').write_text(json.dumps({'result':'PASS','checks':summary},ensure_ascii=False,indent=2)+'\n') print('PASS: все итоговые проверки лабораторной 4',flush=True)