diff --git a/.config/nextest.toml b/.config/nextest.toml index 4481ebc6ba..1f9f3d156f 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -32,6 +32,10 @@ max-threads = 1 [[profile.postgres-ci.overrides]] filter = "test(/cluster_global_/)" test-group = "postgres-cluster-global" +# The group only serializes these tests with each other. They read unfiltered, +# cluster-wide `pg_stat_activity`, so any overlapping test's session can mask +# activity; claim every worker so they run alone. +threads-required = "num-test-threads" [[profile.postgres-ci.scripts]] # Script filters are separate from default-filter: they attach the setup and diff --git a/.env.example b/.env.example index 61f44af72d..6674deec40 100644 --- a/.env.example +++ b/.env.example @@ -151,7 +151,8 @@ BUZZ_PUSH_GATEWAY_DELIVERY_URL=https://push.buzz.xyz/v1/deliveries/apns # Deployment-global operator-listener routes. Each configured Nostr identity # may register target pubkeys and receives mention notifications at its URL. # URLs may use HTTP or HTTPS. Use HTTP only for operator-controlled internal -# connections: NIP-98 signs requests. +# connections: NIP-98 signs requests but does not encrypt them, and +# notifications carry full message content. # Format: pubkey:deliveryUrl;pubkey:deliveryUrl # BUZZ_OPERATOR_LISTENER_TIMEOUT_MS=5000 # BUZZ_OPERATOR_LISTENERS=<64-char hex pubkey>:https://listener.example/mentions diff --git a/.github/workflows/_ci-clients.yml b/.github/workflows/_ci-clients.yml index 310ab676b7..bb62f49e9b 100644 --- a/.github/workflows/_ci-clients.yml +++ b/.github/workflows/_ci-clients.yml @@ -57,11 +57,31 @@ jobs: path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} key: pnpm-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }} + # Mobile lanes run in parallel; the required check reads the combined + # matrix result. `flutter test` shards split tests, not files, so every test + # shard still compiles the whole suite. mobile: - name: Mobile + name: Mobile (${{ matrix.name }}) runs-on: ubuntu-latest timeout-minutes: 30 if: inputs.lane == 'required' && (github.event_name == 'push' || inputs.mobile) + strategy: + fail-fast: false + matrix: + include: + - name: Checks + lane: checks + - name: Tests 1/3 + lane: test + shard: 0 + - name: Tests 2/3 + lane: test + shard: 1 + - name: Tests 3/3 + lane: test + shard: 2 + - name: Android + lane: android permissions: contents: read steps: @@ -107,47 +127,94 @@ jobs: path: ~/.pub-cache key: pub-${{ runner.os }}-${{ hashFiles('mobile/pubspec.lock') }} - name: Format check + if: matrix.lane == 'checks' run: cd mobile && dart format --output=none --set-exit-if-changed . - name: Analyze + if: matrix.lane == 'checks' run: cd mobile && flutter analyze - name: Test - run: cd mobile && flutter test --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example + if: matrix.lane == 'test' + run: cd mobile && flutter test --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example --total-shards=3 --shard-index=${{ matrix.shard }} - name: Test mobile without push configuration + if: matrix.lane == 'checks' run: cd mobile && flutter test test/shared/push/push_unconfigured_build_test.dart - name: Test mobile recipe argument forwarding + if: matrix.lane == 'checks' run: /bin/bash scripts/test-mobile-gateway-recipes.sh + - name: Restore Gradle cache + if: matrix.lane == 'android' + uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('mobile/android/**/*.gradle*', 'mobile/android/gradle/wrapper/gradle-wrapper.properties', 'mobile/pubspec.lock') }} + restore-keys: gradle-${{ runner.os }}- - name: Build Android debug APK + if: matrix.lane == 'android' run: just mobile-build-android + - name: Save Gradle cache + if: matrix.lane == 'android' && github.event_name == 'push' + uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5 + continue-on-error: true + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('mobile/android/**/*.gradle*', 'mobile/android/gradle/wrapper/gradle-wrapper.properties', 'mobile/pubspec.lock') }} + # The unsigned release build needs nothing from the native lane, so it runs + # beside it instead of after the simulator tests. mobile-swift: - name: Mobile Swift + name: Mobile Swift (${{ matrix.name }}) runs-on: macos-latest - timeout-minutes: 30 + timeout-minutes: 45 if: inputs.lane == 'mobile-swift' && inputs.mobile + strategy: + fail-fast: false + matrix: + include: + - name: Native + lane: native + - name: Release + lane: release steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - uses: cashapp/activate-hermit@cea9af7913204a965fd488637a8d1811bba2e616 # v1 - name: Install Flutter dependencies run: cd mobile && flutter pub get - name: Build + if: matrix.lane == 'native' run: swift build --package-path mobile/ios/BuzzPushKit - name: Build release + if: matrix.lane == 'native' run: swift build -c release --package-path mobile/ios/BuzzPushKit - name: Test + if: matrix.lane == 'native' run: swift test --package-path mobile/ios/BuzzPushKit - name: Test native pagination geometry + if: matrix.lane == 'native' run: /bin/bash scripts/test-mobile-pagination.sh - name: Build complete iOS simulator app + if: matrix.lane == 'native' run: cd mobile && flutter build ios --simulator --debug --no-pub - - name: Test native pagination accessibility + - name: Test native controls and push navigation bridge + if: matrix.lane == 'native' run: | device=$(xcrun simctl create "Pagination accessibility" "iPhone 16") trap 'xcrun simctl shutdown "$device"; xcrun simctl delete "$device"' EXIT xcrun simctl boot "$device" xcrun simctl bootstatus "$device" -b /bin/bash scripts/test-mobile-pagination-accessibility.sh "$device" + /bin/bash scripts/test-mobile-carousel.sh "$device" /bin/bash scripts/test-mobile-member-picker.sh "$device" + xcodebuild -workspace mobile/ios/Runner.xcworkspace -scheme Runner \ + -configuration Debug -destination "platform=iOS Simulator,id=$device" \ + -parallel-testing-enabled NO \ + -only-testing:RunnerTests/BuzzPushNavigationBridgeTests \ + CODE_SIGNING_ALLOWED=NO test - name: Build complete unsigned iOS release + if: matrix.lane == 'release' run: | /bin/bash scripts/test-mobile-gateway-recipes.sh cd mobile && flutter build ios --release --no-codesign --no-pub diff --git a/.intersect/sadscan.yaml b/.intersect/sadscan.yaml index 77710ae0d9..7f6c5e57a2 100644 --- a/.intersect/sadscan.yaml +++ b/.intersect/sadscan.yaml @@ -4,11 +4,15 @@ exclude_rules_for_files: - Cargo.lock # Self-signed test fixture generated solely to exercise reqwest identity parsing. kingfisher.privkey.2: + # Published upstream synthetic CA key, compiled only under cfg(test). + # The gateway pins Apple's root and cannot trust this fixture CA. + - "*appattest-test-ca-key.pem" - "*apns-test-identity.pem" - "*apns-test-key-only.pem" - "*apns-test-encrypted-identity.pem" - "*apns-test-mismatched-identity.pem" np.pem.1: + - "*appattest-test-ca-key.pem" - "*apns-test-identity.pem" - "*apns-test-key-only.pem" - "*apns-test-encrypted-identity.pem" diff --git a/AGENTS.md b/AGENTS.md index 5932bcd9e1..bd721075d8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -313,7 +313,9 @@ Filters and queries must scope to `h` tags when operating within a channel. This applies to events *inside* a channel. Addressable events that describe a channel carry its id in their `d` tag instead: kind:39000 (metadata), kind:39001, kind:39002 (membership). `get_channels` resolves a user's channels -from the `d` tag of their kind:39002 events, not from `h`. +from the `d` tag of their kind:39002 events, not from `h`. The relay leaves +system channels out of these reads unless the filter asks for them (see +`docs/nips/NIP-CL.md`). **Agent-facing operations go in `buzz-cli`**: New agent-facing features belong in `buzz-cli` — add a subcommand there first, then wire the REST/WebSocket call in `client.rs`. `buzz-dev-mcp` (shell + file tools for `buzz-agent`) is separate. diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index e0875618dd..633db903c0 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -474,7 +474,7 @@ All database access. Uses `sqlx::query()` (runtime, not compile-time macros) — | `user.rs` | User profile storage | | `error.rs` | Database error types | -**Channel types:** `Stream`, `Forum`, `Dm`, `Workflow` +**Channel types:** `Stream`, `Forum`, `Dm`, `Workflow`, `System` **Member roles:** `Owner`, `Admin`, `Member`, `Guest`, `Bot` **Workflow statuses:** `Active`, `Disabled`, `Archived` **Run statuses:** `Pending`, `Running`, `WaitingApproval`, `Completed`, `Failed`, `Cancelled` diff --git a/Cargo.lock b/Cargo.lock index 798825deaf..94a5ebd139 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,24 +158,6 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" -[[package]] -name = "appattest" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0a66767aaf7d483c556386fb68ca2fba9347684d8bb17a4bd8b755851870f7" -dependencies = [ - "arrayvec", - "aws-lc-rs", - "base64 0.22.1", - "byteorder", - "ciborium", - "minicbor", - "openssl", - "p256", - "rustls-pki-types", - "rustls-webpki", -] - [[package]] name = "apple-native-keyring-store" version = "1.0.2" @@ -1403,21 +1385,25 @@ name = "buzz-push-gateway" version = "0.1.0" dependencies = [ "aes-gcm", - "appattest", "async-trait", + "aws-lc-rs", "axum", "base64 0.22.1", - "byteorder", "chrono", + "ciborium", "getrandom 0.4.3", "hex", "metrics", "metrics-exporter-prometheus", "minicbor", "nostr 0.44.7", + "openssl", + "p256", "proptest", "rand 0.10.1", "reqwest 0.13.4", + "rustls-pki-types", + "rustls-webpki", "serde", "serde_json", "sha2 0.11.0", @@ -1430,6 +1416,7 @@ dependencies = [ "tracing-subscriber", "url", "uuid", + "x509-parser", ] [[package]] @@ -5963,6 +5950,21 @@ name = "minicbor" version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0452a60c1863c1f50b5f77cd295e8d2786849f35883f0b9e18e7e6e1b5691b0" +dependencies = [ + "half", + "minicbor-derive", +] + +[[package]] +name = "minicbor-derive" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd2209fff77f705b00c737016a48e73733d7fbccb8b007194db148f03561fb70" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] [[package]] name = "minidom" @@ -6927,6 +6929,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" +[[package]] +name = "openssl-src" +version = "300.6.1+3.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46eb8fb9fb3b61ce1c0f8a026c4c1a0714d3a9e138e7fbde78753ce2babc3846" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.116" @@ -6935,6 +6946,7 @@ checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/Justfile b/Justfile index 2fb1708316..1218394f22 100644 --- a/Justfile +++ b/Justfile @@ -519,7 +519,8 @@ test-unit: # exact name for the same reason: the rest of handlers::req needs a DB. # The third clause adds the NIP-FI HTTP ingress and its router/config # neighbours: nip_fi_http, nip_fi_config, router, api::parse_query_tests, - # and the Git transport off_mode_precedence_tests. All are infra-free + # the profile search request bounds (api::profiles), and the Git + # transport off_mode_precedence_tests. All are infra-free # and finish in well under a second with no DATABASE_URL, so none wait # out the sqlx acquire timeout. `--bin buzz-relay` adds main.rs's # `tests::` module (JWKS refresh cadence) and `composition_tests::` @@ -531,7 +532,7 @@ test-unit: # are infra-free; config parses env into a struct and never connects. # `^config::` is anchored so it does not also select nip_fi_config. cargo nextest run -p buzz-relay --lib --bin buzz-relay \ - -E 'test(/^api::admin::/) + test(/^push_runtime::/) + test(/^operator_listener::tests::/) + test(/^handlers::channel_authz::/) + test(/^handlers::moderation_authz::/) + test(/^handlers::side_effects::tests::/) + test(/^storage_sweep::tests::/) + test(/^nip_fi_core::tests::/) + test(/^nip_fi_http::tests::/) + test(/^nip_fi_config::tests::/) + test(/^readiness::tests::/) + test(/^router::tests::/) + test(/^api::parse_query_tests::/) + test(/^api::git::transport::off_mode_precedence_tests::/) + test(/^audio::join::tests::/) + test(/^audio::handler::tests::/) + test(/^nip_fi_gate::tests::/) + test(/^nip_fi_session::tests::/) + test(/^nip_fi_shadow::tests::/) + test(/^nip_fi_shadow_session::tests::/) + test(/^startup_steps::tests::/) + test(/^telemetry::tests::/) + test(/^config::tests::/) + test(=state::tests::neither_a_confirmed_inactive_community_nor_a_failed_lookup_admits_the_socket) + test(=state::tests::periodic_revalidation_disconnects_inside_the_fenced_callback) + test(=state::tests::bare_community_disconnect_fails_closed_when_the_fence_is_unavailable) + test(=connection::tests::send_loop_sends_policy_close_when_community_is_archived) + test(=state::tests::community_disconnect_then_nip_fi_keeps_community_deleted_reason) + test(=state::tests::disconnect_community_wins_reason_losing_nip_fi_does_not_enqueue_frame) + test(=handlers::req::tests::timed_out_historical_read_deregisters_before_closed) + test(=handlers::req::tests::superseded_timeout_leaves_replacement_intact) + test(=handlers::req::tests::search_claim_retires_live_and_yields_to_replacement) + test(=handlers::req::tests::concurrent_claims_and_stale_teardowns_keep_the_last_owner) + test(=handlers::req::tests::timeout_closed_is_emitted_before_a_replacement_can_claim) + test(=handlers::req::tests::revoke_then_replacement_keeps_replacement_whole) + test(=handlers::req::tests::claims_after_connection_cleanup_are_refused) + test(=handlers::req::tests::dropped_terminal_frame_cancels_connection) + test(=handlers::req::tests::revoke_dropped_terminal_frame_cancels_connection) + test(=handlers::req::tests::count_fallback_covers_filters_that_can_match_private_deletions) + (kind(bin) & (test(/^tests::/) + test(/^composition_tests::/) + test(/^env_filter_tests::/)) - test(/^tests::postgres_tests::/))' + -E 'test(/^api::admin::/) + test(/^push_runtime::/) + test(/^operator_listener::tests::/) + test(/^handlers::channel_authz::/) + test(/^handlers::moderation_authz::/) + test(/^handlers::side_effects::tests::/) + test(/^handlers::system_channels::tests::/) + test(/^nip11::tests::/) + test(/^storage_sweep::tests::/) + test(/^nip_fi_core::tests::/) + test(/^nip_fi_http::tests::/) + test(/^nip_fi_config::tests::/) + test(/^readiness::tests::/) + test(/^router::tests::/) + test(/^api::parse_query_tests::/) + test(/^api::profiles::/) + test(/^api::git::transport::off_mode_precedence_tests::/) + test(/^audio::join::tests::/) + test(/^audio::handler::tests::/) + test(/^nip_fi_gate::tests::/) + test(/^nip_fi_session::tests::/) + test(/^nip_fi_shadow::tests::/) + test(/^nip_fi_shadow_session::tests::/) + test(/^startup_steps::tests::/) + test(/^telemetry::tests::/) + test(/^config::tests::/) + test(=state::tests::neither_a_confirmed_inactive_community_nor_a_failed_lookup_admits_the_socket) + test(=state::tests::periodic_revalidation_disconnects_inside_the_fenced_callback) + test(=state::tests::bare_community_disconnect_fails_closed_when_the_fence_is_unavailable) + test(=connection::tests::send_loop_sends_policy_close_when_community_is_archived) + test(=state::tests::community_disconnect_then_nip_fi_keeps_community_deleted_reason) + test(=state::tests::disconnect_community_wins_reason_losing_nip_fi_does_not_enqueue_frame) + test(=handlers::req::tests::timed_out_historical_read_deregisters_before_closed) + test(=handlers::req::tests::superseded_timeout_leaves_replacement_intact) + test(=handlers::req::tests::search_claim_retires_live_and_yields_to_replacement) + test(=handlers::req::tests::concurrent_claims_and_stale_teardowns_keep_the_last_owner) + test(=handlers::req::tests::timeout_closed_is_emitted_before_a_replacement_can_claim) + test(=handlers::req::tests::revoke_then_replacement_keeps_replacement_whole) + test(=handlers::req::tests::claims_after_connection_cleanup_are_refused) + test(=handlers::req::tests::dropped_terminal_frame_cancels_connection) + test(=handlers::req::tests::revoke_dropped_terminal_frame_cancels_connection) + test(=handlers::req::tests::count_fallback_covers_filters_that_can_match_private_deletions) + test(=handlers::req::tests::group_state_t_and_creator_tags_reach_sql_only_for_group_state_kinds) + test(=api::bridge::postgres_tests::bridge_search_mode_extension_accepts_prefix_snake_or_camel_case) + test(=api::bridge::postgres_tests::bridge_search_sort_extension_selects_newest_only_when_named) + (kind(bin) & (test(/^tests::/) + test(/^composition_tests::/) + test(/^env_filter_tests::/)) - test(/^tests::postgres_tests::/))' # Note on audio::join::tests scope: the full suite is infra-free (no DB, # no Redis). The infra-free audio/FI regression witnesses — bootstrap # ordering barrier, CommitConfirmed arm, pending-close invisibility, diff --git a/NOSTR.md b/NOSTR.md index bb9b911017..62e438d30d 100644 --- a/NOSTR.md +++ b/NOSTR.md @@ -57,7 +57,7 @@ PGPASSWORD=buzz_dev psql -h localhost -U buzz -d buzz -c \ | **Admin delete event (kind:9005)** | ✅ | Event author can always delete own. Otherwise owner/admin required. Target must be in same channel. | | **Group deletion (kind:9008)** | ✅ | Owner only. | | **Leave group (kind:9022)** | ✅ | Any member. Last-owner guard prevents orphaned groups. | -| **Group metadata (kind:39000)** | ✅ | Relay-signed; always `d`, `name`, `closed`, `["t", ]`, `["P", ]` and `["created_at", ]` tags; `about` only if description non-empty; `private` if applicable; `hidden` for DM channels | +| **Group metadata (kind:39000)** | ✅ | Relay-signed; always `d`, `name`, `closed`, `["t", ]`, `["P", ]` and `["created_at", ]` tags; `about` only if description non-empty; `private` if applicable; `hidden` for DM channels and private system channels | | **Group admins (kind:39001)** | ✅ | Relay-signed; `d`, channel type `t` and creator `P` tags + `p` tags with roles (`owner`, `admin`) | | **Group members (kind:39002)** | ✅ | Relay-signed; `d`, channel type `t` and creator `P` tags + `p` tags for all members | | **Membership notifications** | ✅ | kind:44100 (added) / kind:44101 (removed); relay-signed, community-global scope (`channel_id=None` inside the connected community) | @@ -67,7 +67,7 @@ PGPASSWORD=buzz_dev psql -h localhost -U buzz -d buzz -c \ | **NIP-42 authentication** | ✅ | Proactive challenge; optional pubkey allowlist | | **NIP-11 relay info** | ✅ | `GET /` with `Accept: application/nostr+json` | | **Blossom media** | ✅ | `PUT /media/upload` (BUD-02), `GET /media/{sha256}.{ext}` (BUD-01) | -| **NIP-50 search** | ✅ | One-shot search REQs: `{"search":"query","kinds":[9],"#h":[""]}` → relevance-sorted results → EOSE. Not registered as persistent subscriptions. | +| **NIP-50 search** | ✅ | One-shot search REQs: `{"search":"query","kinds":[9],"#h":[""]}` → relevance-sorted results → EOSE. Not registered as persistent subscriptions. HTTP `POST /query` also accepts `search_sort: "newest"` (advertised as `buzz-search-sort` in NIP-11 `supported_extensions`) for newest-first results, paged with `page`. | | **NIP-10 threads** | ✅ | WS-submitted replies with `["e","","","reply"]` tags create `thread_metadata` atomically. Visible in REST thread queries. Unknown parents rejected. | | **NIP-17 DMs (gift wrap)** | ✅ | kind:1059 accepted with ephemeral signing keys. Stored community-globally (`channel_id=None` inside the connected community). Delivered via `#p`-filtered subscriptions. Not indexed in search. | | **DM discovery** | ✅ | DM creation emits kind:39000 (with `hidden` tag) + kind:44100 membership notifications. NIP-29 clients discover DMs via standard group discovery flow. | @@ -109,7 +109,7 @@ All discovery events include a `d` tag set to the channel UUID (NIP-29 addressab | Kind | Tags | Content | |------|------|---------| -| **39000** | `d=`, `name`, `closed`, `t=`, `P=`, `created_at=` (always); `about` (if description non-empty); `private` (if applicable); `hidden` (DM channels only) | Group metadata. **Note:** `closed` is always emitted per NIP-29 convention (Buzz channels require explicit membership), but open channels are still readable/writable by non-members at runtime. The tag reflects the membership model, not access enforcement. | +| **39000** | `d=`, `name`, `closed`, `t=`, `P=`, `created_at=` (always); `about` (if description non-empty); `private` (if applicable); `hidden` (DM channels and private system channels) | Group metadata. **Note:** `closed` is always emitted per NIP-29 convention (Buzz channels require explicit membership), but open channels are still readable/writable by non-members at runtime. The tag reflects the membership model, not access enforcement. | | **39001** | `d=`, `t=`, `P=`, `p` tags with role label (`owner`, `admin`) | Admin list | | **39002** | `d=`, `t=`, `P=`, `p` tags for all members | Member list | @@ -136,6 +136,24 @@ that is not 1-64 characters from `a-z`, `0-9`, `.`, `:` and `-`, or a label equal to a channel type name (`stream`, `forum`, `dm`, `workflow`, `system`). +**System channels.** A channel with `channel_type` `system` exists only for +access control, for example to hold config that only an agent and its owner +can read. It is an ordinary channel in every other way, but queries leave it +out unless they ask for it: + +- A filter that does not name it, for example a REQ with no `#h`, a COUNT, + a NIP-50 search, or kind:39002 `#p:[me]`, does not return it. +- A filter that names it with `#h`, or with `#d` on kinds 39000–39003, reads + it under the ordinary rules: the reader is a member, or it is open. +- A filter on kinds 39000–39003 with `#t:["system"]` or any `#P` also + returns the system channels the reader can read, then matches as usual. + For example, `{kinds:[39000], #P:[], #t:[