"""Проверка итога приемочного прогона: priemka_check.py. Конвейер не гонит. Коды: 0 годен · 1 не годен (причина в stdout).""" from __future__ import annotations import glob import json import os import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] READY = "ГОТОВ К ПОДАЧЕ" def pribory(copy: Path, docs: list[dict]) -> dict[str, int]: """Три прибора на тех же файлах; код 0 везде - годно.""" def run(script: str, *args: str) -> int: return subprocess.run([sys.executable, str(ROOT / "scripts" / script), *args], stdin=subprocess.DEVNULL, capture_output=True).returncode codes = {"document_guard": 0, "verdict_check": 0, "final_document": 0} for d in docs: codes["final_document"] |= run("final_document.py", str(copy), "--doc", Path(d["draft"]).name) codes["document_guard"] |= run("document_guard.py", str(copy / d["docx"]), "--md", str(copy / d["md"])) codes["verdict_check"] |= run("verdict.py", str(copy / d["draft"]), "--check") return codes def find_report(local: Path) -> Path | None: case = json.loads(local.read_text(encoding="utf-8"))["case"].rstrip("/") found = sorted(glob.glob(glob.escape(case) + "-priemka-*/.agent/next/priemka.json")) return Path(found[-1]) if found else None def check(local: Path) -> list[str]: report = find_report(local) if report is None: return ["нет priemka.json: приемочный прогон не запускали"] data = json.loads(report.read_text(encoding="utf-8")) limit = json.loads(local.read_text(encoding="utf-8"))["limit_s"] problems = [] if data.get("verdikt") != READY: problems.append(f"вердикт не «{READY}»: {data.get('verdikt')}") if not isinstance(data.get("sekundy"), (int, float)) or data["sekundy"] > limit: problems.append(f"время {data.get('sekundy')} с больше предела {limit} с") copy = report.parents[2] docs = data.get("dokumenty") or [] if not docs: problems.append("в итоге нет документов") bad = {k: v for k, v in pribory(copy, docs).items() if v} if bad: problems.append(f"приборы красные: {bad}") return problems def main() -> int: local = Path(os.environ.get("THEMIZ_PRIEMKA_LOCAL", ROOT / "queue" / "priemka.local")) if not local.is_file(): print(f"нет {local.name}: нечего проверять") return 1 problems = check(local) print("\n".join(problems) or "приемка годна") return 1 if problems else 0 if __name__ == "__main__": raise SystemExit(main())