Skip to content

Conversation

@KevLehman
Copy link
Member

@KevLehman KevLehman commented Aug 29, 2025

Proposed changes (including videos or screenshots)

Issue(s)

https://rocketchat.atlassian.net/browse/CTZ-313

Steps to test or reproduce

Further comments

Basically, $addToSet doesnt work when there's no array. So if the field you're trying to apply the action doens't exist or it's not an array, it will fail.

it should not happen anymore :)

Summary by CodeRabbit

  • Bug Fixes

    • Lead capture now safely validates patterns, ignores invalid/empty regex settings, and only saves emails/phones when matches exist; avoids unnecessary updates and duplicates. Agent messages are not recorded as lead data.
  • Tests

    • Added end-to-end tests covering extraction, deduplication, merging, multi-value capture, and settings clearing/restoration.
    • Added a test helper to create visitors with custom data.
  • Chores

    • Bumped two packages to patch releases.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Aug 29, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Aug 29, 2025

🦋 Changeset detected

Latest commit: 09f0bc7

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

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/models Patch
@rocket.chat/meteor Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/media-calls Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/network-broker Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/ddp-client Patch
@rocket.chat/freeswitch Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch

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

@codecov
Copy link

codecov bot commented Aug 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.06%. Comparing base (6a5eb79) to head (09f0bc7).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36835      +/-   ##
===========================================
- Coverage    68.14%   67.06%   -1.08%     
===========================================
  Files         3365     3418      +53     
  Lines       115815   117981    +2166     
  Branches     20958    21611     +653     
===========================================
+ Hits         78918    79128     +210     
- Misses       34204    36154    +1950     
- Partials      2693     2699       +6     
Flag Coverage Δ
e2e 57.51% <ø> (+0.01%) ⬆️
unit 72.15% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KevLehman KevLehman added this to the 7.11.0 milestone Aug 29, 2025
@KevLehman KevLehman marked this pull request as ready for review August 29, 2025 17:22
@KevLehman KevLehman requested review from a team as code owners August 29, 2025 17:22
@KevLehman KevLehman requested a review from Copilot August 30, 2025 03:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where visitor "lead capture" functionality fails when capturing email/phone numbers from messages if the visitor doesn't already have email or phone data stored. The root cause was that MongoDB's $addToSet operator fails when the target field doesn't exist or isn't an array.

Key changes:

  • Replace $addToSet with aggregation pipeline using $setUnion and $ifNull to handle missing fields
  • Add comprehensive test coverage for lead capture scenarios
  • Improve regex handling with safe matching and deduplication

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/models/src/models/LivechatVisitors.ts Replace $addToSet with aggregation pipeline to handle missing email/phone arrays
apps/meteor/app/livechat/server/hooks/leadCapture.ts Add safe regex matching and deduplication of captured data
apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts Add comprehensive test suite for lead capture functionality
apps/meteor/tests/data/livechat/rooms.ts Add utility function to create visitors without email/phone data
.changeset/fair-dolls-trade.md Document the bug fix in changeset

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Sep 1, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Sep 1, 2025
@scuciatto scuciatto removed this from the 7.11.0 milestone Sep 22, 2025
@dionisio-bot dionisio-bot bot removed the stat: ready to merge PR tested and approved waiting for merge label Sep 22, 2025
@KevLehman KevLehman added the stat: ready to merge PR tested and approved waiting for merge label Nov 5, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds safe regex matching and deduplication in lead-capture, skips DB writes when no matches, fixes visitor merge logic to handle null email/phone fields, and introduces test helpers plus end-to-end tests validating email/phone extraction and related scenarios.

Changes

Cohort / File(s) Summary
Lead capture hook
apps/meteor/app/livechat/server/hooks/leadCapture.ts
Replace raw RegExp usage with safeMatch (validates/catches invalid regexes), add uniq deduplication, read regex settings, compute matches, and only call saveGuestEmailPhoneById when matches exist.
Visitor model update
packages/models/src/models/LivechatVisitors.ts
In saveGuestEmailPhoneById, early-return when both saveEmail and savePhone are empty; use $set + $setUnion with $ifNull to merge visitorEmails and phone safely.
Test helpers
apps/meteor/tests/data/livechat/rooms.ts
Add createVisitorWithCustomData(...) to create or fetch visitors with configurable token, email, phone, custom fields, and ignoreEmail/ignorePhone flags for tests.
End-to-end tests
apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
Add lead-capture E2E tests for email/phone extraction, duplicates, agent-message exclusion, combined captures, regex toggling, and merging into existing visitor data.
Changeset
.changeset/fair-dolls-trade.md
Bump @rocket.chat/models and @rocket.chat/meteor to patch; document fix for capturing lead email/phone when visitor lacked data.

Sequence Diagram(s)

sequenceDiagram
    participant Visitor
    participant Room as Livechat Room
    participant Hook as leadCapture Hook
    participant SafeMatch as safeMatch
    participant Model as LivechatVisitors.saveGuestEmailPhoneById

    Visitor->>Room: Send message (may contain email/phone)
    Room->>Hook: Trigger leadCapture callback

    Hook->>SafeMatch: Run email regex (setting)
    SafeMatch-->>Hook: matchedEmails (or empty)
    Hook->>SafeMatch: Run phone regex (setting)
    SafeMatch-->>Hook: matchedPhones (or empty)

    alt matchedEmails or matchedPhones
        Hook->>Model: saveGuestEmailPhoneById(matchedEmails, matchedPhones)
        Model->>Model: Early-return if both empty (guard)
        Model-->>Hook: Update visitor record (merge via $setUnion/$ifNull)
    else no matches
        Note over Hook: Skip DB update
    end

    Hook-->>Room: leadCapture complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay extra attention to: safeMatch regex error handling, uniq deduplication, and the $setUnion/$ifNull merge in saveGuestEmailPhoneById.
  • Review new E2E tests for setup/teardown and flakiness.

Suggested labels

stat: ready to merge

Suggested reviewers

  • ggazzo
  • scuciatto
  • gabriellsh

Poem

🐰 I hopped in quick and scanned the trail,
Found emails and phones behind the veil.
safeMatch sniffs errors, uniq keeps it neat,
Tests clap their paws for every clean feat. ✨

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main fix: resolving lead capture failures when visitors lack pre-existing email or phone data.
Linked Issues check ✅ Passed All coding requirements from CORE-1428 are met: the changes prevent lead capture failures by handling missing/non-array fields and safely merging contact data.
Out of Scope Changes check ✅ Passed All changes directly address the lead capture bug: regex validation in hooks, database update logic refactoring, test utilities expansion, and comprehensive test coverage.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/leadcapture

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

🧹 Nitpick comments (1)
packages/models/src/models/LivechatVisitors.ts (1)

387-410: Remove commented code block.

This substantial commented block (24 lines) should be removed to improve code maintainability. Version control preserves this history if needed for reference.

Apply this diff to remove the commented code:

 		if (!saveEmail.length && !savePhone.length) {
 			return Promise.resolve();
 		}
-
-		// const updatePipeline: Document[] = [];
-
-		// if (saveEmail.length) {
-		// 	updatePipeline.push({
-		// 		$set: {
-		// 			visitorEmails: {
-		// 				$setUnion: [{ $ifNull: ['$visitorEmails', []] }, saveEmail],
-		// 			},
-		// 		},
-		// 	});
-		// }
-
-		// if (savePhone.length) {
-		// 	updatePipeline.push({
-		// 		$set: {
-		// 			phone: {
-		// 				$setUnion: [{ $ifNull: ['$phone', []] }, savePhone],
-		// 			},
-		// 		},
-		// 	});
-		// }
-
-		// return this.updateOne({ _id }, updatePipeline);
 
 		const update: UpdateFilter<ILivechatVisitor> = {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9825c8d and 08d8000.

📒 Files selected for processing (5)
  • .changeset/fair-dolls-trade.md (1 hunks)
  • apps/meteor/app/livechat/server/hooks/leadCapture.ts (1 hunks)
  • apps/meteor/tests/data/livechat/rooms.ts (1 hunks)
  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts (3 hunks)
  • packages/models/src/models/LivechatVisitors.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use descriptive test names that clearly communicate expected behavior

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
  • apps/meteor/tests/data/livechat/rooms.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx,js,jsx} : Follow DRY by extracting reusable logic into helper functions or page objects

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Maintain test isolation between test cases

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
  • apps/meteor/tests/data/livechat/rooms.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (test, page, expect) consistently

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Prefer web-first assertions (e.g., toBeVisible, toHaveText)

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx} : Store commonly used locators in variables/constants for reuse

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx} : Implement proper wait strategies for dynamic content

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx} : Follow the Page Object Model pattern consistently

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use expect matchers (toEqual, toContain, toBeTruthy, toHaveLength, etc.) instead of assert statements

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • apps/meteor/tests/data/livechat/rooms.ts
🧬 Code graph analysis (3)
apps/meteor/app/livechat/server/hooks/leadCapture.ts (2)
packages/mongo-adapter/src/common.ts (1)
  • isTruthy (148-148)
