From 2182de55bb7734b804abd3403570ec45428feece Mon Sep 17 00:00:00 2001 From: Clifford Garwood Date: Fri, 24 Apr 2026 03:16:25 -0400 Subject: [PATCH] fix(matrix): drop needless DeviceID import + mock put_device_id in tests Two adjustments to make CI pass: - In gateway/platforms/matrix.py: `DeviceID` is `NewType("DeviceID", str)`, so passing `client.device_id` directly (already a str) works identically at runtime. The explicit import was cosmetic and tripped CI environments where `mautrix.types` doesn't re-export DeviceID at the expected path ("cannot import name 'DeviceID' from 'mautrix.types' (unknown location)"). - In tests/gateway/test_matrix.py: add `put_device_id` to the hand-written `PgCryptoStore` fake so the three encryption-path tests (test_connect_with_access_token_and_encryption, test_connect_uses_configured_device_id_over_whoami, test_connect_registers_encrypted_event_handler_when_encryption_on) can exercise the new crypto-store binding without AttributeError. --- gateway/platforms/matrix.py | 4 ++-- tests/gateway/test_matrix.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gateway/platforms/matrix.py b/gateway/platforms/matrix.py index 7033e6171a..15589d9910 100644 --- a/gateway/platforms/matrix.py +++ b/gateway/platforms/matrix.py @@ -542,9 +542,9 @@ class MatrixAdapter(BasePlatformAdapter): # no megolm sessions ever land. Setting _device_id here # (in-memory; the on-disk row may not exist yet) makes # the first put_account write the correct value. + # DeviceID is a NewType(str) so plain str works at runtime. if client.device_id: - from mautrix.types import DeviceID as _DeviceID - await crypto_store.put_device_id(_DeviceID(client.device_id)) + await crypto_store.put_device_id(client.device_id) crypto_state = _CryptoStateStore(state_store, self._joined_rooms) olm = OlmMachine(client, crypto_store, crypto_state) diff --git a/tests/gateway/test_matrix.py b/tests/gateway/test_matrix.py index a088ad9ba8..50a8a66756 100644 --- a/tests/gateway/test_matrix.py +++ b/tests/gateway/test_matrix.py @@ -197,10 +197,14 @@ def _make_fake_mautrix(): self.account_id = account_id self.pickle_key = pickle_key self.db = db + self._device_id = "" async def open(self): pass + async def put_device_id(self, device_id): + self._device_id = device_id + mautrix_crypto_store_asyncpg.PgCryptoStore = PgCryptoStore # --- mautrix.util ---