Skip to content

Commit 99d0915

Browse files
Honeyclaude
andcommitted
test(relay): assert rejected oversized typing is not published; clarify presence note
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Honey <8e307ae0076a4dab6b94b036ea3edc7e08f823a625269c1e6919e881a048b4d2@buzz.block.builderlab.xyz>
1 parent 27b5a29 commit 99d0915

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

‎crates/buzz-cli/TESTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ buzz users presence --pubkeys "$MY_PUBKEY" | jq .
333333
buzz users set-presence --status online | jq .
334334
buzz users set-presence --status away | jq .
335335
buzz users set-presence --status offline | jq .
336-
# Note: set-presence may fail — the HTTP bridge accepts kind:20001 (presence) only via WebSocket
336+
# Note: set-presence may fail — the HTTP bridge rejects kind:20001; presence is WebSocket-only
337337

338338
# users set-status — NIP-38 kind:30315 on the d:general coordinate
339339
buzz users set-status --text "reviewing PRs" --emoji "🔍" | jq .

‎crates/buzz-relay/src/api/typing_postgres_tests.rs‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ impl Fixture {
7474
(status, serde_json::from_slice(&bytes).unwrap())
7575
}
7676

77+
/// Subscribes to the channel's Redis topic; acknowledged before returning,
78+
/// so a later publish is not missed.
79+
async fn subscribe_channel(&self) -> redis::aio::PubSub {
80+
let topic = buzz_pubsub::EventTopicKey {
81+
community_id: self.community,
82+
topic: buzz_pubsub::EventTopic::Channel(self.channel),
83+
}
84+
.redis_channel();
85+
let client = redis::Client::open(self.state.config.redis_url.as_str()).unwrap();
86+
let mut pubsub = client.get_async_pubsub().await.unwrap();
87+
pubsub.subscribe(&topic).await.unwrap();
88+
pubsub
89+
}
90+
7791
async fn stored_typing_rows(&self) -> i64 {
7892
sqlx::query_scalar(
7993
"SELECT COUNT(*) FROM events WHERE community_id = $1 AND channel_id = $2 AND kind = 20002",
@@ -91,15 +105,7 @@ impl Fixture {
91105
async fn member_typing_is_broadcast_and_not_stored() {
92106
use futures::StreamExt;
93107
let f = Fixture::new().await;
94-
let topic = buzz_pubsub::EventTopicKey {
95-
community_id: f.community,
96-
topic: buzz_pubsub::EventTopic::Channel(f.channel),
97-
}
98-
.redis_channel();
99-
let client = redis::Client::open(f.state.config.redis_url.as_str()).unwrap();
100-
let mut pubsub = client.get_async_pubsub().await.unwrap();
101-
// Acknowledged by Redis before returning, so the publish below is not missed.
102-
pubsub.subscribe(&topic).await.unwrap();
108+
let pubsub = f.subscribe_channel().await;
103109

104110
let event = f.typing(&f.member, Some(f.channel));
105111
let (status, body) = f.post(&f.member, &event).await;
@@ -227,6 +233,7 @@ async fn oversized_typing_is_rejected() {
227233
.collect(),
228234
),
229235
];
236+
let pubsub = f.subscribe_channel().await;
230237
for (case, content, tags) in cases {
231238
let event = EventBuilder::new(Kind::Custom(20002), content)
232239
.tags(tags)
@@ -246,12 +253,12 @@ async fn oversized_typing_is_rejected() {
246253
"{case}: {body}"
247254
);
248255
}
256+
assert_nothing_published(pubsub, "oversized typing indicator").await;
249257
}
250258

251259
#[tokio::test]
252260
#[ignore = "requires Postgres and Redis"]
253261
async fn fenced_community_typing_is_rejected() {
254-
use futures::StreamExt;
255262
let f = Fixture::new().await;
256263
// Over HTTP a quiescing community's host no longer binds (404), so the
257264
// fence only matters when quiescing starts after the request has bound its
@@ -274,14 +281,7 @@ async fn fenced_community_typing_is_rejected() {
274281
.unwrap();
275282
tx.commit().await.unwrap();
276283

277-
let topic = buzz_pubsub::EventTopicKey {
278-
community_id: f.community,
279-
topic: buzz_pubsub::EventTopic::Channel(f.channel),
280-
}
281-
.redis_channel();
282-
let client = redis::Client::open(f.state.config.redis_url.as_str()).unwrap();
283-
let mut pubsub = client.get_async_pubsub().await.unwrap();
284-
pubsub.subscribe(&topic).await.unwrap();
284+
let pubsub = f.subscribe_channel().await;
285285

286286
let err = crate::handlers::event::publish_http_typing(
287287
&f.state,
@@ -295,11 +295,16 @@ async fn fenced_community_typing_is_rejected() {
295295
matches!(&err, IngestError::Rejected(msg) if msg == "restricted: community writes are fenced"),
296296
"{err:?}"
297297
);
298+
assert_nothing_published(pubsub, "fenced typing indicator").await;
299+
}
300+
301+
async fn assert_nothing_published(pubsub: redis::aio::PubSub, what: &str) {
302+
use futures::StreamExt;
298303
let mut messages = pubsub.into_on_message();
299304
assert!(
300305
tokio::time::timeout(std::time::Duration::from_millis(500), messages.next())
301306
.await
302307
.is_err(),
303-
"fenced typing indicator must not be published"
308+
"{what} must not be published"
304309
);
305310
}

0 commit comments

Comments
 (0)