Skip to content

fix(e2e): more robust user deletion - #9375

Open
dstaley wants to merge 6 commits into
mainfrom
ds.fix/delete-all-match
Open

fix(e2e): more robust user deletion#9375
dstaley wants to merge 6 commits into
mainfrom
ds.fix/delete-all-match

Conversation

@dstaley

@dstaley dstaley commented Aug 10, 2026

Copy link
Copy Markdown
Member

Description

This PR updates the logic we use to create fake users to embed a run key, which is a hash of the unique data for a single test run. After integration tests finish, we manually clean up users that were created with the run key in their username, email address, or metadata.

This also includes a fix for deleteIfExists that will delete all matching users rather than just the first. This handles the case were we generate the same matching email/phone number across multiple tests. This shouldn't be as much of an issue now that we're storing the run key in the identifier, but it doesn't hurt!

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:

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3c096a3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

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

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview Aug 10, 2026 9:33pm
swingset Ready Ready Preview Aug 10, 2026 9:33pm

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@9375

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@9375

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@9375

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@9375

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@9375

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@9375

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@9375

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@9375

@clerk/expo-google-signin

npm i https://pkg.pr.new/@clerk/expo-google-signin@9375

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@9375

@clerk/express

npm i https://pkg.pr.new/@clerk/express@9375

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@9375

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@9375

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@9375

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@9375

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@9375

@clerk/react

npm i https://pkg.pr.new/@clerk/react@9375

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@9375

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@9375

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@9375

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@9375

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@9375

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@9375

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@9375

commit: 3c096a3

@coderabbitai

coderabbitai Bot commented Aug 10, 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: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: dc216e5c-13fa-427b-9c0d-afc71dafc8e7

📥 Commits

Reviewing files that changed from the base of the PR and between 2bd619c and a326a24.

📒 Files selected for processing (1)
  • integration/testUtils/usersService.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • clerk/clerk_go (manual)
  • clerk/dashboard (manual)
  • clerk/accounts (manual)
  • clerk/backoffice (manual)
  • clerk/clerk (manual)
  • clerk/clerk-docs (manual)
  • clerk/cloudflare-workers (manual)
  • clerk/cli (auto-detected)
  • clerk/clerk-ios (auto-detected)
  • clerk/clerk-android (auto-detected)
🚧 Files skipped from review as they are similar to previous changes (1)
  • integration/testUtils/usersService.ts

📝 Walkthrough

Walkthrough

Integration tests now receive a unique run key from CI. Generated users include a derived E2E marker in identifiers and private metadata. Cleanup discovers and deletes users for the active run, verifies that no marked users remain, and reports run-scoped failures. Turbo passes the run key through the environment. Two changeset files were added.

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

Possibly related PRs

  • clerk/javascript#9367: Both PRs modify integration/cleanup/cleanup.setup.ts to improve E2E cleanup behavior.
  • clerk/javascript#9374: Both PRs modify integration/testUtils/usersService.ts to embed identifying metadata in generated E2E users.

Suggested reviewers: maxyinger

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main E2E change: more robust deletion of test users.
Description check ✅ Passed The description directly explains run-key user cleanup and deletion of all matching users.
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.

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 `@integration/testUtils/usersService.ts`:
- Around line 205-207: Update the empty-user branch in the user cleanup flow to
replace the interpolated opts.email and opts.phoneNumber values with a generic
cleanup message, ensuring no supplied user identifier is written to logs while
preserving the early return.

In `@turbo.json`:
- Line 37: Update the Turbo integration task configuration containing
INTEGRATION_TEST_RUN_KEY so CI integration tasks do not reuse cached results:
set cache to false for those tasks, or move INTEGRATION_TEST_RUN_KEY into
globalEnv to include it in the cache key.
🪄 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: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: a309c6ba-20fe-4646-87e4-e7652685a849

📥 Commits

Reviewing files that changed from the base of the PR and between 52ec5cd and d76132e.

📒 Files selected for processing (7)
  • .changeset/fair-llamas-shout.md
  • .changeset/silver-lands-cut.md
  • .github/workflows/ci.yml
  • integration/cleanup/cleanup.setup.ts
  • integration/testUtils/e2eRun.ts
  • integration/testUtils/usersService.ts
  • turbo.json
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • clerk/clerk_go (manual)
  • clerk/dashboard (manual)
  • clerk/accounts (manual)
  • clerk/backoffice (manual)
  • clerk/clerk (manual)
  • clerk/clerk-docs (manual)
  • clerk/cloudflare-workers (manual)
  • clerk/cli (auto-detected)
  • clerk/clerk-ios (auto-detected)
  • clerk/clerk-android (auto-detected)

