From 447d25931b03e29d22bd81519ac705c11f84260b Mon Sep 17 00:00:00 2001 From: mehdikarimi55 <9496476+mehdikarimi55@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:14:08 +0330 Subject: [PATCH 1/3] test: pin the suite interpreter on PATH for parity script subprocesses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The parity tests' script variants resolve python3 -> python -> py -3 through the ambient PATH. Under `uv run pytest` the venv's bin directory is first on PATH, so the scripts see the suite interpreter (with PyYAML) and CI passes. Under the direct `.venv/bin/python -m pytest` invocation that AGENTS.md prescribes, an ambient python3 without PyYAML fails every composed-template test with "PyYAML is required" (11 failures on macOS). Prepend the running interpreter's own bin directory in parity_helpers.clean_env() so both invocations behave the same; tests that install their own shim prepend afterwards and keep precedence. Delegate test_check_prerequisites_python_parity's duplicate _clean_env() to the shared helper so the fix applies there too. Fixes #5359 AI disclosure: agent-authored commit — OpenCode running GLM 5.3 Flash (Z.ai), agent mode under human supervision by mehdikarimi55; root-cause analysis, code change, and test execution performed by the agent. --- tests/parity_helpers.py | 13 +++++++++++++ tests/test_check_prerequisites_python_parity.py | 14 ++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/parity_helpers.py b/tests/parity_helpers.py index 56bee0806b..cd11c11eff 100644 --- a/tests/parity_helpers.py +++ b/tests/parity_helpers.py @@ -89,6 +89,19 @@ def clean_env() -> dict[str, str]: # silently override the "unset" baseline for every other test. env.pop("SPECKIT_PYTHON_EXECUTABLE", None) env.pop("SPECKIT_PYTHON", None) + # The script variants resolve python3 -> python -> py -3 through PATH. + # Under `uv run` the venv's bin directory is already first on PATH, so + # the scripts see the interpreter the suite runs on, including its + # site-packages (PyYAML among them). A direct + # `.venv/bin/python -m pytest` — the invocation AGENTS.md prescribes — + # leaves PATH untouched, and an ambient python3 without PyYAML then + # fails every composed-template test with "PyYAML is required". + # Prepend the running interpreter's own directory so subprocesses see + # the same Python under either invocation. + env["PATH"] = ( + f"{Path(sys.executable).absolute().parent}" + f"{os.pathsep}{env.get('PATH', '')}" + ) return env diff --git a/tests/test_check_prerequisites_python_parity.py b/tests/test_check_prerequisites_python_parity.py index 56c5c0d4e7..dbe8752596 100644 --- a/tests/test_check_prerequisites_python_parity.py +++ b/tests/test_check_prerequisites_python_parity.py @@ -12,7 +12,11 @@ import pytest from tests.conftest import requires_bash -from tests.parity_helpers import install_composition_stack, run +from tests.parity_helpers import ( + clean_env, + install_composition_stack, + run, +) PROJECT_ROOT = Path(__file__).resolve().parent.parent COMMON_SH = PROJECT_ROOT / "scripts" / "bash" / "common.sh" @@ -56,11 +60,9 @@ def _write_feature_json( def _clean_env() -> dict[str, str]: - env = os.environ.copy() - for key in list(env): - if key.startswith("SPECIFY_"): - env.pop(key) - return env + # Delegate to the shared helper so the PATH fix that pins the suite's + # own interpreter (see parity_helpers.clean_env) applies here too. + return clean_env() def _git_init(repo: Path) -> None: From edfe98bdc380874048dded295d75b74551540940 Mon Sep 17 00:00:00 2001 From: mehdikarimi55 <9496476+mehdikarimi55@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:24:16 +0330 Subject: [PATCH 2/3] test: cover the python3 resolver's first candidate on Windows too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copilot review follow-up (#5361): a Windows venv ships python.exe but no python3.exe, so putting the venv's bin directory first on PATH cannot shadow an ambient python3 — the first name the script resolvers probe (command -v python3 succeeds and wins before the python fallback is tried). clean_env() now also prepends a cached python3 shim built with the existing make_python3_path_shim() helper (shell shim plus a .cmd for PowerShell), so parity subprocesses resolve the suite interpreter on every platform. AI disclosure: agent-authored commit — OpenCode running GLM 5.3 Flash (Z.ai), agent mode under human supervision by mehdikarimi55; fix drafted in response to the Copilot review finding, verified by rerunning the affected parity suites. --- tests/parity_helpers.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/parity_helpers.py b/tests/parity_helpers.py index cd11c11eff..5404e8d96b 100644 --- a/tests/parity_helpers.py +++ b/tests/parity_helpers.py @@ -8,6 +8,7 @@ import shutil import subprocess import sys +import tempfile from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parent.parent @@ -97,14 +98,37 @@ def clean_env() -> dict[str, str]: # leaves PATH untouched, and an ambient python3 without PyYAML then # fails every composed-template test with "PyYAML is required". # Prepend the running interpreter's own directory so subprocesses see - # the same Python under either invocation. + # the same Python under either invocation. A Windows venv ships + # ``python.exe`` but no ``python3.exe``, so the bin directory alone + # cannot shadow an ambient ``python3`` — the first name the script + # resolvers probe — and a cached ``python3`` shim (see + # :func:`make_python3_path_shim`, shell shim plus a ``.cmd`` for + # PowerShell) covers that first candidate on every platform. env["PATH"] = ( + f"{_python3_shim_dir()}{os.pathsep}" f"{Path(sys.executable).absolute().parent}" f"{os.pathsep}{env.get('PATH', '')}" ) return env +_PYTHON3_SHIM_DIR: Path | None = None + + +def _python3_shim_dir() -> Path: + """A cached directory whose ``python3`` execs the suite interpreter. + + Built once per pytest process with :func:`make_python3_path_shim`, which + deliberately does not resolve the interpreter so the venv's + ``site-packages`` (PyYAML among them) stay reachable. + """ + global _PYTHON3_SHIM_DIR + if _PYTHON3_SHIM_DIR is None: + _PYTHON3_SHIM_DIR = Path(tempfile.mkdtemp(prefix="spec-kit-parity-shim-")) + make_python3_path_shim(_PYTHON3_SHIM_DIR) + return _PYTHON3_SHIM_DIR + + def venv_python3_exe(venv_dir: Path) -> Path: """Path to the python3 executable of a venv created with ``--without-pip``.""" if os.name == "nt": From 2bbbfc8852edc9bdb565b829e3c503b711fd8516 Mon Sep 17 00:00:00 2001 From: mehdikarimi55 <9496476+mehdikarimi55@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:32:37 +0330 Subject: [PATCH 3/3] test: survive missing Git Bash when building the Windows python3 shim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copilot review follow-up (#5361): _bash_posix_path() shells out to bash on Windows to convert the interpreter path, and a Windows machine with Git Bash not on PATH raised FileNotFoundError from clean_env() itself, failing every parity test during environment setup — including the python and PowerShell variants that never invoke bash. Catch the OSError and fall through to the static /mnt/ form, which the existing returncode fallback already accepts; bash-invoked tests skip when bash is absent, so the converted form is only needed where it can be exec'd. AI disclosure: agent-authored commit — OpenCode running GLM 5.3 Flash (Z.ai), agent mode under human supervision by mehdikarimi55; fix for the review finding, verified locally with the parity suites and a simulated no-bash subprocess failure. --- tests/parity_helpers.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/parity_helpers.py b/tests/parity_helpers.py index 5404e8d96b..92339df7bc 100644 --- a/tests/parity_helpers.py +++ b/tests/parity_helpers.py @@ -171,19 +171,27 @@ def _bash_posix_path(path: Path) -> str: resolved = os.path.abspath(path) if os.name != "nt": return resolved - converted = subprocess.run( - [ - "bash", - "-lc", - 'command -v cygpath >/dev/null 2>&1 && cygpath -u "$1"', - "bash", - resolved, - ], - capture_output=True, - text=True, - timeout=30, - ) - if converted.returncode == 0 and converted.stdout.strip(): + try: + converted = subprocess.run( + [ + "bash", + "-lc", + 'command -v cygpath >/dev/null 2>&1 && cygpath -u "$1"', + "bash", + resolved, + ], + capture_output=True, + text=True, + timeout=30, + ) + except OSError: + # Bash is not on PATH (e.g. a Windows machine without Git-for-Windows + # in it). The converted form is only needed by bash-invoked tests, + # which skip when bash is unavailable, so fall through to the static + # /mnt/ form rather than failing environment setup for every parity + # test, including the ones that never invoke bash. + converted = None + if converted is not None and converted.returncode == 0 and converted.stdout.strip(): return converted.stdout.strip() drive = path.drive.rstrip(":").lower() posix = path.as_posix()