packages/models/src/index.ts (1)
  • LivechatVisitors (178-178)
apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts (3)
packages/core-typings/src/ILivechatVisitor.ts (1)
  • ILivechatVisitor (28-55)
apps/meteor/tests/data/livechat/rooms.ts (5)
  • createVisitorWithCustomData (58-105)
  • createLivechatRoom (22-34)
  • sendMessage (337-354)
  • sendAgentMessage (372-392)
  • createVisitor (107-141)
apps/meteor/tests/data/api-data.ts (1)
  • credentials (39-42)
apps/meteor/tests/data/livechat/rooms.ts (3)
packages/core-typings/src/ILivechatVisitor.ts (1)
  • ILivechatVisitor (28-55)
apps/meteor/tests/data/livechat/users.ts (1)
  • getRandomVisitorToken (28-28)
apps/meteor/tests/data/api-data.ts (1)
  • credentials (39-42)
🪛 ast-grep (0.39.7)
apps/meteor/app/livechat/server/hooks/leadCapture.ts

[warning] 47-47: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(pattern, flags)
Note: [CWE-1333] Inefficient Regular Expression Complexity [REFERENCES]
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
- https://cwe.mitre.org/data/definitions/1333.html

(regexp-from-variable)

⏰ 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). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (10)
.changeset/fair-dolls-trade.md (1)

1-6: LGTM!

The changeset correctly documents the fix with appropriate patch-level version bumps for both affected packages.

packages/models/src/models/LivechatVisitors.ts (1)

383-385: LGTM! Core fix for the lead capture issue.

The early return when both email and phone arrays are empty prevents the MongoDB $addToSet operation from failing when the visitor record lacks these fields.

apps/meteor/app/livechat/server/hooks/leadCapture.ts (3)

43-53: Defensive regex handling prevents failures from invalid patterns.

The safeMatch helper correctly handles invalid regex patterns by returning an empty array. The static analysis ReDoS warning can be safely disregarded here since regex patterns are admin-controlled via settings, not user input.

However, consider adding error logging to aid debugging when admins configure invalid patterns, as noted in the past review comment.


55-58: LGTM! Clean deduplication and matching logic.

The uniq helper combined with safeMatch correctly extracts and deduplicates lead data from visitor messages.


60-63: Core fix: Conditional save prevents unnecessary operations.

Only invoking saveGuestEmailPhoneById when matches exist aligns with the model's early return logic and prevents MongoDB $addToSet failures on non-existent fields.

apps/meteor/tests/data/livechat/rooms.ts (1)

58-105: LGTM! Well-designed test utility.

The createVisitorWithCustomData function provides flexible visitor creation for test scenarios, properly handling visitor reuse and conditional field inclusion. The implementation is clean and consistent with existing patterns in the file.

apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts (4)

1441-1455: LGTM! Proper test setup for lead capture scenarios.

The test suite correctly creates a visitor without email/phone data to validate the fix for lead capture when these fields are missing.


1457-1551: LGTM! Comprehensive test coverage for lead capture.

The test cases thoroughly validate email and phone capture, including multiple matches, duplicate prevention, agent message filtering, and combined capture scenarios.


1553-1580: LGTM! Important edge case testing.

This test block correctly validates that lead capture can be disabled via settings and properly restores the default regex patterns afterward.


1582-1607: LGTM! Critical test for existing visitor data.

This test validates that lead capture correctly merges new data with existing email/phone arrays, ensuring the fix doesn't break the normal case when fields are already present.

@d-gubert d-gubert added this to the 7.13.0 milestone Nov 5, 2025
@dionisio-bot dionisio-bot bot removed the stat: ready to merge PR tested and approved waiting for merge label Nov 5, 2025
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/meteor/tests/end-to-end/api/livechat/09-visitors.ts (1)

1487-1493: Minor: Typo in test descriptions.

The test descriptions use "thats" which should be "that's" or "that is" for grammatical correctness.

