#!/usr/bin/env python3 """Сохранить только реально выполненные локальные проверки без запуска инфраструктуры.""" from datetime import datetime, timezone import json from pathlib import Path import shutil import subprocess import sys import time ROOT = Path(__file__).resolve().parents[1] def main(): out = ROOT / "evidence/local" out.mkdir(parents=True, exist_ok=True) checks = [ ("01_check", [sys.executable, "scripts/check_contract.py"]), ("02_openapi", [sys.executable, "scripts/validate_openapi.py"]), ("03_static_lab3", [sys.executable, "scripts/check_lab3.py"]), ("04_unit", [sys.executable, "-m", "pytest", "-q", "unit-tests", "-p", "no:cacheprovider"]), ("05_collection", [sys.executable, "-m", "pytest", "--collect-only", "-q", "-p", "no:cacheprovider"]), ("06_dependencies", [sys.executable, "-m", "pip", "check"]), ] manifest = [] for name, command in checks: started = time.monotonic() run = subprocess.run(command, cwd=ROOT, text=True, capture_output=True) (out / (name + ".txt")).write_text("$ " + " ".join(command) + "\n" + run.stdout + run.stderr + "\nexit_code=" + str(run.returncode) + "\n") manifest.append({"name": name, "command": command, "exit_code": run.returncode, "elapsed_seconds": round(time.monotonic() - started, 3)}) print(name, "PASS" if run.returncode == 0 else "FAIL", flush=True) (out / "manifest.json").write_text(json.dumps({"at_utc": datetime.now(timezone.utc).isoformat(), "python": sys.version.split()[0], "checks": manifest}, indent=2) + "\n") (out / "runtime_status.json").write_text(json.dumps({ "docker_cli_available": shutil.which("docker") is not None, "nginx_binary_available": shutil.which("nginx") is not None, "compose_nginx_postgresql_redis_experiments": "NOT_RUN", "reason": "This local checker does not run infrastructure; execute make lab3-evidence separately", "required_command_on_docker_host": "make lab3-evidence", }, indent=2) + "\n") return int(any(check["exit_code"] != 0 for check in manifest)) if __name__ == "__main__": sys.exit(main())