"""Delegate e2e runs to wise-validator (sand-boxer + validate run).""" from __future__ import annotations import os import shutil import subprocess import sys from pathlib import Path DEPRECATION_MSG = ( "[e2e_framework] DEPRECATED: use `validate run ` (wise-validator) or " "`make e2e REPO=` from the-custodian. Provision is sand-boxer; validation is " "wise-validator. This module will be removed after one release cycle." ) def _resolve_host(host: str | None) -> str: for candidate in (host, os.environ.get("SANDBOXER_HOST"), os.environ.get("RAILIANCE01_HOST")): if candidate: return candidate return "" def run_via_validate( repo_path: Path, *, host: str | None = None, keep: bool = False, workstream_id: str | None = None, no_report: bool = False, ssh_user: str | None = None, ssh_key: str | None = None, ) -> int: """Invoke `validate run` and return its exit code.""" print(DEPRECATION_MSG, file=sys.stderr) validate_bin = os.environ.get("VALIDATE_BIN", "validate") if not shutil.which(validate_bin): print( f"ERROR: {validate_bin} not found on PATH. " "Install wise-validator: cd ~/wise-validator && make install", file=sys.stderr, ) return 1 sandboxer_bin = os.environ.get("SANDBOXER_BIN", "sandboxer") if not shutil.which(sandboxer_bin): print( f"ERROR: {sandboxer_bin} not found on PATH. " "Install sand-boxer: cd ~/sand-boxer && make install", file=sys.stderr, ) return 1 resolved_host = _resolve_host(host) if not resolved_host: print( "ERROR: sandbox host required. Set SANDBOXER_HOST, RAILIANCE01_HOST, or --host.", file=sys.stderr, ) return 1 env = os.environ.copy() env["SANDBOXER_HOST"] = resolved_host if ssh_user: env["SANDBOXER_SSH_USER"] = ssh_user if ssh_key: env["SANDBOXER_SSH_KEY"] = ssh_key cmd = [validate_bin, "run", str(repo_path), "--host", resolved_host] if keep: cmd.append("--keep") if workstream_id: cmd.extend(["--workstream-id", workstream_id]) if no_report: cmd.append("--no-report") result = subprocess.run(cmd, env=env) return result.returncode