Commit Graph

33 Commits

Author SHA1 Message Date
fdlamotte
5728463f21 Merge pull request #77 from mwolter805/fix/transport-symmetry
fix: symmetric disconnect signaling, serial timeout, BLE callback, oversize-frame recovery
2026-04-25 15:05:32 +02:00
fdlamotte
2aff27e725 Merge pull request #76 from mwolter805/fix/error-response-handling
fix: add EventType.ERROR to command expected_events and guard error payloads
2026-04-25 15:04:30 +02:00
fdlamotte
1c08569f07 Merge pull request #75 from mwolter805/fix/reconnect-path
fix: resolve reconnect storm — TCP Future return, missing appstart, task overwrite race
2026-04-25 15:02:30 +02:00
fdlamotte
df6cec1d0b Merge pull request #78 from mwolter805/fix/asyncio-lifecycle
fix: track background tasks, defer Queue/Lock construction, use get_running_loop
2026-04-25 15:00:44 +02:00
Matthew Wolter
4fddbffa3d Remove internal references from asyncio lifecycle tests
Rename test_g5_asyncio_lifecycle.py to test_asyncio_lifecycle.py.
Strip G5 from module docstring, finding IDs (F05, F07, F08, F19)
from class names and docstrings.
2026-04-12 07:57:23 -07:00
Matthew Wolter
b4b40718e9 Remove internal references from transport symmetry tests
Rename test_g4_transport_symmetry.py to test_transport_symmetry.py.
Strip G4 from module docstring, _g4_ from function names, and finding
IDs (F04, NEW-A, F18, M06, N04) from docstrings and section comments.
2026-04-12 07:56:48 -07:00
Matthew Wolter
578ac36ccd Remove internal references from error handling tests
Rename test_g2_error_handling.py to test_error_handling.py. Strip G2
prefix from module docstring, _g2_ from function names, and finding
IDs (F22, F21/M01, M02, M04, N06, F14) from docstrings and section
comments. Proposal cross-references removed.
2026-04-12 07:56:06 -07:00
Matthew Wolter
f3aa131019 Remove finding IDs from test_connection_manager.py
Strip internal forensics finding references (F01, F02, F03, N11)
from docstrings and section comments. The descriptive text is
preserved — only the ID prefixes are removed.
2026-04-12 07:54:02 -07:00
Matthew Wolter
9e2fc0d63e Remove internal G-numbering from test_connection_manager.py
Strip G3 from module docstring and _g3_ from function names.
Finding IDs (F01, F02, F03, N11) are preserved.
2026-04-12 07:53:10 -07:00
Matthew Wolter
75c4a58841 Fix test fixture to resolve events immediately instead of blocking
The mock_dispatcher fixture's fake_subscribe recorded event handlers
but never called them, causing asyncio.wait() to block for the full
DEFAULT_TIMEOUT (15s) on every test that passes expected_events to
send(). With 28 affected tests, the suite wasted ~8 minutes on dead
waits and required an undocumented pytest-timeout plugin to complete.

Add call_soon to the default fake_subscribe so futures resolve on the
next event loop iteration, matching the pattern already used by
setup_event_response(). Override with a non-resolving mock in
test_send_timeout to preserve timeout path coverage.

Suite now completes in <1 second with no --timeout flag.
2026-04-12 06:57:53 -07:00
Matthew Wolter
7b459aa6a5 G5: add verification tests for F05, F07, F08, F19
10 new tests in tests/unit/test_g5_asyncio_lifecycle.py:

- TestF05: _spawn_background retains tasks in TCP, Serial, and
  EventDispatcher; tracked tasks survive gc.collect(); TCP handle_rx
  and connection_lost use tracked dispatch.
- TestF07: stop() waits for in-flight async callbacks to complete.
- TestF08: EventDispatcher.queue is None before start(), created on
  start(), dispatch() before start() raises RuntimeError;
  CommandHandlerBase lock is None before access, created lazily.
- TestF19: send() calls get_running_loop (not get_event_loop).

