mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-29 09:11:17 +01:00
Connection.disconnect only ran device.disconnect() while isConnected was
true, but both drop listeners (BLE connectionStream, DirCon onDisconnected)
clear that flag before calling in. So an unexpected drop removed the
ProxyDevice from the list without its teardown: the FitnessBikeDefinition
stayed attached to the shared emulator with a dead transport, every trainer
app control-point write still hit it ("Bad state: DirconClient is not
connected" once per write, per leaked definition), gear commands routed to
the stale first-of-type definition went nowhere, and "<trainer> -
BikeControl" kept advertising with no trainer behind it (support bd2f3b55).
The listeners now pass dropped: true so the teardown runs. The BLE listener
passes it only when the device was connected until that event, so a late
echo of a deliberate disconnect stays on the old path; and a re-entrant call
for the platform event that lands mid-teardown skips a second teardown
(_disconnecting), which is what emulation_forget_test tripped over.
Regression tests drop a real loopback DirCon socket and a fake BLE
peripheral under a live bridge and assert the definition is detached, the
emulator stopped and nothing advertised.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>