Skip to content

fix: preserve prerelease identifiers during version comparison - #10817

Open
rwzdk wants to merge 1 commit into
AstrBotDevs:masterfrom
rwzdk:fix/prerelease-version-normalization
Open

rwzdk wants to merge 1 commit into
AstrBotDevs:masterfrom
rwzdk:fix/prerelease-version-normalization

Conversation

@rwzdk

@rwzdk rwzdk commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

VersionComparator.compare_version() currently lowercases the entire version and removes every v. This changes valid prerelease identifiers before comparison: 1.0.0-v1 compares equal to 1.0.0-1, and 1.0.0-dev compares lower than 1.0.0-delta. Mixed-case identifiers also lose the ASCII ordering required by SemVer section 11.

The comparator is used by core update checks, version sorting, and CLI plugin update detection, so these inputs can hide an available update or report the wrong precedence.

Modifications

  • Strip only an optional leading v or V in both the core and CLI comparators; preserve prerelease identifiers unchanged.

  • Add focused tests for both actual implementations: internal v, case-sensitive ordering, version prefixes, ignored build metadata, numeric precedence, and the SemVer ordering example.

  • The test module loads the production comparator files with runpy so this pure utility can be tested without initializing AstrBot's database and provider integrations.

  • This is NOT a breaking change.

Verification Steps and Test Results

On Python 3.13.7:

python -m pytest tests/test_version_comparator.py -q
28 passed

pre-commit run --files astrbot/core/utils/version_comparator.py astrbot/cli/utils/version_comparator.py tests/test_version_comparator.py
ruff check: Passed
ruff format: Passed
pyupgrade: Passed

git diff --check
passed

Running the same new test file against the unmodified comparator files from master@dad255c produced 10 failed, 18 passed. No comparator logic is mocked or rewritten in these tests.

The full backup tests/application suite were not run. An attempted pytest tests/test_backup.py -k VersionComparison stopped during collection because the environment lacks google.genai; the focused module above passes through normal pytest collection without those integrations.

Checklist

  • Bug fix only; no new feature or dependency.
  • Regression results and reproduction command are provided above.
  • No WebUI navigation, labels, API schemas, or documentation workflows change.
  • Changes do not introduce malicious code.

AI assistance: this patch and its tests were developed and checked with OpenAI Codex. The validation results above are executed checks, not a claim of a human review or full application testing.

Summary by Sourcery

Correct version comparison so valid prerelease identifiers retain their SemVer ordering.

Bug Fixes:

  • Preserve prerelease identifiers and their case during core and CLI version comparisons while continuing to support optional leading version prefixes.

Tests:

  • Add focused regression coverage for both comparator implementations, including SemVer precedence, numeric ordering, prefixes, and build metadata.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
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