Skip to content

Fix firmware version parser to accept SemVer 2.0 build metadata - #12

Merged
JamesSmartCell merged 1 commit into
masterfrom
cursor/fix-semver-build-metadata-d9b8
Nov 17, 2026
Merged

JamesSmartCell merged 1 commit into
masterfrom
cursor/fix-semver-build-metadata-d9b8

Conversation

@JamesSmartCell

Copy link
Copy Markdown
Owner

Problem

Devices built from dirty git trees report versions like garagedoor@1.2.2+a57a610-dirty, which fail the current firmware version regex. This causes the device to not be recognized as project garagedoor, and POST /api/firmware/:project/notify (and upload ?notify=true) skips it, showing "Notified 0 device(s)" even though the device is connected.

Solution

Updated the firmware version parser to accept SemVer 2.0 compliant build metadata:

  • Build metadata can now include dot-separated identifiers
  • Each identifier comprises only ASCII alphanumerics and hyphens [0-9A-Za-z-]
  • Examples now supported: a57a610-dirty, abc.def-1, e2e-5f3075a

Changes

  1. Updated three regexes consistently to accept proper SemVer 2.0 build metadata:

    • Main FIRMWARE_VERSION_REGEX (line 19)
    • Full device format regex in extractSemver() (line 69)
    • Semver with build suffix regex in extractSemver() (line 75)
  2. Regex pattern: [0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*

    • Matches one or more alphanumeric/hyphen characters
    • Optionally followed by dot-separated additional identifiers
  3. Maintained existing behavior:

    • Version length limit (32 chars) unchanged
    • Plain semver validation remains strict MAJOR.MINOR.PATCH
    • Version comparison ignores build metadata (as per SemVer 2.0)

Testing

Added comprehensive unit tests for:

  • ✅ garagedoor@1.2.2+a57a610-dirty (dirty git build)
  • ✅ garagedoor@1.2.0+a4eda92 (simple hash)
  • ✅ garagedoor@1.2.0 (no build metadata)
  • ✅ Dot-separated identifiers: abc.def-1, e2e-5f3075a
  • ✅ Notify eligibility for dirty-tagged older devices
  • ✅ Invalid formats rejected:
    • garagedoor@1.2 (incomplete semver)
    • @1.2.0 (no project)
    • garagedoor@1.2.0+ (empty metadata)
    • garagedoor@1.2.0+a b (spaces)
    • garagedoor@1.2.0+a+b (double plus)
    • garagedoor@1.2.0+a..b (double dot)

Test Results: ✅ All 244 tests passing (14 test files, 50 tests in firmware-version-parser)

Impact

  • Devices with dirty git builds will now be recognized and can receive OTA notifications
  • Semver extraction, project extraction, and notify eligibility logic all work correctly with these formats
  • No breaking changes to existing functionality
Open in Web Open in Cursor 

- Update FIRMWARE_VERSION_REGEX to accept dot-separated build metadata identifiers
  following SemVer 2.0 spec: [0-9A-Za-z-] characters with dot separators
- Fix all three regexes consistently (main parser, full device format, semver with build)
- Now accepts versions like garagedoor@1.2.2+a57a610-dirty (dirty git builds)
- Add comprehensive unit tests for:
  - Dirty git tags (a57a610-dirty)
  - Simple hash build metadata (a4eda92)
  - Dot-separated identifiers (abc.def-1, e2e-5f3075a)
  - Invalid formats (empty metadata, spaces, double plus signs)
  - Notify eligibility for dirty-tagged older devices
- Version comparison ignores build metadata (as per SemVer 2.0)
- All 244 tests passing

Fixes issue where devices with dirty git builds were not recognized for OTA notifications.

Co-authored-by: James Brown <JamesSmartCell@users.noreply.github.com>
@JamesSmartCell
JamesSmartCell merged commit bd3e55e into master Nov 17, 2026
4 checks 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.

2 participants