Skip to content

test: deflake livechat business-hours and room.forward queue tests - #41538

Merged
ggazzo merged 3 commits into
developfrom
test/deflake-livechat-bh-forward
Jul 27, 2026
Merged

test: deflake livechat business-hours and room.forward queue tests#41538
ggazzo merged 3 commits into
developfrom
test/deflake-livechat-bh-forward

Conversation

@ggazzo

@ggazzo ggazzo commented Jul 23, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Two unrelated flakes in the API Livechat (EE) suite, both surfaced in the merge queue (run 1, run 2) on a PR that only touches thread rendering — i.e. pre-existing flakes, not caused by that PR.

1. 19-business-hours.ts — agent status race

[CE][BH] On Agent created/removed › ... default business hour which is closed:

AssertionError: expected 'available' to equal 'not-available'
  at 19-business-hours.ts:972

Closing the default BH recalculates agent statuses via an async callback. The test closed the BH and immediately created a new agent — when the close had not propagated yet, the agent was created while the BH still counted as open and came up available, and nothing re-flips an already-created agent.

Fix: after closing the BH, poll the pre-existing agent until it loses the BH assignment (openBusinessHours empty — the same positive signal the next test already asserts) before creating the new agent. Replaces reliance on implicit timing with a bounded poll.

2. 00-rooms.ts — closing a queued room

livechat/room.forward ... waiting_queue enabled, but department is online, transfer should succeed but it should end queued on target:

Error: expected 200 "OK", got 400 "Bad Request"
  at closeOmnichannelRoom (tests/data/livechat/rooms.ts:428)
  at 00-rooms.ts:1793

The test's own scenario leaves the room queued (asserts inquiry.status === 'queued'). Cleanup then called closeOmnichannelRoomroom.closeByUser, which rejects a room that is not being served (400). It only passed when the queue processor happened to assign the room to the online target agent before cleanup ran — hence the flake.

Fix: close the room as the visitor (livechat/room.close with the visitor token), which is valid for a queued room, then run the rest of the cleanup.

Issue(s)

Steps to test or reproduce

yarn testapi:livechat --grep "On Agent created/removed"
yarn testapi:livechat --grep "should end queued on target"

Both races are load-dependent; the fixes remove the timing assumption rather than reproduce the race.

Further comments

Test-only, no changeset.

Review in cubic

Task: ARCH-2294

Summary by CodeRabbit

  • Tests
    • Improved live chat end-to-end test cleanup to prevent room/department lifecycle conflicts during teardown.
    • Enhanced business-hours end-to-end tests with retry handling to better account for asynchronous propagation and reduce intermittent failures.

- 19-business-hours: closing the default BH recalculates agent status
  asynchronously; the [CE][BH] closed test created the new agent before
  the close propagated, so it came up available. Poll the existing agent
  until it loses the BH assignment before creating the new one.
- 00-rooms: the waiting_queue forward test leaves the room queued (never
  served); cleanup used room.closeByUser, which rejects a room that is
  not being served (400). Close it as the visitor instead.
@dionisio-bot

dionisio-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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

@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d2e3b6d

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

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Livechat end-to-end tests now close rooms before related cleanup and retry business-hours assertions until asynchronous state changes complete.

Changes

Livechat E2E reliability

Layer / File(s) Summary
Room cleanup lifecycle
apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
Room cleanup closes both rooms before deleting visitors and departments, and closes queued rooms through livechat/room.close with the visitor token.
Retry business-hours state assertion
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
The test uses retry to wait until the agent’s openBusinessHours becomes empty before creating another user and agent.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: type: chore

Suggested reviewers: jessicaschelly, sampaiodiego

🚥 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 reflects the test-only deflake changes in livechat business-hours and room.forward queue flows.
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.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • ARCH-2294: Request failed with status code 401

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.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.69%. Comparing base (6edcdd7) to head (d2e3b6d).
⚠️ Report is 8 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41538      +/-   ##
===========================================
+ Coverage    68.64%   68.69%   +0.04%     
===========================================
  Files         4139     4139              
  Lines       159115   159112       -3     
  Branches     27900    28008     +108     
===========================================
+ Hits        109232   109309      +77     
+ Misses       44748    44660      -88     
- Partials      5135     5143       +8     
Flag Coverage Δ
e2e 58.83% <ø> (+<0.01%) ⬆️
e2e-api 45.60% <ø> (+0.23%) ⬆️
unit 70.66% <ø> (-0.02%) ⬇️

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.

@ggazzo ggazzo added this to the 8.8.0 milestone Jul 23, 2026
@ggazzo
ggazzo marked this pull request as ready for review July 23, 2026 19:39
@ggazzo
ggazzo requested a review from a team as a code owner July 23, 2026 19:39
@ggazzo

ggazzo commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

/jira ARCH-2200

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

🧹 Nitpick comments (1)
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts (1)

966-967: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove implementation comments.

