Skip to content

refactor(supabase_common): share the local stack test configuration - #1640

Merged
spydon merged 4 commits into
mainfrom
refactor/shared-local-stack-config
Aug 5, 2026
Merged

refactor(supabase_common): share the local stack test configuration#1640
spydon merged 4 commits into
mainfrom
refactor/shared-local-stack-config

Conversation

@spydon

@spydon spydon commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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 refactor(supabase): rename stream regex filters and cover stream filters with tests #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.

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.

@spydon
spydon requested a review from a team as a code owner August 4, 2026 13:29
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 190b2de9-3378-417e-9047-144f11c4cb7d

📥 Commits

Reviewing files that changed from the base of the PR and between 3c7b3ce and b4df42b.

📒 Files selected for processing (3)
  • packages/gotrue/test/client_test.dart
  • packages/realtime_client/test/utils/realtime_test_utils.dart
  • packages/storage_client/test/client_test.dart
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/realtime_client/test/utils/realtime_test_utils.dart
  • packages/storage_client/test/client_test.dart

📝 Walkthrough

Walkthrough

The change centralizes local Supabase stack URLs, credentials, mail settings, and database settings in supabase_common. Integration tests across GoTrue, PostgREST, Realtime, Storage, and Supabase now use the shared configuration.

Changes

Shared local-stack configuration

