Skip to content

Commit cd02b69

Browse files
TheSentinel454claudecodex
authored
refactor(relay): extract NIP-29 membership authorization (block#7285)
## Why NIP-29 membership authorization for kinds 9000, 9001, and 9022 was embedded in a large async handler, requiring Postgres and Redis to test and repeating the last-owner rule across five call sites. This addresses [TheSentinel454#24](TheSentinel454#24) without adding the broader state/repository abstraction suggested there because HTTP and WebSocket writes already share ingestion. ## What - Extract pure, typed membership authorization decisions while leaving database reads and mutations in `validate_admin_event`. - Preserve existing client-visible errors and independent database last-owner safeguards. - Collapse five last-owner policy restatements into one predicate and share the identical self-departure policy. - Include the relay decision modules in `just test-unit`, so these tests execute in CI. ## Risk Assessment Medium-low. This touches production relay authorization, but intentionally preserves wire behavior and database defense in depth; exhaustive decision tables and relay-backed tests cover the affected paths. ## Simplification This removes repeated policy from the orchestration path and makes the rule set directly testable without introducing a repository trait or second transport path. ## Verification Verified at `15255a090797f85874921120003c645962fefaed`: - `just test-unit` — all 10 package summaries passed. An initial run hit two unrelated timing-sensitive `buzz-acp` failures; the complete retry passed 905/905 in that package. - `cargo fmt --all -- --check` - `cargo clippy --workspace --all-targets -- -D warnings` - `just file-size-check` — 10/10 policy tests passed. - `just security-review-check` — 13/13 tests passed. - Push preflight — `push-head-scope`, `branch-skew`, `file-size-check`, `rust-tests`, and `desktop-tauri-checks` passed. - Blox Postgres relay lane — 84/84 at the byte-identical source patch; full live `e2e_relay` behavior matched the clean base (45 pass and the same pre-existing kind:9002 failure on each). Generated with Claude Code --------- Signed-off-by: tornquist <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]> Co-authored-by: Codex <[email protected]>
1 parent 01bacb8 commit cd02b69

8 files changed

Lines changed: 916 additions & 134 deletions

File tree

‎.github/workflows/_ci-relay.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ jobs:
569569
cargo test -p buzz-test-client --test e2e_persona --test e2e_team_catalog --test e2e_nostr_interop --test e2e_project -- --ignored --nocapture
570570
cargo test -p buzz-test-client --test e2e_relay invite -- --ignored --nocapture
571571
cargo test -p buzz-test-client --test e2e_relay nip43_membership_snapshots_are_rejected -- --ignored --nocapture
572+
cargo test -p buzz-test-client --test e2e_relay nip29_departure_wire -- --ignored --nocapture
572573
env:
573574
RELAY_URL: ws://localhost:3000
574575
GIT_CREDENTIAL_NOSTR_BIN: ${{ github.workspace }}/target/ci/git-credential-nostr

‎Justfile‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,21 @@ test-unit:
429429
# disabled_mode_regression_pin_unauthenticated_request_is_served on the
430430
# DB-free /probe route, and its Host/Origin gating is covered here by
431431
# disabled_mode_still_requires_the_correct_host / _a_matching_origin.
432+
# The second clause adds the relay's pure authorization-decision tests:
433+
# the NIP-29 channel membership grid (handlers::channel_authz), the
434+
# moderation capability grid (handlers::moderation_authz), and the pure
435+
# helpers in handlers::side_effects. They ran in NO lane before —
436+
# `test(/^api::admin::/)` never matched them, and the PostgreSQL lane
437+
# pairs `--run-ignored ignored-only` with a `postgres_tests::`
438+
# default-filter — so a red one shipped green, exactly the gap the
439+
# api::admin clause above was added to close.
440+
# Deliberately scoped to these three modules instead of all of
441+
# `handlers::`: the wider set is mostly Postgres-backed, and five of its
442+
# non-postgres_tests cases only "pass" without a database by waiting out
443+
# the ~30s sqlx acquire timeout, so they do not belong in the infra-free
444+
# unit job either.
432445
cargo nextest run -p buzz-relay --lib \
433-
-E 'test(/^api::admin::/) - test(=api::admin::tests::disabled_mode_allows_unauthenticated_requests_on_the_admin_host) - test(=api::admin::tests::nip98_mode_unrostered_signer_does_not_consume_a_replay_slot)'
446+
-E '(test(/^api::admin::/) - test(=api::admin::tests::disabled_mode_allows_unauthenticated_requests_on_the_admin_host) - test(=api::admin::tests::nip98_mode_unrostered_signer_does_not_consume_a_replay_slot)) + test(/^handlers::channel_authz::/) + test(/^handlers::moderation_authz::/) + test(/^handlers::side_effects::tests::/)'
434447
# ACP author-gate and queue tests protect the trust boundary between
435448
# relay events and agent prompts. They are infra-free; ignored lifecycle
436449
# tests remain excluded and run in their dedicated integration lanes.

0 commit comments

Comments
 (0)