@@ -23,6 +23,8 @@ def test_install_zh_bash_bootstrap_uses_gitee_archive_and_delegates_to_zh_worksp
2323 assert 'zh-CN' in script
2424 assert 'FLOCKS_UV_INSTALL_SH_URL' in script
2525 assert 'https://astral.org.cn/uv/install.sh' in script
26+ assert 'FLOCKS_UV_INSTALL_SH_FALLBACK_URL' in script
27+ assert 'https://uv.agentsmirror.com/install-cn.sh' in script
2628 assert 'FLOCKS_UV_INSTALL_PS1_URL' in script
2729 assert 'https://astral.org.cn/uv/install.ps1' in script
2830 assert 'PUPPETEER_CHROME_DOWNLOAD_BASE_URL' in script
@@ -110,10 +112,13 @@ def test_main_bash_installer_uses_configured_default_sources_without_probing() -
110112 assert 'FLOCKS_UV_DEFAULT_INDEX' in script
111113 assert 'FLOCKS_UV_INSTALL_SH_URL' in script
112114 assert 'https://astral.sh/uv/install.sh' in script
115+ assert 'FLOCKS_UV_INSTALL_SH_FALLBACK_URL' in script
113116 assert 'FLOCKS_NPM_REGISTRY' in script
114117 assert 'Using PyPI index: $UV_DEFAULT_INDEX' in script
115118 assert 'Using npm registry: $NPM_REGISTRY' in script
116119 assert 'Using uv install script: $UV_INSTALL_SH_URL' in script
120+ assert 'Using uv fallback script' not in script
121+ assert '使用 uv 备用安装脚本: $UV_INSTALL_SH_FALLBACK_URL' in script
117122 assert 'pick_fastest_url' not in script
118123 assert 'Probing PyPI and npm registries to choose the faster source' not in script
119124 assert 'npm_config_registry="$NPM_REGISTRY" npm install' in script
@@ -126,6 +131,7 @@ def test_main_bash_installer_uses_configured_default_sources_without_probing() -
126131 assert "load_nvm()" in script
127132 assert 'curl -o- "$NVM_INSTALL_SCRIPT_URL" | bash' in script
128133 assert 'curl -LsSf "$UV_INSTALL_SH_URL" | sh' in script
134+ assert 'curl -LsSf "$UV_INSTALL_SH_FALLBACK_URL" | sh' in script
129135 assert 'nvm install "$MIN_NODE_MAJOR"' in script
130136 assert 'nvm use "$MIN_NODE_MAJOR" >/dev/null' in script
131137 assert "Homebrew was not found. Trying to install nvm..." in script
@@ -354,6 +360,99 @@ def test_main_bash_installer_checks_node_modules_dir_before_accepting_global_pre
354360 assert result .returncode == 0 , output
355361
356362
363+ def test_main_bash_installer_uses_cn_uv_fallback_when_primary_script_fails () -> None :
364+ script = (SCRIPT_DIR / "install.sh" ).read_text (encoding = "utf-8" )
365+ script_without_main = re .sub (r'\nmain "\$@"\s*$' , "\n " , script )
366+ test_script = script_without_main + textwrap .dedent (
367+ r"""
368+
369+ export HOME="$(mktemp -d)"
370+ export FLOCKS_INSTALL_LANGUAGE="zh-CN"
371+ export FLOCKS_UV_INSTALL_SH_URL="https://primary.example/install.sh"
372+ export FLOCKS_UV_INSTALL_SH_FALLBACK_URL="https://uv.agentsmirror.com/install-cn.sh"
373+ export TEST_LOG="$HOME/install-uv.log"
374+ INSTALL_LANGUAGE="$FLOCKS_INSTALL_LANGUAGE"
375+ UV_INSTALL_SH_URL="$FLOCKS_UV_INSTALL_SH_URL"
376+ UV_INSTALL_SH_FALLBACK_URL="$FLOCKS_UV_INSTALL_SH_FALLBACK_URL"
377+
378+ has_cmd() {
379+ case "$1" in
380+ curl)
381+ return 0
382+ ;;
383+ uv)
384+ [[ -f "$HOME/uv-installed" ]]
385+ return $?
386+ ;;
387+ *)
388+ command -v "$1" >/dev/null 2>&1
389+ ;;
390+ esac
391+ }
392+
393+ info() {
394+ printf '%s\n' "$1" >> "$TEST_LOG"
395+ }
396+
397+ fail() {
398+ printf 'FAIL:%s\n' "$1" >&2
399+ exit 1
400+ }
401+
402+ refresh_path() {
403+ :
404+ }
405+
406+ ensure_path_persisted() {
407+ :
408+ }
409+
410+ curl() {
411+ printf '%s\n' "$*" >> "$HOME/curl-commands.log"
412+ if [[ "$*" == *"primary.example"* ]]; then
413+ return 22
414+ fi
415+
416+ cat <<'EOF'
417+ touch "$HOME/uv-installed"
418+ EOF
419+ }
420+
421+ install_uv
422+
423+ curl_commands="$(<"$HOME/curl-commands.log")"
424+ install_log="$(<"$TEST_LOG")"
425+
426+ [[ -f "$HOME/uv-installed" ]] || {
427+ printf 'uv was not installed by fallback script\n' >&2
428+ exit 1
429+ }
430+ [[ "$curl_commands" == *"https://primary.example/install.sh"* ]] || {
431+ printf 'primary uv script was not attempted: %s\n' "$curl_commands" >&2
432+ exit 1
433+ }
434+ [[ "$curl_commands" == *"https://uv.agentsmirror.com/install-cn.sh"* ]] || {
435+ printf 'fallback uv script was not attempted: %s\n' "$curl_commands" >&2
436+ exit 1
437+ }
438+ [[ "$install_log" == *"默认 uv 安装脚本失败,正在尝试中国大陆备用源"* ]] || {
439+ printf 'fallback log missing: %s\n' "$install_log" >&2
440+ exit 1
441+ }
442+ """
443+ )
444+
445+ result = subprocess .run (
446+ ["bash" , "-c" , test_script ],
447+ check = False ,
448+ capture_output = True ,
449+ text = True ,
450+ )
451+
452+ output = f"{ result .stdout } \n { result .stderr } "
453+ assert result .returncode == 0 , output
454+
455+
357456def test_main_powershell_installer_uses_configured_default_sources_without_probing () -> None :
358457 script = (SCRIPT_DIR / "install.ps1" ).read_text (encoding = "utf-8-sig" )
359458
0 commit comments