Skip to content

Fix/mock relay live subscriptions#648

Open
nogringo wants to merge 2 commits into
masterfrom
fix/mock-relay-live-subscriptions
Open

Fix/mock relay live subscriptions#648
nogringo wants to merge 2 commits into
masterfrom
fix/mock-relay-live-subscriptions

Conversation

@nogringo

@nogringo nogringo commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Fixed MockRelay's EVENT handling to correctly suppress broadcasting for replaceable and addressable events when they should not replace stored data.
  • Tests

    • Added integration test for MockRelay live subscriptions, verifying cross-instance event broadcasting and subscription delivery.

@nogringo nogringo requested review from 1-leo and frnandu June 6, 2026 11:37
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

MockRelay's EVENT processing now conditionally broadcasts incoming events based on a shouldBroadcastToSubscriptions flag. For replaceable/addressable and special-kind events (contact lists, metadata), broadcasting is suppressed when the event does not replace the currently stored one. A new integration test validates that live subscriptions correctly receive events through the mock relay.

Changes

MockRelay Broadcast Suppression and Live Subscription Test

Layer / File(s) Summary
Broadcast suppression for non-replacement events
packages/ndk/test/mocks/mock_relay.dart
shouldBroadcastToSubscriptions boolean controls whether EVENT is broadcast to subscriptions. Contact list, metadata, replaceable-kind, and addressable-kind branches explicitly set the flag to false when replacement does not occur. Ephemeral-kind events defer broadcasting to centralized conditional logic instead of broadcasting immediately.
Live subscription integration test
packages/ndk/test/mocks/mock_relay_live_subscription_test.dart
New test creates two NDK instances, registers a subscription filter in one instance for text note events, broadcasts a signed NIP01 event from the other instance to the mock relay, and asserts the subscription receives the event with correct ID and content within a 2-second timeout.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • relaystr/ndk#605: Both PRs modify packages/ndk/test/mocks/mock_relay.dart's "EVENT" handling for replaceable/addressable/NIP-01 kinds (including ContactList and Metadata), changing how replacement vs non-replacement is processed—main PR adds shouldBroadcastToSubscriptions-based broadcast suppression while the retrieved PR implements _shouldReplace/identity-based replacement rules.

Suggested reviewers

  • frnandu
  • 1-leo

Poem

🐰 A relay springs to life, events now flow with grace,
Broadcast flags dance gently, knowing their rightful place,
When replacements falter, silence falls just so,
Live subscriptions thrive now—watch the test events go! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix/mock relay live subscriptions' directly relates to the main changes: fixing MockRelay event broadcasting behavior for live subscriptions and adding a comprehensive integration test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mock-relay-live-subscriptions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ndk/test/mocks/mock_relay_live_subscription_test.dart`:
- Around line 15-18: The test uses a fixed port by constructing MockRelay with
explicitPort: 4070 which can cause bind failures; update the setup where
mockRelay is created (the MockRelay instantiation assigned to mockRelay) to omit
explicitPort (or pass null/undefined per API) so MockRelay auto-allocates a free
port instead, ensuring parallel tests won't conflict.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b0f54742-2ad6-4c39-a6b4-c9f4958e7aa6

📥 Commits

Reviewing files that changed from the base of the PR and between 8f3a3b9 and fbdc15d.

📒 Files selected for processing (2)
  • packages/ndk/test/mocks/mock_relay.dart
  • packages/ndk/test/mocks/mock_relay_live_subscription_test.dart

Comment on lines +15 to +18
mockRelay = MockRelay(
name: 'live-subscription-test-relay',
explicitPort: 4070,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid fixed port in integration test setup.

Using explicitPort: 4070 can cause intermittent bind failures under parallel test runs or when the port is occupied. Let MockRelay auto-allocate its test port.

Suggested change
       mockRelay = MockRelay(
         name: 'live-subscription-test-relay',
-        explicitPort: 4070,
       );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
mockRelay = MockRelay(
name: 'live-subscription-test-relay',
explicitPort: 4070,
);
mockRelay = MockRelay(
name: 'live-subscription-test-relay',
);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ndk/test/mocks/mock_relay_live_subscription_test.dart` around lines
15 - 18, The test uses a fixed port by constructing MockRelay with explicitPort:
4070 which can cause bind failures; update the setup where mockRelay is created
(the MockRelay instantiation assigned to mockRelay) to omit explicitPort (or
pass null/undefined per API) so MockRelay auto-allocates a free port instead,
ensuring parallel tests won't conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant