buzzkit 0.3.1__tar.gz → 0.3.2__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.
Files changed (37) hide show
  1. {buzzkit-0.3.1 → buzzkit-0.3.2}/.github/workflows/release.yml +4 -3
  2. {buzzkit-0.3.1 → buzzkit-0.3.2}/CHANGELOG.md +17 -0
  3. {buzzkit-0.3.1 → buzzkit-0.3.2}/Cargo.lock +1 -1
  4. {buzzkit-0.3.1 → buzzkit-0.3.2}/Cargo.toml +1 -1
  5. {buzzkit-0.3.1 → buzzkit-0.3.2}/PKG-INFO +1 -1
  6. {buzzkit-0.3.1 → buzzkit-0.3.2}/pyproject.toml +1 -1
  7. {buzzkit-0.3.1 → buzzkit-0.3.2}/python/buzzkit/client.py +39 -11
  8. {buzzkit-0.3.1 → buzzkit-0.3.2}/tests/test_client.py +61 -0
  9. {buzzkit-0.3.1 → buzzkit-0.3.2}/.cargo/config.toml +0 -0
  10. {buzzkit-0.3.1 → buzzkit-0.3.2}/.github/workflows/CI.yml +0 -0
  11. {buzzkit-0.3.1 → buzzkit-0.3.2}/.gitignore +0 -0
  12. {buzzkit-0.3.1 → buzzkit-0.3.2}/LICENSE +0 -0
  13. {buzzkit-0.3.1 → buzzkit-0.3.2}/LICENSE-APACHE +0 -0
  14. {buzzkit-0.3.1 → buzzkit-0.3.2}/NOTICE +0 -0
  15. {buzzkit-0.3.1 → buzzkit-0.3.2}/README.md +0 -0
  16. {buzzkit-0.3.1 → buzzkit-0.3.2}/build-support/vendored-libopus.cmake +0 -0
  17. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/_shared.py +0 -0
  18. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/analyze_audio_tap.py +0 -0
  19. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/claim_invite.py +0 -0
  20. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/huddle_echo.py +0 -0
  21. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/huddle_wire_recorder.py +0 -0
  22. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/list_channels.py +0 -0
  23. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/offline_sign.py +0 -0
  24. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/send_message.py +0 -0
  25. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/set_profile.py +0 -0
  26. {buzzkit-0.3.1 → buzzkit-0.3.2}/examples/subscribe.py +0 -0
  27. {buzzkit-0.3.1 → buzzkit-0.3.2}/python/buzzkit/__init__.py +0 -0
  28. {buzzkit-0.3.1 → buzzkit-0.3.2}/python/buzzkit/_native.pyi +0 -0
  29. {buzzkit-0.3.1 → buzzkit-0.3.2}/python/buzzkit/agents.py +0 -0
  30. {buzzkit-0.3.1 → buzzkit-0.3.2}/python/buzzkit/huddle.py +0 -0
  31. {buzzkit-0.3.1 → buzzkit-0.3.2}/python/buzzkit/py.typed +0 -0
  32. {buzzkit-0.3.1 → buzzkit-0.3.2}/src/huddle.rs +0 -0
  33. {buzzkit-0.3.1 → buzzkit-0.3.2}/src/lib.rs +0 -0
  34. {buzzkit-0.3.1 → buzzkit-0.3.2}/tests/test_agents.py +0 -0
  35. {buzzkit-0.3.1 → buzzkit-0.3.2}/tests/test_huddle.py +0 -0
  36. {buzzkit-0.3.1 → buzzkit-0.3.2}/tests/test_live_relay.py +0 -0
  37. {buzzkit-0.3.1 → buzzkit-0.3.2}/tests/test_signing.py +0 -0
@@ -22,9 +22,10 @@ jobs:
22
22
  - { os: ubuntu-latest, target: x86_64 }
23
23
  - { os: ubuntu-latest, target: aarch64 }
24
24
  # Intel wheel is cross-compiled from the ARM runner: GitHub retired
25
- # the macos-13 (Intel) runners — the label queues forever.
26
- - { os: macos-14, target: x86_64 }
27
- - { os: macos-14, target: aarch64 }
25
+ # the macos-13 (Intel) runners, then macos-14. macos-latest follows
26
+ # the retirements, like ubuntu-latest and windows-latest.
27
+ - { os: macos-latest, target: x86_64 }
28
+ - { os: macos-latest, target: aarch64 }
28
29
  - { os: windows-latest, target: x64 }
29
30
  steps:
