Skip to content

fix: correct semver compare and cross-year date matching - #20

Merged
PttCodingMan merged 2 commits into
mainfrom
fix/version-compare-and-cross-year-date
Jun 29, 2026
Merged

fix: correct semver compare and cross-year date matching#20
PttCodingMan merged 2 commits into
mainfrom
fix/version-compare-and-cross-year-date

Conversation

@PttCodingMan

Copy link
Copy Markdown
Member

修掉的 bug

1. auto_version.py 版本比較錯誤

原本 int(v.replace('.', '')) 把點去掉轉 int 不是正確的 semver 比較,各段位數不同時會誤判:

  • 0.3.030 vs 0.2.15215 → 誤判 0.2.15 較新
  • 1.0.0100 vs 0.20.0200 → 誤判 0.20.0 較新

CI 用 python src/auto_version.py 的 stdout 決定要不要 rebuild / 打哪個 tag,遲早選錯版本。改用 _version_key() 以 int tuple 比較,stdout 行為不變。

2. get_post_index_range 跨年日期永遠對不上

PTT list_date 是無年份的 M/DDparse_date_str 一律補當年;若 target 帶非當年年份(docstring 範例就是 1987/09/06),post_date == target_date 永遠 False → 一律回報「找不到文章」。

改成所有比較只比 (month, day)(兩段 binary search + 兩段 verification 全改)。

已知上限(已用 ponytail: 註解標明,本次不處理)

  • 目標日期區間**跨年(12月→1月)**會打破 binary search 單調性,仍不支援;要支援得改用文章 header 的完整日期。
  • 刪文/缺號 → low = mid + 1 的 best-effort 行為未動。

測試

新增純 assert self-check,python src/test_auto_version.pypython src/test_api_post.py 皆印 OK

🤖 Generated with Claude Code

PttCodingMan and others added 2 commits June 29, 2026 21:39
- auto_version: compare versions via int tuples instead of stripping
  dots, which mis-ordered multi-digit segments (e.g. 0.2.15 vs 0.3.0).
- get_post_index_range: compare PTT list_date (yearless M/DD) by
  (month, day) only, so a target date carrying a non-current year no
  longer fails to match. Cross-year ranges remain unsupported (noted).
- Add assert-based self-checks for both.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CI runs flake8/mypy over the whole repo. The module-level sys.modules
stubbing before importing api_post triggered E402. Move it into a
helper function (function-level import is exempt) and use setattr for
the stub attribute to keep mypy's warn_unused_ignores happy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@PttCodingMan
PttCodingMan merged commit d19632b into main Jun 29, 2026
1 check 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.

1 participant