From 1c1afeb50934b2445f5cae6eef0f0e1b40d60ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Neo=20=E5=AD=AB?= Date: Tue, 4 Aug 2026 17:42:51 +0800 Subject: [PATCH] fix(tests): the packaging guard was inert on Python 3.10, the declared minimum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A second test sweep ran the layers the first one had not: the 8 iac-cdk stack tests (CI only, never run locally — all pass via `npx ts-node`), terraform fmt/validate (clean), the 4 specialists' A2A entrypoints (all execute offline), and the suite on Python 3.10 as well as 3.13. 3.10 reported 3686 passed / 13 skipped against 3.13's 3693 / 6. Seven of the extra skips were `test_packaging.py` — the whole file's pyproject-reading half, because the module did `tomllib = None` on 3.10 and the fixture skipped: 3.10 5 passed, 7 skipped 3.13 12 passed `requires-python = ">=3.10"`, so those 7 were inert on the project's own floor version — including `test_registry_yaml_is_declared_as_package_data`, the INV-MCP-2 wheel guard added in round 20 for a defect that made every pip-installed MCP server fail open. CI's 3.11+ legs kept the guard honest, so nothing was actually unprotected, but a guard that evaporates on the minimum supported version is a guard with a hole documented in its own skip message. `tomli` is the standard 3.10 backport with an identical API, so the fallback is a two-line import and a marker-gated test dependency (`python_version<'3.11'`, so 3.11+ installs nothing extra). Both versions now report 3693 / 6 — identical coverage. Positive-controlled on 3.10 specifically: emptying `[tool.setuptools.package-data]` fails `test_registry_yaml_is_declared_as_package_data` there now, where before it skipped and the defect would have shipped. Also corrected two of my own slips while editing (JS `//` comments written into a Python file, caught immediately by reading the result back rather than by the linter). Verification: 3693 passed on 3.10 AND 3.13; 8/8 CDK stack tests; terraform fmt -check and validate clean; 4/4 specialists execute offline; ruff clean; both mypy gates clean; make ci green. --- pyproject.toml | 6 +++++- tests/test_packaging.py | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4f89956..9ecae01 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,11 @@ dependencies = ["boto3>=1.40.0", "botocore>=1.43.0", "pyyaml>=6.0"] # and coverage; pytest-randomly surfaces cross-file import-order coupling. Install # with `pip install -e '.[test]'` (mirrors the Makefile/CI invocation). [project.optional-dependencies] -test = ["pytest>=8.0", "hypothesis>=6.0", "pytest-randomly>=3.15", "coverage>=7.0", "mcp>=1.0", "anyio[trio]>=4.0", "pytest-anyio>=0.0.0"] +# `tomli` is the 3.10-only TOML reader (stdlib `tomllib` arrives in 3.11). Without it the +# packaging tripwire — which reads pyproject.toml as data — silently SKIPPED its whole +# file on 3.10, the project's own declared minimum, taking the INV-MCP-2 wheel guard with +# it. Marker-gated so 3.11+ does not install a redundant dependency. +test = ["pytest>=8.0", "hypothesis>=6.0", "pytest-randomly>=3.15", "coverage>=7.0", "mcp>=1.0", "anyio[trio]>=4.0", "pytest-anyio>=0.0.0", "tomli>=2.0; python_version<'3.11'"] mcp = ["mcp>=1.0"] [project.scripts] diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 1ee0738..cc18c6c 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -17,10 +17,21 @@ import pytest +# TOML reader. `tomllib` is stdlib from 3.11; on 3.10 — which `requires-python = ">=3.10"` +# declares as supported — the standard backport `tomli` provides the identical API. +# +# This used to be `tomllib = None` on 3.10, and the fixture skipped. The consequence was +# that EVERY test reading pyproject.toml — 7 of this file's 12, including the INV-MCP-2 +# packaging guard added in round 20 — was inert on the project's own minimum version. CI +# covers 3.11+ so the guard still had teeth there, but a guard that evaporates on the +# floor version is a guard with a documented hole in it. if sys.version_info >= (3, 11): import tomllib -else: # pragma: no cover — py3.10 fallback - tomllib = None +else: # pragma: no cover — py3.10 path, exercised in the 3.10 CI leg + try: + import tomli as tomllib # type: ignore[no-redef] + except ImportError: # pragma: no cover + tomllib = None # type: ignore[assignment] _REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PYPROJECT = os.path.join(_REPO_ROOT, "pyproject.toml")