Skip to content

test(ble): add mocked transport coverage for BLE commands - #47

Merged
Bre77 merged 2 commits into
mainfrom
fm/tfa-ble-pr0-scaffold-s3
Jul 9, 2026
Merged

test(ble): add mocked transport coverage for BLE commands#47
Bre77 merged 2 commits into
mainfrom
fm/tfa-ble-pr0-scaffold-s3

Conversation

@Bre77

@Bre77 Bre77 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Intent

Add foundational BLE test scaffolding (PR-0 of the BLE production-readiness master plan): a reusable in-repo mocked-transport unit-test base (tests/ble_mocked_transport.py + tests/test_ble_mocked_commands.py) that patches VehicleBluetooth._send with canned RoutableMessage replies so inherited Commands (door_lock/VCSEC, set_temps/INFO action, charge_state/INFO typed read) can be driven and their signed RoutableMessage + decoded reply asserted with NO real BLE/GATT connection ever opened. This is infrastructure only - no new BLE actuation behavior, no live car interaction. The master plan (report.md) established that VehicleBluetooth already inherits the entire ~110-command signed-command surface from Commands, so this program is verify+test scaffolding, not re-implementation; PR-0 is explicitly the safe-to-self-merge first step every later BLE command-test PR builds on. A second deliverable (extending the local dev-only BLE harness with a generic snapshot->act->verify->restore 'cmd' subcommand) was done in scripts/ble-harness/, which is deliberately git-excluded via .git/info/exclude and does not appear in this diff - it was verified with --help only, never run against a real car, and was re-persisted to the external harness snapshot location outside this repo. AGENTS.md was updated with a short pointer to the new test base for future BLE test-writing sessions.

What Changed

  • Added a reusable mocked BLE transport test base that patches VehicleBluetooth._send, supplies canned signed-command replies, and exposes helpers for decrypting/asserting generated RoutableMessage payloads without opening a real BLE/GATT connection.
  • Added BLE command coverage for representative VCSEC, infotainment action, and infotainment vehicle-data read flows through inherited Commands methods.
  • Documented the mocked transport test pattern in AGENTS.md for future BLE command tests.

Risk Assessment

✅ Low: The branch is narrowly scoped to BLE test scaffolding and documentation, with no production behavior changes and no material correctness risks found in the reviewed diff.

Testing

Inspected the BLE test-scaffold diff, ran the focused mocked BLE command tests and the full test suite successfully, then produced JSON evidence showing decoded signed command payloads and canned replies for VCSEC, infotainment action, and typed read paths with real BLE connection attempts guarded and unused.

Evidence: Mocked BLE transport behavior evidence
{
  "ble_connection_guard": "tesla_fleet_api.tesla.vehicle.bluetooth.establish_connection was patched to raise if called",
  "checks": [
    {
      "command": "door_lock",
      "connect_if_needed": "AsyncMock awaited instead of real method",
      "decoded_command": {
        "RKEAction": "RKE_ACTION_LOCK"
      },
      "decoded_reply": {
        "response": {
          "reason": "",
          "result": true
        }
      },
      "send_await_count": 1,
      "sent_domain": "DOMAIN_VEHICLE_SECURITY",
      "signed_with": "AES_GCM_Personalized_data",
      "transport": "VehicleBluetooth._send AsyncMock"
    },
    {
      "command": "set_temps(21.5, 19.0)",
      "connect_if_needed": "AsyncMock awaited instead of real method",
      "decoded_command": {
        "driver_temp_celsius": 21.5,
        "passenger_temp_celsius": 19.0
      },
      "decoded_reply": {
        "response": {
          "reason": "",
          "result": true
        }
      },
      "send_await_count": 1,
      "sent_domain": "DOMAIN_INFOTAINMENT",
      "signed_with": "AES_GCM_Personalized_data",
      "transport": "VehicleBluetooth._send AsyncMock"
    },
    {
      "command": "charge_state",
      "connect_if_needed": "AsyncMock awaited instead of real method",
      "decoded_command": {
        "getVehicleData.getChargeState": true
      },
      "decoded_reply": {
        "ChargeState.battery_level": 42
      },
      "send_await_count": 1,
      "sent_domain": "DOMAIN_INFOTAINMENT",
      "signed_with": "AES_GCM_Personalized_data",
      "transport": "VehicleBluetooth._send AsyncMock"
    }
  ],
  "intent": "Drive VehicleBluetooth signed commands through a mocked _send transport with no real BLE/GATT connection.",
  "real_ble_establish_connection_await_count": 0
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • git diff --stat c16d2540ec1a67fe24d152fac7597bb2379e8464..HEAD and related file inspection of tests/ble_mocked_transport.py, tests/test_ble_mocked_commands.py, and AGENTS.md
  • uv run pytest tests/test_ble_mocked_commands.py -vv
  • uv run pytest tests
  • Generated /tmp/no-mistakes-evidence/01KX2YR32ZVB7W6R2F6W2HHGQQ/ble_mocked_transport_evidence.json by driving door_lock, set_temps(21.5, 19.0), and charge_state through MockedBleTransportTestCase, decrypting sent RoutableMessage payloads, and patching establish_connection to raise if real BLE connect was attempted
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

firstmate crewmate added 2 commits July 9, 2026 18:05
VehicleBluetooth inherits its entire signed-command surface from Commands
but had zero BLE-specific command tests. tests/ble_mocked_transport.py
patches _send with canned RoutableMessage replies (no real BLE/GATT
connection) so command-to-proto construction and reply decoding are
unit-testable; every later BLE command-test PR builds on this base.
@Bre77
Bre77 merged commit 15b3726 into main Jul 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant