ble-reticulum/migration/phase2/Gate2C_BLEPeerSessionManager_pybind_tests_20260518_1507.md

3.4 KiB

Gate 2C: BLEPeerSessionManager pybind11 Tests

Date: 2026-05-18 15:07 America/Los_Angeles

Scope: pybind11 exposure and Python unit tests only.

Summary

Gate 2C exposed the native C++ BLEPeerSessionManager skeleton through the existing ble_protocol_core_cpp pybind11 module and added Python tests for the binding surface. No live BLE behavior was changed.

Modified:

  • migration/protocol_core/ble_protocol_core.cpp
  • migration/protocol_core/setup.py

Added:

  • migration/tests/test_ble_peer_session_manager_pybind.py
  • migration/phase2/Gate2C_BLEPeerSessionManager_pybind_tests_20260518_1507.md
  • migration/sql/mark_gate2c_protocol_session_pybind_tests_20260518_1507.sql

Not changed:

  • src/ble_reticulum/BLEInterface.py
  • live BLE backend selection behavior
  • BlueZ/Bleak/DBus integration
  • RNS.Transport integration
  • ESP32 BLE integration

Binding Surface

Bound classes and structs:

  • BLEPeerSessionManager
  • ConnectionId
  • ConnectionSnapshot
  • HandshakeResult
  • SessionAction
  • PeerSessionView

Bound enums:

  • LocalRole
  • InputDecision
  • SessionActionType

Bound static helpers:

  • is_identity_handshake_payload
  • identity_from_payload
  • compute_identity_key
  • compute_fragmenter_key

The binding accepts Python bytes for identities and payloads, while preserving the C++ manager as the native source of session decisions.

Tests Added

migration/tests/test_ble_peer_session_manager_pybind.py covers:

  • import module succeeds;
  • non-16-byte payload returns PassToReassembler and consumed=false;
  • new 16-byte identity returns AcceptedNewIdentity and consumed=true;
  • identity key equals first 8 bytes as 16 lowercase hex chars;
  • fragmenter key equals full 16-byte identity as 32 lowercase hex chars;
  • known identity duplicate same returns ConsumedDuplicateSameIdentity;
  • known identity duplicate mismatch returns ConsumedDuplicateMismatchedIdentity;
  • MTU provided is preserved;
  • MTU missing falls back to 23;
  • duplicate identity active elsewhere requests DisconnectCurrentPeer;
  • pending identity timeout can be marked and expired;
  • peer address update preserves identity and fragmenter key;
  • invalid identity_from_payload input raises.

Verification

Build command:

cd migration/protocol_core
python3 setup.py build_ext --inplace

New test command:

PYTHONPATH=migration/protocol_core pytest -q migration/tests/test_ble_peer_session_manager_pybind.py

Result:

12 passed, 2 warnings in 0.12s

Full requested test command:

pytest -q migration/tests/test_fragmentation_cpp_equivalence.py migration/tests/test_fragmentation_backend_shim.py migration/tests/test_identity_helpers_cpp_equivalence.py migration/tests/test_ble_peer_session_manager_pybind.py

Result:

68 passed, 1 skipped, 2 warnings in 1.00s

Note: running the full set with an outer PYTHONPATH=src:migration/protocol_core makes test_python_backend_still_works_when_cpp_backend_is_unavailable fail because that test intentionally controls PYTHONPATH inside subprocesses to simulate C++ backend absence. The passing command above leaves that isolation intact.

SQL

Companion SQL:

migration/sql/mark_gate2c_protocol_session_pybind_tests_20260518_1507.sql

The SQL marks _handle_identity_handshake as PYTHON_BOUND in phase 2_ble_protocol_session_manager, keeps tag GLUE, keeps cpp_candidate=1, and does not mark any Gate 2F or field-accepted status.