Refs: Forensics report findings F05, F07, F08, F19
2026-04-12 03:57:35 -07:00
Matthew Wolter
f6bc0908b0 G4: add verification tests for F04, NEW-A, F18, M06, F16, F17, N04
10 new tests in tests/unit/test_g4_transport_symmetry.py covering all
G4 findings:

- test_g4_tcp_send_write_error_fires_disconnect (F04): TCP write
  OSError fires _disconnect_callback.
- test_g4_serial_send_no_transport_fires_disconnect (NEW-A): serial
  send on None transport fires _disconnect_callback.
- test_g4_serial_send_write_error_fires_disconnect (F04): serial write
  OSError fires _disconnect_callback.
- test_g4_ble_send_no_client_fires_disconnect (F04): BLE send with no
  client fires _disconnect_callback.
- test_g4_serial_connect_timeout (F18): connect raises TimeoutError
  when connection_made never fires.
- test_g4_tcp_oversize_frame_empty_data_returns (M06): oversize header
  with empty trailing data returns without dispatch.
- test_g4_serial_oversize_frame_empty_data_returns (M06): same for
  serial transport.
- test_g4_tcp_receive_count_per_frame_not_per_segment (N04): 3 TCP
  segments carrying 1 frame yield _receive_count == 1.
- test_g4_tcp_multiple_frames_count_correctly (N04): 2 complete frames
  yield _receive_count == 2.

F16 and F17 are covered by the updated pre-existing test in
tests/test_ble_pin_pairing.py (committed with F17).

Refs: Forensics report findings F04, NEW-A, F18, M06, N04
2026-04-11 20:25:52 -07:00
Matthew Wolter
76e2e54157 G4: F17 — re-raise BLE pairing failure instead of swallowing
Why: When BLE pairing failed during connect(), the exception was caught
as a warning and connect() continued normally. This left the transport
in a half-usable state — the BLE link was up but the pairing handshake
never completed, so encrypted characteristics could silently fail.
Now the pairing exception disconnects the client and re-raises, giving
the caller a clean failure. Updated the pre-existing
test_ble_connection_with_pin_failed_pairing test to assert the re-raise
behavior instead of the old swallow-and-continue behavior.
Refs: Forensics report finding F17
2026-04-11 20:25:04 -07:00
Matthew Wolter
7293933582 G2: add verification tests for F22, F21/M01, M02, M04, N06, F14
12 new tests in tests/unit/test_g2_error_handling.py covering all
G2 findings:

- test_g2_event_is_error_true/false (F22): is_error() helper works.
- test_g2_send_msg_with_retry_error_no_keyerror (F21/M01): retry
  loop continues on ERROR instead of KeyError on missing expected_ack.
- test_g2_send_appstart_returns_error (M02): ERROR event returned
  immediately instead of hanging until timeout.
- test_g2_set_telemetry_mode_base/loc/env_error (M04): setters
  return ERROR instead of KeyError on appstart failure.
- test_g2_set_manual_add_contacts/advert_loc_policy/multi_acks_error
  (M04): remaining three setters return ERROR cleanly.
- test_g2_send_anon_req_contact_not_found (N06): returns ERROR
  instead of TypeError on NoneType subscript.
- test_g2_send_trace_unknown_path_hash_len (F14): returns ERROR
  instead of NameError on undefined 'e'.

Refs: Forensics report findings F22, F21, M01, M02, M04, N06, F14
2026-04-11 20:05:07 -07:00
Matthew Wolter
073fa26aa0 G3: add verification tests for F01, F02, F03, N11
Seven new tests in tests/unit/test_connection_manager.py covering all
four G3 findings:

- test_g3_tcp_connect_returns_plain_string (F01): CONNECTED event
  payload contains a plain string, not an asyncio.Future.
- test_g3_reconnect_loop_does_not_compound (F03): after max_attempts
  failures, exactly that many connect() calls are made — no fan-out.
- test_g3_disconnect_cancels_reconnect_loop (F03): disconnect()
  mid-loop cancels the single task cleanly.
