Commit graph

10 commits

Author SHA1 Message Date
torlando-tech
49d6321ae0 refactor: extract testable utilities to improve test coverage
Extracted business logic from ViewModels and UI components into testable utility classes (InterfaceFormattingUtils, DeviceNameValidator, RssiThrottler, DeviceClassifier) to enable comprehensive unit testing without platform dependencies. Added 116 new tests covering formatting, validation, throttling, and device classification logic, increasing patch coverage from 23.5% to approximately 35-40%.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-20 17:46:09 -05:00
torlando-tech
df4e7761f0 feat: add USB-assisted Bluetooth pairing with device selection
When pairing a USB-connected RNode via Bluetooth, the wizard now:
- Adds "Pair via USB" option to the Bluetooth tab
- Receives PIN from RNode over USB connection
- Scans for unbonded RNodes and shows device selection list
- Auto-selects if only one unbonded RNode is found
- Uses BroadcastReceiver to properly detect bond state changes

This solves the issue where multiple RNodes in range would cause
pairing failures because the PIN belongs to the USB-connected device,
not necessarily the first discovered one.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 12:21:04 -05:00
torlando-tech
07893238cd test: improve rnode_interface.py coverage and fix PIN parsing
Test coverage improvements (26% -> 47%):
- Add tests for _get_usb_bridge() success/failure cases
- Add tests for _start_usb() VID/PID lookup, connection, callbacks
- Add tests for _on_usb_connection_state_changed() callback
- Add tests for USB VID/PID config attributes
- Add tests for start() routing to correct implementation

PIN parsing fix:
- Fix CMD_BT_PIN parsing to use 4-byte big-endian integer format
- Matches Kotlin KotlinUSBBridge implementation
- Update test to verify correct frame structure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 00:52:45 -05:00
torlando-tech
686120a737 Add unit tests for USB RNode support
Add comprehensive unit tests for the USB bridge and RNode interface:

Python tests (test_usb_bridge.py - 43 tests):
- USB bridge setup and initialization
- Device enumeration
- Permission handling
- Connection/disconnection
- Read/write operations
- Callback setters

Python tests (test_rnode_interface.py - added USB tests):
- USB mode constants (MODE_USB, CMD_BT_PIN, BT_CTRL_PAIRING_MODE)
- USB mode interface configuration
- Bluetooth pairing mode over USB
- KISS Bluetooth command framing
- Fixed existing tests to work with new connection_mode field

Kotlin tests (KotlinUSBBridgeTest.kt - 21 tests):
- Bridge initialization
- Connection listener registration/removal
- Duplicate listener prevention
- Listener exception isolation
- Bluetooth PIN callback handling
- Write/read operations when not connected
- Permission checking
- Thread safety for concurrent listener registration
- Coroutine scope shutdown
- Disconnect state clearing
- UsbDeviceInfo data class
- Supported VID verification

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 20:31:29 -05:00
torlando-tech
5a9fd950de fix: TDD fixes for BLE deduplication cooldown asymmetry and test stability
- Fix BLE cooldown asymmetry: set deduplication cooldown BEFORE deciding
  which connection to keep, ensuring cooldown is applied regardless of
  whether central or peripheral connection is retained
- Fix InterfaceManagementViewModel test OOM: make STATUS_POLL_INTERVAL_MS
  testable (const→var) and add conditional return when interval <= 0
- Fix KISS.unescape() to properly skip invalid escape sequences (0xDB
  followed by invalid byte) and trailing FESC bytes instead of corrupting
  the data buffer
- Add comprehensive unit tests for all fixes following strict TDD approach

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 18:56:16 -05:00
torlando-tech
4a70196e31 fix: TDD fixes for PR #36 and custom mode UX improvements
- Fix Python RSSI/SNR race condition with proper lock acquisition
- Add manual device name validation (32 char limit, RNode name check)
- Add regulatory warnings for custom mode without region selection
- Preserve user-modified field errors during wizard navigation
- Improve custom mode UX: highlight selection, skip modem/slot steps
- Auto-expand advanced settings in custom mode review
- Hide region/modem/slot summary cards in custom mode
- Split large test file to pass detekt LargeClass rule

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 16:00:12 -05:00
torlando-tech
6fc4b519a6 fix: increase TX power validation limit to support regional maximums
The Python RNode interface hardcoded a 22 dBm maximum TX power, which
rejected valid regional settings (US allows 30 dBm, NZ allows 36 dBm).

Changes:
- Update Python validation to accept TX power up to 36 dBm (NZ max)
- Add Python tests for regional TX power limits (US 30, EU 27, NZ 36)
- Add Kotlin tests for NZ region validation (36 dBm max)

The Kotlin validator already correctly uses regional limits. The RNode
firmware provides final hardware validation and returns error 0x40 if
TX power exceeds device capability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 14:14:45 -05:00
torlando-tech
cf49225939 fix: Python RNode interface thread safety and CI improvements
- Add lock around self.online status in _set_online() and process_outgoing()
  to prevent frame loss during online/offline transitions
- Add lock around RSSI/SNR updates for consistency with other radio state
- Log warning for malformed KISS escape sequences instead of silent ignore
- Add Python unit tests for thread safety fixes (6 new tests, 68 total)
- Add Python pytest step to CI workflow before Gradle tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 13:58:30 -05:00
torlando-tech
166bb16300 fix: address 8 critical issues from PR review with TDD
Critical fixes:
- Fix memory leak: RSSI polling now stopped in onCleared()
- Fix silent BLE scan errors: user-friendly error messages added
- Fix double-check locking bug in Python RNode initialization
- Fix interface registration order: start() before Transport register
- Fix race condition: use threading.Event for read loop control
- Fix write retry: implement exponential backoff (0.3s, 1s, 3s)
- Fix BLE write latch race: null check prevents stale callbacks
- Fix MTU request hang: 2-second timeout falls back to discoverServices

Tests added:
- RSSI polling cancellation test
- BLE scan error handling test
- Thread safety tests for read loop
- Write retry exponential backoff tests

Also includes ktlint format auto-fixes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 13:07:10 -05:00
torlando-tech
5d1cb96e30 refactor: extract RNodeConfigValidator and add comprehensive unit tests
- Extract validation logic from RNodeWizardViewModel into RNodeConfigValidator
- Add unit tests for FrequencySlotCalculator, ModemPreset, FrequencyRegion
- Add unit tests for RNodeRegionalPresets, CommunitySlots
- Add unit tests for RNodeConfigValidator (45 tests)
- Add Python tests for KISS protocol and config validation (52 tests)
- Refactor startDeviceScan() into smaller helper methods
- Update detekt baseline for new code structure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 21:58:48 -05:00