From adfdd5672cb3806bff7bf6c6228d7f5b854e0ce1 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Mon, 23 Nov 2026 12:43:38 -0800 Subject: [PATCH] test: cover Python 3.15 worker and bundled installs Extend both Python CI matrices through stable 3.15, exercise real worker RPC and isolated target installation, and add the pinned shared Python-version coverage action. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 85ef72cc-9e26-4bc4-b1c3-55256d9bef91 --- .github/workflows/check-python-versions.yml | 35 ++++++++++++ .github/workflows/pr-check.yml | 2 +- .github/workflows/push-check.yml | 2 +- CONTRIBUTING.md | 42 +++++++++++++++ noxfile.py | 1 + python/pyproject.toml | 2 + python/tests/fixtures/bundled_smoke.py | 30 +++++++++++ python/tests/fixtures/worker.py | 14 +++++ python/tests/fixtures/worker_tool.py | 23 ++++++++ python/tests/test_jsonrpc.py | 60 +++++++++++++++++++++ python/tests/test_package.py | 50 +++++++++++++++++ 11 files changed, 259 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/check-python-versions.yml create mode 100644 python/tests/fixtures/bundled_smoke.py create mode 100644 python/tests/fixtures/worker.py create mode 100644 python/tests/fixtures/worker_tool.py diff --git a/.github/workflows/check-python-versions.yml b/.github/workflows/check-python-versions.yml new file mode 100644 index 0000000..7bfa086 --- /dev/null +++ b/.github/workflows/check-python-versions.yml @@ -0,0 +1,35 @@ +name: Check Python Versions + +on: + pull_request: + branches: [main] + paths: + - '.github/workflows/check-python-versions.yml' + - '.github/workflows/pr-check.yml' + - '.github/workflows/push-check.yml' + schedule: + - cron: '0 12 * * 1' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: check-python-versions-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: false + +jobs: + check: + name: Python Version Coverage + if: github.repository_owner == 'microsoft' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: microsoft/vscode-python-ci/actions/check-python-versions@066d9e604a509ec5cbc11141280cdfb48d7700b7 + with: + files: | + - path: .github/workflows/pr-check.yml + key: python + - path: .github/workflows/push-check.yml + key: python + create-issue: 'false' diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index e9b4447..9920cc4 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -30,7 +30,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python: ["3.10", "3.11", "3.12", "3.13", "3.14"] + python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Use Python ${{ matrix.python }} diff --git a/.github/workflows/push-check.yml b/.github/workflows/push-check.yml index 8fe4ec3..a2fedd5 100644 --- a/.github/workflows/push-check.yml +++ b/.github/workflows/push-check.yml @@ -41,7 +41,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python: ["3.10", "3.11", "3.12", "3.13", "3.14"] + python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Use Python ${{ matrix.python }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d013861..62267b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,6 +22,48 @@ Use the [supported architecture and adoption guide](docs/supported-apis.md) when choosing extension-owned policy, shared public APIs or private implementation boundaries. Recommended facade adoption does not deprecate manual composition. +### Python compatibility coverage + +Both PR and push CI run `nox -s tests` on stable Python 3.10-3.15 on Ubuntu and +Windows. Each session installs `./python[dev]` into a fresh environment and logs +the resolved dependency versions with `pip list --format=freeze`. This tests +the resolver-selected, mutually compatible runtime and development dependencies +available for that interpreter at run time, not a locked or minimum-version +combination. Runtime requirements are `pygls>=1.1.0`, +`lsprotocol>=2023.0.0` and `packaging>=22.0`; transitive requirements also +participate in resolution. + +The suite includes a real subprocess worker using shared `JsonRpc`, +`run_message_loop` and `run_module`, with tool output, exception recovery and +process cleanup checks. It does not depend on Pylint or another external tool. +The target-install smoke builds a clean staged copy using +`pip install --target ... --no-deps --no-cache-dir --no-build-isolation --upgrade`. +The development extra supplies the build backend (`setuptools` and `wheel`); +the nox environment supplies runtime dependencies. An isolated (`python -I`) +subprocess verifies package and distribution metadata originate in the target +and executes the installed runner. Staging keeps build artifacts out of the +source package. `--no-build-isolation` avoids downloading build tools in this +smoke; consumers may retain pip's normal isolated-build behavior. + +These runs do not establish compatibility with every minimum dependency +combination, consumers' reviewed dependency locks/bundles, or consumer-provided +optional `debugpy`. Those require separate consumer validation. In particular, +shared-runtime coverage does not diagnose or fix downstream Pylint failures. +Older local Python 3.15 alphas are not stable-3.15 evidence, and CI does not pin +pytest to accommodate such alphas. Source-only, pinned-submodule consumption +and the consumer-owned dependency policy remain unchanged. + +The dedicated `Check Python Versions` workflow invokes the SHA-pinned +`microsoft/vscode-python-ci/actions/check-python-versions` action for both +matrices. It runs on relevant PR workflow changes, weekly on Mondays at 12:00 +UTC, and on manual dispatch. The action compares declared versions with the +newest Python 3 series that has a published release candidate; it does not run +tests or establish stable-interpreter support itself. This rollout uses +read-only, check-only mode: missing coverage is reported in the job summary, +not treated as a failing check, and no issues are created. Upstream issue mode +does not yet deduplicate issues. Release lookup or action/configuration errors +still fail the job. + ### Settings boundary tests The JSON corpus in `python/tests/fixtures/settings/` characterizes the existing diff --git a/noxfile.py b/noxfile.py index 0aa5e33..f7fd280 100644 --- a/noxfile.py +++ b/noxfile.py @@ -15,6 +15,7 @@ def install(session: nox.Session) -> None: def tests(session: nox.Session) -> None: """Run Python tests.""" session.install("-e", "./python[dev]") + session.run("python", "-m", "pip", "list", "--format=freeze") session.run("pytest", "python/tests", "-v") diff --git a/python/pyproject.toml b/python/pyproject.toml index d2353d9..afb7593 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -26,6 +26,8 @@ dev = [ "black", "isort", "flake8", + "setuptools>=68.0", + "wheel", ] [tool.setuptools.packages.find] diff --git a/python/tests/fixtures/bundled_smoke.py b/python/tests/fixtures/bundled_smoke.py new file mode 100644 index 0000000..22f1ca8 --- /dev/null +++ b/python/tests/fixtures/bundled_smoke.py @@ -0,0 +1,30 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +"""Executed with -I so environment paths and the checkout cannot supply the package.""" + +import importlib +import importlib.metadata +import json +import pathlib +import sys + +target = pathlib.Path(sys.argv[1]).resolve() +sys.path.insert(0, str(target)) +package = importlib.import_module("vscode_common_python_lsp") +assert pathlib.Path(package.__file__).resolve().is_relative_to(target) +distribution = importlib.metadata.distribution("vscode-python-tool-internal") +assert distribution.locate_file("").resolve() == target +assert distribution.version + +runner = importlib.import_module("vscode_common_python_lsp.runner") +assert pathlib.Path(runner.__file__).resolve().is_relative_to(target) +result = runner.run_module( + "json.tool", + ["json.tool"], + use_stdin=True, + cwd=str(target.parent), + source='{"message": "héllo 日本語"}', +) +assert json.loads(result.stdout) == {"message": "héllo 日本語"} +assert result.stderr == "" +assert result.exit_code in (None, 0) diff --git a/python/tests/fixtures/worker.py b/python/tests/fixtures/worker.py new file mode 100644 index 0000000..71e1526 --- /dev/null +++ b/python/tests/fixtures/worker.py @@ -0,0 +1,14 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +"""Test-only worker using the same shared runner primitives as consumers.""" + +import sys + +from vscode_common_python_lsp.jsonrpc import JsonRpc +from vscode_common_python_lsp.process_runner import run_message_loop +from vscode_common_python_lsp.runner import RunResult, run_module + +if __name__ == "__main__": + run_message_loop( + JsonRpc(sys.stdin.buffer, sys.stdout.buffer), run_module, RunResult + ) diff --git a/python/tests/fixtures/worker_tool.py b/python/tests/fixtures/worker_tool.py new file mode 100644 index 0000000..c000080 --- /dev/null +++ b/python/tests/fixtures/worker_tool.py @@ -0,0 +1,23 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +"""Deterministic tool for real worker transport tests.""" + +import json +import os +import sys + +if __name__ == "__main__": + if "--fail" in sys.argv: + raise RuntimeError("worker tool failure") + print( + json.dumps( + { + "pid": os.getpid(), + "executable": sys.executable, + "cwd": os.getcwd(), + "argv": sys.argv, + "source": sys.stdin.read(), + } + ) + ) + print("worker tool stderr", file=sys.stderr) diff --git a/python/tests/test_jsonrpc.py b/python/tests/test_jsonrpc.py index e8df729..15d07ce 100644 --- a/python/tests/test_jsonrpc.py +++ b/python/tests/test_jsonrpc.py @@ -3,12 +3,17 @@ """Tests for vscode_common_python_lsp.jsonrpc.""" import io +import json +import os +import pathlib +import sys import threading import unittest from unittest.mock import MagicMock, patch import pytest +from vscode_common_python_lsp import jsonrpc from vscode_common_python_lsp.jsonrpc import ( CONTENT_LENGTH, JsonRpc, @@ -19,6 +24,61 @@ ) +def test_real_worker_roundtrip_exception_recovery_and_cleanup(tmp_path): + """Execute a tool in a real worker, including recovery after a failed request.""" + python_root = pathlib.Path(__file__).resolve().parents[1] + worker = pathlib.Path(__file__).parent / "fixtures" / "worker.py" + workspace = str(tmp_path) + cwd = tmp_path / "workspace café" + cwd.mkdir() + + def run_tool(*args): + return run_over_json_rpc( + workspace, + [sys.executable], + "worker_tool", + ["worker_tool", *args], + True, + str(cwd), + str(worker), + source="héllo 日本語\n", + env={"PYTHONPATH": str(python_root)}, + timeout=20, + ) + + process = None + try: + result = run_tool("--argument", "café") + process = jsonrpc._process_manager._processes[workspace] + payload = json.loads(result.stdout) + worker_pid = payload.pop("pid") + assert worker_pid != os.getpid() + assert payload == { + "executable": sys.executable, + "cwd": str(cwd), + "argv": ["worker_tool", "--argument", "café"], + "source": "héllo 日本語\n", + } + assert result.stderr == "worker tool stderr\n" + assert result.exception is None + + failure = run_tool("--fail") + assert failure.stdout == "" + assert failure.stderr == "" + assert "RuntimeError: worker tool failure" in failure.exception + + recovered = run_tool("--recovered") + assert json.loads(recovered.stdout)["pid"] == worker_pid + assert recovered.exception is None + finally: + jsonrpc._process_manager.stop_process(workspace) + + assert process.poll() is not None + assert process.stdin.closed and process.stdout.closed + with pytest.raises(StreamClosedException): + jsonrpc._process_manager.get_json_rpc(workspace) + + class TestJsonRpcReadWrite(unittest.TestCase): """Tests for JsonRpc read/write round-trip.""" diff --git a/python/tests/test_package.py b/python/tests/test_package.py index 6fd3dc1..849ce17 100644 --- a/python/tests/test_package.py +++ b/python/tests/test_package.py @@ -1,9 +1,59 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +import pathlib +import shutil +import subprocess +import sys + import vscode_common_python_lsp def test_package_importable(): """Verify the package is importable.""" assert hasattr(vscode_common_python_lsp, "classify_python_file") + + +def test_noneditable_target_install(tmp_path): + """Build from clean sources and execute the installed target, not this checkout.""" + python_root = pathlib.Path(__file__).resolve().parents[1] + source = tmp_path / "source" + source.mkdir() + for name in ("pyproject.toml", "README.md"): + shutil.copy2(python_root / name, source / name) + shutil.copytree( + python_root / "vscode_common_python_lsp", + source / "vscode_common_python_lsp", + ignore=shutil.ignore_patterns("__pycache__", "*.pyc"), + ) + target = tmp_path / "bundled" / "libs" + subprocess.run( + [ + sys.executable, + "-m", + "pip", + "--disable-pip-version-check", + "install", + "--target", + str(target), + "--no-deps", + "--no-cache-dir", + "--no-build-isolation", + "--upgrade", + str(source), + ], + cwd=tmp_path, + check=True, + timeout=120, + ) + subprocess.run( + [ + sys.executable, + "-I", + str(pathlib.Path(__file__).parent / "fixtures" / "bundled_smoke.py"), + str(target), + ], + cwd=tmp_path, + check=True, + timeout=20, + )