test: deflake livechat BH on-agent-created assertions - #41633
Conversation
The BH assignment for a newly created agent runs on a fire-and-forget callback (callbacks.runAsync -> setTimeout 0), so the create-agent request returns before openBusinessHours is set and before the agent is moved to not-available. Both assertions now retry instead of reading the intermediate state once.
|
Looks like this PR is ready to merge! 🎉 |
|
WalkthroughThe Livechat business-hours end-to-end tests now retry agent lookups after creation, covering asynchronous updates for open and closed default business hours. ChangesBusiness-hours test timing
Estimated code review effort: 1 (Trivial) | ~5 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 #41633 +/- ##
===========================================
+ Coverage 68.72% 68.76% +0.04%
===========================================
Files 4151 4151
Lines 159513 159513
Branches 27988 27953 -35
===========================================
+ Hits 109621 109688 +67
+ Misses 44721 44653 -68
- Partials 5171 5172 +1
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
🤖 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/19-business-hours.ts`:
- Around line 988-999: Remove the explanatory implementation comment immediately
before retry in the livechat business-hours test, while preserving the retry
call, description, and assertions 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: 40a5aa34-6757-4106-9d96-c623375a2ff8
📒 Files selected for processing (1)
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
🧰 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
🧠 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
📚 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
📚 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
🔇 Additional comments (1)
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts (1)
957-967: LGTM!
Proposed changes
Deflakes the two
[CE][BH] On Agent created/removedtests in19-business-hours.ts, which failed ondevelopin run 30497840427:Test API Livechat (FIPS):AssertionError: expected undefined to be an arrayat19-business-hours.ts:959(openBusinessHours)Test API Livechat (CE):AssertionError: expected 'available' to equal 'not-available'at19-business-hours.ts:984Why it flakes
afterAgentAddedsets the agent as available/not-available and then fires the business-hour logic without awaiting it:callbacks.runAsyncschedules each callback withsetTimeout(fn, 0), so the create-agent request responds beforeSingleBusinessHourBehavior.onNewAgentCreatedruns. That callback is what actually:openBusinessHoursviaUsers.addBusinessHourByAgentIdswhen the BH is open, andnot-availableviaUsers.setLivechatStatuswhen the BH is closed, undoing theavailablewritten a line earlier.Both tests read the agent right after
createAgent(), so they can observe the pre-callback state. Which of the two trips depends on timing, which is why CE and FIPS failed on different tests in the same run.Change
Wraps both post-
createAgentassertion blocks in the existingretryhelper (same pattern already used a few lines below for the BH-close propagation). No production code touched.Issue(s)
Follow-up to #41538, which deflaked the BH-close propagation in the same describe block but not the read right after agent creation.
Steps to test or reproduce
yarn testapi:livechat --grep "On Agent created/removed"Further comments
The server-side alternative would be
await callbacks.run('livechat.onNewAgentCreated', ...)inafterAgentAdded, making the endpoint consistent when it returns. That changes POST latency and affects every caller of the hook including the EEMultiplebehavior, so it is intentionally left out of this test-only fix.Task: ARCH-2319
Summary by CodeRabbit