holon-sh 0.0.1.dev14__tar.gz → 0.0.1.dev16__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.
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/PKG-INFO +1 -1
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/events/_server.py +23 -34
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/pyproject.toml +1 -1
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/tests/test_events.py +80 -58
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/tests/test_package.py +9 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/.gitignore +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/LICENSE +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/README.md +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/client.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/context.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/__init__.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/events/__init__.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/events/_client.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/events/_wire.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/files/__init__.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/files/_client.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/files/_server.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/ext/files/_wire.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/py.typed +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/holon/serve.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/scripts/verify_distribution.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/tests/fixtures/caller/holon/apps/__init__.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/tests/test_context.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/tests/test_elicit.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/tests/test_files.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/tests/test_runtime.py +0 -0
- {holon_sh-0.0.1.dev14 → holon_sh-0.0.1.dev16}/tests/test_serve.py +0 -0
|
@@ -77,7 +77,10 @@ T = TypeVar("T")
|
|
|
77
77
|
Match: TypeAlias = Callable[[RequestContext, Event[D], A], bool]
|
|
78
78
|
Transform: TypeAlias = Callable[[RequestContext, Event[D], A], object]
|
|
79
79
|
Authorize: TypeAlias = Callable[[RequestContext, A], bool | Awaitable[bool]]
|
|
80
|
-
|
|
80
|
+
Cleanup: TypeAlias = Callable[[], None | Awaitable[None]]
|
|
81
|
+
SubscriptionHook: TypeAlias = Callable[
|
|
82
|
+
[RequestContext, A, str], Cleanup | None | Awaitable[Cleanup | None]
|
|
83
|
+
]
|
|
81
84
|
|
|
82
85
|
|
|
83
86
|
class _SubscribeParams(RequestParams):
|
|
@@ -138,9 +141,7 @@ class _Kept:
|
|
|
138
141
|
class _Entry:
|
|
139
142
|
"""A subscription, held by one or more streams or poll leases."""
|
|
140
143
|
|
|
141
|
-
|
|
142
|
-
"""The request that began it."""
|
|
143
|
-
setup: asyncio.Future[None]
|
|
144
|
+
setup: asyncio.Future[Cleanup | None]
|
|
144
145
|
holds: set[_Hold] = field(default_factory=set)
|
|
145
146
|
teardown: asyncio.Future[None] | None = None
|
|
146
147
|
|
|
@@ -171,7 +172,6 @@ class EventType(Generic[A, D]):
|
|
|
171
172
|
_delivery: list[Delivery]
|
|
172
173
|
_authorize: Authorize[A] | None
|
|
173
174
|
_on_subscribe: SubscriptionHook[A] | None
|
|
174
|
-
_on_unsubscribe: SubscriptionHook[A] | None
|
|
175
175
|
# Emitted events, oldest first; `_dropped` is the last sequence evicted.
|
|
176
176
|
_kept: list[_Kept] = field(default_factory=list)
|
|
177
177
|
_sequence: int = 0
|
|
@@ -413,26 +413,27 @@ class Events(Extension):
|
|
|
413
413
|
name: str,
|
|
414
414
|
*,
|
|
415
415
|
input_schema: type[A] | TypeAdapter[A],
|
|
416
|
-
payload_schema:
|
|
416
|
+
payload_schema: dict[str, Any],
|
|
417
417
|
description: str | None = None,
|
|
418
418
|
match: Match[D, A] | None = None,
|
|
419
419
|
transform: Transform[D, A] | None = None,
|
|
420
420
|
delivery: Sequence[Delivery] = ("poll", "push"),
|
|
421
421
|
authorize: Authorize[A] | None = None,
|
|
422
422
|
on_subscribe: SubscriptionHook[A] | None = None,
|
|
423
|
-
on_unsubscribe: SubscriptionHook[A] | None = None,
|
|
424
423
|
) -> EventType[A, D]:
|
|
425
424
|
"""Declare an event type.
|
|
426
425
|
|
|
426
|
+
Annotate the result as ``EventType[Arguments, Data]`` to type ``emit``.
|
|
427
|
+
|
|
427
428
|
Args:
|
|
428
429
|
input_schema: Type of a subscription's arguments.
|
|
429
|
-
payload_schema:
|
|
430
|
+
payload_schema: JSON Schema of each occurrence's data.
|
|
430
431
|
match: ``(context, event, arguments)``: whether a subscription receives an event. Defaults to all.
|
|
431
432
|
transform: ``(context, event, arguments)``: the data a subscription receives.
|
|
432
433
|
delivery: The delivery modes offered.
|
|
433
434
|
authorize: ``(context, arguments)``: whether the caller may subscribe, checked again while subscribed.
|
|
434
435
|
on_subscribe: ``(context, arguments, subscription_id)``: called when a subscription begins.
|
|
435
|
-
|
|
436
|
+
May return a zero-argument cleanup function, called when the subscription ends.
|
|
436
437
|
"""
|
|
437
438
|
if name in self._types:
|
|
438
439
|
raise ValueError(f"Event {name} is already declared.")
|
|
@@ -443,16 +444,11 @@ class Events(Extension):
|
|
|
443
444
|
if isinstance(input_schema, TypeAdapter)
|
|
444
445
|
else TypeAdapter(input_schema)
|
|
445
446
|
)
|
|
446
|
-
payload = (
|
|
447
|
-
payload_schema
|
|
448
|
-
if isinstance(payload_schema, TypeAdapter)
|
|
449
|
-
else TypeAdapter(payload_schema)
|
|
450
|
-
)
|
|
451
447
|
descriptor = {
|
|
452
448
|
"name": name,
|
|
453
449
|
**({"description": description} if description else {}),
|
|
454
450
|
"inputSchema": arguments.json_schema(),
|
|
455
|
-
"payloadSchema":
|
|
451
|
+
"payloadSchema": payload_schema,
|
|
456
452
|
}
|
|
457
453
|
declared = EventType(
|
|
458
454
|
name,
|
|
@@ -464,7 +460,6 @@ class Events(Extension):
|
|
|
464
460
|
list(delivery),
|
|
465
461
|
authorize,
|
|
466
462
|
on_subscribe,
|
|
467
|
-
on_unsubscribe,
|
|
468
463
|
)
|
|
469
464
|
self._types[name] = declared
|
|
470
465
|
return declared
|
|
@@ -664,16 +659,16 @@ class Events(Extension):
|
|
|
664
659
|
entry = subscriptions.get(request.id)
|
|
665
660
|
if entry is None:
|
|
666
661
|
setup = asyncio.ensure_future(self._set_up(request))
|
|
667
|
-
entry = subscriptions[request.id] = _Entry(
|
|
662
|
+
entry = subscriptions[request.id] = _Entry(setup)
|
|
668
663
|
hold = _Hold(request, entry)
|
|
669
664
|
entry.holds.add(hold)
|
|
670
665
|
return hold
|
|
671
666
|
|
|
672
|
-
async def _set_up(self, request: _Request) -> None:
|
|
667
|
+
async def _set_up(self, request: _Request) -> Cleanup | None:
|
|
673
668
|
if request.type._on_subscribe is None:
|
|
674
|
-
return
|
|
669
|
+
return None
|
|
675
670
|
async with asyncio.timeout(_SUBSCRIBE_TIMEOUT):
|
|
676
|
-
await _settle(
|
|
671
|
+
return await _settle(
|
|
677
672
|
request.type._on_subscribe(
|
|
678
673
|
request.context, request.arguments, request.id
|
|
679
674
|
)
|
|
@@ -691,23 +686,17 @@ class Events(Extension):
|
|
|
691
686
|
entry.holds.discard(hold)
|
|
692
687
|
_release(self._held, hold.request.caller, 1)
|
|
693
688
|
if not entry.holds:
|
|
694
|
-
entry.teardown = asyncio.ensure_future(self._tear_down(
|
|
689
|
+
entry.teardown = asyncio.ensure_future(self._tear_down(hold))
|
|
695
690
|
|
|
696
|
-
#
|
|
697
|
-
async def _tear_down(self,
|
|
698
|
-
request =
|
|
691
|
+
# Cleanup follows only a setup that succeeded; a failing hook is logged.
|
|
692
|
+
async def _tear_down(self, hold: _Hold) -> None:
|
|
693
|
+
request = hold.request
|
|
699
694
|
try:
|
|
700
|
-
await entry.setup
|
|
701
|
-
if
|
|
702
|
-
await _settle(
|
|
703
|
-
request.type._on_unsubscribe(
|
|
704
|
-
request.context, request.arguments, request.id
|
|
705
|
-
)
|
|
706
|
-
)
|
|
695
|
+
cleanup = await hold.entry.setup
|
|
696
|
+
if cleanup is not None:
|
|
697
|
+
await _settle(cleanup())
|
|
707
698
|
except Exception:
|
|
708
|
-
logger.exception(
|
|
709
|
-
"An event subscription's on_subscribe or on_unsubscribe failed"
|
|
710
|
-
)
|
|
699
|
+
logger.exception("An event subscription's setup or cleanup failed")
|
|
711
700
|
finally:
|
|
712
701
|
del request.type._subscriptions[request.id]
|
|
713
702
|
|
|
@@ -25,12 +25,12 @@ from mcp.types import (
|
|
|
25
25
|
CallToolResult,
|
|
26
26
|
ErrorData,
|
|
27
27
|
)
|
|
28
|
-
from pydantic import BaseModel
|
|
28
|
+
from pydantic import BaseModel
|
|
29
29
|
from starlette.applications import Starlette
|
|
30
30
|
from starlette.routing import Mount
|
|
31
31
|
|
|
32
32
|
from holon.client import Apps
|
|
33
|
-
from holon.ext.events import Events, NoCompatibleDeliveryMode, _server
|
|
33
|
+
from holon.ext.events import Events, EventType, NoCompatibleDeliveryMode, _server
|
|
34
34
|
from holon.serve import App, _asgi
|
|
35
35
|
|
|
36
36
|
IDENTITY = {"name": "watcher", "version": "1", "requires": {"boards": {}}}
|
|
@@ -53,10 +53,13 @@ def asynchronous(test):
|
|
|
53
53
|
return run
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
def declare(events=None, **hooks):
|
|
56
|
+
def declare(events=None, **hooks) -> tuple[Events, EventType[Board, Change]]:
|
|
57
57
|
events = events or Events()
|
|
58
58
|
return events, events.event(
|
|
59
|
-
"board.changed",
|
|
59
|
+
"board.changed",
|
|
60
|
+
input_schema=Board,
|
|
61
|
+
payload_schema=Change.model_json_schema(),
|
|
62
|
+
**hooks,
|
|
60
63
|
)
|
|
61
64
|
|
|
62
65
|
|
|
@@ -184,25 +187,25 @@ async def test_a_subscription_hears_what_its_arguments_match_as_shaped_across_a_
|
|
|
184
187
|
await stop()
|
|
185
188
|
|
|
186
189
|
|
|
190
|
+
@pytest.mark.parametrize("user", ["ann", None])
|
|
187
191
|
@asynchronous
|
|
188
|
-
async def
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
192
|
+
async def test_targeted_events_follow_shared_identity_but_isolate_anonymous_readers(
|
|
193
|
+
user,
|
|
194
|
+
):
|
|
195
|
+
subscribed = asyncio.Queue()
|
|
196
|
+
events, changed = declare(
|
|
197
|
+
on_subscribe=lambda context, arguments, id: subscribed.put_nowait(id)
|
|
193
198
|
)
|
|
194
199
|
async with served(events) as port:
|
|
195
|
-
|
|
196
|
-
async with (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
async with ann.subscribe("board.changed", {"board": "b1"}):
|
|
205
|
-
assert began[3] == began[0]
|
|
200
|
+
reader = client(port, user=user)
|
|
201
|
+
async with reader.subscribe("board.changed", {"board": "b1"}) as first:
|
|
202
|
+
subscription_id = await subscribed.get()
|
|
203
|
+
async with reader.subscribe("board.changed", {"board": "b1"}) as second:
|
|
204
|
+
say(changed, "b1", "private", to=subscription_id)
|
|
205
|
+
say(changed, "b1", "public")
|
|
206
|
+
assert await take(first, 2) == ["private", "public"]
|
|
207
|
+
for expected in ["private", "public"] if user else ["public"]:
|
|
208
|
+
assert (await anext(second)).event_id == expected
|
|
206
209
|
|
|
207
210
|
|
|
208
211
|
@pytest.mark.parametrize("targeted", [False, True])
|
|
@@ -212,9 +215,9 @@ async def test_a_subscription_behind_what_is_kept_is_told_of_the_gap_and_carries
|
|
|
212
215
|
monkeypatch, delivery, targeted
|
|
213
216
|
):
|
|
214
217
|
monkeypatch.setattr(_server, "_KEEP_EVENTS", 2)
|
|
215
|
-
|
|
218
|
+
subscribed, heard = asyncio.Queue(), []
|
|
216
219
|
events, changed = declare(
|
|
217
|
-
on_subscribe=lambda context, arguments, id:
|
|
220
|
+
on_subscribe=lambda context, arguments, id: subscribed.put_nowait(id)
|
|
218
221
|
)
|
|
219
222
|
owed = delivery == "push" and targeted
|
|
220
223
|
async with (
|
|
@@ -226,8 +229,9 @@ async def test_a_subscription_behind_what_is_kept_is_told_of_the_gap_and_carries
|
|
|
226
229
|
on_gap=lambda: heard.append("gap"),
|
|
227
230
|
) as changes,
|
|
228
231
|
):
|
|
232
|
+
subscription_id = await subscribed.get()
|
|
229
233
|
for text in ["a", "b", "c", "d"]:
|
|
230
|
-
say(changed, "b1", text, to=
|
|
234
|
+
say(changed, "b1", text, to=subscription_id if targeted else None)
|
|
231
235
|
heard.extend(await take(changes, 2))
|
|
232
236
|
assert heard == (["a", "b"] if owed else ["gap", "c", "d"])
|
|
233
237
|
|
|
@@ -260,9 +264,11 @@ async def test_what_a_subscribe_hook_emits_reaches_its_subscription_first_and_a_
|
|
|
260
264
|
@asynchronous
|
|
261
265
|
async def test_a_subscription_the_app_ends_is_sent_what_was_emitted_to_it_unless_it_lost_access():
|
|
262
266
|
ids = {}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
267
|
+
|
|
268
|
+
def on_subscribe(context, arguments, id):
|
|
269
|
+
ids[arguments.board] = id
|
|
270
|
+
|
|
271
|
+
events, changed = declare(on_subscribe=on_subscribe)
|
|
266
272
|
async with served(events) as port:
|
|
267
273
|
boards = client(port, user="ann")
|
|
268
274
|
async with (
|
|
@@ -292,6 +298,16 @@ async def test_a_subscription_the_app_ends_is_sent_what_was_emitted_to_it_unless
|
|
|
292
298
|
|
|
293
299
|
@asynchronous
|
|
294
300
|
async def test_the_messages_on_the_wire_are_the_sketchs():
|
|
301
|
+
recursive = {
|
|
302
|
+
"$ref": "#/$defs/Node",
|
|
303
|
+
"$defs": {
|
|
304
|
+
"Node": {
|
|
305
|
+
"type": "object",
|
|
306
|
+
"properties": {"child": {"$ref": "#/$defs/Node"}},
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
}
|
|
310
|
+
|
|
295
311
|
def shaped(context, event, arguments):
|
|
296
312
|
if event.data.text == "bad":
|
|
297
313
|
raise ValueError("cannot be shaped")
|
|
@@ -305,28 +321,31 @@ async def test_the_messages_on_the_wire_are_the_sketchs():
|
|
|
305
321
|
events.event(
|
|
306
322
|
"board.locked",
|
|
307
323
|
input_schema=Board,
|
|
308
|
-
payload_schema=
|
|
324
|
+
payload_schema=recursive,
|
|
309
325
|
delivery=["poll"],
|
|
310
326
|
authorize=lambda context, arguments: arguments.board != "secret",
|
|
311
327
|
)
|
|
312
328
|
async with served(events) as port, httpx2.AsyncClient(timeout=10) as http:
|
|
313
329
|
discovered = await call(http, port, "server/discover", {})
|
|
314
|
-
assert discovered["result"]["capabilities"]["events"]
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
"
|
|
330
|
+
assert discovered["result"]["capabilities"]["events"]["listChanged"] is False
|
|
331
|
+
listed = {
|
|
332
|
+
event["name"]: event
|
|
333
|
+
for event in (await call(http, port, "events/list", {}))["result"]["events"]
|
|
334
|
+
}
|
|
335
|
+
assert listed["board.locked"]["payloadSchema"] == recursive
|
|
336
|
+
assert set(listed["board.changed"]["delivery"]) == {"poll", "push"}
|
|
337
|
+
expected = {
|
|
318
338
|
"description": "A board changed",
|
|
319
|
-
"delivery": ["poll", "push"],
|
|
320
339
|
"inputSchema": Board.model_json_schema(),
|
|
321
340
|
"payloadSchema": Change.model_json_schema(),
|
|
322
341
|
}
|
|
342
|
+
assert {key: listed["board.changed"][key] for key in expected} == expected
|
|
323
343
|
# A poll from null has no events, and a cursor from before its setup's welcome.
|
|
324
344
|
now = (await call(http, port, "events/poll", changed_on("b1")))["result"]
|
|
325
|
-
assert (now["events"], now["truncated"], now["hasMore"]
|
|
345
|
+
assert (now["events"], now["truncated"], now["hasMore"]) == (
|
|
326
346
|
[],
|
|
327
347
|
False,
|
|
328
348
|
False,
|
|
329
|
-
1000,
|
|
330
349
|
)
|
|
331
350
|
for text in ["one", "bad", "two", "three"]:
|
|
332
351
|
say(changed, "b1", text)
|
|
@@ -342,7 +361,6 @@ async def test_the_messages_on_the_wire_are_the_sketchs():
|
|
|
342
361
|
"one",
|
|
343
362
|
True,
|
|
344
363
|
)
|
|
345
|
-
assert set(one) == {"eventId", "name", "timestamp", "data"}
|
|
346
364
|
rest = await call(
|
|
347
365
|
http, port, "events/poll", changed_on("b1", page["result"]["cursor"])
|
|
348
366
|
)
|
|
@@ -375,9 +393,11 @@ async def test_the_messages_on_the_wire_are_the_sketchs():
|
|
|
375
393
|
frames = (
|
|
376
394
|
json.loads(frame.data) async for frame in httpx2.EventSource(stream)
|
|
377
395
|
)
|
|
378
|
-
meta = {"_meta": {SUBSCRIPTION_ID_META_KEY: 7}}
|
|
379
396
|
active = await anext(frames)
|
|
380
|
-
assert active["params"]
|
|
397
|
+
assert (active["params"]["cursor"], active["params"]["truncated"]) == (
|
|
398
|
+
opened,
|
|
399
|
+
False,
|
|
400
|
+
)
|
|
381
401
|
assert (await anext(frames))["params"]["eventId"] == "welcome"
|
|
382
402
|
say(changed, "b1", "bad")
|
|
383
403
|
say(changed, "b1", "four")
|
|
@@ -387,19 +407,19 @@ async def test_the_messages_on_the_wire_are_the_sketchs():
|
|
|
387
407
|
INTERNAL_ERROR,
|
|
388
408
|
)
|
|
389
409
|
event = (await anext(frames))["params"]
|
|
390
|
-
|
|
410
|
+
expected = {
|
|
391
411
|
"eventId": "four",
|
|
392
412
|
"name": "board.changed",
|
|
393
|
-
"timestamp": event["timestamp"],
|
|
394
413
|
"data": {"board": "b1", "text": "four"},
|
|
395
414
|
"cursor": changed.cursor(),
|
|
396
|
-
**meta,
|
|
397
415
|
}
|
|
416
|
+
assert {key: event[key] for key in expected} == expected
|
|
417
|
+
assert event["_meta"][SUBSCRIPTION_ID_META_KEY] == 7
|
|
398
418
|
changed.terminate()
|
|
399
419
|
terminated = await anext(frames)
|
|
400
|
-
assert (terminated["method"], terminated["params"]["error"]) == (
|
|
420
|
+
assert (terminated["method"], terminated["params"]["error"]["code"]) == (
|
|
401
421
|
"notifications/events/terminated",
|
|
402
|
-
|
|
422
|
+
-32024,
|
|
403
423
|
)
|
|
404
424
|
assert "result" in await anext(frames)
|
|
405
425
|
|
|
@@ -410,16 +430,18 @@ async def test_a_poll_that_gives_up_while_it_is_set_up_holds_its_place_until_its
|
|
|
410
430
|
):
|
|
411
431
|
monkeypatch.setattr(_server, "_POLL_SUBSCRIPTION_TTL", 0.1)
|
|
412
432
|
monkeypatch.setattr(_server, "_MAX_SUBSCRIPTIONS", 1)
|
|
413
|
-
setting_up, release, ended = asyncio.Event(), asyncio.Event(),
|
|
433
|
+
setting_up, release, ended = asyncio.Event(), asyncio.Event(), asyncio.Event()
|
|
414
434
|
|
|
415
435
|
async def on_subscribe(context, arguments, id):
|
|
416
436
|
setting_up.set()
|
|
417
437
|
await release.wait()
|
|
418
438
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
439
|
+
async def cleanup():
|
|
440
|
+
ended.set()
|
|
441
|
+
|
|
442
|
+
return cleanup
|
|
443
|
+
|
|
444
|
+
events, _ = declare(on_subscribe=on_subscribe)
|
|
423
445
|
app, left = mounted(events), asyncio.Event()
|
|
424
446
|
|
|
425
447
|
# Tells when the server sees the poll that gives up disconnect.
|
|
@@ -442,33 +464,32 @@ async def test_a_poll_that_gives_up_while_it_is_set_up_holds_its_place_until_its
|
|
|
442
464
|
await setting_up.wait()
|
|
443
465
|
async with httpx2.AsyncClient(timeout=10) as http:
|
|
444
466
|
exhausted = await call(http, port, "events/poll", changed_on("b2"))
|
|
445
|
-
|
|
467
|
+
limit = exhausted["error"]["data"]
|
|
468
|
+
assert (limit["limit"], limit["max"]) == ("subscriptions", 1)
|
|
446
469
|
giving_up.cancel()
|
|
447
470
|
await left.wait()
|
|
448
471
|
release.set()
|
|
449
|
-
await
|
|
472
|
+
await ended.wait()
|
|
450
473
|
assert "result" in await call(http, port, "events/poll", changed_on("b2"))
|
|
451
474
|
await stop()
|
|
452
475
|
|
|
453
476
|
|
|
454
477
|
@asynchronous
|
|
455
|
-
async def
|
|
478
|
+
async def test_a_subscription_can_be_retried_after_setup_times_out(
|
|
456
479
|
monkeypatch,
|
|
457
480
|
):
|
|
458
481
|
monkeypatch.setattr(_server, "_SUBSCRIBE_TIMEOUT", 0.1)
|
|
459
|
-
|
|
482
|
+
ready = asyncio.Event()
|
|
460
483
|
|
|
461
484
|
async def on_subscribe(context, arguments, id):
|
|
462
|
-
|
|
463
|
-
if len(calls) == 1:
|
|
464
|
-
await asyncio.Event().wait()
|
|
485
|
+
await ready.wait()
|
|
465
486
|
|
|
466
487
|
events, _ = declare(on_subscribe=on_subscribe)
|
|
467
488
|
async with served(events) as port, httpx2.AsyncClient(timeout=10) as http:
|
|
468
489
|
refused = await call(http, port, "events/poll", changed_on("b1"))
|
|
469
490
|
assert refused["error"]["code"] == INTERNAL_ERROR
|
|
491
|
+
ready.set()
|
|
470
492
|
assert "result" in await call(http, port, "events/poll", changed_on("b1"))
|
|
471
|
-
assert calls[0] == calls[1]
|
|
472
493
|
|
|
473
494
|
|
|
474
495
|
@asynchronous
|
|
@@ -509,8 +530,8 @@ async def test_where_push_cannot_be_served_a_subscription_polls(monkeypatch):
|
|
|
509
530
|
@asynchronous
|
|
510
531
|
async def test_a_subscription_from_the_cursor_read_with_a_snapshot_hears_every_change_after_it_on_a_json_endpoint():
|
|
511
532
|
events, said = Events(), []
|
|
512
|
-
changed = events.event(
|
|
513
|
-
"board.changed", input_schema=Board, payload_schema=
|
|
533
|
+
changed: EventType[Board, Change] = events.event(
|
|
534
|
+
"board.changed", input_schema=Board, payload_schema=Change.model_json_schema()
|
|
514
535
|
)
|
|
515
536
|
|
|
516
537
|
def tell(text):
|
|
@@ -540,5 +561,6 @@ async def test_a_subscription_from_the_cursor_read_with_a_snapshot_hears_every_c
|
|
|
540
561
|
) as changes:
|
|
541
562
|
assert changes.delivery == "push"
|
|
542
563
|
tell("once subscribed")
|
|
543
|
-
assert state["said"]
|
|
564
|
+
assert state["said"] == ["in the snapshot"]
|
|
565
|
+
assert await take(changes, 2) == ["after the snapshot", "once subscribed"]
|
|
544
566
|
await stop()
|
|
@@ -16,6 +16,15 @@ def test_generated_namespace_combines_app_types_with_installed_runtime(tmp_path)
|
|
|
16
16
|
import holon
|
|
17
17
|
import holon.client
|
|
18
18
|
from holon.apps import apps, Inputs, Outputs
|
|
19
|
+
from holon.ext.events import Events, EventType
|
|
20
|
+
|
|
21
|
+
def emit() -> None:
|
|
22
|
+
changed: EventType[dict[str, str], dict[str, str]] = Events().event(
|
|
23
|
+
"board.changed", input_schema=dict[str, str],
|
|
24
|
+
payload_schema={"type": "object", "additionalProperties": {"type": "string"}},
|
|
25
|
+
)
|
|
26
|
+
changed.emit({"text": "hello"})
|
|
27
|
+
changed.emit("wrong") # type: ignore[arg-type]
|
|
19
28
|
|
|
20
29
|
async def run() -> float:
|
|
21
30
|
arguments: Inputs.orders.read = {
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|