#!/usr/bin/env bash # Checks that Python resolution skips a PATH entry that cannot run Python (such as the Windows # Store app execution alias) and that check-capabilities reports the resolved interpreter. set -euo pipefail summary=false [ "${1:-}" != --summary ] || summary=true root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd) stubs=$(mktemp -d) trap 'rm -rf -- "$stubs"' EXIT # python3 imitates the Store alias: it is on PATH but only prints an install hint. printf '#!/bin/sh\necho "Python was not found; run without arguments to install from the Microsoft Store" >&2\nexit 9009\n' > "$stubs/python3" printf '#!/bin/sh\nfor arg in "$@"; do [ "$arg" != -c ] || { echo 3.12.0; exit 0; }; done\nexit 0\n' > "$stubs/python" chmod +x "$stubs/python3" "$stubs/python" # shellcheck disable=SC2016 # Expanded by the child shell. resolved=$(PATH="$stubs:$PATH" bash -c '. "$1/shared/hooks/scripts/resolve-python.sh"; resolve_python && printf "%s" "$(python_display)"' _ "$root") [ "$resolved" = python ] || { printf 'FAIL resolver chose "%s" instead of skipping the broken python3\n' "$resolved" >&2; exit 1; } output=$(PATH="$stubs:$PATH" bash "$root/scripts/commands/check-capabilities.sh" 2>&1) || true grep -q 'PASS Python 3.12.0' <<<"$output" || { printf 'FAIL check-capabilities did not use the resolved interpreter:\n%s\n' "$output" >&2; exit 1; } if [ "$summary" = true ]; then printf 'Tests: PASS | capabilities\n'; else printf 'PASS capabilities: broken Python aliases are skipped\n'; fi