These comments duplicate the retry description and violate the guideline to avoid code comments in TypeScript/JavaScript implementation. As per coding guidelines, TypeScript/JavaScript implementation should avoid code comments.

Proposed fix
-			// the BH close recalculates agent statuses asynchronously; wait for it to propagate (existing agent loses the
-			// BH assignment) before creating the new agent, otherwise it is created while the BH still counts as open
🤖 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 `@apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts` around lines
966 - 967, Remove the implementation comment immediately preceding the retry
logic in the business-hours test, leaving the retry behavior unchanged.

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 `@apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts`:
- Around line 1790-1791: Remove the implementation comment immediately above the
livechat room.close API request, leaving the request and its assertions
unchanged.

---

Nitpick comments:
In `@apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts`:
- Around line 966-967: Remove the implementation comment immediately preceding
the retry logic in the business-hours test, leaving the retry behavior
unchanged.
🪄 Autofix (Beta)

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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c5b514f7-8448-4d45-b0a2-52c89204846f

📥 Commits

Reviewing files that changed from the base of the PR and between 6edcdd7 and 2f6e810.

📒 Files selected for processing (2)
  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (14)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (1/5)
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (5/5)
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (4/5)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (1/4)
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (3/5)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (2/4)
  • GitHub Check: 🔨 Test API Livechat (FIPS) / MongoDB 8.0 (1/1)
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (2/5)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (4/4)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (3/4)
  • GitHub Check: 🔨 Test API Livechat (EE) / MongoDB 8.0 coverage (1/1)
  • GitHub Check: 🔨 Test API (EE) / MongoDB 8.0 coverage (1/1)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
🔇 Additional comments (2)
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts (2)

34-34: LGTM!


968-975: LGTM!

Comment on lines +1790 to +1791
// the room ends queued (never taken), so close it as the visitor — room.closeByUser rejects a room that is not being served
await request.post(api('livechat/room.close')).send({ rid: newRoom._id, token: newVisitor.token }).expect(200);

@coderabbitai coderabbitai Bot Jul 23, 2026

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the implementation comment.

The API call is correct, but this TypeScript test adds an implementation comment despite the repository guideline to avoid code comments. Remove it and keep the behavior self-documenting through the API call and test structure.

🤖 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 `@apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts` around lines 1790 -
1791, Remove the implementation comment immediately above the livechat
room.close API request, leaving the request and its assertions unchanged.

Source: Coding guidelines

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fair — a silent "dev-secret" fallback on a security-critical value is exactly the kind of slip that bites in production. Fixed in the latest push.

The CLI now requires BETTER_AUTH_SECRET alongside DATABASE_URL: it's added to the usage guard (fail-fast, non-zero exit) and named in the usage string, with an explicit "refusing to use a default" error when the DB is set but the secret isn't. No fallback literal remains.

Verified both paths: with the secret exported it creates the admin; with it unset it prints the usage + error and exits 1 without touching the DB.

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.

@mzuniga84, thanks for the detailed verification. That addresses the BETTER_AUTH_SECRET fallback concern, but it appears to belong to a different review thread.

This thread is specifically about removing the implementation comment above the livechat/room.close request in apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Re-trigger cubic

The test's heavy sequential setup plus cleanup exceeded the 10s mocha
timeout on the slower FIPS runner. Close both rooms in parallel, then
remove visitors and departments in parallel (keeping close-before-delete
ordering), cutting several sequential round-trips off the test.
@ggazzo

ggazzo commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

Added a third deflake to this PR (same file): livechat/rooms › should return only rooms served by the given agents hit the 10s mocha timeout on the FIPS runner (run) — its heavy sequential setup (2 departments + 2 agents + 2 taken rooms) plus sequential cleanup didn't fit in 10s on the slower runner. Parallelized the cleanup (close both rooms, then remove visitors + departments together, keeping the close-before-delete order) to cut several round-trips. No timeout bump.

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

🤖 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 `@apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts`:
- Line 667: Remove the implementation comment preceding the room cleanup
sequence; leave the sequential await blocks and their behavior unchanged.
🪄 Autofix (Beta)

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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a2836bc9-939e-448f-8c7e-34ce590b4bb3

📥 Commits

Reviewing files that changed from the base of the PR and between 2f6e810 and d2e3b6d.

📒 Files selected for processing (1)
  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
⚠️ CI failures not shown inline (3)

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
🔇 Additional comments (1)
apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts (1)

1793-1793: Duplicate of the existing implementation-comment finding.

The comment above the livechat/room.close request remains covered by the previous review comment and should be removed.

Comment thread apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Jul 27, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 27, 2026
@ggazzo
ggazzo merged commit 5ba7bd5 into develop Jul 27, 2026
56 checks passed
@ggazzo
ggazzo deleted the test/deflake-livechat-bh-forward branch July 27, 2026 14:44
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 type: chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants