Skip to content

The agent that grows with you

fix: the CI replay starts python3/python and coreutils on native Windows

Teknium855a4b21aa6a
diff --git a/tests/ci/test_update_ci_routing.py b/tests/ci/test_update_ci_routing.py
index c8552da5cda..025f7e3ea57 100644
--- a/tests/ci/test_update_ci_routing.py
+++ b/tests/ci/test_update_ci_routing.py
@@ -509,6 +509,36 @@ def test_replay_uses_executed_gate_output(monkeypatch):
test_update_owner_change_dispatches_its_suites_end_to_end(path, ("desktop_updater",))
+_PROBE_STEP = {"run": r'''python3 -c 'import sys; print("py3=" + sys.executable)' >> "$GITHUB_OUTPUT"
+python -c 'import sys; print("py=" + sys.prefix)' >> "$GITHUB_OUTPUT"
+echo "tools=$(printf 'b\na\n' | sort | tr -d '\r' | paste -sd , -)$(find . -maxdepth 0)" >> "$GITHUB_OUTPUT"
+'''}
+
+
+def test_replay_starts_the_python_and_tools_hosted_steps_call():
+ """Every host (native Windows included) runs python3/python and the coreutils selection steps use."""
+ out = workflow_steps.outputs(_PROBE_STEP, {})
+ assert (out["py"], out["tools"]) == (sys.prefix, "a,b.")
+ assert subprocess.run([out["py3"], "-c", "import sys; print(sys.prefix)"], capture_output=True,
+ text=True, check=True, timeout=60).stdout.strip() == sys.prefix
+
+
+def test_replay_python3_is_the_replay_interpreter_when_its_dir_has_only_python(tmp_path):
+ """A Windows venv dir holds only ``python``: python3 must not fall through to a host interpreter."""
+ interpreter = tmp_path / "Scripts" / "python"
+ interpreter.parent.mkdir()
+ interpreter.symlink_to(os.path.realpath(sys.executable))
+ probe = ("import json, sys; from tests.ci import workflow_steps; "
+ "print(json.dumps([sys.executable, workflow_steps.outputs(json.loads(sys.argv[1]), {})]))")
+ env = {**os.environ, "PYTHONPATH": str(_REPO)}
+ result = subprocess.run([str(interpreter), "-c", probe, json.dumps(_PROBE_STEP)], cwd=_REPO, env=env,
+ capture_output=True, text=True, timeout=60)
+ assert result.returncode == 0, result.stderr
+ replay_python, out = json.loads(result.stdout)
+ assert out["py3"] == replay_python
+
+
@pytest.mark.parametrize("missing", ["fixture", "consumer", "readers", "listed"])
def test_shared_fixture_guard_rejects_phantom_graph(monkeypatch, tmp_path, missing):
fixture = "tests/fixtures/owned_corpus.json"
diff --git a/tests/ci/workflow_steps.py b/tests/ci/workflow_steps.py
index c099ae89539..549575facc5 100644
--- a/tests/ci/workflow_steps.py
+++ b/tests/ci/workflow_steps.py
@@ -13,6 +13,7 @@ import sys
import tempfile
from pathlib import Path
+from hermes_platform.resolver import LookupContext, locate_command
from tests.ci import _gha_expr as gha
@@ -36,6 +37,24 @@ def required(step: dict, ctx: dict) -> None:
assert not gha.truthy(gha.render(step.get("continue-on-error", False), ctx)), f"{label}: advisory"
+def _interpreter_dirs(root: Path) -> tuple[str, ...]:
+ """The replay interpreter's dir, plus shims for the names setup-python puts on PATH.
+
+ Steps call ``python3`` (Linux runners) or ``python`` (Windows runners); a
+ Windows venv only ships ``python.exe``, so a missing name would otherwise
+ hit an unrelated host interpreter on os.defpath, or none at all.
+ """
+ interpreter = Path(sys.executable).parent
+ shims = root / "bin"
+ shims.mkdir()
+ for name in ("python", "python3"):
+ if not locate_command(name, LookupContext(path=str(interpreter))).found:
+ shim = shims / name
+ shim.write_text('#!/bin/sh\nexec "$REPLAY_PYTHON" "$@"\n', encoding="utf-8")
+ shim.chmod(0o755)
+ return str(interpreter), str(shims)
+
+
def _run(step: dict, ctx: dict, cwd: Path | None = None, *, receipt: bool = False) -> tuple[dict, list]:
required(step, ctx)
assert step.get("shell", "bash") == "bash", "only safe Bash selection steps are replayed"
@@ -44,8 +63,9 @@ def _run(step: dict, ctx: dict, cwd: Path | None = None, *, receipt: bool = Fals
output, calls = root / "outputs", root / "calls"
output.touch()
calls.touch()
+ bash = locate_command("bash").command[0]
env = {
- "PATH": os.pathsep.join((str(Path(sys.executable).parent), os.defpath)),
+ "PATH": os.pathsep.join((*_interpreter_dirs(root), os.defpath, str(Path(bash).parent))),
"HOME": directory, "RUNNER_TEMP": directory, "GITHUB_OUTPUT": str(output),
"REPLAY_PYTHON": sys.executable, "REPLAY_CALLS": str(calls),
**{k: gha.to_string(gha.render(v, ctx)) for k, v in step.get("env", {}).items()},
@@ -53,7 +73,7 @@ def _run(step: dict, ctx: dict, cwd: Path | None = None, *, receipt: bool = Fals
script = root / "step.sh"
script.write_text((_RECEIPTS if receipt else "") + gha.render(step["run"], ctx), encoding="utf-8")
result = subprocess.run(
- ["bash", "--noprofile", "--norc", "-eo", "pipefail", str(script)],
+ [bash, "--noprofile", "--norc", "-eo", "pipefail", str(script)],
cwd=cwd or root, env=env, stdin=subprocess.DEVNULL,
capture_output=True, text=True, timeout=30,
)