Files
mtusi2026lab6/student-tests/review_checks.py
T
2026-11-06 11:12:38 +03:00

23 lines
1.6 KiB
Python

"""Repeat short review checks; experiments are separate and intentionally disruptive."""
from datetime import datetime, timezone
import json
from pathlib import Path
import subprocess
ROOT=Path(__file__).resolve().parents[1]
checks=[['make','check'],['make','validate','PYTHON=.venv/bin/python'],
['docker','compose','config','--quiet'],
['docker','run','--rm','-v',f'{ROOT}:/workspace:ro','--entrypoint','promtool','prom/prometheus:v3.2.1','test','rules',
'/workspace/student-tests/alerts.test.yaml','/workspace/student-tests/burn_rules.test.yaml','/workspace/student-tests/telemetry_alerts.test.yaml'],
['make','test'],['python3','student-tests/check_dashboard.py']]
results=[]
for command in checks:
proc=subprocess.run(command,cwd=ROOT,capture_output=True,text=True,timeout=180)
results.append({'command':command,'exit_code':proc.returncode,'output':proc.stdout+proc.stderr})
for filename in ('telemetry_unit.py','pipeline_critical.py','slo_commit_integration.py'):
command=['docker','compose','exec','-T','api-a','/app/.venv/bin/python','-']
proc=subprocess.run(command,input=(ROOT/'student-tests'/filename).read_text(),cwd=ROOT,capture_output=True,text=True,timeout=60)
results.append({'command':command,'stdin':f'student-tests/{filename}','exit_code':proc.returncode,'output':proc.stdout+proc.stderr})
(ROOT/'evidence/review-checks.json').write_text(json.dumps({'utc':datetime.now(timezone.utc).isoformat(),'checks':results},ensure_ascii=False,indent=2)+'\n')
for r in results:print('PASS' if r['exit_code']==0 else 'FAIL',r.get('stdin',r['command']))
raise SystemExit(any(r['exit_code'] for r in results))