#!/usr/bin/env python3 """Run one end-to-end realtime probe: the real Docs server (seeded with a generated document) and the production DocsModel in an XCTest process. run-e2e.py [KEY=VALUE ...] TestName is testEndToEndLocalTyping, testEndToEndRemoteUpdates or testEndToEndIdle. KEY=VALUE pairs become DOCS_RT_AUDIT_* environment variables (KEYS=40 CADENCE_MS=125 BURST=10 IDLE_S=40). Expects the Go test binary at $DOCS_RT_AUDIT_GOTEST (built with `go test -c ./internal/docs`) and a release test build of native/apple. Never touches user data. """ import os from pathlib import Path import signal import subprocess import sys import tempfile import time root = Path(__file__).resolve().parents[3] seed, test = sys.argv[1], sys.argv[2] extra = dict(arg.split("=", 1) for arg in sys.argv[3:]) gotest = os.environ.get("DOCS_RT_AUDIT_GOTEST", "/tmp/rt-audit/docs.test") with tempfile.TemporaryDirectory(prefix="docs-rt-e2e-", dir="/tmp") as tmp: scratch = Path(tmp) env = dict(os.environ, DOCS_RT_AUDIT_DIR=tmp, DOCS_RT_AUDIT_SEED=seed, TMPDIR="/tmp") for key, value in extra.items(): env["DOCS_RT_AUDIT_" + key] = value log = (scratch / "server.log").open("w") server = subprocess.Popen([gotest, "-test.run", "^TestNativeRealtimeAuditServer$", "-test.count=1", "-test.timeout=25m"], cwd=root / "internal/docs", env=env, stdout=log, stderr=subprocess.STDOUT, start_new_session=True) try: deadline = time.monotonic() + 120 while not (scratch / "connection.json").exists(): if server.poll() is not None: print((scratch / "server.log").read_text()[-4000:]) raise SystemExit("server exited") if time.monotonic() > deadline: raise SystemExit("server did not start") time.sleep(0.05) result = subprocess.run(["swift", "test", "-c", "release", "-Xswiftc", "-enable-testing", "--skip-build", "--package-path", str(root / "native/apple"), "--filter", "RealtimeAuditE2ETests/" + test], env=env, capture_output=True, text=True, timeout=1500) out = result.stdout + result.stderr for line in out.splitlines(): if line.startswith(("RTE2E", "RTAUDIT")) or ": error:" in line: print(line) if os.environ.get("DOCS_RT_AUDIT_KEEP"): keep = Path(os.environ["DOCS_RT_AUDIT_KEEP"]) keep.mkdir(parents=True, exist_ok=True) (keep / f"{Path(seed).stem}-{test}.requests.jsonl").write_text((scratch / "requests.jsonl").read_text()) (scratch / "done").touch() server.wait(timeout=20) raise SystemExit(result.returncode) finally: if server.poll() is None: os.killpg(server.pid, signal.SIGTERM) server.wait(timeout=10) log.close()