Comment on lines +205 to 207
if (ids.size === 0) {
console.log(`User "${opts.email || opts.phoneNumber}" does not exist!`);
return;

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.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Do not log the supplied email address or phone number.

Line 206 writes a user identifier to CI logs. Log a generic cleanup message instead.

Proposed fix
-        console.log(`User "${opts.email || opts.phoneNumber}" does not exist!`);
+        console.log('No user exists for the supplied cleanup criteria.');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (ids.size === 0) {
console.log(`User "${opts.email || opts.phoneNumber}" does not exist!`);
return;
if (ids.size === 0) {
console.log('No user exists for the supplied cleanup criteria.');
return;
🧰 Tools
🪛 ast-grep (0.45.0)

[warning] 205-205: Avoid logging sensitive data
Context: console.log(User "${opts.email || opts.phoneNumber}" does not exist!)
Note: [CWE-532] Insertion of Sensitive Information into Log File.

(log-sensitive-data-typescript)

🤖 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 `@integration/testUtils/usersService.ts` around lines 205 - 207, Update the
empty-user branch in the user cleanup flow to replace the interpolated
opts.email and opts.phoneNumber values with a generic cleanup message, ensuring
no supplied user identifier is written to logs while preserving the early
return.

Sources: Coding guidelines, Linters/SAST tools

Comment thread turbo.json
"globalPassThroughEnv": [
"AWS_SECRET_KEY",
"GITHUB_TOKEN",
"INTEGRATION_TEST_RUN_KEY",

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Every integration task must report cache=false.
jq -r '
  (.tasks // {}) | to_entries[]
  | select(.key | test("test:integration"))
  | "\(.key): cache=\(.value.cache // true)"
' turbo.json

Repository: clerk/javascript

Length of output: 1212


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- turbo.json ---'
cat -n turbo.json | sed -n '1,90p'

printf '%s\n' '--- Turbo version and integration scripts ---'
rg -n '"turbo"|test:integration|INTEGRATION_TEST_RUN_KEY' package.json pnpm-lock.yaml packages apps examples .github 2>/dev/null | head -240

Repository: clerk/javascript

Length of output: 7965


🌐 Web query:

Turborepo globalPassThroughEnv cache key behavior passThroughEnv cacheable task

💡 Result:

In Turborepo, both globalPassThroughEnv and passThroughEnv serve to expose environment variables to task runtimes without including them in the task's cache key [1][2][3]. Because these variables are intentionally omitted from the hashing process, changes to their values will not trigger a cache miss, even if the change would logically affect the output of the task [1][4]. The fundamental behaviors for these configurations are: 1. Cache Key Exclusion: Variables listed in either globalPassThroughEnv or passThroughEnv do not contribute to the task hash [2][3]. Consequently, Turborepo may serve a cached result even if the underlying environment variable has changed [1][4]. This is why these keys should only be used for variables that do not affect the build output, such as authentication tokens (e.g., SENTRY_AUTH_TOKEN), CI metadata, or credentials consumed at runtime after the build process [2][4]. 2. Runtime Exposure: By including a variable in either key, you satisfy Turborepo's Strict Environment Mode, ensuring the task has access to that variable at runtime [1][5][3]. If a task attempts to access an environment variable that is not accounted for in env, globalEnv, passThroughEnv, or globalPassThroughEnv while in Strict Mode, the task may fail [1][5]. 3. Scope Differences: - globalPassThroughEnv (or global.passThroughEnv when using the global configuration flag) applies the passthrough behavior to all tasks within the repository [2][6]. - passThroughEnv applies only to the specific task where it is configured [3]. If you need a change in an environment variable to invalidate the cache and trigger a rebuild, you must include that variable in env or globalEnv instead of the passthrough keys [1][3].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- integration task definitions ---'
rg -n -C 3 '"[`#/`]?test:integration|test:integration' turbo.json

printf '%s\n' '--- CI Turbo arguments and integration invocation ---'
sed -n '400,535p' .github/workflows/ci.yml
sed -n '260,300p' .github/workflows/e2e-staging.yml

printf '%s\n' '--- exact task keys parsed from turbo.json ---'
jq -r '(.tasks // {}) | to_entries[] | select(.key | contains("test:integration")) | [.key, (.value.cache // true | tostring)] | `@tsv`' turbo.json

Repository: clerk/javascript

Length of output: 16346


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

python3 - <<'PY'
import json
from pathlib import Path

config = json.loads(Path("turbo.json").read_text())
tasks = config.get("tasks", {})
matches = [(name, task.get("cache", True)) for name, task in tasks.items()
           if "test:integration" in name]
print("matching task count:", len(matches))
for name, cache in matches:
    print(f"{name}: cache={cache}")
PY

Repository: clerk/javascript

Length of output: 1236


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- all Turbo force/argument settings ---'
rg -n -C 4 'TURBO_(ARGS|FORCE)|pnpm turbo test:integration|pnpm turbo run test:integration' .github/workflows package.json

printf '%s\n' '--- CI workflow environment and matrix context ---'
sed -n '1,120p' .github/workflows/ci.yml
sed -n '380,445p' .github/workflows/ci.yml
sed -n '495,535p' .github/workflows/ci.yml

printf '%s\n' '--- staging workflow context ---'
sed -n '1,110p' .github/workflows/e2e-staging.yml
sed -n '270,320p' .github/workflows/e2e-staging.yml

Repository: clerk/javascript

Length of output: 30087


Disable caching for CI integration tasks.

The CI integration job does not set TURBO_FORCE, and all 25 integration tasks inherit cache: true. globalPassThroughEnv does not affect the cache key. Set cache: false for these tasks, or move INTEGRATION_TEST_RUN_KEY to globalEnv.

🤖 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 `@turbo.json` at line 37, Update the Turbo integration task configuration
containing INTEGRATION_TEST_RUN_KEY so CI integration tasks do not reuse cached
results: set cache to false for those tasks, or move INTEGRATION_TEST_RUN_KEY
into globalEnv to include it in the cache key.

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.

1 participant