test(core): don't fail codec_v1 `sync_responses()` on unexpected magic
What changed, and why it matters
This is a small test-infrastructure change for the Trezor hardware wallet. It makes the test harness more tolerant of unexpected protocol responses and logs the full error trace instead of immediately stopping the entire pytest session. It does not change the device firmware or how real user transactions are validated; it only affects automated testing of the older protocol-v1 communication code.
No security action required. Treat as a normal test-maintenance commit. Reviewers may optionally confirm that `_ignore_bad_magic=True` does not mask genuine protocol errors in production code paths, but the flag is only used inside the test helper `sync_responses()`.
Security signals we found
Change is confined to test framework and host-side Python test library
No firmware or cryptographic code is modified
No privilege boundary, authentication, or asset-handling logic is changed
No changelog entry, consistent with a minor test fix
Evidence from the diff
The commit modifies python/src/trezorlib/protocol_v1.py so that sync_responses() calls read(transport, _ignore_bad_magic=True), and updates tests/conftest.py to log the exception traceback before marking the pytest session as failed. The change prevents a single unexpected/malformed response from aborting the whole test run. It is a test-only quality-of-life fix with no apparent security boundary change.
Changed components
python/src/trezorlib/protocol_v1.pytests/conftest.pyInspect captured patch +5 / −3
diff --git a/python/src/trezorlib/protocol_v1.py b/python/src/trezorlib/protocol_v1.py
index dbf541e0..692f20eb 100644
--- a/python/src/trezorlib/protocol_v1.py
+++ b/python/src/trezorlib/protocol_v1.py
@@ -392,7 +392,7 @@ def sync_responses(
write(transport, *ping_msg)
for _ in range(retries):
- resp_type, resp_bytes = read(transport)
+ resp_type, resp_bytes = read(transport, _ignore_bad_magic=True)
resp = mapping.decode(resp_type, resp_bytes)
if isinstance(resp, messages.Success) and resp.message == sync_string:
return
diff --git a/tests/conftest.py b/tests/conftest.py
index d39c4326..c6dea67b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -358,8 +358,10 @@ def _prepared_test_ctx(
try:
_raw_test_ctx.sync_responses()
except Exception:
- request.session.shouldstop = "Failed to communicate with Trezor"
- pytest.fail("Failed to communicate with Trezor")
+ msg = "Failed to communicate with Trezor"
+ LOG.exception(msg)
+ request.session.shouldstop = msg
+ pytest.fail(msg)
# Use DebugLink to wipe (since THP channel requires unlocked device)
_raw_test_ctx.wipe_device()
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.