Layer / File(s) Summary
Testing configuration foundation
packages/supabase_common/lib/testing.dart, packages/supabase_common/lib/src/testing/local_stack.dart
Adds exported constants for local-stack services, database settings, mail settings, API keys, and the JWT secret.
GoTrue test configuration
packages/gotrue/test/*
Replaces hardcoded Auth, Mailpit, reset, and credential values with shared constants. Environment overrides remain supported. The PKCE email-change helper now derives verification-link matching from the configured Auth URL.
PostgREST test configuration
packages/postgrest/test/*
Updates PostgREST clients and service-role headers to use shared local-stack values.
Realtime, Storage, and Supabase tests
packages/realtime_client/test/*, packages/storage_client/test/*, packages/supabase/test/*
Updates endpoints, database settings, signing secrets, and service-role credentials to use the shared testing library.

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

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 clearly and concisely describes the main change: sharing local Supabase stack test configuration through supabase_common.
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 refactor/shared-local-stack-config

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.

@Vinzent03 Vinzent03 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like that most of them should be usable by normal package users as well for their own testing suites. Unsure if that should/could be documented somewhere such that users are aware of this.

Base automatically changed from fix/stream-filter-followup to main August 5, 2026 07:15
@spydon

spydon commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

I like that most of them should be usable by normal package users as well for their own testing suites. Unsure if that should/could be documented somewhere such that users are aware of this.

Right now the package is marked as internal, but later we can for sure document it and open it up. :)

spydon added 3 commits August 5, 2026 09:17
The URL, ports and API keys of the local Supabase CLI stack were duplicated
across the test suites, the service role key alone in five places. Move them
into a testing library of supabase_common, annotated with @VisibleForTesting so
they cannot leak into runtime code.
The per package aliases only pointed at the shared constants, so the call
sites now reference those. Only the values that are actually derived from
them stay local.
@spydon
spydon force-pushed the refactor/shared-local-stack-config branch from 53ce320 to 3c7b3ce Compare August 5, 2026 07:21

@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: 3

🧹 Nitpick comments (2)
packages/gotrue/test/admin_test.dart (1)

14-20: 🗄️ Data Integrity & Integration | 🔵 Trivial

Run the GoTrue integration tests sequentially.

These tests reset and mutate shared authentication state. Run dart test -j 1 from packages/gotrue against the local Supabase stack. Run melos analyze and melos format before commit.

As per coding guidelines, backend-dependent GoTrue tests must run sequentially with dart test -j 1, and Dart changes require melos analyze and melos format.

🤖 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/gotrue/test/admin_test.dart` around lines 14 - 20, Update the GoTrue
integration test configuration around the shared client setup and tests in
packages/gotrue so backend-dependent tests are explicitly run sequentially with
dart test -j 1. Before committing, run melos analyze and melos format to
validate and format the Dart changes.

Source: Coding guidelines

packages/postgrest/test/basic_test.dart (1)

17-27: 🗄️ Data Integrity & Integration | 🔵 Trivial

Run PostgREST tests sequentially against the shared stack.

These tests mutate shared database tables. Run dart test -j 1 from packages/postgrest against the local Supabase stack.

As per coding guidelines, backend-dependent PostgREST tests must run sequentially with dart test -j 1.

🤖 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/postgrest/test/basic_test.dart` around lines 17 - 27, Configure the
PostgREST test setup around the shared-stack tests in basic_test.dart to run
sequentially, ensuring the package test command uses dart test -j 1. Preserve
the existing setup and teardown behavior while applying the single-worker
requirement to these backend-dependent tests.

Source: Coding guidelines

🤖 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/gotrue/test/client_test.dart`:
- Line 17: Update the email-change PKCE test flow in client_test so
_pkceCodeFromEmailChange uses the effective gotrueUrl instead of
localStackAuthUrl. Pass gotrueUrl into that helper and use the same value in the
RegExp.escape prefix so verification link parsing matches the URL used by the
PKCE client and avoids the firstMatch(... )! failure when GOTRUE_URL is set.

In `@packages/storage_client/test/client_test.dart`:
- Line 282: Wrap the long public transformed URL string assertion in the client
test into adjacent string literals so the source stays within the 80-character
limit. Preserve the exact URL value, then run dart format on the Dart file.

In `@packages/supabase_common/lib/src/testing/local_stack.dart`:
- Around line 64-72: In
packages/supabase_common/lib/src/testing/local_stack.dart lines 64-72, split
both JWT constants, localStackAnonKey and localStackServiceRoleKey, into
adjacent string literals so every Dart source line stays within 80 characters.
In packages/realtime_client/test/utils/realtime_test_utils.dart line 23, wrap
the documentation comment to the same limit. Run dart format afterward.

---

Nitpick comments:
In `@packages/gotrue/test/admin_test.dart`:
- Around line 14-20: Update the GoTrue integration test configuration around the
shared client setup and tests in packages/gotrue so backend-dependent tests are
explicitly run sequentially with dart test -j 1. Before committing, run melos
analyze and melos format to validate and format the Dart changes.

In `@packages/postgrest/test/basic_test.dart`:
- Around line 17-27: Configure the PostgREST test setup around the shared-stack
tests in basic_test.dart to run sequentially, ensuring the package test command
uses dart test -j 1. Preserve the existing setup and teardown behavior while
applying the single-worker requirement to these backend-dependent tests.
🪄 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: a6a6194a-81f7-46d7-8ee7-b502a79029d8

📥 Commits

Reviewing files that changed from the base of the PR and between b9c31bb and 3c7b3ce.

📒 Files selected for processing (28)
  • packages/gotrue/test/admin_test.dart
  • packages/gotrue/test/client_test.dart
  • packages/gotrue/test/custom_oauth_provider_test.dart
  • packages/gotrue/test/get_claims_test.dart
  • packages/gotrue/test/provider_test.dart
  • packages/gotrue/test/src/gotrue_admin_custom_providers_api_test.dart
  • packages/gotrue/test/src/gotrue_admin_mfa_api_test.dart
  • packages/gotrue/test/src/gotrue_admin_oauth_api_test.dart
  • packages/gotrue/test/src/gotrue_mfa_api_test.dart
  • packages/gotrue/test/src/gotrue_oauth_api_test.dart
  • packages/gotrue/test/utils.dart
  • packages/gotrue/test/web3_auth_integration_test.dart
  • packages/postgrest/test/basic_test.dart
  • packages/postgrest/test/filter_test.dart
  • packages/postgrest/test/prefer_header_test.dart
  • packages/postgrest/test/resource_embedding_test.dart
  • packages/postgrest/test/test_utils.dart
  • packages/postgrest/test/transforms_test.dart
  • packages/postgrest/test/upsert_test.dart
  • packages/realtime_client/test/realtime_integration_test.dart
  • packages/realtime_client/test/utils/realtime_test_utils.dart
  • packages/storage_client/test/client_test.dart
  • packages/storage_client/test/vector_integration_test.dart
  • packages/supabase/test/stream_filter_test.dart
  • packages/supabase/test/stream_integration_test.dart
  • packages/supabase/test/utils/local_stack.dart
  • packages/supabase_common/lib/src/testing/local_stack.dart
  • packages/supabase_common/lib/testing.dart
💤 Files with no reviewable changes (1)
  • packages/supabase/test/utils/local_stack.dart

Comment thread packages/gotrue/test/client_test.dart
Comment thread packages/storage_client/test/client_test.dart Outdated
Comment thread packages/supabase_common/lib/src/testing/local_stack.dart
@spydon
spydon merged commit a08f06d into main Aug 5, 2026
45 checks passed
@spydon
spydon deleted the refactor/shared-local-stack-config branch August 5, 2026 08:02
spydon added a commit that referenced this pull request Aug 5, 2026
Stacked on #1640, since it touches the same file.

The storage suite created buckets and never removed them, while `List
buckets` asserted the total bucket count. A second run against the same
stack therefore failed twice over: the listing saw the leftovers, and
`Create new public bucket` hit a 409 because it uses a fixed name. Only
CI got away with it, because every job starts a fresh stack.

- Sweeps the buckets the suite creates before and after the run, so
leftovers of an interrupted run cannot break the next one either. Only
names the suite itself uses are removed, never the seeded buckets or
those of another suite.
- `List buckets` now asserts that the seeded buckets are listed instead
of counting every bucket on the stack, so a suite running in parallel
cannot fail it.

Verified by running the suite twice in a row against a stack that had 20
leftover buckets: both runs pass and leave exactly the four seeded
buckets.


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

- **Tests**
- Improved storage client test reliability by documenting shared-state
behavior and using a consistent temporary bucket namespace.
- Added comprehensive cleanup for temporary buckets, including emptying
buckets before removal and safely handling concurrent cleanup races.
- Updated bucket listing coverage to verify expected seeded buckets are
present without relying on a fixed total count.
- Added safeguards to preserve seeded data and tolerate cleanup timing
differences.
<!-- 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.

3 participants