Skip to content

test(e2e): Add an e2e test for Handshake (prod) #6072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

jfoshee
Copy link

@jfoshee jfoshee commented Jun 5, 2025

Description

Add a test of basic handshake flow against a production instance (for reason of no client UAT cookie).

Updated sessionsProd1 environment.

Remove an obsolete E2E test.

Co-author @nikosdouvlis

SDKI-1024

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other: E2E test improvement

Summary by CodeRabbit

  • New Features

    • Introduced a new integration test suite for handshake flows in a production-like environment.
    • Added a dedicated script to run handshake-related integration tests.
  • Documentation

    • Expanded documentation with an appendix on production hosts and instructions for adding new hostnames.
  • Chores

    • Added a new environment configuration and long-running app setup for production-like session testing.
  • Tests

    • Removed an outdated test suite for session persistence across production app instances.
    • Added and exported a new user type for test utilities.

Copy link

vercel bot commented Jun 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2025 4:55pm

Copy link

changeset-bot bot commented Jun 5, 2025

⚠️ No Changeset found

Latest commit: c85b45c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@jfoshee jfoshee changed the title test(handshake): add an e2e test for Handshake (prod) test(e2e): Add an e2e test for Handshake (prod) Jun 5, 2025
test.describe.configure({ mode: 'serial' });

