test: deflake livechat business-hours and room.forward queue tests - #41538
Conversation
- 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.
|
Looks like this PR is ready to merge! 🎉 |
|
WalkthroughLivechat end-to-end tests now close rooms before related cleanup and retry business-hours assertions until asynchronous state changes complete. ChangesLivechat E2E reliability
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
/jira ARCH-2200 |
There was a problem hiding this comment.
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 winRemove 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
📒 Files selected for processing (2)
apps/meteor/tests/end-to-end/api/livechat/00-rooms.tsapps/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.tsapps/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.tsapps/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.tsapps/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.tsapps/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!
| // 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); |
There was a problem hiding this comment.
📐 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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
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.
|
Added a third deflake to this PR (same file): |
There was a problem hiding this comment.
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
📒 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
**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
**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
**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.closerequest remains covered by the previous review comment and should be removed.
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: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 (
openBusinessHoursempty — 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 roomlivechat/room.forward ... waiting_queue enabled, but department is online, transfer should succeed but it should end queued on target:The test's own scenario leaves the room queued (asserts
inquiry.status === 'queued'). Cleanup then calledcloseOmnichannelRoom→room.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.closewith the visitor token), which is valid for a queued room, then run the rest of the cleanup.Issue(s)
Steps to test or reproduce
Both races are load-dependent; the fixes remove the timing assumption rather than reproduce the race.
Further comments
Test-only, no changeset.
Task: ARCH-2294
Summary by CodeRabbit