Skip to content

refactor(supabase): rename stream regex filters and cover stream filters with tests - #1639

Merged
spydon merged 5 commits into
mainfrom
fix/stream-filter-followup
Aug 5, 2026
Merged

spydon merged 5 commits into
mainfrom
fix/stream-filter-followup

Conversation

@spydon

@spydon spydon commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1610.

  • Renames match and imatch to matchRegex and imatchRegex. PostgrestFilterBuilder.match takes a map of equality checks and maps to a different capability, its regex filters are matchRegex and imatchRegex, and the stream filters delegated to query.matchRegex while being named match. Every other stream filter already mirrors the PostgREST name. Both methods are unreleased, so no published API changes.
  • Fixes the stream() docs: filter list, and what the DELETE limitation means and how replica identity full lifts it.
  • Registers the remaining stream filters in sdk-compliance.yaml.
  • Adds test/stream_filter_test.dart, which asserts what every filter sends to realtime and to PostgREST against a mock server, so the mapping is covered without a backend.
  • Extends the integration tests to unfiltered streams, more filter combinations, updates that stay inside, leave and enter the filter, deletes, and order with limit.
  • Makes the integration tests wait for the channel to join instead of sleeping, warm up replication once, and settle their mutations before the test ends.

Summary by CodeRabbit

  • New Features

    • Expanded stream filtering with comparison, membership, pattern, null, boolean, and distinct filters.
    • Added support for ordering and limiting stream results.
    • Renamed regex filters to matchRegex and imatchRegex.
    • Multiple stream filters are now combined with AND.
  • Documentation

    • Clarified delete behavior, replica identity requirements, supported filters, and usage examples.
  • Tests

    • Added comprehensive coverage for filter serialization, combined filters, updates, deletes, ordering, and limits.

spydon added 3 commits August 4, 2026 13:58
…tchRegex

Aligns them with PostgrestFilterBuilder, where match takes a map of column
equality checks and the regex filters are called matchRegex and imatchRegex.
Also registers the remaining stream filters in the compliance matrix and
renames the private filter list to match its plural content.
@spydon
spydon requested a review from a team as a code owner August 4, 2026 11:58
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The stream filter collection was renamed, regex filter methods were renamed, and stream documentation was expanded. Mock-server tests verify filter serialization. Local-stack integration tests now cover filtering, updates, deletes, ordering, limits, and deterministic replication behavior.

Changes

Stream filters

Layer / File(s) Summary
Filter API and query wiring
packages/supabase/lib/src/supabase_query_builder.dart, packages/supabase/lib/src/supabase_stream_*.dart, sdk-compliance.yaml
The internal filter collection is now _streamFilters. Filters are documented as combining with AND. matchRegex and imatchRegex replace match and imatch. Stream documentation and compliance symbols were updated.
Filter serialization tests
packages/supabase/test/stream_filter_test.dart
Mock-server tests cover Realtime payloads and PostgREST parameters for comparisons, membership, patterns, null and boolean checks, distinct filters, combined filters, and comma-containing values.
Local-stack integration setup
packages/supabase/test/utils/local_stack.dart, packages/supabase/test/stream_integration_test.dart
Integration tests use shared local-stack settings, seed restoration, replication warm-up, asynchronous mutations, and regex filter coverage.
Stream mutation and modifier coverage
packages/supabase/test/stream_integration_test.dart
Tests cover records entering or leaving matches, deletes, ordering, limits, channel readiness, snapshot deduplication, and mutation error handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: tr00d

