Repository navigation
refactor(supabase): rename stream regex filters and cover stream filters with tests - #1639
Conversation
…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.
📝 WalkthroughWalkthroughThe 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. ChangesStream filters
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
packages/supabase/lib/src/supabase_query_builder.dartpackages/supabase/lib/src/supabase_stream_builder.dartpackages/supabase/lib/src/supabase_stream_filter_builder.dartpackages/supabase/test/stream_filter_test.dartpackages/supabase/test/stream_integration_test.dartpackages/supabase/test/utils/local_stack.dartsdk-compliance.yaml
There was a problem hiding this comment.
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/imatchtomatchRegex/imatchRegexand ensured PostgREST mapping usesmatchRegex/imatchRegex. - Improved
stream()docs (filter list, AND semantics, and DELETE behavior withreplica 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.
There was a problem hiding this comment.
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 winRequire the
ONLINEtransition in this test.
_usernamesmaps theOFFLINEinsert and theONLINEupdate to the samemoves_invalue. If the stream incorrectly delivers theOFFLINEinsert, the second expected snapshot matches and the later update is not asserted. Project statuses and requiremoves_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 winAssert the ordered snapshot snapshot instead of a set.
This test sets
.order('username', ascending: true).limit(2), but_usernames()projects toSet<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 winDo not mask mutation failures with a stream timeout.
The mutation future catches its error and completes successfully. If
mutatefails beforeexpectLaterreceives all expected snapshots, the assertion times out and returns before the stored error can be rethrown. Await both assertions together withFuture.wait(..., eagerError: true), and consumemutationsduring 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
📒 Files selected for processing (3)
packages/supabase/test/stream_filter_test.dartpackages/supabase/test/stream_integration_test.dartsdk-compliance.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
- sdk-compliance.yaml
…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 -->
Follow-up to #1610.
matchandimatchtomatchRegexandimatchRegex.PostgrestFilterBuilder.matchtakes a map of equality checks and maps to a different capability, its regex filters arematchRegexandimatchRegex, and the stream filters delegated toquery.matchRegexwhile being namedmatch. Every other stream filter already mirrors the PostgREST name. Both methods are unreleased, so no published API changes.stream()docs: filter list, and what the DELETE limitation means and howreplica identity fulllifts it.sdk-compliance.yaml.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.orderwithlimit.Summary by CodeRabbit
New Features
matchRegexandimatchRegex.AND.Documentation
Tests