#!/usr/bin/env python3 """Run the VS Code client acceptance in a disposable extension host.""" import argparse import os from pathlib import Path import shutil import subprocess import tempfile ROOT = Path(__file__).resolve().parents[2] CLIENT = ROOT / "clients/vscode" def check(condition, detail): if not condition: raise ValueError(detail) def application(code): """The Nix `code` wrapper starts a detached CLI; the app binary runs tests in-process.""" resolved = code.resolve(strict=True) candidate = resolved.parent.parent / "lib/vscode/code" return candidate if candidate.is_file() else resolved def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--code", default=shutil.which("code"), help="VS Code launcher (default: code on PATH)") parser.add_argument("--server", required=True, type=Path) parser.add_argument("--adapter", required=True, type=Path) parser.add_argument("--trace", required=True, type=Path) parser.add_argument("--timeout", type=float, default=240) options = parser.parse_args() check(options.code, "code is not on PATH") check((CLIENT / "node_modules").is_dir(), "run `npm install` in clients/vscode once as a development step") subprocess.run(["npm", "run", "compile"], cwd=CLIENT, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, timeout=120) tests = CLIENT / "out/test/run.js" check(tests.is_file(), "the extension test entry was not compiled") executable = application(Path(options.code)) server = options.server.resolve(strict=True) adapter = options.adapter.resolve(strict=True) trace = options.trace.resolve(strict=True) with tempfile.TemporaryDirectory(prefix="vls-vscode-client-") as temp: work = Path(temp) workspace = work / "workspace" workspace.mkdir() (workspace / "unit.cpp").write_text("int value = 17;\nint read() { return value; }\n", encoding="utf-8") command = [ str(executable), f"--extensionDevelopmentPath={CLIENT}", f"--extensionTestsPath={tests}", f"--user-data-dir={work / 'user'}", f"--extensions-dir={work / 'extensions'}", "--no-sandbox", "--disable-gpu", "--disable-workspace-trust", "--skip-welcome", "--skip-release-notes", str(workspace), ] environment = {**os.environ, "VLS_SERVER": str(server), "VLS_DAP": str(adapter), "VLS_TRACE": str(trace)} result = subprocess.run(command, env=environment, capture_output=True, text=True, timeout=options.timeout) output = result.stdout + result.stderr if result.returncode != 0 or "VSCODE_CLIENT_PASS" not in output: print(output[-5000:]) raise SystemExit(f"VS Code client acceptance failed (exit {result.returncode})") print("VS Code client passed: LSP status, replay session, timeline, source, stale " "rejection and transactional rename") if __name__ == "__main__": try: main() except (OSError, ValueError, subprocess.SubprocessError) as exc: raise SystemExit(f"verify-vscode-client: {exc}")