fix(utils): support dev and custom firmware version strings#613
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
c450e7f to
481a764
Compare
481a764 to
f26ee3e
Compare
|
Oops, something went wrong! Please try again later. 🐰 💔 |
📝 Line-by-Line Code Review for PR #613 —
|
| Category | Count |
|---|---|
| Critical | 1 |
| Warning | 2 |
| Suggestion | 1 |
The PR is mostly sound and correct. The only real issue is the test with _rc1 — its expected outcome needs clarification. The other findings are minor. LGTM with minor fixes.
Estimated effort to review & fix: ~30 minutes
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_client.py (1)
637-666: ⚡ Quick winExpand test coverage for edge cases.
The test validates core dev-detection scenarios, but given the substring-matching approach in
utils.py, consider adding test cases for:
- Standalone branch names:
"main","master"(without trailing hash)- Potential false positives:
"domain_abc123","webmaster_def456"to verify they're NOT incorrectly treated as dev- Uppercase hex hashes:
"feature_1A2B3C"to ensure case-insensitive matching works (after fixing the regex)- "master" detection: Currently only "main" is tested; add
"master_abc1234"These additional cases would strengthen confidence that the dev-detection logic handles real-world version strings correctly.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_client.py` around lines 637 - 666, Add tests to tests/test_client.py covering the edge cases missing from _version_check detection: include standalone branch names "main" and "master" (no trailing hash), a "master_abc1234" case, potential false positives such as "domain_abc123" and "webmaster_def456" which must NOT be treated as dev, and an uppercase hex-hash case like "feature_1A2B3C" to verify case-insensitive matching; these new assertions should call charger._version_check(...) and expect True for genuine dev branches and False for false-positive strings, and ensure the utils.py dev-detection regex/logic is adjusted to be case-insensitive and word-boundary-aware if necessary to make the tests pass.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openevsehttp/utils.py`:
- Line 26: The regex r"_[a-f0-9]{6,40}$" in utils.py is case-sensitive and
misses uppercase hex commit hashes; update the dev-build detection to accept
uppercase hex by either changing the character class to include A-F (e.g.,
"_[A-Fa-f0-9]{6,40}$") or by adding the re.IGNORECASE flag to the re.search
call, and apply the same change to any other occurrences of this pattern.
---
Nitpick comments:
In `@tests/test_client.py`:
- Around line 637-666: Add tests to tests/test_client.py covering the edge cases
missing from _version_check detection: include standalone branch names "main"
and "master" (no trailing hash), a "master_abc1234" case, potential false
positives such as "domain_abc123" and "webmaster_def456" which must NOT be
treated as dev, and an uppercase hex-hash case like "feature_1A2B3C" to verify
case-insensitive matching; these new assertions should call
charger._version_check(...) and expect True for genuine dev branches and False
for false-positive strings, and ensure the utils.py dev-detection regex/logic is
adjusted to be case-insensitive and word-boundary-aware if necessary to make the
tests pass.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ff8d3bd8-f63e-44dd-8141-b9b00464262f
📒 Files selected for processing (3)
openevsehttp/utils.pytests/fixtures/v4_json/config-unknown-semver.jsontests/test_client.py
… for PR 613 comments
🔴 Criticalopenevsehttp/utils.py — Line 19-24Issue: The Suggestion: The current behavior is intentional per the PR requirements — it treats any 6-char hex suffix as a dev branch. However, the regex should explicitly exclude pre-release patterns (like Suggested fix (more explicit pattern):# Match 6-char hex commit hashes EXACTLY (not in the middle of words)
is_dev = version[-6:] == version[-6:].ljust(6)[6:]This uses a simple string slice comparison — no regex, no ambiguity. The original regex: r"(?:^|[^a-zA-Z0-9])(dev|feature|fix|main|master)(?:[^a-zA-Z0-9].*?)?_[a-fA-F0-9]{6}$"has a flaw: Bottom line: The regex works as intended per tests. No critical bug, but the function could benefit from a clearer docstring or comment explaining the exact dev-branch semantics.
|
There was a problem hiding this comment.
♻️ Duplicate comments (1)
openevsehttp/utils.py (1)
23-25:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPre-release handling is documented incorrectly and currently gets coerced to stable.
At Line 25, the docstring says pre-release versions are parsed as semver, but the non-dev path later strips to the first
X.Y.Zmatch, so inputs like4.1.2_rc1become4.1.2. That makes pre-release/build-tagged firmware compare as stable.Suggested fix (keep only full stable semver extraction)
- if "dev" not in version: - firmware_search = re.search(r"\d+\.\d+\.\d+", value) - if firmware_search: - value = firmware_search.group(0) + if "dev" not in version: + firmware_match = re.fullmatch(r"v?(\d+\.\d+\.\d+)", value) + if firmware_match: + value = firmware_match.group(1)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openevsehttp/utils.py` around lines 23 - 25, The docstring is wrong: pre-release/build-tagged firmware like "4.1.2_rc1" is currently coerced to stable because the non-dev path strips to the first X.Y.Z match; update the docstring in utils.py to state that non-dev inputs are normalized by extracting the first stable X.Y.Z (i.e., pre-release/build tags are removed), and mention the specific non-dev extraction behavior (the code path that strips to the first X.Y.Z match) so readers know pre-release tags are not preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@openevsehttp/utils.py`:
- Around line 23-25: The docstring is wrong: pre-release/build-tagged firmware
like "4.1.2_rc1" is currently coerced to stable because the non-dev path strips
to the first X.Y.Z match; update the docstring in utils.py to state that non-dev
inputs are normalized by extracting the first stable X.Y.Z (i.e.,
pre-release/build tags are removed), and mention the specific non-dev extraction
behavior (the code path that strips to the first X.Y.Z match) so readers know
pre-release tags are not preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fd944a26-4d63-468e-898d-da7070b096cb
📒 Files selected for processing (2)
openevsehttp/utils.pytests/test_client.py
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/test_client.py
This PR updates
get_awesome_versionto recognize dev/main and branch_hash patterns asdevso that features are not disabled under dev/custom firmware builds.Fixes firstof9/openevse#642
Summary by CodeRabbit
Bug Fixes
Tests