-	it('should not add an email thats already registered', async () => {
+	it('should not add an email that is already registered', async () => {
-	it('should not add a phone number thats already registered', async () => {
+	it('should not add a phone number that is already registered', async () => {

Also applies to: 1523-1529

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7f64a4c and 3abcb06.

📒 Files selected for processing (1)
  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (10)
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use descriptive test names that clearly communicate expected behavior

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx,js,jsx} : Follow DRY by extracting reusable logic into helper functions or page objects

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (test, page, expect) consistently

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Maintain test isolation between test cases

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,tsx} : Implement proper wait strategies for dynamic content

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure a clean state for each test execution

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use test.beforeAll() and test.afterAll() for setup and teardown

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use test.step() to organize complex test scenarios

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use expect matchers (toEqual, toContain, toBeTruthy, toHaveLength, etc.) instead of assert statements

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
🧬 Code graph analysis (1)
apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts (3)
packages/core-typings/src/ILivechatVisitor.ts (1)
  • ILivechatVisitor (28-55)
apps/meteor/tests/data/livechat/rooms.ts (7)
  • createVisitorWithCustomData (58-105)
  • createLivechatRoom (22-34)
  • createAgent (247-261)
  • closeOmnichannelRoom (417-423)
  • sendMessage (337-354)
  • sendAgentMessage (372-392)
  • createVisitor (107-141)
apps/meteor/tests/data/api-data.ts (1)
  • credentials (39-42)
⏰ 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). (2)
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (4)
apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts (4)

16-18: LGTM! Imports support the new lead capture test scenarios.

The imported functions are appropriately used throughout the new test block to create visitors without initial email/phone data and to send messages for capture testing.


1641-1666: Good test isolation in this nested block.

This nested describe block properly creates its own visitor and room with existing email/phone data, ensuring it doesn't depend on state from other tests. The assertions (lengthOf 2) correctly reflect adding 1 new item to the 1 existing item. This demonstrates good test isolation practices.

Based on learnings.


1445-1666: Excellent edge case coverage for lead capture functionality.

The test suite comprehensively covers:

  • Visitors without initial email/phone (directly addresses PR objective)
  • Multiple captures in single message
  • Duplicate prevention
  • Agent vs visitor message distinction
  • Empty/broken regex configurations
  • Merging with existing visitor data

This thorough coverage validates the fix for the MongoDB $addToSet issue when fields are missing or not arrays.


1463-1463: Good use of optional chaining and defensive coding.

The tests consistently use optional chaining (?.) and fallback patterns (|| []) to safely access potentially missing fields. This prevents brittle tests and aligns with TypeScript best practices.

Also applies to: 1472-1472, 1509-1509, 1518-1518, 1575-1575, 1578-1578, 1609-1609, 1632-1632

@sampaiodiego sampaiodiego added the stat: ready to merge PR tested and approved waiting for merge label Nov 5, 2025
@dionisio-bot dionisio-bot bot removed the stat: ready to merge PR tested and approved waiting for merge label Nov 5, 2025
@sampaiodiego sampaiodiego added the stat: ready to merge PR tested and approved waiting for merge label Nov 5, 2025
@kodiakhq kodiakhq bot merged commit 83642cb into develop Nov 6, 2025
61 checks passed
@kodiakhq kodiakhq bot deleted the fix/leadcapture branch November 6, 2025 10:40
MartinSchoeler pushed a commit that referenced this pull request Nov 6, 2025
…eady registered (#36835)

Co-authored-by: Diego Sampaio <8591547+sampaiodiego@users.noreply.github.com>
@scuciatto
Copy link
Member

/backport 7.10.4

dionisio-bot bot pushed a commit that referenced this pull request Nov 7, 2025
…eady registered (#36835)

Co-authored-by: Diego Sampaio <8591547+sampaiodiego@users.noreply.github.com>
@scuciatto
Copy link
Member

/backport 7.11.1

@scuciatto
Copy link
Member

/patch

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Nov 7, 2025

Pull request #37434 added to Project: "Patch 7.10.4"

dionisio-bot bot pushed a commit that referenced this pull request Nov 7, 2025
…eady registered (#36835)

Co-authored-by: Diego Sampaio <8591547+sampaiodiego@users.noreply.github.com>
dionisio-bot bot pushed a commit that referenced this pull request Nov 7, 2025
…eady registered (#36835)

Co-authored-by: Diego Sampaio <8591547+sampaiodiego@users.noreply.github.com>
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Nov 7, 2025

Pull request #37435 added to Project: "Patch 7.11.1"

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Nov 7, 2025

Pull request #37436 added to Project: "Patch 7.12.1"

@coderabbitai coderabbitai bot mentioned this pull request Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants