Skip to content

Comments

Add NIP-50 search filter support#56

Merged
kwsantiago merged 6 commits intomainfrom
NIP-50
Jan 24, 2026
Merged

Add NIP-50 search filter support#56
kwsantiago merged 6 commits intomainfrom
NIP-50

Conversation

@wksantiago
Copy link
Contributor

@wksantiago wksantiago commented Jan 24, 2026

Adds search field to filters for relay full-text search capability.

Summary by CodeRabbit

  • New Features

    • Added NIP-50 search support for filters: optional query-based matching with accessors and new match APIs that invoke search callbacks when present.
  • Tests

    • Added a comprehensive NIP-50 test suite and test executable covering parsing, cloning, search matching, client message handling, and memory/safety scenarios.
  • Documentation

    • Updated README to list NIP-50 as an optional feature.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 24, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

Adds NIP‑50 "search" support: a search field on nostr_filter_t, a search callback type, search-aware matching APIs and accessors, JSON parsing/clone/free updates, a new NIP‑50 test suite, CMake test target, and README feature flag update.

Changes

Cohort / File(s) Summary
Relay Protocol Header
include/nostr_relay_protocol.h
Adds char *search to nostr_filter_t, defines nostr_search_callback_t, and declares nostr_filter_matches_with_search, nostr_filters_match_with_search, nostr_filter_get_search, and nostr_filter_has_search.
Filter Implementation
src/relay_filter.c
Parses/validates search from JSON, allocates/frees/clones filter->search, adds nostr_filter_matches_with_search and batch variant, and implements accessors and search-aware matching integration.
Tests & Build
tests/CMakeLists.txt, tests/test_nip50.c
Adds test_nip50 target and an extensive NIP‑50 test suite (parsing, cloning, matching, REQ parsing) with Unity and standalone runner support.
Docs / Flags
README.md
Adds NIP‑50 to the optional NIPs list exposed via feature flags.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I sniffed the relay and found a thread,
A curious search string where events are led,
Filters lean closer, callbacks hop in tune,
Tests hum softly beneath the moon,
Hooray for NIP‑50 — nibble, then sprint.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change—adding NIP-50 search filter support—which is the primary objective across all modified files.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@wksantiago wksantiago requested a review from kwsantiago January 24, 2026 13:13
@wksantiago wksantiago self-assigned this Jan 24, 2026
@wksantiago wksantiago linked an issue Jan 24, 2026 that may be closed by this pull request
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/test_nip50.c`:
- Around line 59-66: The TEST_ASSERT_EQUAL_STRING macro can dereference NULL via
strcmp; update the macro (TEST_ASSERT_EQUAL_STRING) to first check if either
expected or actual is NULL, handle cases where both are NULL (treat as equal) or
one is NULL (log which side is NULL), set g_test_failed = 1 and return, and only
call strcmp when both pointers are non-NULL so no undefined behavior occurs.
🧹 Nitpick comments (2)
src/relay_filter.c (1)

437-447: Consider documenting the silent failure when callback is NULL but search is specified.

When a filter has a non-empty search field but search_cb is NULL, the function returns false. While this is a reasonable defensive behavior, it may silently fail from the caller's perspective if they forget to provide a callback for a filter with search.

Consider whether logging a warning or documenting this behavior more explicitly would help developers debug issues where filters unexpectedly don't match.

tests/test_nip50.c (1)

167-186: Test test_filter_clone_with_search has a subtle memory safety concern.

The test sets src.kinds to point to a stack-allocated array (int32_t kinds[] = {1}). While this works because nostr_filter_clone copies the data and the stack array remains valid throughout the function, this pattern could be fragile if the test structure changes. Also, nostr_filter_free is only called on dst, not src, which is correct here since src uses stack memory for most fields, but src.search is heap-allocated and properly freed.

The test is correct as written, but consider adding a comment explaining the intentional partial initialization for clarity.

@wksantiago
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 24, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/test_nip50.c`:
- Around line 161-173: Capture and assert the result of nostr_filter_parse in
test_filter_get_search before using the filter; e.g., store its return in a
variable (rc) and add an assertion that parsing succeeded (use
TEST_ASSERT_TRUE(rc == 0) or TEST_ASSERT_EQUAL_INT(0, rc) depending on the
project's convention) prior to calling nostr_filter_get_search,
nostr_filter_has_search, and nostr_filter_free.

@wksantiago
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 24, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kwsantiago kwsantiago merged commit e98d271 into main Jan 24, 2026
11 of 12 checks passed
@kwsantiago kwsantiago deleted the NIP-50 branch January 24, 2026 22:58
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.

NIP-50: Search Capability (Relay)

2 participants