Skip to content

test: add metadata NIP-65 relay discovery regression - #698

Open
nogringo wants to merge 4 commits into
masterfrom
test/metadata-nip65-relay-discovery
Open

test: add metadata NIP-65 relay discovery regression#698
nogringo wants to merge 4 commits into
masterfrom
test/metadata-nip65-relay-discovery

Conversation

@nogringo

@nogringo nogringo commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Improvements

    • Metadata loading now follows an author’s preferred write relay when available, improving profile information retrieval.
  • Bug Fixes

    • Relay responses now correctly return multiple event types from combined queries, including metadata, contacts, relay lists, and replaceable events.
  • Tests

    • Added coverage for metadata retrieval through author write relays across supported relay engines.
    • Added validation for combined event-kind queries.

@nogringo
nogringo marked this pull request as draft July 16, 2026 14:20
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Metadata loading now resolves the author’s NIP-65 write relays and queries them explicitly. Initialization supplies UserRelayLists to Metadatas. MockRelay now supports independent multi-kind event matching with integration tests.

Changes

Metadata relay routing and mock relay matching

Layer / File(s) Summary
Metadata write-relay routing and validation
packages/ndk/lib/domain_layer/usecases/metadatas/metadatas.dart, packages/ndk/lib/presentation_layer/init.dart, packages/ndk/test/usecases/metadatas/metadata_nip65_test.dart
Metadatas receives UserRelayLists, resolves author write relays, and passes them through explicitRelays. Initialization creates the dependency first. Tests cover both engine modes.
Multi-kind MockRelay matching
packages/ndk/test/mocks/mock_relay.dart, packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart
MockRelay evaluates event categories independently. The integration test verifies retrieval of relay-list, contact-list, metadata, and parameterized replaceable events from one filter.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Metadatas
  participant UserRelayLists
  participant Requests
  participant AuthorWriteRelay
  Metadatas->>UserRelayLists: Load author relay list
  UserRelayLists-->>Metadatas: Return write relay URLs
  Metadatas->>Requests: Query metadata with explicitRelays
  Requests->>AuthorWriteRelay: Request metadata
  AuthorWriteRelay-->>Requests: Return metadata event
Loading

Possibly related PRs

Suggested reviewers: frnandu, 1-leo

🚥 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 clearly describes the added metadata NIP-65 relay discovery regression test and matches the main purpose of the changes.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/metadata-nip65-relay-discovery

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.

@nogringo
nogringo force-pushed the test/metadata-nip65-relay-discovery branch from 3d6b5b3 to 5063baf Compare August 8, 2026 10:13
@nogringo
nogringo marked this pull request as ready for review August 8, 2026 10:54
@nogringo
nogringo requested review from 1-leo and frnandu August 8, 2026 10:54
@nogringo nogringo self-assigned this Aug 8, 2026

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/ndk/test/mocks/mock_relay.dart (2)

530-544: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep one text-note response path.

This block adds raw textNotes. Lines 576-608 add the same matching notes again after cloning and signing them. A request can receive duplicate events or select the unsigned event first.

Remove this raw path, or move its filter logic into the existing signing path.

🤖 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.dart` around lines 530 - 544, Remove the
raw textNotes addition block from the response-building flow, leaving the
existing cloning and signing path as the sole source of text-note events.
Preserve its filtering behavior by relying on the matching logic in the signing
path, preventing duplicate or unsigned events from being returned.

485-513: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Apply all filter constraints to specialized events.

The metadata and NIP-85 branches ignore filter.ids. The NIP-85 branch also ignores since and until. A multi-kind query can therefore receive an unrelated specialized event.

Apply the ID and time predicates before adding these candidates. Keep the NIP-85 dTags predicate.

🤖 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.dart` around lines 485 - 513, Update the
metadata branch and NIP-85 assertion branch in the relay filter logic to enforce
filter.ids plus the existing time constraints before adding events to
eventsForThisFilter. For NIP-85 candidates, retain the current dTags predicate
and combine it with ID, since, and until matching; ensure specialized events
only pass when all applicable filter constraints match.
🤖 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_multi_kind_filter_test.dart`:
- Around line 27-33: Register teardown callbacks immediately after constructing
ndkWriter at
packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart:27-33 and
ndkReader at
packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart:112-119, calling
each instance’s destroy() method so cleanup runs even when assertions fail.

---

Outside diff comments:
In `@packages/ndk/test/mocks/mock_relay.dart`:
- Around line 530-544: Remove the raw textNotes addition block from the
response-building flow, leaving the existing cloning and signing path as the
sole source of text-note events. Preserve its filtering behavior by relying on
the matching logic in the signing path, preventing duplicate or unsigned events
from being returned.
- Around line 485-513: Update the metadata branch and NIP-85 assertion branch in
the relay filter logic to enforce filter.ids plus the existing time constraints
before adding events to eventsForThisFilter. For NIP-85 candidates, retain the
current dTags predicate and combine it with ID, since, and until matching;
ensure specialized events only pass when all applicable filter constraints
match.
🪄 Autofix

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 Plus

Run ID: 59afd68e-8e33-4049-ac8e-3f71922e0732

📥 Commits

Reviewing files that changed from the base of the PR and between 4e28d2e and f509816.

📒 Files selected for processing (5)
  • packages/ndk/lib/domain_layer/usecases/metadatas/metadatas.dart
  • packages/ndk/lib/presentation_layer/init.dart
  • packages/ndk/test/mocks/mock_relay.dart
  • packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart
  • packages/ndk/test/usecases/metadatas/metadata_nip65_test.dart

Comment on lines +27 to +33
final ndkWriter = Ndk(
NdkConfig(
cache: MemCacheManager(),
eventVerifier: MockEventVerifier(),
bootstrapRelays: [mockRelay.url],
),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Destroy each NDK instance through teardown.

If an assertion fails before Lines 155-156, neither destroy() call runs. The test can leave relay connections and retry work active.

  • packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart#L27-L33: Register addTearDown(() => ndkWriter.destroy()) immediately after construction.
  • packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart#L112-L119: Register addTearDown(() => ndkReader.destroy()) immediately after construction.
📍 Affects 1 file
  • packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart#L27-L33 (this comment)
  • packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart#L112-L119
🤖 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_multi_kind_filter_test.dart` around lines
27 - 33, Register teardown callbacks immediately after constructing ndkWriter at
packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart:27-33 and
ndkReader at
packages/ndk/test/mocks/mock_relay_multi_kind_filter_test.dart:112-119, calling
each instance’s destroy() method so cleanup runs even when assertions fail.

@1-leo 1-leo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This works, however in the initial concept of NDK gossip the engines are responsible for calling the right relays.
This shortcuts this by passing explicit relays.
Not sure if we want this, because for consistency we would need it in other use cases as well, making the discovery part in the engines obsolete.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.37%. Comparing base (4e28d2e) to head (f509816).

Files with missing lines Patch % Lines
...lib/domain_layer/usecases/metadatas/metadatas.dart 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #698      +/-   ##
==========================================
+ Coverage   71.32%   71.37%   +0.05%     
==========================================
  Files         225      225              
  Lines       13201    13211      +10     
==========================================
+ Hits         9416     9430      +14     
+ Misses       3785     3781       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nogringo

nogringo commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

As in the tests actually both engines were failing

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.

2 participants