test: fix test suite for BLE interface changes

- Fix mock_ble_driver.py import path (src/RNS/Interfaces -> src/ble_reticulum)
- Add address_to_interface, _pending_detach, _pending_detach_grace_period to test fixture
- Update test_identity_cache to expect grace period behavior (deferred cleanup)
- Update test_v2_2_mac_sorting to use renamed _cleanup_stale_address function

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
torlando-tech 2026-01-01 14:03:59 -05:00
commit 5947544cd7
3 changed files with 16 additions and 9 deletions

View file

@ -41,7 +41,7 @@ if src_path not in sys.path:
# Import directly using importlib to bypass RNS namespace conflicts
# This avoids issues when a real RNS package is installed globally
import importlib.util
bluetooth_driver_path = os.path.join(src_path, 'RNS', 'Interfaces', 'bluetooth_driver.py')
bluetooth_driver_path = os.path.join(src_path, 'ble_reticulum', 'bluetooth_driver.py')
spec = importlib.util.spec_from_file_location("bluetooth_driver", bluetooth_driver_path)
bluetooth_driver = importlib.util.module_from_spec(spec)
spec.loader.exec_module(bluetooth_driver)

View file

@ -85,8 +85,11 @@ def ble_interface(mock_rns, mock_driver):
interface.spawned_interfaces = {}
interface.address_to_identity = {}
interface.identity_to_address = {}
interface.address_to_interface = {} # address -> BLEPeerInterface
interface._identity_cache = {}
interface._identity_cache_ttl = 60
interface._pending_detach = {} # identity_hash -> timestamp
interface._pending_detach_grace_period = 2.0 # seconds
# Fragmentation
interface.fragmenters = {}
@ -143,12 +146,16 @@ class TestIdentityCacheOnDisconnect:
assert cached_identity == identity
assert time.time() - cached_time < 2 # Cached recently
# Assert: Active mappings should be cleaned up
# Assert: Address-specific mappings should be cleaned up immediately
assert mac not in ble_interface.address_to_identity
assert identity_hash not in ble_interface.identity_to_address
# Assert: Peer interface was detached
mock_peer_if.detach.assert_called_once()
# Assert: identity_to_address and interface are NOT cleaned up immediately
# (grace period allows reconnection with same identity at new address)
assert identity_hash in ble_interface.identity_to_address
# Assert: Detach is scheduled, not immediate
assert identity_hash in ble_interface._pending_detach
mock_peer_if.detach.assert_not_called()
def test_disconnect_unknown_address_no_crash(self, ble_interface, mock_rns):
"""

View file

@ -360,7 +360,7 @@ class TestMACRotationBypassesSorting:
list regardless of MAC sorting. Previously, the code fell through to the MAC
sorting check which could skip the peer if local MAC > peer MAC.
Fix: After _cleanup_stale_interface(), immediately add peer and continue,
Fix: After _cleanup_stale_address(), immediately add peer and continue,
bypassing the MAC sorting check.
"""
@ -419,7 +419,7 @@ class TestMACRotationBypassesSorting:
"MAC rotation should bypass MAC sorting and add peer"
def test_mac_rotation_cleanup_is_called(self):
"""Test that _cleanup_stale_interface is called during MAC rotation."""
"""Test that _cleanup_stale_address is called during MAC rotation."""
driver = MockBLEDriver(local_address="FF:FF:FF:FF:FF:FF")
owner = MockOwner()
@ -430,13 +430,13 @@ class TestMACRotationBypassesSorting:
# Track cleanup calls
cleanup_calls = []
original_cleanup = interface._cleanup_stale_interface
original_cleanup = interface._cleanup_stale_address
def tracked_cleanup(identity_hash, old_address):
cleanup_calls.append((identity_hash, old_address))
return original_cleanup(identity_hash, old_address)
interface._cleanup_stale_interface = tracked_cleanup
interface._cleanup_stale_address = tracked_cleanup
# Set up MAC rotation scenario
old_address = "AA:AA:AA:AA:AA:AA"