Skip to content

fix(xiaoyuzhou): verify python candidates actually run before selecting one (#566) - #717

Open
smartworldarafath wants to merge 1 commit into
Panniantong:mainfrom
smartworldarafath:fix/xiaoyuzhou-python-interpreter-probe
Open

smartworldarafath wants to merge 1 commit into
Panniantong:mainfrom
smartworldarafath:fix/xiaoyuzhou-python-interpreter-probe

Conversation

@smartworldarafath

@smartworldarafath smartworldarafath commented Sep 22, 2026 •

Copy link
Copy Markdown

Problem

ensure_python() in agent_reach/scripts/transcribe_xiaoyuzhou.sh only checked whether an
interpreter name exists on PATH — never whether it can actually run:

if command -v python3 >/dev/null 2>&1; then
    PYTHON_CMD=(python3)

On Windows (Git Bash) command -v python3 resolves to the Microsoft Store App Execution Alias
%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe. That file ships on PATH by default, but it is
not Python — it just exits:

$ python3 --version
Python was not found; run without arguments to install from the Microsoft Store, or disable this
shortcut from Settings > Apps > Advanced app settings > App execution aliases.
$ echo $?
49

Since that alias is ordered before a real python install (e.g.
...\Programs\Python\Python312\python.exe), the script selected the stub and every subsequent
Python call failed
. The first step that uses Python is the URL check, so the user-visible error
points in the wrong direction entirely — a perfectly valid link is reported as an unsupported host:

$ bash transcribe_xiaoyuzhou.sh https://www.xiaoyuzhoufm.com/episode/123
❌ 仅支持 xiaoyuzhoufm.com 及其子域的 http/https 链接

Result: the script is unusable on Windows even when a working Python is installed, and the
python3 / python / py -3 probe added in #575 cannot detect it either, because that check
is existence-only too.

This is exactly the third failure mode agent_reach/probe.py documents —
"command exists but cannot execute" (stale venv shims) — it simply had not been applied here.
The repo's own test.sh already uses the correct form (command -v … && python3 -c …);
this PR just brings the script in line with that convention.

Fix

A candidate is accepted only after it actually executes; otherwise the script falls through to the
next candidate and reports "no usable Python" only when none of them runs:

if command -v python3 >/dev/null 2>&1 && python3 -c "" >/dev/null 2>&1; then
    PYTHON_CMD=(python3)
elif command -v python >/dev/null 2>&1 && python -c "" >/dev/null 2>&1; then
    PYTHON_CMD=(python)
elif command -v py >/dev/null 2>&1 && py -3 -c "" >/dev/null 2>&1; then
    PYTHON_CMD=(py -3)
else
    echo "❌ 未找到可用的 Python(尝试过 python3、python、py -3)" >&2
    return 1
fi

Only ensure_python() changes (5 logic lines). Linux/macOS behaviour is unchanged: a real
python3 returns 0 from -c "" immediately, so it is still selected first.

Regression test

New tests/test_xiaoyuzhou_install.py::test_transcribe_script_skips_unrunnable_python3_stub
reproduces the field condition using the BASH_ENV injection the file's tests already use:

  • python3 → exists but returns 49 (same as the Store alias)
  • python → points at the running test interpreter (sys.executable)

It asserts the valid URL reaches curl (and is then stopped by the fake curl's exit code 42)
instead of being misreported as an unsupported host.

# without the patch (git checkout -- agent_reach/scripts/transcribe_xiaoyuzhou.sh)
$ pytest tests/test_xiaoyuzhou_install.py -k skips_unrunnable_python3_stub
FAILED ... AssertionError: assert '仅支持 xiaoyuzhoufm.com' not in '...❌ 仅支持 xiaoyuzhoufm.com 及其子域的 http/https 链接\n'

# with the patch
$ pytest tests/test_xiaoyuzhou_install.py -q
16 passed in 7.16s

Verification

  • pytest tests/test_xiaoyuzhou_install.py → 16 passed (10 passed / 6 failed before the fix)
  • pytest (full suite, Windows 10 + Git Bash + Python 3.12) → 576 passed / 4 failed / 28 skipped.
    All 4 remaining failures are WinError 1314 symlink-privilege environment failures that fail on
    unmodified main here as well; they are unrelated to this change and already handled by test(windows): skip symlink tests when symlinks are unavailable #681
    ("skip symlink tests when symlinks are unavailable").
  • ruff check tests agent_reach → All checks passed

Refs #566 (the remaining piece of P1-2, "transcribe.sh 在 Windows 完全不可用")

…ng one (Panniantong#566)

`ensure_python()` accepted the first interpreter whose *name* existed on PATH.
On Windows Git Bash `command -v python3` resolves to the Microsoft Store App
Execution Alias (`%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe`), which
exits 49 without running Python. That stub shadows a real `python` install
later in PATH, so the script selected it and every Python step afterwards
failed.

The first Python step is the URL check, so the user-visible symptom is a
misleading rejection of perfectly valid links:

    $ bash transcribe.sh https://www.xiaoyuzhoufm.com/episode/123
    ❌ 仅支持 xiaoyuzhoufm.com 及其子域的 http/https 链接

Existence-only detection cannot tell "exists" from "can execute" — the same
failure mode `agent_reach/probe.py` documents for stale venv shims, and the
pattern `test.sh` already uses (`command -v … && python3 -c …`).

Fix: each candidate must execute `-c ""` before it is accepted; otherwise the
script falls through to the next candidate and only reports "no usable Python"
when none of them runs.

Regression test `test_transcribe_script_skips_unrunnable_python3_stub` injects
a `python3` that exists but returns 49 (like the Store alias) plus a working
`python`, then asserts the URL reaches curl instead of being rejected. It fails
before this change and passes after it.

Verified: 576 passed / 4 failed locally; the 4 remaining failures are Windows
symlink-privilege environment failures that also fail on unmodified main, and
the 6 previously failing `test_xiaoyuzhou_install.py` cases now pass.
@smartworldarafath
smartworldarafath force-pushed the fix/xiaoyuzhou-python-interpreter-probe branch from a7e0e36 to a4ad685 Compare September 22, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant