test(core): fix `test_emu_sanity` on T3W1 non-debug emulators
What changed, and why it matters
This commit fixes an internal test helper so that non-debug Trezor emulator builds can complete a basic sanity check. It is purely a test-infrastructure change and does not affect the firmware that runs on real devices or any user-facing security behavior.
No security action required; this is a test-only fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change adds a new DebugLinkNotFound exception and makes the Emulator wrapper catch it when TrezorClientDebugLink cannot open a debug transport. Previously, the debuglink code only logged a warning when ping failed; now it raises DebugLinkNotFound, and emulator.py catches that exception during start() so that test_emu_sanity can run against non-debug T3W1 emulators. No cryptographic, transport, or device logic is modified.
Changed components
python/src/trezorlib/_internal/emulator.pypython/src/trezorlib/debuglink.pyInspect captured patch +16 / −8
diff --git a/python/src/trezorlib/_internal/emulator.py b/python/src/trezorlib/_internal/emulator.py
index ce501a0a1..7ccce1243 100644
--- a/python/src/trezorlib/_internal/emulator.py
+++ b/python/src/trezorlib/_internal/emulator.py
@@ -22,7 +22,7 @@ import time
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Sequence, TextIO, Union, cast
-from ..debuglink import TrezorClientDebugLink
+from ..debuglink import DebugLinkNotFound, TrezorClientDebugLink
from ..transport import Transport
from ..transport.udp import UdpTransport
@@ -194,12 +194,16 @@ class Emulator:
(self.profile_dir / "trezor.pid").write_text(str(self.process.pid) + "\n")
(self.profile_dir / "trezor.port").write_text(str(self.port) + "\n")
- self._client = TrezorClientDebugLink(
- self.transport,
- auto_interact=self.auto_interact,
- open_transport=True,
- debug_transport=debug_transport,
- )
+ try:
+ self._client = TrezorClientDebugLink(
+ self.transport,
+ auto_interact=self.auto_interact,
+ open_transport=True,
+ debug_transport=debug_transport,
+ )
+ except DebugLinkNotFound as e:
+ # Don't fail `start()` to allow non-debug emulator sanity test.
+ LOG.warning("DebugLink not found: %s", e)
def stop(self) -> None:
if self._client:
diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py
index f87fcc417..86f973201 100644
--- a/python/src/trezorlib/debuglink.py
+++ b/python/src/trezorlib/debuglink.py
@@ -1245,6 +1245,10 @@ class SessionDebugWrapper(Session):
self.refresh_features()
+class DebugLinkNotFound(Exception):
+ pass
+
+
class TrezorClientDebugLink(TrezorClient):
# This class implements automatic responses
# and other functionality for unit tests
@@ -1277,7 +1281,7 @@ class TrezorClientDebugLink(TrezorClient):
self.debug.open()
# try to open debuglink, see if it works
if not self.debug.transport.ping():
- LOG.warning("DebugLink is not available")
+ raise DebugLinkNotFound(self.debug.transport.get_path())
except Exception:
if not auto_interact:
Why this scored 15/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.