"""Register every invocation before launching pytest, including startup errors.""" import json import os from pathlib import Path import subprocess import sys root = Path(__file__).resolve().parents[3] / ".hermes/test-runtime/unified-execution/b04-control" root.mkdir(parents=True, exist_ok=True) nodes = sys.argv[2:] for node in nodes: path = root / (node + ".jsonl") records = path.read_text().splitlines() if path.exists() else [] assert len(records) < 5, "node budget exhausted" for node in nodes: path = root / (node + ".jsonl") used = len(path.read_text().splitlines()) if path.exists() else 0 with path.open("a") as out: out.write(json.dumps(dict(node=node, attempt=used + 1, phase=sys.argv[1])) + "\n") out.flush() os.fsync(out.fileno()) result = subprocess.run([sys.executable, "-m", "pytest", "-q", *[ "tests/test_host_registry_control.py::test_" + node for node in nodes ]], capture_output=True, text=True) print(result.stdout, end="") print(result.stderr, end="", file=sys.stderr) (root / (sys.argv[1] + "-" + "-".join(nodes) + ".txt")).write_text(result.stdout + result.stderr) sys.exit(result.returncode)