+
Skip to content

Conversation

ianmaccallum
Copy link
Contributor

@ianmaccallum ianmaccallum commented Oct 1, 2025

Adds the following test env vars for local development:

  • TEST_DOMAINS
  • TEST_SKIP_ADD_DOMAIN
  • TEST_SKIP_BOT_DETECTION
  • TEST_SKIP_RATE_LIMIT

Summary by CodeRabbit

  • Tests

    • Added environment-driven toggles to optionally skip domain provisioning, bot detection, and rate limiting in development/tests; improved domain parsing for local/test domains; production behavior unchanged.
  • Chores

    • Updated example environment configuration with new test-related variables and descriptive comments.

Copy link
Contributor

vercel bot commented Oct 1, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 1, 2025 8:05pm

Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

Walkthrough

Adds environment-driven test toggles and domain normalization for the web app: optional Vercel domain addition, optional bot-detection bypass, optional rate-limit bypass, and TEST_DOMAINS parsing; exposes those variables in .env.example. Updates click-recording to respect skip flags and renames an internal parameter.

Changes

Cohort / File(s) Summary
Environment variables (test toggles)
apps/web/.env.example
Adds TEST_DOMAINS, TEST_SKIP_ADD_DOMAIN, TEST_SKIP_BOT_DETECTION, TEST_SKIP_RATE_LIMIT with comments; preserves existing HUBSPOT lines.
Domains API flow control
apps/web/app/api/domains/route.ts
Makes addDomainToVercel conditional: skipped when TEST_SKIP_ADD_DOMAIN === "true", bypassing the Vercel call and its error handling.
Middleware: bot detection and domain parsing
apps/web/lib/middleware/link.ts, apps/web/lib/middleware/utils/parse.ts
link.ts: bypasses detectBot(req) when TEST_SKIP_BOT_DETECTION === "true". parse.ts: honors TEST_DOMAINS list and strips port when matched to normalize domain.
Click recording toggles
apps/web/lib/tinybird/record-click.ts
Adds test-driven skips: forces isBot = false when TEST_SKIP_BOT_DETECTION === "true", and allows rate-limit bypass via TEST_SKIP_RATE_LIMIT or skipRateLimitProp; renames destructured param to skipRateLimitProp internally.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant API as Domains API
  participant Vercel as Vercel API

  Client->>API: POST /api/domains
  alt TEST_SKIP_ADD_DOMAIN !== "true"
    API->>Vercel: addDomainToVercel(domain)
    Vercel-->>API: response / error
    API-->>Client: Result based on Vercel response
  else Skip enabled
    API-->>Client: Result without calling Vercel
  end
Loading
sequenceDiagram
  autonumber
  actor User
  participant Srv as Server
  participant Bot as Bot Detector
  participant RL as Rate Limiter
  participant TB as Analytics (recordClick)

  User->>Srv: Request
  opt Link middleware
    alt TEST_SKIP_BOT_DETECTION === "true"
      Srv->>Srv: isBot = false
    else
      Srv->>Bot: detectBot(req)
      Bot-->>Srv: isBot flag
    end
  end

  User->>TB: recordClick(...)
  alt TEST_SKIP_RATE_LIMIT === "true" or skipRateLimitProp
    TB->>TB: Bypass rate limit
  else
    TB->>RL: Check rate
    RL-->>TB: Allow / Deny
  end
  TB-->>User: Recorded / Skipped
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • steven-tey

Poem

In test-time fields I hop with glee,
Flipping flags as light as breeze—
No bots, no caps, domains run free,
A rabbit’s tweak for QA ease.
When prod arrives, I tuck them tight. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Adds test env vars” directly captures the primary change of introducing new environment variables for testing without extraneous detail, clearly aligning with the pull request’s objective to add TEST_DOMAINS, TEST_SKIP_ADD_DOMAIN, TEST_SKIP_BOT_DETECTION, and TEST_SKIP_RATE_LIMIT for local development. It is concise, descriptive, and informs reviewers of the main intent.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-test-env-vars

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc669f and fe02573.

📒 Files selected for processing (1)
  • apps/web/.env.example (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build

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 and usage tips.

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: 1

🧹 Nitpick comments (1)
apps/web/lib/middleware/utils/parse.ts (1)

19-30: Consider trimming test domains to handle whitespace.

If TEST_DOMAINS contains spaces around commas (e.g., "click.localhost:8888, other.localhost:8888"), the current implementation won't match domains correctly. Consider trimming each entry after splitting.

Apply this diff:

   } else if (process.env.TEST_DOMAINS) {
-    const testDomains = process.env.TEST_DOMAINS.split(",");
+    const testDomains = process.env.TEST_DOMAINS.split(",").map(d => d.trim());
 
     // Check if the current domain (with port) matches any test domain, and if so, strip the port
     const matchedTestDomain = testDomains.find(
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2100740 and 1bc669f.

📒 Files selected for processing (5)
  • apps/web/.env.example (1 hunks)
  • apps/web/app/api/domains/route.ts (1 hunks)
  • apps/web/lib/middleware/link.ts (1 hunks)
  • apps/web/lib/middleware/utils/parse.ts (1 hunks)
  • apps/web/lib/tinybird/record-click.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/app/api/domains/route.ts (1)
apps/web/lib/api/domains/add-domain-vercel.ts (1)
  • addDomainToVercel (5-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (5)
apps/web/lib/middleware/link.ts (1)

300-301: LGTM! Bot detection bypass is correctly implemented.

The conditional bot detection logic properly checks for the exact string "true" and falls back to the original detectBot(req) behavior otherwise. This enables testing without bot interference while preserving production behavior.

apps/web/app/api/domains/route.ts (1)

139-150: LGTM! Domain addition skip is correctly implemented.

The conditional logic properly gates the Vercel API call and its error handling, allowing tests to bypass external dependencies without affecting production behavior.

apps/web/lib/tinybird/record-click.ts (3)

75-76: LGTM! Bot detection bypass is consistent.

The test-time bot detection bypass matches the implementation in link.ts and correctly defaults to detectBot(req) when the flag is not set.


91-92: LGTM! Rate limit bypass logic is correct.

The implementation properly computes skipRatelimit from either the function parameter or the test environment flag, enabling flexible test-time behavior.


38-38: Parameter name inconsistency detected.

Line 38 renames the destructured parameter to skipRateLimitProp, but line 52 in the type definition still declares it as skipRatelimit?: boolean. This creates a mismatch between the parameter name and its type definition.

Apply this diff to align the type definition:

   webhookIds?: string[];
   workspaceId: string | undefined;
-  skipRatelimit?: boolean;
+  skipRateLimitProp?: boolean;
   timestamp?: string;
   referrer?: string;
   trigger?: string;

Likely an incorrect or invalid review comment.

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.

1 participant

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载