test(ws-client): cover relay message parsing, NIP-42 auth flow, and connection state machine - #2609
Open
SeanGearin wants to merge 1 commit into
Open
test(ws-client): cover relay message parsing, NIP-42 auth flow, and connection state machine#2609SeanGearin wants to merge 1 commit into
SeanGearin wants to merge 1 commit into
Conversation
…onnection state machine Signed-off-by: Sean Gearin <sgearin@gmail.com>
SeanGearin
force-pushed
the
test-ws-client-coverage
branch
from
July 23, 2026 20:20
a23e93d to
f8410b8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
crates/buzz-ws-clientis the NIP-42 WebSocket client that buzz-cli andbuzz-test-client use to talk to relays, but it currently has almost no test
coverage: the only tests are three const assertions on timeout floors. The
crate's actual behavior — NIP-01 frame parsing, NIP-42 AUTH event
construction, challenge handling, OK-response matching, out-of-order message
buffering, ping/pong keepalive, and close/timeout error paths — is entirely
unexercised, so regressions in any of it would only surface as live relay
failures.
Fix
Pure test addition — no production code changes, no new dependencies (dev or
otherwise).
src/message.rs(+217): unit tests forparse_relay_messageandbuild_auth_event:NOTICE, AUTH), including the NIP-01 defaulting rules (short OK defaults to
rejected/empty message, CLOSED without reason defaults to empty);
unknown message type, malformed event payload) maps to the right
WsClientErrorvariant;Kind::Authenticationevents carrying the NIP-42challenge/relay tags, the optional NIP-OA auth tag is injected when
provided, and invalid relay URLs are rejected.
src/connection.rs(+323): integration-style tests forNostrWsConnectionand
publish_eventagainst an in-process scripted relay (bind127.0.0.1:0+tokio_tungstenite::accept_async— same idiom as theexisting
test_ws_pairhelper inbuzz-acp/src/relay.rs; no network, nomock frameworks):
sent AUTH event verifies (kind/pubkey/signature/challenge tag);
AuthFailedwith the relay's reason;in order by
next_eventafterwards;send_eventmatches the OK for its own event id, buffering interleavedEOSE/foreign-OK frames for later delivery;
disrupting the OK wait;
reused by a later
authenticate()call (no second challenge needed);Timeout; server-initiated close →ConnectionClosed;invalid URL →
Urlerror;publish_eventone-shot helper: connect → auth → publish → OK end to end.All server-side reads are bounded by 5s timeouts so failures are fast, and
ephemeral ports keep the tests parallel-safe under nextest.
Test evidence
Against the pinned toolchain (Rust 1.95.0, per
rust-toolchain.toml):Links
crates/buzz-ws-client(used bycrates/buzz-cli,crates/buzz-test-client)crates/buzz-acp/src/relay.rstests