30
31
  - uses: actions/checkout@v4
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.2] — 2026-12-02
11
+
12
+ ### Fixed
13
+
14
+ - `BuzzClient.publish` (and `join_channel`, `publish_presence`, every
15
+ WebSocket publish) fails at once with `RuntimeError("connection closed
16
+ before the relay answered (code …)")` when the socket closes before the
17
+ relay's OK. It waited out its 20 s timeout and raised a `TimeoutError`
18
+ with no message: the read loop settled the pending AUTH and the
19
+ subscriptions on a close, not the pending publishes. A publish started
20
+ once the socket is closed fails the same way, where it raised websockets'
21
+ `ConnectionClosedError`; and a publish no longer leaves its wait behind
22
+ when it fails or times out.
23
+ - `BuzzClient.close` closes the WebSocket when the read loop ended on an
24
+ error, a frame it could not read (a JSON object, a missing field). It
25
+ raised that error before closing, and left the socket open.
26
+
10
27
  ## [0.3.1] — 2026-10-01
11
28
 
12
29
  ### Security
@@ -180,7 +180,7 @@ dependencies = [
180
180
 
181
181
  [[package]]
182
182
  name = "buzzkit"
183
- version = "0.3.1"
183
+ version = "0.3.2"
184
184
  dependencies = [
185
185
  "base64",
186
186
  "buzz-core",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "buzzkit"
3
- version = "0.3.1"
3
+ version = "0.3.2"
4
4
  edition = "2021"
5
5
  publish = false
6
6
  description = "PyO3 bindings over Block's Buzz zero-I/O crates (buzz-core / buzz-sdk)"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: buzzkit
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "buzzkit"
7
- version = "0.3.1"
7
+ version = "0.3.2"
8
8
  description = "Python bindings + async client for Block's Buzz (Nostr) protocol, backed by Rust buzz-core/buzz-sdk"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -11,7 +11,8 @@ first — or use the client as an async context manager::
11
11
 
12
12
  Reconnection is intentionally left to the caller (e.g. RoomKit's SourceProvider
13
13
  already owns reconnect/health); on a dropped socket, active subscriptions receive
14
- a final ``closed`` and their iterators stop.
14
+ a final ``closed`` and their iterators stop, and a :meth:`publish` still waiting
15
+ for its OK fails at once.
15
16
  """
16
17
 
17
18
  from __future__ import annotations
@@ -473,9 +474,21 @@ class BuzzClient:
473
474
  self._settle_auth(
474
475
  f"connection closed before NIP-42 auth completed (code {self.close_code})"
475
476
  )
477
+ self._settle_publishes(self._closed_before_answer())
476
478
  for q in self._subs.values():
477
479
  q.put_nowait(("closed", "connection lost"))
478
480
 
481
+ def _closed_before_answer(self) -> str:
482
+ return f"connection closed before the relay answered (code {self.close_code})"
483
+
484
+ def _settle_publishes(self, error: str) -> None:
485
+ """Fail every :meth:`publish` still waiting for its OK: no answer
486
+ comes on a closed socket, so none waits out its timeout."""
487
+ pending, self._pending_ok = self._pending_ok, {}
488
+ for fut in pending.values():
489
+ if not fut.done():
490
+ fut.set_exception(RuntimeError(error))
491
+
479
492
  async def _on_auth_challenge(self, challenge: str) -> None:
480
493
  auth_ev = json.loads(
481
494
  _native.build_auth_event(self._secret, challenge, self._ws_url, self._auth_tag)
@@ -499,15 +512,24 @@ class BuzzClient:
499
512
  async def publish(self, event_json: str) -> dict:
500
513
  """Publish a signed event over the WebSocket and await the relay OK.
501
514
 
515
+ Raises ``RuntimeError`` at once when the socket closes before the
516
+ relay answered, and ``TimeoutError`` when no answer comes in 20 s.
517
+
502
518
  Use this for ephemeral kinds (20000–29999) which the HTTP bridge rejects.
503
519
  """
504
520
  if self._ws is None:
505
521
  raise RuntimeError("call connect() before publish()")
522
+ if self._reader is not None and self._reader.done():
523
+ raise RuntimeError(self._closed_before_answer())
506
524
  ev = json.loads(event_json)
507
525
  fut: asyncio.Future = asyncio.get_running_loop().create_future()
508
526
  self._pending_ok[ev["id"]] = fut
509
- await self._ws.send(json.dumps(["EVENT", ev]))
510
- accepted, message = await asyncio.wait_for(fut, timeout=_OK_TIMEOUT)
527
+ try:
528
+ await self._ws.send(json.dumps(["EVENT", ev]))
529
+ accepted, message = await asyncio.wait_for(fut, timeout=_OK_TIMEOUT)
530
+ finally:
531
+ if self._pending_ok.get(ev["id"]) is fut:
532
+ del self._pending_ok[ev["id"]]
511
533
  return {"accepted": accepted, "event_id": ev["id"], "message": message}
512
534
 
513
535
  async def subscribe(
@@ -544,12 +566,18 @@ class BuzzClient:
544
566
  yield ev
545
567
 
546
568
  async def close(self) -> None:
547
- """Cancel the reader task and close the WebSocket."""
548
- if self._reader is not None:
549
- self._reader.cancel()
550
- with contextlib.suppress(asyncio.CancelledError):
551
- await self._reader
569
+ """Cancel the reader task and close the WebSocket.
570
+
571
+ The WebSocket is closed even when the reader ended on an error,
572
+ which is raised once it is.
573
+ """
574
+ try:
575
+ if self._reader is not None:
576
+ self._reader.cancel()
577
+ with contextlib.suppress(asyncio.CancelledError):
578
+ await self._reader
579
+ finally:
552
580
  self._reader = None
553
- if self._ws is not None:
554
- await self._ws.close()
555
- self._ws = None
581
+ if self._ws is not None:
582
+ await self._ws.close()
583
+ self._ws = None
@@ -92,6 +92,67 @@ async def test_connect_fails_fast_when_closed_before_auth():
92
92
  assert bz.close_code == 1008
93
93
 
94
94
 
95
+ async def test_a_publish_fails_fast_when_the_socket_closes_before_its_ok():
96
+ async def handler(ws):
97
+ auth = await _challenge_and_read_auth(ws)
98
+ await ws.send(json.dumps(["OK", auth["id"], True, ""]))
99
+ await ws.recv() # the published event, never answered
100
+ await ws.close(code=1011, reason="gone")
101
+
102
+ nsec, _, _ = buzzkit.generate_keypair()
103
+ async with serve(handler) as url:
104
+ bz = BuzzClient(url, nsec)
105
+ await asyncio.wait_for(bz.connect(), 2)
106
+ event = buzzkit.build_presence_event(nsec, "online")
107
+ # Well under the 20 s OK timeout: the closed socket ends the wait.
108
+ with pytest.raises(
109
+ RuntimeError, match=r"connection closed before the relay answered \(code 1011\)"
110
+ ):
111
+ await asyncio.wait_for(bz.publish(event), 2)
112
+ await bz.close()
113
+
114
+
115
+ async def test_a_publish_after_the_socket_closed_fails_at_once():
116
+ async def handler(ws):
117
+ auth = await _challenge_and_read_auth(ws)
118
+ await ws.send(json.dumps(["OK", auth["id"], True, ""]))
119
+ await ws.close(code=1011, reason="gone")
120
+
121
+ nsec, _, _ = buzzkit.generate_keypair()
122
+ async with serve(handler) as url:
123
+ bz = BuzzClient(url, nsec)
124
+ await asyncio.wait_for(bz.connect(), 2)
125
+ await asyncio.wait_for(bz._reader, 2) # the relay's close was read
126
+ event = buzzkit.build_presence_event(nsec, "online")
127
+ with pytest.raises(RuntimeError, match=r"closed before the relay answered \(code 1011\)"):
128
+ await asyncio.wait_for(bz.publish(event), 2)
129
+ assert bz._pending_ok == {}
130
+ await bz.close()
131
+
132
+
133
+ async def test_close_closes_the_socket_after_a_frame_the_reader_fails_on():
134
+ closed: asyncio.Future = asyncio.get_running_loop().create_future()
135
+
136
+ async def handler(ws):
137
+ auth = await _challenge_and_read_auth(ws)
138
+ await ws.send(json.dumps(["OK", auth["id"], True, ""]))
139
+ await ws.send(json.dumps({"a": 1})) # no list: the reader fails on it
140
+ await ws.wait_closed()
141
+ closed.set_result(ws.close_code)
142
+
143
+ nsec, _, _ = buzzkit.generate_keypair()
144
+ async with serve(handler) as url:
145
+ bz = BuzzClient(url, nsec)
146
+ await asyncio.wait_for(bz.connect(), 2)
147
+ await asyncio.wait({bz._reader}, timeout=2)
148
+ assert isinstance(bz._reader.exception(), KeyError)
149
+ # The reader's error still reaches the caller, once the socket is closed.
150
+ with pytest.raises(KeyError):
151
+ await bz.close()
152
+ assert await asyncio.wait_for(closed, 2) == 1000
153
+ assert bz._ws is None
154
+
155
+
95
156
  # ── start_huddle ─────────────────────────────────────────────────────────────
96
157
 
97
158
 
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