ble-reticulum/tests
torlando-tech 8cd54443c8 fix: Clean up identity mappings on disconnect to prevent stale connections
Fix stale connection issue where identity mappings persist after disconnect,
preventing automatic reconnection when peer returns with different MAC address.

ROOT CAUSE:
- _device_disconnected_callback() cleaned up spawned_interfaces but NOT:
  - address_to_identity mapping
  - identity_to_address mapping
- handle_central_disconnected() had same issue
- Result: Laptop thinks it's still connected after Android restarts
- Manual rnsd restart required to clear stale state

THE FIX (TDD Approach):
1. RED: Wrote 5 tests demonstrating the bug (all FAILED initially)
2. GREEN: Added identity mapping cleanup to both disconnect methods
3. GREEN: All 5 tests now PASS

Changes:
- BLEInterface.py _device_disconnected_callback():
  - Added del address_to_identity[address]
  - Added del identity_to_address[identity_hash]

- BLEInterface.py handle_central_disconnected():
  - Added del address_to_identity[address]
  - Added del identity_to_address[identity_hash]

- linux_bluetooth_driver.py:
  - Added RNS warning handler for better logging

- tests/test_identity_mapping_cleanup.py (NEW):
  - 5 tests verifying identity mapping cleanup
  - Tests both central and peripheral disconnect modes
  - Reproduces real-world stale connection scenario
  - Verifies automatic reconnection after fix

Test Results:
 All 5 tests PASS after fix
 Mappings properly cleaned up on disconnect
 Automatic reconnection enabled

Impact:
- No more manual rnsd restart needed
- Android MAC rotation handled correctly
- Stale connections automatically cleaned up
- Reconnection works without intervention

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-13 15:37:54 -05:00
..
conftest.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
mock_ble_driver.py Refactor BLEInterface to driver-based architecture 2025-11-03 23:15:22 -05:00
test_ble_peer_interface.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_bleak_threading_hang.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_bleak_with_exec_loading.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_bluez_state_cleanup.py fix(ble): Add BlueZ state cleanup to prevent persistent "Operation already in progress" errors 2025-11-10 00:51:27 -05:00
test_breddr_fallback_prevention.py fix(ble): Clarify ConnectDevice() object path return as success 2025-11-10 19:47:34 -05:00
test_config_directory.py fix: support custom config directories via RNS.Reticulum.configdir 2025-10-28 19:09:48 -04:00
test_dbus_disconnect_monitoring.py fix(ble): Fix D-Bus disconnect monitoring with ObjectManager and polling fallback 2025-11-12 20:10:44 -05:00
test_error_recovery.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_fragmentation.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_gatt_server.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_gatt_server_readiness.py fix(ble): Add D-Bus verification to prevent GATT server initialization race 2025-11-10 19:51:23 -05:00
test_identity_mapping_cleanup.py fix: Clean up identity mappings on disconnect to prevent stale connections 2025-11-13 15:37:54 -05:00
test_installer.sh refactor: make libffi-dev conditional for armhf (32-bit ARM) only 2025-10-29 11:02:51 -04:00
test_integration.py test: Add comprehensive v2.2 protocol test suites 2025-11-07 23:00:30 -05:00
test_multi_device_simulation.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_peripheral_disconnect_cleanup.py fix(ble): Fix D-Bus disconnect monitoring with ObjectManager and polling fallback 2025-11-12 20:10:44 -05:00
test_prioritization.py test: Update integration tests for driver abstraction refactor 2025-11-07 22:48:38 -05:00
test_scanner_connection_coordination.py fix(ble): Add scanner-connection coordination to prevent "InProgress" errors 2025-11-10 19:44:20 -05:00
test_stale_connection_polling.py fix(ble): Fix D-Bus disconnect monitoring with ObjectManager and polling fallback 2025-11-12 20:10:44 -05:00
test_v2_2_identity_handshake.py test: Add comprehensive v2.2 protocol test suites 2025-11-07 23:00:30 -05:00
test_v2_2_mac_sorting.py test: Add comprehensive v2.2 protocol test suites 2025-11-07 23:00:30 -05:00
test_v2_2_race_conditions.py test: Add comprehensive v2.2 protocol test suites 2025-11-07 23:00:30 -05:00