hookbridge 2.1.1__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hookbridge-2.1.1 → hookbridge-2.2.0}/PKG-INFO +22 -1
- {hookbridge-2.1.1 → hookbridge-2.2.0}/README.md +21 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/hookbridge/__init__.py +12 -2
- hookbridge-2.2.0/hookbridge/_version.py +1 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/hookbridge/client.py +144 -2
- {hookbridge-2.1.1 → hookbridge-2.2.0}/hookbridge/types.py +29 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/pyproject.toml +1 -1
- hookbridge-2.2.0/tests/test_dry_run_actions.py +169 -0
- hookbridge-2.2.0/tests/test_version.py +42 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/.claude/settings.local.json +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/.gitignore +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/hookbridge/errors.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/hookbridge/py.typed +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/requirements-dev.txt +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/requirements.txt +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/__init__.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/conftest.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/test_async_client.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/test_client.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/test_client_spec_parity.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/test_errors.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/test_openapi_sync_2026_11.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/test_positional_compat.py +0 -0
- {hookbridge-2.1.1 → hookbridge-2.2.0}/tests/test_removed_session_only_methods.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: hookbridge
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Official HookBridge SDK for Python
|
|
5
5
|
Project-URL: Homepage, https://hookbridge.io
|
|
6
6
|
Project-URL: Documentation, https://hookbridge.io/docs/sdks/python
|
|
@@ -165,6 +165,27 @@ for msg in dlq.messages:
|
|
|
165
165
|
client.replay_from_dlq(msg.message_id)
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
+
### Dry-Run a Bulk Replay
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
preview = client.replay_all_messages_dry_run(status="failed_permanent")
|
|
172
|
+
print(f"Would replay {preview.would_replay} messages")
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Use `replay_all_inbound_messages_dry_run` for inbound messages.
|
|
176
|
+
|
|
177
|
+
### List Message Actions
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
page = client.list_message_actions(message_id, limit=50)
|
|
181
|
+
for action in page.actions:
|
|
182
|
+
print(action.action, action.via, action.created_at)
|
|
183
|
+
if page.has_more:
|
|
184
|
+
page = client.list_message_actions(message_id, cursor=page.next_cursor)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Use `list_inbound_message_actions` for inbound messages.
|
|
188
|
+
|
|
168
189
|
### Manage Retries
|
|
169
190
|
|
|
170
191
|
```python
|
|
@@ -130,6 +130,27 @@ for msg in dlq.messages:
|
|
|
130
130
|
client.replay_from_dlq(msg.message_id)
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
### Dry-Run a Bulk Replay
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
preview = client.replay_all_messages_dry_run(status="failed_permanent")
|
|
137
|
+
print(f"Would replay {preview.would_replay} messages")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Use `replay_all_inbound_messages_dry_run` for inbound messages.
|
|
141
|
+
|
|
142
|
+
### List Message Actions
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
page = client.list_message_actions(message_id, limit=50)
|
|
146
|
+
for action in page.actions:
|
|
147
|
+
print(action.action, action.via, action.created_at)
|
|
148
|
+
if page.has_more:
|
|
149
|
+
page = client.list_message_actions(message_id, cursor=page.next_cursor)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Use `list_inbound_message_actions` for inbound messages.
|
|
153
|
+
|
|
133
154
|
### Manage Retries
|
|
134
155
|
|
|
135
156
|
```python
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
HookBridge SDK for Python.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
from hookbridge._version import __version__
|
|
5
6
|
from hookbridge.client import AsyncHookBridge, HookBridge
|
|
6
7
|
from hookbridge.errors import (
|
|
7
8
|
AuthenticationError,
|
|
@@ -58,8 +59,12 @@ from hookbridge.types import (
|
|
|
58
59
|
ListenInboundEndpointResponse,
|
|
59
60
|
ListenMessage,
|
|
60
61
|
ListInboundEndpointsResponse,
|
|
62
|
+
ListMessageActionsResponse,
|
|
61
63
|
LogsResponse,
|
|
62
64
|
Message,
|
|
65
|
+
MessageAction,
|
|
66
|
+
MessageActionType,
|
|
67
|
+
MessageActionVia,
|
|
63
68
|
MessageStatus,
|
|
64
69
|
MessageSummary,
|
|
65
70
|
Metrics,
|
|
@@ -80,6 +85,7 @@ from hookbridge.types import (
|
|
|
80
85
|
PullTimeSeriesMetrics,
|
|
81
86
|
PullTimingBreakdown,
|
|
82
87
|
ReplayableMessageStatus,
|
|
88
|
+
ReplayAllDryRunResponse,
|
|
83
89
|
ReplayAllMessagesResponse,
|
|
84
90
|
ReplayBatchMessagesResponse,
|
|
85
91
|
ReplayBatchResult,
|
|
@@ -98,9 +104,8 @@ from hookbridge.types import (
|
|
|
98
104
|
UsageHistoryRow,
|
|
99
105
|
)
|
|
100
106
|
|
|
101
|
-
__version__ = "2.1.1"
|
|
102
|
-
|
|
103
107
|
__all__ = [
|
|
108
|
+
"__version__",
|
|
104
109
|
"HookBridge",
|
|
105
110
|
"AsyncHookBridge",
|
|
106
111
|
"APIKeyInfo",
|
|
@@ -166,7 +171,12 @@ __all__ = [
|
|
|
166
171
|
"PullTimeSeriesBucket",
|
|
167
172
|
"PullTimeSeriesMetrics",
|
|
168
173
|
"PullTimingBreakdown",
|
|
174
|
+
"ReplayAllDryRunResponse",
|
|
169
175
|
"ReplayAllMessagesResponse",
|
|
176
|
+
"ListMessageActionsResponse",
|
|
177
|
+
"MessageAction",
|
|
178
|
+
"MessageActionType",
|
|
179
|
+
"MessageActionVia",
|
|
170
180
|
"ReplayBatchMessagesResponse",
|
|
171
181
|
"ReplayBatchResult",
|
|
172
182
|
"ReplayErrorCode",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.2.0"
|
|
@@ -6,10 +6,11 @@ import os
|
|
|
6
6
|
import time
|
|
7
7
|
from datetime import date, datetime
|
|
8
8
|
from typing import Any, Optional, Union
|
|
9
|
-
from urllib.parse import urlencode
|
|
9
|
+
from urllib.parse import quote, urlencode
|
|
10
10
|
|
|
11
11
|
import httpx
|
|
12
12
|
|
|
13
|
+
from hookbridge._version import __version__
|
|
13
14
|
from hookbridge.errors import (
|
|
14
15
|
AuthenticationError,
|
|
15
16
|
HookBridgeError,
|
|
@@ -63,10 +64,12 @@ from hookbridge.types import (
|
|
|
63
64
|
ListenInboundEndpointResponse,
|
|
64
65
|
ListenMessage,
|
|
65
66
|
ListInboundEndpointsResponse,
|
|
67
|
+
ListMessageActionsResponse,
|
|
66
68
|
ListPullEndpointsResponse,
|
|
67
69
|
ListPullEventsResponse,
|
|
68
70
|
LogsResponse,
|
|
69
71
|
Message,
|
|
72
|
+
MessageAction,
|
|
70
73
|
MessageStatus,
|
|
71
74
|
MessageSummary,
|
|
72
75
|
Metrics,
|
|
@@ -85,6 +88,7 @@ from hookbridge.types import (
|
|
|
85
88
|
PullTimeSeriesMetrics,
|
|
86
89
|
PullTimingBreakdown,
|
|
87
90
|
ReplayableMessageStatus,
|
|
91
|
+
ReplayAllDryRunResponse,
|
|
88
92
|
ReplayAllMessagesResponse,
|
|
89
93
|
ReplayBatchMessagesResponse,
|
|
90
94
|
ReplayBatchResult,
|
|
@@ -330,6 +334,30 @@ def _parse_replay_all_messages(data: dict[str, Any]) -> ReplayAllMessagesRespons
|
|
|
330
334
|
)
|
|
331
335
|
|
|
332
336
|
|
|
337
|
+
def _parse_replay_all_dry_run(data: dict[str, Any]) -> ReplayAllDryRunResponse:
|
|
338
|
+
return ReplayAllDryRunResponse(would_replay=data["would_replay"])
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _parse_message_actions(response: dict[str, Any]) -> ListMessageActionsResponse:
|
|
342
|
+
meta = response.get("meta", {})
|
|
343
|
+
return ListMessageActionsResponse(
|
|
344
|
+
actions=[
|
|
345
|
+
MessageAction(
|
|
346
|
+
id=item["id"],
|
|
347
|
+
action=item["action"],
|
|
348
|
+
user_id=item.get("user_id"),
|
|
349
|
+
api_key_id=item.get("api_key_id"),
|
|
350
|
+
via=item["via"],
|
|
351
|
+
client_name=item.get("client_name"),
|
|
352
|
+
created_at=_parse_datetime(item["created_at"]),
|
|
353
|
+
)
|
|
354
|
+
for item in response.get("data", [])
|
|
355
|
+
],
|
|
356
|
+
has_more=meta.get("has_more", False),
|
|
357
|
+
next_cursor=meta.get("next_cursor"),
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
|
|
333
361
|
def _parse_replay_batch_messages(data: dict[str, Any]) -> ReplayBatchMessagesResponse:
|
|
334
362
|
return ReplayBatchMessagesResponse(
|
|
335
363
|
replayed=data["replayed"],
|
|
@@ -773,7 +801,7 @@ def _build_common_headers(api_key: str) -> dict[str, str]:
|
|
|
773
801
|
"Authorization": f"Bearer {api_key}",
|
|
774
802
|
"Content-Type": "application/json",
|
|
775
803
|
"Accept": "application/json",
|
|
776
|
-
"User-Agent": "hookbridge-python/
|
|
804
|
+
"User-Agent": f"hookbridge-python/{__version__}",
|
|
777
805
|
}
|
|
778
806
|
|
|
779
807
|
|
|
@@ -887,6 +915,32 @@ class HookBridge:
|
|
|
887
915
|
)
|
|
888
916
|
return _parse_replay_all_messages(self._request("POST", path)["data"])
|
|
889
917
|
|
|
918
|
+
def replay_all_messages_dry_run(
|
|
919
|
+
self,
|
|
920
|
+
*,
|
|
921
|
+
status: ReplayableMessageStatus,
|
|
922
|
+
endpoint_id: Optional[str] = None,
|
|
923
|
+
limit: Optional[int] = None,
|
|
924
|
+
) -> ReplayAllDryRunResponse:
|
|
925
|
+
path = _with_query(
|
|
926
|
+
"/v1/messages/replay-all",
|
|
927
|
+
{"status": status, "endpoint_id": endpoint_id, "limit": limit, "dry_run": "true"},
|
|
928
|
+
)
|
|
929
|
+
return _parse_replay_all_dry_run(self._request("POST", path)["data"])
|
|
930
|
+
|
|
931
|
+
def list_message_actions(
|
|
932
|
+
self,
|
|
933
|
+
message_id: str,
|
|
934
|
+
*,
|
|
935
|
+
cursor: Optional[str] = None,
|
|
936
|
+
limit: Optional[int] = None,
|
|
937
|
+
) -> ListMessageActionsResponse:
|
|
938
|
+
path = _with_query(
|
|
939
|
+
f"/v1/messages/{quote(message_id, safe='')}/actions",
|
|
940
|
+
{"cursor": cursor, "limit": limit},
|
|
941
|
+
)
|
|
942
|
+
return _parse_message_actions(self._request("GET", path))
|
|
943
|
+
|
|
890
944
|
def replay_batch_messages(self, message_ids: list[str]) -> ReplayBatchMessagesResponse:
|
|
891
945
|
response = self._request(
|
|
892
946
|
"POST", "/v1/messages/replay-batch", json={"message_ids": message_ids}
|
|
@@ -1465,6 +1519,37 @@ class HookBridge:
|
|
|
1465
1519
|
)
|
|
1466
1520
|
return _parse_replay_all_messages(self._request("POST", path)["data"])
|
|
1467
1521
|
|
|
1522
|
+
def replay_all_inbound_messages_dry_run(
|
|
1523
|
+
self,
|
|
1524
|
+
*,
|
|
1525
|
+
status: ReplayableMessageStatus,
|
|
1526
|
+
inbound_endpoint_id: Optional[str] = None,
|
|
1527
|
+
limit: Optional[int] = None,
|
|
1528
|
+
) -> ReplayAllDryRunResponse:
|
|
1529
|
+
path = _with_query(
|
|
1530
|
+
"/v1/inbound-messages/replay-all",
|
|
1531
|
+
{
|
|
1532
|
+
"status": status,
|
|
1533
|
+
"inbound_endpoint_id": inbound_endpoint_id,
|
|
1534
|
+
"limit": limit,
|
|
1535
|
+
"dry_run": "true",
|
|
1536
|
+
},
|
|
1537
|
+
)
|
|
1538
|
+
return _parse_replay_all_dry_run(self._request("POST", path)["data"])
|
|
1539
|
+
|
|
1540
|
+
def list_inbound_message_actions(
|
|
1541
|
+
self,
|
|
1542
|
+
message_id: str,
|
|
1543
|
+
*,
|
|
1544
|
+
cursor: Optional[str] = None,
|
|
1545
|
+
limit: Optional[int] = None,
|
|
1546
|
+
) -> ListMessageActionsResponse:
|
|
1547
|
+
path = _with_query(
|
|
1548
|
+
f"/v1/inbound-messages/{quote(message_id, safe='')}/actions",
|
|
1549
|
+
{"cursor": cursor, "limit": limit},
|
|
1550
|
+
)
|
|
1551
|
+
return _parse_message_actions(self._request("GET", path))
|
|
1552
|
+
|
|
1468
1553
|
def replay_batch_inbound_messages(self, message_ids: list[str]) -> ReplayBatchMessagesResponse:
|
|
1469
1554
|
response = self._request(
|
|
1470
1555
|
"POST", "/v1/inbound-messages/replay-batch", json={"message_ids": message_ids}
|
|
@@ -1836,6 +1921,32 @@ class AsyncHookBridge:
|
|
|
1836
1921
|
)
|
|
1837
1922
|
return _parse_replay_all_messages((await self._request("POST", path))["data"])
|
|
1838
1923
|
|
|
1924
|
+
async def replay_all_messages_dry_run(
|
|
1925
|
+
self,
|
|
1926
|
+
*,
|
|
1927
|
+
status: ReplayableMessageStatus,
|
|
1928
|
+
endpoint_id: Optional[str] = None,
|
|
1929
|
+
limit: Optional[int] = None,
|
|
1930
|
+
) -> ReplayAllDryRunResponse:
|
|
1931
|
+
path = _with_query(
|
|
1932
|
+
"/v1/messages/replay-all",
|
|
1933
|
+
{"status": status, "endpoint_id": endpoint_id, "limit": limit, "dry_run": "true"},
|
|
1934
|
+
)
|
|
1935
|
+
return _parse_replay_all_dry_run((await self._request("POST", path))["data"])
|
|
1936
|
+
|
|
1937
|
+
async def list_message_actions(
|
|
1938
|
+
self,
|
|
1939
|
+
message_id: str,
|
|
1940
|
+
*,
|
|
1941
|
+
cursor: Optional[str] = None,
|
|
1942
|
+
limit: Optional[int] = None,
|
|
1943
|
+
) -> ListMessageActionsResponse:
|
|
1944
|
+
path = _with_query(
|
|
1945
|
+
f"/v1/messages/{quote(message_id, safe='')}/actions",
|
|
1946
|
+
{"cursor": cursor, "limit": limit},
|
|
1947
|
+
)
|
|
1948
|
+
return _parse_message_actions(await self._request("GET", path))
|
|
1949
|
+
|
|
1839
1950
|
async def replay_batch_messages(self, message_ids: list[str]) -> ReplayBatchMessagesResponse:
|
|
1840
1951
|
response = await self._request(
|
|
1841
1952
|
"POST", "/v1/messages/replay-batch", json={"message_ids": message_ids}
|
|
@@ -2429,6 +2540,37 @@ class AsyncHookBridge:
|
|
|
2429
2540
|
)
|
|
2430
2541
|
return _parse_replay_all_messages((await self._request("POST", path))["data"])
|
|
2431
2542
|
|
|
2543
|
+
async def replay_all_inbound_messages_dry_run(
|
|
2544
|
+
self,
|
|
2545
|
+
*,
|
|
2546
|
+
status: ReplayableMessageStatus,
|
|
2547
|
+
inbound_endpoint_id: Optional[str] = None,
|
|
2548
|
+
limit: Optional[int] = None,
|
|
2549
|
+
) -> ReplayAllDryRunResponse:
|
|
2550
|
+
path = _with_query(
|
|
2551
|
+
"/v1/inbound-messages/replay-all",
|
|
2552
|
+
{
|
|
2553
|
+
"status": status,
|
|
2554
|
+
"inbound_endpoint_id": inbound_endpoint_id,
|
|
2555
|
+
"limit": limit,
|
|
2556
|
+
"dry_run": "true",
|
|
2557
|
+
},
|
|
2558
|
+
)
|
|
2559
|
+
return _parse_replay_all_dry_run((await self._request("POST", path))["data"])
|
|
2560
|
+
|
|
2561
|
+
async def list_inbound_message_actions(
|
|
2562
|
+
self,
|
|
2563
|
+
message_id: str,
|
|
2564
|
+
*,
|
|
2565
|
+
cursor: Optional[str] = None,
|
|
2566
|
+
limit: Optional[int] = None,
|
|
2567
|
+
) -> ListMessageActionsResponse:
|
|
2568
|
+
path = _with_query(
|
|
2569
|
+
f"/v1/inbound-messages/{quote(message_id, safe='')}/actions",
|
|
2570
|
+
{"cursor": cursor, "limit": limit},
|
|
2571
|
+
)
|
|
2572
|
+
return _parse_message_actions(await self._request("GET", path))
|
|
2573
|
+
|
|
2432
2574
|
async def replay_batch_inbound_messages(
|
|
2433
2575
|
self, message_ids: list[str]
|
|
2434
2576
|
) -> ReplayBatchMessagesResponse:
|
|
@@ -254,6 +254,35 @@ class ReplayAllMessagesResponse:
|
|
|
254
254
|
stuck_message_ids: list[str]
|
|
255
255
|
|
|
256
256
|
|
|
257
|
+
@dataclass(frozen=True)
|
|
258
|
+
class ReplayAllDryRunResponse:
|
|
259
|
+
would_replay: int
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
MessageActionType = Literal[
|
|
263
|
+
"replay", "retry_now", "cancel", "replay_batch", "replay_all", "dlq_replay"
|
|
264
|
+
]
|
|
265
|
+
MessageActionVia = Literal["console", "api", "mcp-local", "mcp-hosted"]
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@dataclass(frozen=True)
|
|
269
|
+
class MessageAction:
|
|
270
|
+
id: str
|
|
271
|
+
action: MessageActionType
|
|
272
|
+
user_id: Optional[str]
|
|
273
|
+
api_key_id: Optional[str]
|
|
274
|
+
via: MessageActionVia
|
|
275
|
+
client_name: Optional[str]
|
|
276
|
+
created_at: datetime
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
@dataclass(frozen=True)
|
|
280
|
+
class ListMessageActionsResponse:
|
|
281
|
+
actions: list[MessageAction]
|
|
282
|
+
has_more: bool
|
|
283
|
+
next_cursor: Optional[str] = None
|
|
284
|
+
|
|
285
|
+
|
|
257
286
|
@dataclass(frozen=True)
|
|
258
287
|
class ReplayBatchResult:
|
|
259
288
|
message_id: str
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for replay-all dry run and message action listing (sync and async).
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
|
|
7
|
+
from pytest_httpx import HTTPXMock
|
|
8
|
+
|
|
9
|
+
from hookbridge import AsyncHookBridge, HookBridge
|
|
10
|
+
|
|
11
|
+
ENDPOINT_ID = "ep_550e8400e29b41d4a716446655440000"
|
|
12
|
+
INBOUND_ENDPOINT_ID = "01935abc-def0-7123-4567-890abcdef099"
|
|
13
|
+
|
|
14
|
+
ACTIONS_BODY = {
|
|
15
|
+
"data": [
|
|
16
|
+
{
|
|
17
|
+
"id": "0190a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b",
|
|
18
|
+
"action": "replay",
|
|
19
|
+
"user_id": None,
|
|
20
|
+
"api_key_id": "01935abc-def0-7123-4567-890abcdef0aa",
|
|
21
|
+
"via": "mcp-local",
|
|
22
|
+
"client_name": "Claude Desktop",
|
|
23
|
+
"created_at": "2026-11-18T10:11:12.345Z",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "0190a1b2-0000-7e5f-8a9b-0c1d2e3f4a5b",
|
|
27
|
+
"action": "retry_now",
|
|
28
|
+
"user_id": "6d1f0a52-2a43-4a4e-9d1e-3f4f6b7c8d90",
|
|
29
|
+
"api_key_id": None,
|
|
30
|
+
"via": "console",
|
|
31
|
+
"client_name": None,
|
|
32
|
+
"created_at": "2026-11-18T09:00:00.000Z",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
"meta": {"request_id": "req_1", "has_more": True, "next_cursor": "cur_2"},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _dry_run_body(n: int) -> dict:
|
|
40
|
+
return {"data": {"would_replay": n}, "meta": {"request_id": "req_1"}}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _assert_actions(result) -> None: # type: ignore[no-untyped-def]
|
|
44
|
+
assert result.has_more is True
|
|
45
|
+
assert result.next_cursor == "cur_2"
|
|
46
|
+
first, second = result.actions
|
|
47
|
+
assert first.id == "0190a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b"
|
|
48
|
+
assert first.action == "replay"
|
|
49
|
+
assert first.user_id is None
|
|
50
|
+
assert first.api_key_id == "01935abc-def0-7123-4567-890abcdef0aa"
|
|
51
|
+
assert first.via == "mcp-local"
|
|
52
|
+
assert first.client_name == "Claude Desktop"
|
|
53
|
+
assert first.created_at == datetime(2026, 11, 18, 10, 11, 12, 345000, tzinfo=UTC)
|
|
54
|
+
assert second.user_id == "6d1f0a52-2a43-4a4e-9d1e-3f4f6b7c8d90"
|
|
55
|
+
assert second.api_key_id is None
|
|
56
|
+
assert second.client_name is None
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class TestSyncDryRun:
|
|
60
|
+
def test_outbound(self, client: HookBridge, httpx_mock: HTTPXMock) -> None:
|
|
61
|
+
httpx_mock.add_response(
|
|
62
|
+
method="POST",
|
|
63
|
+
url=(
|
|
64
|
+
f"{client._base_url}/v1/messages/replay-all"
|
|
65
|
+
f"?status=failed_permanent&endpoint_id={ENDPOINT_ID}&limit=50&dry_run=true"
|
|
66
|
+
),
|
|
67
|
+
json=_dry_run_body(7),
|
|
68
|
+
)
|
|
69
|
+
result = client.replay_all_messages_dry_run(
|
|
70
|
+
status="failed_permanent", endpoint_id=ENDPOINT_ID, limit=50
|
|
71
|
+
)
|
|
72
|
+
assert result.would_replay == 7
|
|
73
|
+
|
|
74
|
+
def test_inbound(self, client: HookBridge, httpx_mock: HTTPXMock) -> None:
|
|
75
|
+
httpx_mock.add_response(
|
|
76
|
+
method="POST",
|
|
77
|
+
url=(
|
|
78
|
+
f"{client._base_url}/v1/inbound-messages/replay-all"
|
|
79
|
+
f"?status=pending_retry&inbound_endpoint_id={INBOUND_ENDPOINT_ID}&dry_run=true"
|
|
80
|
+
),
|
|
81
|
+
json=_dry_run_body(3),
|
|
82
|
+
)
|
|
83
|
+
result = client.replay_all_inbound_messages_dry_run(
|
|
84
|
+
status="pending_retry", inbound_endpoint_id=INBOUND_ENDPOINT_ID
|
|
85
|
+
)
|
|
86
|
+
assert result.would_replay == 3
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class TestSyncActions:
|
|
90
|
+
def test_list_message_actions(self, client: HookBridge, httpx_mock: HTTPXMock) -> None:
|
|
91
|
+
httpx_mock.add_response(
|
|
92
|
+
method="GET",
|
|
93
|
+
url=f"{client._base_url}/v1/messages/msg_1/actions?cursor=cur_1&limit=2",
|
|
94
|
+
json=ACTIONS_BODY,
|
|
95
|
+
)
|
|
96
|
+
_assert_actions(client.list_message_actions("msg_1", cursor="cur_1", limit=2))
|
|
97
|
+
|
|
98
|
+
def test_list_message_actions_encodes_id_and_defaults(
|
|
99
|
+
self, client: HookBridge, httpx_mock: HTTPXMock
|
|
100
|
+
) -> None:
|
|
101
|
+
httpx_mock.add_response(
|
|
102
|
+
method="GET",
|
|
103
|
+
url=f"{client._base_url}/v1/messages/a%2Fb/actions",
|
|
104
|
+
json={"data": [], "meta": {"has_more": False}},
|
|
105
|
+
)
|
|
106
|
+
result = client.list_message_actions("a/b")
|
|
107
|
+
assert result.actions == []
|
|
108
|
+
assert result.has_more is False
|
|
109
|
+
assert result.next_cursor is None
|
|
110
|
+
|
|
111
|
+
def test_list_inbound_message_actions(self, client: HookBridge, httpx_mock: HTTPXMock) -> None:
|
|
112
|
+
httpx_mock.add_response(
|
|
113
|
+
method="GET",
|
|
114
|
+
url=f"{client._base_url}/v1/inbound-messages/a%2Fb/actions?limit=2",
|
|
115
|
+
json=ACTIONS_BODY,
|
|
116
|
+
)
|
|
117
|
+
_assert_actions(client.list_inbound_message_actions("a/b", limit=2))
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class TestAsyncDryRun:
|
|
121
|
+
async def test_outbound(self, async_client: AsyncHookBridge, httpx_mock: HTTPXMock) -> None:
|
|
122
|
+
httpx_mock.add_response(
|
|
123
|
+
method="POST",
|
|
124
|
+
url=(
|
|
125
|
+
f"{async_client._base_url}/v1/messages/replay-all"
|
|
126
|
+
f"?status=failed_permanent&endpoint_id={ENDPOINT_ID}&limit=50&dry_run=true"
|
|
127
|
+
),
|
|
128
|
+
json=_dry_run_body(7),
|
|
129
|
+
)
|
|
130
|
+
result = await async_client.replay_all_messages_dry_run(
|
|
131
|
+
status="failed_permanent", endpoint_id=ENDPOINT_ID, limit=50
|
|
132
|
+
)
|
|
133
|
+
assert result.would_replay == 7
|
|
134
|
+
|
|
135
|
+
async def test_inbound(self, async_client: AsyncHookBridge, httpx_mock: HTTPXMock) -> None:
|
|
136
|
+
httpx_mock.add_response(
|
|
137
|
+
method="POST",
|
|
138
|
+
url=(
|
|
139
|
+
f"{async_client._base_url}/v1/inbound-messages/replay-all"
|
|
140
|
+
f"?status=pending_retry&inbound_endpoint_id={INBOUND_ENDPOINT_ID}&dry_run=true"
|
|
141
|
+
),
|
|
142
|
+
json=_dry_run_body(3),
|
|
143
|
+
)
|
|
144
|
+
result = await async_client.replay_all_inbound_messages_dry_run(
|
|
145
|
+
status="pending_retry", inbound_endpoint_id=INBOUND_ENDPOINT_ID
|
|
146
|
+
)
|
|
147
|
+
assert result.would_replay == 3
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class TestAsyncActions:
|
|
151
|
+
async def test_list_message_actions(
|
|
152
|
+
self, async_client: AsyncHookBridge, httpx_mock: HTTPXMock
|
|
153
|
+
) -> None:
|
|
154
|
+
httpx_mock.add_response(
|
|
155
|
+
method="GET",
|
|
156
|
+
url=f"{async_client._base_url}/v1/messages/a%2Fb/actions?cursor=cur_1&limit=2",
|
|
157
|
+
json=ACTIONS_BODY,
|
|
158
|
+
)
|
|
159
|
+
_assert_actions(await async_client.list_message_actions("a/b", cursor="cur_1", limit=2))
|
|
160
|
+
|
|
161
|
+
async def test_list_inbound_message_actions(
|
|
162
|
+
self, async_client: AsyncHookBridge, httpx_mock: HTTPXMock
|
|
163
|
+
) -> None:
|
|
164
|
+
httpx_mock.add_response(
|
|
165
|
+
method="GET",
|
|
166
|
+
url=f"{async_client._base_url}/v1/inbound-messages/msg_1/actions",
|
|
167
|
+
json=ACTIONS_BODY,
|
|
168
|
+
)
|
|
169
|
+
_assert_actions(await async_client.list_inbound_message_actions("msg_1"))
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Version consistency tests."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import hookbridge
|
|
7
|
+
from hookbridge import AsyncHookBridge, HookBridge
|
|
8
|
+
|
|
9
|
+
PYPROJECT = Path(__file__).resolve().parent.parent / "pyproject.toml"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _pyproject_version() -> str:
|
|
13
|
+
text = PYPROJECT.read_text()
|
|
14
|
+
try:
|
|
15
|
+
import tomllib
|
|
16
|
+
except ImportError:
|
|
17
|
+
match = re.search(r'^version\s*=\s*"([^"]+)"', text, re.MULTILINE)
|
|
18
|
+
assert match is not None
|
|
19
|
+
return match.group(1)
|
|
20
|
+
version: str = tomllib.loads(text)["project"]["version"]
|
|
21
|
+
return version
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_dunder_version_matches_pyproject() -> None:
|
|
25
|
+
assert hookbridge.__version__ == _pyproject_version()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_sync_client_user_agent_matches_version() -> None:
|
|
29
|
+
with HookBridge(api_key="hb_test_key") as client:
|
|
30
|
+
expected = f"hookbridge-python/{_pyproject_version()}"
|
|
31
|
+
assert client._client.headers["User-Agent"] == expected
|
|
32
|
+
assert client._send_client.headers["User-Agent"] == expected
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async def test_async_client_user_agent_matches_version() -> None:
|
|
36
|
+
client = AsyncHookBridge(api_key="hb_test_key")
|
|
37
|
+
try:
|
|
38
|
+
expected = f"hookbridge-python/{_pyproject_version()}"
|
|
39
|
+
assert client._client.headers["User-Agent"] == expected
|
|
40
|
+
assert client._send_client.headers["User-Agent"] == expected
|
|
41
|
+
finally:
|
|
42
|
+
await client.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|