Skip to content

Fix Version beta/dev ordering and previous_patch_version typo#17

Draft
esphbot wants to merge 1 commit into
esphome:mainfrom
esphbot:koan/fix-version-ordering
Draft

Fix Version beta/dev ordering and previous_patch_version typo#17
esphbot wants to merge 1 commit into
esphome:mainfrom
esphbot:koan/fix-version-ordering

Conversation

@esphbot

@esphbot esphbot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What

Fix two correctness bugs in Version (esphomerelease/model.py) and add the first unit tests for the module.

Why

Version.__lt__ compared self.dev (a bool) against other.beta (an int) with is, an identity check that is effectively always true. The method therefore returned early on self.dev for every comparison of versions sharing the same major.minor.patch, making the beta/stable logic below it unreachable. Observable effects:

  • 1.15.0b1 < 1.15.0b2False (betas never ordered numerically)
  • 1.15.0b1 < 1.15.0False (a beta sorted after its stable release)
  • sorted([...]) placed 1.15.0 before its own betas

This directly corrupts Project.latest_release(include_prereleases=True), which selects the newest release with max() over parsed tags — the base version that feeds changelog generation.

Separately, previous_patch_version called replace(path=...) instead of patch=..., raising TypeError on every invocation.

How

  • Replaced the tangled dev/beta branch in __lt__ with a small _prerelease_rank ordering key so dev < betaN < stable holds consistently within a major.minor.patch.
  • Fixed the path=patch= typo.
  • Added tests/test_model.py (the tests/ dir was empty) covering parse/round-trip, version arithmetic, and the full ordering chain 1.14.5 < 1.15.0-dev < 1.15.0b1 < 1.15.0b2 < 1.15.0 < 1.15.1 < 2.0.0, plus a regression test for max() over prereleases.

Testing

python3 -m pytest tests/test_model.py → 29 passed. model.py imports only the stdlib, so the tests run without config.json or sibling checkouts.


Quality Report

Changes: 2 files changed, 154 insertions(+), 13 deletions(-)

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan

Version.__lt__ compared self.dev (bool) against other.beta (int) with 'is',
which is always true, so the method returned early on self.dev for every
same-major.minor.patch comparison. Beta versions never compared in numeric
order (1.15.0b1 < 1.15.0b2 was False) and betas sorted after their stable
release. This corrupted Project.latest_release(include_prereleases=True),
which picks the newest release via max().

Replace the dev/beta branch with a _prerelease_rank ordering key so
dev < betaN < stable holds consistently.

Also fix previous_patch_version passing path= instead of patch= to
dataclasses.replace, which raised TypeError on every call.

Add tests/test_model.py covering parsing, version arithmetic and full
ordering (the tests/ directory was previously empty).
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