Commit Graph

5 Commits

Author SHA1 Message Date
Jonas Bark
20ea804198 Reapply "refactor(emulation): promote fake BLE harness from test/ to lib/bluetooth/emulation"
This reverts commit 0346594c2e.
2026-07-02 09:14:48 +02:00
Jonas Bark
0346594c2e Revert "refactor(emulation): promote fake BLE harness from test/ to lib/bluetooth/emulation"
This reverts commit 45e987ef97.
2026-07-02 09:06:53 +02:00
Jonas Bark
45e987ef97 refactor(emulation): promote fake BLE harness from test/ to lib/bluetooth/emulation 2026-07-02 09:05:06 +02:00
Jonas Bark
3eaea1932d Stop battery-saver-disconnected controllers from auto-reconnecting
The inactivity disconnector parks idle controllers with
disconnect(forget: true, persistForget: false) so they stay off the
ignore list and the user can reconnect. But controllers auto-connect
unconditionally at the addDevices() choke point, so the controller
reconnected the instant it was rediscovered (scan result /
getSystemDevices / the disconnect listener's performScanning) — right
after being parked, defeating the battery saver.

Track parked controllers in a session-scoped _suppressedAutoReconnect
set, populated before each inactivity disconnect and filtered at the
addDevices() choke point. Clear it only on explicit intent — the alert's
Reconnect action and connectDevice() — and wholesale in disconnectAll().
Clearing on every successful _connect raced: a connect still in flight
when the timeout fires resolved afterwards and wiped the fresh
suppression, so the controller looped straight back.

disconnectAll() clears the set (BT off / full reset makes it moot), and
the integration harness reset routes through it so a parked controller
can't leak into the next test and block its connect.

Tests: a parked controller is not auto-reconnected on rediscovery, and
the Reconnect action lifts the suppression and brings it back.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 16:55:36 +02:00
Jonas Bark
e9e7425c29 Integration tests: controller connections + virtual shifting through fake platform seams
Add test/integration with platform fakes installed at the plugin seams
(UniversalBle.setInstance, NsdPlatformInterface.instance); everything
above them — Connection, device classification, protocol parsers, press
state machine, keymaps, ProxyDevice — is the real code:

- controller_connection_test: scan→classification (Zwift Click/Ride via
  manufacturer data, Di2 via service UUID, FTMS trainer→ProxyDevice,
  ignored names/devices), connect lifecycle (device-info reads, battery,
  RideOn handshake, subscriptions), drops, dedupe, forget list.
- controller_button_chain_test: byte-accurate BLE notifications through
  the full reaction chain — single/double/long press, trigger remapping,
  duplicate-frame dedupe, unmapped-button error surfacing, multi-button
  Ride presses.
- virtual_shifting_connection_logic_test: retrofit-mode defaults (WiFi /
  BT-wins / proxy for power meters), auto-connect consent gating,
  in-place "No connection" disconnect + in-place reconnect, WiFi trainer
  discovery rules (found/lost/connected-survives-flap, self-exclusion),
  and an end-to-end Click-press → real action pipeline → gear shift.

Protocol-level coverage (DirCon over real TCP, BLE peripheral) lives in
the prop submodule's own tests — no prop internals in this repo.

Bug fix found by these tests: Connection.disconnect(keepInList: true)
was defeated — UniversalBle.disconnect resolves only after the platform
disconnect event, so the still-attached connectionStream listener
re-entered disconnect() without keepInList and dropped the device,
orphaning the object the open details page holds (the exact bug
0db8cf0c addressed). Guarded via _inPlaceDisconnects.

Also update stale tests to current behavior: sim-mode shifts return
Ignored since e0e4494d (handled by the bridge, not forwarded, logged
neutrally), ControllerButton.initials direction arrows, and skip the
third BC2 state-machine test consistently with its siblings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 18:59:14 +02:00