test.describe('with Production instance', () => {
// TODO: change host name
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to address the TODO here?
Probably a low priority for the time being, but leaving some high-level instructions here for when we get to this:

  • create a new .clerk.app host domain
  • create and configure a new Clerk prod app
  • update the local certificates used by the tests to include the new domain in addition to the existing ones
  • finally, update the tests

Copy link
Author

Choose a reason for hiding this comment

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

OK sounds like a task for later. I added that info to an appendix in the integration README.

@jfoshee jfoshee marked this pull request as ready for review June 18, 2025 17:07
@jfoshee jfoshee requested review from aeliox, wobsoriano and a team as code owners June 18, 2025 17:07
Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new Playwright end-to-end test suite for the handshake flow in a production-like environment, targeting a specific app instance with a dedicated environment configuration. Supporting updates include the addition of a new environment (sessionsProd1), corresponding long-running app configuration, and a new test script for running handshake-related integration tests. Documentation is updated with guidance on production host setup. A new type, FakeUserWithEmail, is added and exported for use in tests. An older test suite for multi-app session migration is removed.

Assessment against linked issues

Objective Addressed Explanation
Implement E2E tests for handshake flow (SDKI-1024)
Provide Playwright test for handshake with production-like environment (SDKI-1024)
Add required environment and app configurations for handshake E2E (SDKI-1024)
Update test utilities/types as needed for handshake E2E (SDKI-1024)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Removal of the multi-app migration E2E test suite (integration/tests/sessions/prod-app-migration.test.ts) The deletion of the session migration test is not described or required by SDKI-1024, which only requests handshake E2E coverage.
Addition of documentation about production hosts (integration/README.md) The new appendix section on production hosts, while useful, is not directly related to the handshake flow E2E objective.
Addition and export of FakeUserWithEmail type (integration/testUtils/usersService.ts, integration/testUtils/index.ts) The handshake flow objective does not explicitly require new types, though this may be a supporting change.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

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

♻️ Duplicate comments (1)
integration/tests/handshake/handshake.test.ts (1)

15-16: Address the TODO for production host configuration.

Based on past review comments, this TODO is acknowledged as a lower priority task. The current setup works for testing but will need updating when moving to a dedicated production host.

🧹 Nitpick comments (3)
integration/README.md (1)

594-606: Good documentation addition with minor suggestions for clarity.

The new "Production Hosts" section effectively documents the DNS and proxy infrastructure for production testing.

Consider these minor improvements for clarity:

-Production instances necessitate the use of DNS hostnames.
+Production test instances require DNS hostnames for proper testing.

-During a test, a local proxy is established to direct requests from the DNS host to a local server.
+During tests, a local proxy routes requests from the DNS hostname to the local development server.

-To incorporate a new hostname:
+To add a new hostname:
integration/tests/handshake/handshake.test.ts (2)

43-43: Consider safer type handling for fake user creation.

The type assertion as FakeUserWithEmail could be unsafe if createFakeUser({ withEmail: true }) doesn't guarantee the return type. Consider using type guards or ensuring the function signature properly types the return value.

-      fakeUser = u.services.users.createFakeUser({ withEmail: true }) as FakeUserWithEmail;
+      const tempUser = u.services.users.createFakeUser({ withEmail: true });
+      if (!tempUser.email) {
+        throw new Error('Expected user with email');
+      }
+      fakeUser = tempUser as FakeUserWithEmail;

28-40: Consider extracting proxy server setup to a helper function.

The proxy server setup logic is correct, but as noted in the TODO comment, it could be factored out into a reusable helper function for other tests that need similar functionality.

Would you like me to help create a reusable proxy server helper function?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68ed585 and c85b45c.

📒 Files selected for processing (8)
  • integration/README.md (1 hunks)
  • integration/presets/envs.ts (2 hunks)
  • integration/presets/longRunningApps.ts (1 hunks)
  • integration/testUtils/index.ts (1 hunks)
  • integration/testUtils/usersService.ts (1 hunks)
  • integration/tests/handshake/handshake.test.ts (1 hunks)
  • integration/tests/sessions/prod-app-migration.test.ts (0 hunks)
  • package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • integration/tests/sessions/prod-app-migration.test.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.md`: Follow all instructions, patterns and conventions that are defined in these MD files.

**/*.md: Follow all instructions, patterns and conventions that are defined in these MD files.

  • integration/README.md
🔇 Additional comments (9)
integration/testUtils/usersService.ts (1)

54-54: LGTM! Clean type definition.

The FakeUserWithEmail type appropriately extends FakeUser while ensuring the email property is required. This provides type safety for test scenarios that depend on having an email address.

integration/presets/envs.ts (2)

197-197: LGTM! Consistent export pattern.

The export follows the established pattern for making environment configurations available.


45-50: Verify the empty CLERK_JS_URL configuration.

The environment configuration follows the established pattern, but setting CLERK_JS_URL to an empty string differs from other environments. Please confirm this is intentional for production testing scenarios.

#!/bin/bash
# Description: Check how CLERK_JS_URL is configured in other environments
# Expected: Most environments set CLERK_JS_URL to a specific URL

echo "Checking CLERK_JS_URL configurations across environments:"
rg "CLERK_JS_URL" integration/presets/envs.ts -A 1 -B 1
integration/testUtils/index.ts (1)

9-9: LGTM! Proper type re-export.

The import and export of FakeUserWithEmail follows the established pattern and makes the type available for use in test files.

Also applies to: 12-12

integration/presets/longRunningApps.ts (1)

27-27: LGTM! Consistent long-running app configuration.

The new next.appRouter.sessionsProd1 configuration follows the established pattern and correctly uses the new production environment for testing.

package.json (1)

42-42: LGTM! Script follows established patterns.

The new handshake integration test script correctly follows the pattern of other integration test scripts, with appropriate environment variables and filtering.

integration/tests/handshake/handshake.test.ts (3)

1-12: LGTM! Clean imports and appropriate test structure.

The imports are well-organized and the use of serial mode is appropriate for tests that maintain state across multiple test steps.


47-82: LGTM! Comprehensive handshake flow testing.

The test logic effectively verifies the handshake flow by:

  1. Establishing a signed-in state
  2. Forcing handshake by clearing client UAT cookies
  3. Verifying proper cookie restoration and absence of temporary cookies

The assertions are thorough and cover the essential aspects of the handshake mechanism.


76-77: Refresh cookie verification is already implemented.

The test appropriately checks for refresh cookies as suggested in the past review comments. The assertion ensures that refresh cookies are present after the handshake flow completes.

@jfoshee jfoshee enabled auto-merge (squash) June 18, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants