#!/usr/bin/env python3 """Supply local batch fixtures, run all configurations, and publish the outcome.""" import hashlib import json import os from pathlib import Path import signal import subprocess import sys ROOT = Path(__file__).resolve().parents[2] BASE = ROOT / "tests/golden/WBV2-P1424-001" def execute(command, env=None): process = subprocess.Popen(command, cwd=ROOT, env=env) try: return process.wait() finally: if process.poll() is None: process.terminate() try: process.wait(timeout=15) except subprocess.TimeoutExpired: process.kill() process.wait() def interrupted(signum, _frame): raise KeyboardInterrupt(f"Received signal {signum}") def main(): batch_path = ROOT / "tests/golden/WBV2-P1152-001/modifier-reader-batch-production.json" batch = json.loads(batch_path.read_text()) for name in batch["fixtures"]: path = ROOT / name if hashlib.sha256(path.read_bytes()).hexdigest() != batch["fixtureSha256"][name]: raise RuntimeError(f"Local batch fixture changed: {name}") env = {**{key: value for key, value in os.environ.items() if not key.startswith("WBV2_BATCH_")}, "WBV2_MODIFIER_BATCH_FIXTURES": json.dumps(batch["fixtures"]), "WBV2_MODIFIER_BATCH_TYPES": json.dumps(batch["expectedTypes"]), "WBV2_MODIFIER_BATCH_UNITS": json.dumps(batch["sourceUnits"]), "WBV2_MODIFIER_BATCH_TASK": "WBV2-P1424-001", "WBV2_MODIFIER_BATCH_PRODUCTION": "tests/golden/WBV2-P1424-001/full-smoke-modifier-batch-production.json"} latest = BASE / "full-smoke-latest.json" previous = latest.read_bytes() if latest.exists() else None code = execute([sys.executable, str(ROOT / "tools/web/run-wbv2-full-smoke.py"), *sys.argv[1:]], env) if not latest.exists() or latest.read_bytes() == previous: return code or 1 pointer = json.loads(latest.read_text()) report = ROOT / pointer["report"]["path"] recorded = execute([sys.executable, str(ROOT / "tools/web/record-wbv2-full-smoke.py"), str(report.parent)]) return recorded or code if __name__ == "__main__": signal.signal(signal.SIGTERM, interrupted) raise SystemExit(main())