Skip to content

fix(self-update): 修复 gh-proxy 前缀代理触发 uv panic - #11

Merged
MimoKit merged 2 commits into
MimoKit:masterfrom
yiwuerxin:fix/gh-proxy-self-update-panic
Jul 27, 2026
Merged

fix(self-update): 修复 gh-proxy 前缀代理触发 uv panic#11
MimoKit merged 2 commits into
MimoKit:masterfrom
yiwuerxin:fix/gh-proxy-self-update-panic

Conversation

@yiwuerxin

Copy link
Copy Markdown
Contributor

问题

启用 gh-proxy 风格前缀代理(MIMO_CONSOLE_GITHUB_PROXY=https://gh-proxy.com,即 GITHUB_PROXY_PRESETS 内置预设之一)后,概览页「一键更新」必然失败:

Updating https://gh-proxy.com/https://github.com/MimoKit/nonebot-plugin-mimo-console.git (HEAD)
Updated https://gh-proxy.com/.../nonebot-plugin-mimo-console.git (f430a205...)
thread 'uv-resolver' panicked at crates/uv-pypi-types/src/parsed_url.rs:530:14:
Git URL is invalid: AmbiguousAuthority("git+https:***@f430a205...")
error: The channel closed unexpectedly

根因

resolve_git_url() 把前缀代理拼到 GitHub URL 前,产生含多个 :// 的套娃 URL:https://gh-proxy.com/https://github.com/MimoKit/nonebot-plugin-mimo-console.git

build_self_update_command() 的 uv 分支拼成 pkg @ git+<套娃URL>,uv 解析 git+<套娃URL>@<ref> 时其 URL 解析器(url crate)对「多 :// + @ref」报 AmbiguousAuthority 并 panic。git clone 本身能成功(日志里 Updating/Updated 已拉到 commit),崩在随后 uv 内部解析阶段。

pip 分支(pip install --upgrade git+<套娃URL>)把套娃 URL 当普通 HTTPS 直接 git clone,正常工作。

CNB 镜像(is_mirror_repo)走完整仓库 URL、直连走原始 URL,二者都是单 scheme 干净 URL,uv 分支不受影响。只有 gh-proxy 前缀式(套娃)触发 panic —— gh-proxy 前缀本就只适合 HTTP(检测版本/拉商店),git 操作走 CNB 镜像或本修复的 pip fallback。

修复

build_self_update_command() 增加套娃判定,套娃 URL 走 pip,干净 URL 保留 uv:

is_prefix_proxy_url = git_url.count("://") > 1
if (
    uv
    and (project_root / "pyproject.toml").is_file()
    and not is_prefix_proxy_url
):
    return [uv, "add", f"{project_name} @ git+{git_url}", "--upgrade-package", project_name]
return [sys.executable, "-m", "pip", "install", "--upgrade", f"git+{git_url}"]

测试

新增 test_build_self_update_command_uses_pip_for_prefix_proxy:在有 uv + pyproject 的前提下,套娃 URL 仍走 pip。全部 store 测试通过。

附:uv 的 panic

畸形/套娃 git URL 应报清晰错误而非 thread panic。reproducer:uv add "x @ git+https://gh-proxy.com/https://github.com/MimoKit/nonebot-plugin-mimo-console.git"。建议一并反馈 astral-sh/uv。

gh-proxy 风格前缀代理产生含多个 :// 的套娃 URL,uv 解析 git+套娃URL@ref 时其 URL 解析器 panic (AmbiguousAuthority)。检测套娃 URL (count(://) > 1) 时走 pip;干净 URL (直连/CNB镜像) 保留 uv。

新增 test_build_self_update_command_uses_pip_for_prefix_proxy。
store.py: build_self_update_command 的 if 条件压单行(本 PR 代码)。api.py: 顺带 format master 既有 _re.match/raw_url(上游 format 债,非本 PR 引入,让 prek --all-files 过)。
@MimoKit
MimoKit merged commit 052358f into MimoKit:master Jul 27, 2026
9 checks passed
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.

2 participants