Fix serial port listing with unknown serial subsystems (Linux)#54
Fix serial port listing with unknown serial subsystems (Linux)#54
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #54 +/- ##
==========================================
+ Coverage 89.00% 89.05% +0.05%
==========================================
Files 19 19
Lines 2800 2804 +4
==========================================
+ Hits 2492 2497 +5
+ Misses 308 307 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a Linux serial port enumeration crash when encountering TTY devices whose sysfs entries lack a resolvable subsystem symlink (as seen on GitHub Actions runner VMs). It hardens linux_list_serial_ports() to skip broken/nonexistent sysfs paths and adds regression coverage to prevent UnboundLocalError from recurring.
Changes:
- Use
Path.resolve(strict=True)when resolving tty devices and theirsubsystem, skipping entries that can’t be resolved. - Ensure the “unknown subsystem” branch no longer falls through to
results.append(info)by explicitly continuing. - Add Linux tests for devices with no subsystem and for an empty sysfs tree; run
serialx.tools.list_portsin CI to surface enumeration failures early.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
serialx/platforms/serial_linux.py |
Makes sysfs resolution strict and avoids appending undefined info for unknown subsystems. |
tests/test_list_serial_ports_linux.py |
Adds regression tests for missing-subsystem TTYs and empty listings. |
.github/workflows/ci.yml |
Updates Python setup to check-latest: true and runs port listing in test jobs to catch runtime enumeration issues. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Caught (again) in https://github.com/home-assistant/core/actions/runs/24216216900/job/70698025832?pr=167615.
A follow-up PR will enable as much of mypy as we can to catch things like this in the future.
The underlying issue is that
Path.resolve()on a nonexistent path will return the same path unless called withstrict=True. The GitHub Actions runner VM seems to have a custom device with TTYs whoseplatformsymlink is missing, causing an the "unknown serial device subsystem" branch to be taken erroneously.