- test_g3_reconnect_callback_called_after_reconnect (F02): callback
  is invoked after a successful reconnect.
- test_g3_reconnect_callback_failure_does_not_crash_loop (F02):
  callback exception is logged, reconnect still succeeds.
- test_g3_connect_none_is_soft_failure (N11): connect() returning
  None does not set _is_connected or emit CONNECTED.
- test_g3_no_reconnect_callback_is_noop (N11/F02): no callback
  provided — reconnect works, backwards-compatible.

Refs: Forensics report findings F01, F02, F03, N11
2026-04-11 19:48:02 -07:00
Alex Wolden
ed96df197a Fix 16 failing unit tests to match current source behavior
- Update mock dispatcher to use subscribe-before-send pattern matching
  the rewritten CommandHandler.send() method
- Use 32-byte pubkeys in tests for commands that now require
  prefix_length=32 (login, logout, statusreq, reset_path, share/export/remove contact)
- Fix send_trace test path format to match flags=1 (2-byte path hashes)
- Update LPP current test to expect signed wrap for values > 32.767
- Fix BinaryReqType import (moved from meshcore.parsing to meshcore.packets)
- Fix register_binary_request call signature (added pubkey_prefix param)
- Update timeout test to expect 'no_event_received' instead of 'timeout'
2026-04-05 18:38:16 -07:00
fdlamotte
52ad5c201c Merge pull request #67 from jkingsman/respect-found-idx
Use the frame start once we've found it
2026-03-22 12:48:11 -04:00
Jack Kingsman
4df3655752 Use the frame start once we've found it 2026-03-21 21:08:04 -07:00
Jack Kingsman
3ad77d364d Fix three byte path packets 2026-03-18 17:31:17 -07:00
jkingsman
1ea32885a3 Add typing to send_chan_message with test 2025-12-23 18:40:59 -08:00
agessaman
e0f71482c6 Add private key export support
- Add PRIVATE_KEY and DISABLED event types
- Add packet parsing for private key export responses
- Add export_private_key() method to DeviceCommands
- Add comprehensive unit tests
- Add BLE private key export example
- Update documentation with security notes
2025-10-12 18:23:32 -07:00
Copilot
29003b94dc Implement BLE PIN pairing support for enhanced security
* Implement BLE pin pairing support with comprehensive tests and documentation
2025-09-24 00:21:30 +02:00
Alex Wolden
ccb1d6eb9e Revert "Refactor command system to be queue based"
This reverts commit 28957a4b60.
2025-09-04 15:08:08 -07:00
fdlamotte
4ce3a6fd9a Merge branch 'main' into feature/refactor 2025-08-06 10:56:24 +02:00
Alex Wolden
43e2cfc724 timing and test fixes 2025-08-05 23:08:17 -07:00
Alex Wolden
968e42c6c8 Add testing workflow 2025-08-05 13:21:30 -07:00
Ventz Petkov
f4d3be1360 Fix: Improved BLE Connection Logic on macOS 2025-08-05 15:52:44 -04:00
Ventz Petkov
36727f4ea3 feat: Refactor binary commands and apply BLE fixes
Refactored the BinaryCommandHandler to align with the other command handlers, inheriting from CommandHandlerBase. This resolves an AttributeError and simplifies the command structure. Moved binary_commands.py into the commands module. Applied fixes to the BLE connection handler based on feedback, improving reliability on macOS and ensuring the device address is correctly handled.
2025-08-05 15:31:54 -04:00
Ventz Petkov
c19fd166f8 Fix: Improved BLE Connection Logic on macOS 2025-08-05 07:50:59 -04:00
Alex Wolden
cca0ca90e9 Add channel commands and fix a lint error 2025-06-01 20:31:37 -07:00
Alex Wolden
6fbf15885d Change contract for commands to return full event 2025-04-14 11:23:10 -07:00
Alex Wolden
52553a41bd Handle error events properly in commands 2025-04-14 09:03:56 -07:00
Alex Wolden
3f7155d913 Added in some unit tests 2025-04-13 22:55:39 -07:00