🚥 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 accurately summarizes the main changes: renaming stream regex filter methods and adding comprehensive test coverage for stream filters.
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 fix/stream-filter-followup

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 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/supabase/lib/src/supabase_query_builder.dart`:
- Line 69: Reflow the added Dart documentation to keep every line within 80
characters, then run dart format. In
packages/supabase/lib/src/supabase_query_builder.dart lines 69-69, split the
stream chain and format the eq arguments; at lines 73-73, split the chained
filter example; and at lines 57-57, shorten or reflow the documentation link. In
packages/supabase/lib/src/supabase_stream_filter_builder.dart lines 144-144 and
159-159, split the matchRegex and imatchRegex examples respectively.

In `@packages/supabase/test/stream_filter_test.dart`:
- Around line 22-36: Update the mock server setup around HttpServer.bind and
SupabaseClient to bind an explicit numeric loopback address instead of resolving
“localhost”. Construct the client URL from the bound server address (or the same
explicit loopback value) so the endpoint used by SupabaseClient always matches
the listening server.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 56ed0b2d-0afe-4cf2-98a3-c0cdaf084f56

📥 Commits

Reviewing files that changed from the base of the PR and between 5447063 and 3950dae.

📒 Files selected for processing (7)
  • packages/supabase/lib/src/supabase_query_builder.dart
  • packages/supabase/lib/src/supabase_stream_builder.dart
  • packages/supabase/lib/src/supabase_stream_filter_builder.dart
  • packages/supabase/test/stream_filter_test.dart
  • packages/supabase/test/stream_integration_test.dart
  • packages/supabase/test/utils/local_stack.dart
  • sdk-compliance.yaml

Copilot AI 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.

Pull request overview

This PR refactors Supabase’s stream() filter API to align naming with PostgREST (clarifying regex vs map-based match), updates stream() documentation to better explain filter behavior and DELETE limitations, and strengthens coverage with both mock-based and local-stack integration tests.

Changes:

  • Renamed stream regex filters from match/imatch to matchRegex/imatchRegex and ensured PostgREST mapping uses matchRegex/imatchRegex.
  • Improved stream() docs (filter list, AND semantics, and DELETE behavior with replica identity full).
  • Added/extended tests: mock server assertions for filter serialization and more robust local-stack integration tests (join-waiting, replication warm-up, more scenarios).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sdk-compliance.yaml Registers additional SupabaseStreamFilterBuilder symbols (including renamed regex filters) for compliance tracking.
packages/supabase/test/utils/local_stack.dart Introduces shared local Supabase stack constants for supabase package tests.
packages/supabase/test/stream_integration_test.dart Expands and stabilizes realtime stream integration tests (no-filter streams, AND semantics, update/delete scenarios, join waiting).
packages/supabase/test/stream_filter_test.dart Adds mock-based tests asserting realtime join filter serialization and PostgREST query parameters for each stream filter.
packages/supabase/lib/src/supabase_stream_filter_builder.dart Renames and documents regex filter methods as matchRegex/imatchRegex; updates internal filter accumulation.
packages/supabase/lib/src/supabase_stream_builder.dart Renames internal filter list to _streamFilters, ensures realtime and PostgREST both apply all filters, and maps regex types to matchRegex/imatchRegex.
packages/supabase/lib/src/supabase_query_builder.dart Updates stream() documentation to reflect the new filter names, semantics, and DELETE filtering caveat.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai coderabbitai Bot 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.

Caution

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

⚠️ Outside diff range comments (3)
packages/supabase/test/stream_integration_test.dart (3)

443-462: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Require the ONLINE transition in this test.

_usernames maps the OFFLINE insert and the ONLINE update to the same moves_in value. If the stream incorrectly delivers the OFFLINE insert, the second expected snapshot matches and the later update is not asserted. Project statuses and require moves_in:ONLINE.

🤖 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/supabase/test/stream_integration_test.dart` around lines 443 - 462,
Update the test around `_expectSnapshots` so expected snapshots include each
username’s status, requiring `moves_in` to be `ONLINE` in the final snapshot.
Ensure the assertion cannot pass from the initial `OFFLINE` insert and
specifically verifies the subsequent status transition.

520-536: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the ordered snapshot snapshot instead of a set.

This test sets .order('username', ascending: true).limit(2), but _usernames() projects to Set<String> and _isSameSnapshot() only checks membership and count. A reversed two-row projection would still satisfy this test. Use an order-preserving projection and matcher for this modifier test.

🤖 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/supabase/test/stream_integration_test.dart` around lines 520 - 536,
The test uses set notation in expectedSnapshots which loses ordering
information, allowing reversed results to pass. Replace the set-based
expectedSnapshots (currently shown as curly braces like {'awailas',
'dragarcia'}) with list-based snapshots using square brackets to preserve
insertion order. Ensure the underlying _usernames() projection and
_isSameSnapshot() comparison logic also preserve order instead of treating
results as unordered collections.

542-593: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Do not mask mutation failures with a stream timeout.

The mutation future catches its error and completes successfully. If mutate fails before expectLater receives all expected snapshots, the assertion times out and returns before the stored error can be rethrown. Await both assertions together with Future.wait(..., eagerError: true), and consume mutations during cleanup with error handling so it does not throw again.

🤖 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/supabase/test/stream_integration_test.dart` around lines 542 - 593,
In the _expectSnapshots function, the mutations future completes successfully
even when mutate fails, allowing expectLater to timeout and mask the mutation
error. Replace the try-finally block that separately awaits expectLater and
mutations with a Future.wait call that includes both the expectLater stream
assertion and the mutations future, passing eagerError: true so either failure
is caught immediately. Then in the finally cleanup, consume the mutations future
with error handling using catchError or similar to prevent it from throwing
again after the primary assertion has already failed.
🤖 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.

Outside diff comments:
In `@packages/supabase/test/stream_integration_test.dart`:
- Around line 443-462: Update the test around `_expectSnapshots` so expected
snapshots include each username’s status, requiring `moves_in` to be `ONLINE` in
the final snapshot. Ensure the assertion cannot pass from the initial `OFFLINE`
insert and specifically verifies the subsequent status transition.
- Around line 520-536: The test uses set notation in expectedSnapshots which
loses ordering information, allowing reversed results to pass. Replace the
set-based expectedSnapshots (currently shown as curly braces like {'awailas',
'dragarcia'}) with list-based snapshots using square brackets to preserve
insertion order. Ensure the underlying _usernames() projection and
_isSameSnapshot() comparison logic also preserve order instead of treating
results as unordered collections.
- Around line 542-593: In the _expectSnapshots function, the mutations future
completes successfully even when mutate fails, allowing expectLater to timeout
and mask the mutation error. Replace the try-finally block that separately
awaits expectLater and mutations with a Future.wait call that includes both the
expectLater stream assertion and the mutations future, passing eagerError: true
so either failure is caught immediately. Then in the finally cleanup, consume
the mutations future with error handling using catchError or similar to prevent
it from throwing again after the primary assertion has already failed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d8e8d89e-8ac0-4023-a104-8f3f9622bb46

📥 Commits

Reviewing files that changed from the base of the PR and between 14a8b66 and 7700919.

📒 Files selected for processing (3)
  • packages/supabase/test/stream_filter_test.dart
  • packages/supabase/test/stream_integration_test.dart
  • sdk-compliance.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdk-compliance.yaml

@spydon
spydon merged commit b9c31bb into main Aug 5, 2026
39 checks passed
@spydon
spydon deleted the fix/stream-filter-followup branch August 5, 2026 07:15
spydon added a commit that referenced this pull request Aug 5, 2026
…1640)

Follow-up to #1639.

The URL, ports and API keys of the local Supabase CLI stack were copied
into every test suite that talks to it. The service role JWT alone
existed in five places, port 54421 in more than twenty.

- Adds `package:supabase_common/testing.dart`, holding the host, ports,
per-service URLs, the mail server address, the anon and service role
keys and the JWT secret. Every package already depends on
`supabase_common`, so no pubspec changes.
- Annotates the constants with `@visibleForTesting`, so they are usable
from any package's test directory but rejected in library code, which CI
catches through `dart analyze --fatal-infos`.
- Points postgrest, realtime_client, storage_client, gotrue and supabase
at them directly. Only values that are actually derived stay local:
`apiHeaders`, `resetAuthDataUrl` and the Postgres endpoint record.
- Removes `packages/supabase/test/utils/local_stack.dart`, which #1639
had added.
- Simplifies the verify link pattern in the gotrue tests, which no
longer needs double escaping.

No hardcoded stack address or key is left outside the shared library.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Standardized integration tests across Auth, REST, Realtime, Storage,
and database services to use shared local stack settings.
  * Improved portability across configurable environments.
  * Updated email-link matching and authentication fixture setup.
* Removed duplicated local URLs and credentials from test
configurations.
* **Chores**
* Added centralized testing utilities for service endpoints,
credentials, mail, and database settings.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

4 participants