test(pairing-cli): add unit coverage for buzz-pairing-cli - #2610
Open
SeanGearin wants to merge 1 commit into
Open
test(pairing-cli): add unit coverage for buzz-pairing-cli#2610SeanGearin wants to merge 1 commit into
SeanGearin wants to merge 1 commit into
Conversation
Signed-off-by: Sean Gearin <sgearin@gmail.com>
SeanGearin
force-pushed
the
test-pairing-cli-coverage
branch
from
July 23, 2026 20:20
380bb04 to
915cbb7
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-pairing-cli(623 LOC) had zero tests. All of its relay-protocolparsing, CLI argument handling, and error paths were unverified — regressions
in QR/offer/abort handling or NIP-42 auth framing would only surface during a
live interop run against a real relay.
Fix
Adds a
#[cfg(test)]unit suite (42 tests) insidesrc/main.rs, mirroring theinline-test idiom used in
buzz-auth(crates/buzz-auth/src/nip42.rs). Nolive relay is used anywhere: WebSocket I/O is stubbed with in-memory
futures_util::streamsources and a smallCaptureSinkthat records outgoingframes, and time-dependent paths run under
#[tokio::test(start_paused = true)]so timeout tests complete instantly.
Coverage by area:
debug_assert,sourcedefault relay +--relay/--nsec,targetdefaults +--relay/--show-secret,test-vectors, missing-subcommand and unknown-flag rejection.parse_auth_challenge(6): valid AUTH frame, non-AUTH types, malformedJSON, short array, non-string challenge, non-array JSON.
parse_relay_event(6): valid EVENT for the right sub id, wrong sub id,OK/EOSE frames, short array, invalid event payload, non-array JSON.
resolve_payload(3): valid nsec passthrough, invalid nsec ->CliError::InvalidNsec, generated test key parses as an nsec.hex_to_32(3): round trip, non-hex input, wrong length.parse_yes_no(2): affirmative and negative variants. (Tiny seamextraction: the
matches!inread_yes_nomoved to a pureparse_yes_no(&str)so the logic is testable without stdin — behaviorunchanged.)
cmd_test_vectors(1): spec vectors derive without error.check_for_abort(2): non-abort events pass through; a real peer abort(full offline source->target handshake via
PairingSession::new_source/new_target/handle_offer) is surfaced with its reason.publish_event(1): emits a["EVENT", ...]frame that round-trips tothe same event id.
wait_for_event(4): skips junk/OK/EOSE/binary/wrong-sub frames thenreturns the matching event; timeout ->
CliError::Timeout; closed stream ->CliError::Other; websocket error propagates asCliError::WebSocket.wait_for_eose(2): matches only its sub id; timeout path.handle_nip42_auth(4): no-challenge relays are skipped cleanly (nothingsent); a challenge is answered with a kind-22242 event signed by the
session's ephemeral key (signature verified, challenge tag present);
missing OK after AUTH is tolerated; invalid relay URL is rejected.
Only non-test changes: the 4-line
parse_yes_noextraction and a[dev-dependencies]entry adding tokio'stest-utilfeature (same pattern asbuzz-pair-relay,buzz-media,buzz-relay-mesh,buzz-acp).Test evidence
Links
crates/buzz-pairing-cli/src/main.rscrates/buzz-auth/src/nip42.rs🤖 Generated with Claude Code