fix: skip stable update prompt for newer prereleases

This commit is contained in:
Lightjunction Assistant
2026-06-29 03:18:20 +08:00
parent 6067a70803
commit 0a8fb37ca3
2 changed files with 51 additions and 5 deletions

View File

@@ -234,6 +234,16 @@ class RepoZipUpdator:
"""Semver 版本比较"""
return VersionComparator.compare_version(v1, v2)
def _is_prerelease_version(self, version: str) -> bool:
"""Check if a version string is a prerelease version."""
return bool(
re.search(
r"[\-_.]?(alpha|beta|rc|dev)[\-_.]?\d*$",
version,
re.IGNORECASE,
)
)
async def check_update(
self,
url: str,
@@ -241,6 +251,7 @@ class RepoZipUpdator:
consider_prerelease: bool = True,
) -> ReleaseInfo | None:
update_data = await self.fetch_release_info(url)
current_is_prerelease = self._is_prerelease_version(current_version)
sel_release_data = None
if consider_prerelease:
@@ -249,11 +260,7 @@ class RepoZipUpdator:
else:
for data in update_data:
# 跳过带有 alpha、beta 等预发布标签的版本
if re.search(
r"[\-_.]?(alpha|beta|rc|dev)[\-_.]?\d*$",
data["tag_name"],
re.IGNORECASE,
):
if self._is_prerelease_version(data["tag_name"]):
continue
tag_name = data["tag_name"]
sel_release_data = data
@@ -263,6 +270,10 @@ class RepoZipUpdator:
logger.error("未找到合适的发布版本")
return None
if current_is_prerelease and not self._is_prerelease_version(tag_name):
if self.compare_version(current_version, tag_name) >= 0:
return None
if self.compare_version(current_version, tag_name) >= 0:
return None
return ReleaseInfo(

View File

@@ -418,6 +418,41 @@ async def test_plugin_update_validates_archive_before_removing_existing_plugin(
assert marker_path.read_text(encoding="utf-8") == "VALUE = 'old'\n"
@pytest.mark.asyncio
async def test_check_update_skips_stable_when_current_prerelease_is_newer(
monkeypatch: pytest.MonkeyPatch,
) -> None:
updator = RepoZipUpdator()
async def fake_fetch_release_info(url: str, latest: bool = True): # noqa: ARG001
return [
{
"version": "AstrBot v4.26.0-beta.1",
"published_at": "2026-06-20T00:00:00Z",
"body": "beta",
"tag_name": "v4.26.0-beta.1",
"zipball_url": "https://github.example/beta.zip",
},
{
"version": "AstrBot v4.25.6",
"published_at": "2026-06-19T00:00:00Z",
"body": "stable",
"tag_name": "v4.25.6",
"zipball_url": "https://github.example/stable.zip",
},
]
monkeypatch.setattr(updator, "fetch_release_info", fake_fetch_release_info)
result = await updator.check_update(
"https://example.invalid/releases",
current_version="v4.26.0-dev",
consider_prerelease=False,
)
assert result is None
@pytest.mark.asyncio
async def test_astrbot_updator_prefers_hosted_core_package(
monkeypatch: pytest.MonkeyPatch,