Self-hosted AI workspace.
Python
fix: capture download exit code before test consumes it (#1497)
Paulo Victor Cordeiro0b58446e8a21
diff --git a/routes/cookbook_routes.py b/routes/cookbook_routes.pyindex 77531f6fc..cc245f0eb 100644--- a/routes/cookbook_routes.py+++ b/routes/cookbook_routes.py@@ -580,7 +580,7 @@ def setup_cookbook_routes() -> APIRouter:runner_lines.append(" python3 -c 'import hf_transfer' 2>/dev/null && export HF_HUB_ENABLE_HF_TRANSFER=1")runner_lines.append(f' python3 -c "import os; from huggingface_hub import snapshot_download; snapshot_download(\'{req.repo_id}\'{_dl_pyarg}, max_workers={4 if req.disable_hf_transfer else 8})"')runner_lines.append('fi')- runner_lines.append('if [ $? -eq 0 ]; then echo ""; echo "DOWNLOAD_OK"; else echo ""; echo "DOWNLOAD_FAILED (exit $?)"; fi')+ runner_lines.append('_ec=$?; if [ $_ec -eq 0 ]; then echo ""; echo "DOWNLOAD_OK"; else echo ""; echo "DOWNLOAD_FAILED (exit $_ec)"; fi')runner_lines.append(f"rm -f {remote_runner}")runner_lines.append('exec "${SHELL:-/bin/bash}"')runner_path = TMUX_LOG_DIR / f"{session_id}_run.sh"@@ -611,11 +611,11 @@ def setup_cookbook_routes() -> APIRouter:# Detached path: no controlling TTY, so skip `< /dev/null`# (handled by Popen stdin=DEVNULL) and don't keep a shell open.lines.append(hf_cmd)- lines.append('if [ $? -eq 0 ]; then echo ""; echo "DOWNLOAD_OK"; else echo ""; echo "DOWNLOAD_FAILED (exit $?)"; fi')+ lines.append('_ec=$?; if [ $_ec -eq 0 ]; then echo ""; echo "DOWNLOAD_OK"; else echo ""; echo "DOWNLOAD_FAILED (exit $_ec)"; fi')else:# < /dev/null suppresses interactive "update available? [Y/n]" promptlines.append(f"{hf_cmd} < /dev/null")- lines.append('if [ $? -eq 0 ]; then echo ""; echo "DOWNLOAD_OK"; else echo ""; echo "DOWNLOAD_FAILED (exit $?)"; fi')+ lines.append('_ec=$?; if [ $_ec -eq 0 ]; then echo ""; echo "DOWNLOAD_OK"; else echo ""; echo "DOWNLOAD_FAILED (exit $_ec)"; fi')lines.append(f"rm -f '{wrapper_script}'")lines.append('exec "${SHELL:-/bin/bash}"')wrapper_script.write_text("\n".join(lines) + "\n", encoding="utf-8")