Skip to content

test: deflake livechat BH on-agent-created assertions - #41633

Merged
ggazzo merged 1 commit into
developfrom
test/deflake-bh-agent-created
Jul 30, 2026
Merged

test: deflake livechat BH on-agent-created assertions#41633
ggazzo merged 1 commit into
developfrom
test/deflake-bh-agent-created

Conversation

@ggazzo

@ggazzo ggazzo commented Jul 30, 2026

Copy link
Copy Markdown
Member

Proposed changes

Deflakes the two [CE][BH] On Agent created/removed tests in 19-business-hours.ts, which failed on develop in run 30497840427:

  • Test API Livechat (FIPS): AssertionError: expected undefined to be an array at 19-business-hours.ts:959 (openBusinessHours)
  • Test API Livechat (CE): AssertionError: expected 'available' to equal 'not-available' at 19-business-hours.ts:984

Why it flakes

afterAgentAdded sets the agent as available/not-available and then fires the business-hour logic without awaiting it:

export async function afterAgentAdded(user: IUser) {
	await setUserStatusLivechat(user._id, user.status !== 'offline' ? ILivechatAgentStatus.AVAILABLE : ILivechatAgentStatus.NOT_AVAILABLE);
	callbacks.runAsync('livechat.onNewAgentCreated', user._id);

	return user;
}

callbacks.runAsync schedules each callback with setTimeout(fn, 0), so the create-agent request responds before SingleBusinessHourBehavior.onNewAgentCreated runs. That callback is what actually:

  • fills openBusinessHours via Users.addBusinessHourByAgentIds when the BH is open, and
  • moves the agent to not-available via Users.setLivechatStatus when the BH is closed, undoing the available written 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-createAgent assertion blocks in the existing retry helper (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', ...) in afterAgentAdded, making the endpoint consistent when it returns. That changes POST latency and affects every caller of the hook including the EE Multiple behavior, so it is intentionally left out of this test-only fix.

Review in cubic

Task: ARCH-2319

Summary by CodeRabbit

  • Tests
    • Updated live chat business-hours coverage to account for asynchronous status updates.
    • Improved test reliability when verifying agent availability after creation under open or closed business hours.

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.
@dionisio-bot

dionisio-bot Bot commented Jul 30, 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 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fb02dec

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 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The Livechat business-hours end-to-end tests now retry agent lookups after creation, covering asynchronous updates for open and closed default business hours.

Changes

Business-hours test timing

Layer / File(s) Summary
Retry asynchronous agent state assertions
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
Agent creation checks now poll until the expected openBusinessHours and statusLivechat values are available for open and closed default business-hour scenarios.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested labels: type: chore

Suggested reviewers: kevlehman

🚥 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 matches the main change: deflaking Livechat business-hours on-agent-created test assertions.
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-2319: 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.

@ggazzo ggazzo added this to the 8.8.0 milestone Jul 30, 2026
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.76%. Comparing base (a18df96) to head (fb02dec).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
e2e 58.83% <ø> (-0.02%) ⬇️
e2e-api 45.95% <ø> (+0.27%) ⬆️
unit 70.72% <ø> (+0.03%) ⬆️

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 commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

/jira ARCH-2200

@ggazzo
ggazzo marked this pull request as ready for review July 30, 2026 02:21
@ggazzo
ggazzo requested a review from a team as a code owner July 30, 2026 02:21

@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/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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c136e0 and fb02dec.

📒 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!

Comment thread apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Jul 30, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 30, 2026

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

Re-trigger cubic

@ggazzo
ggazzo added this pull request to the merge queue Jul 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 30, 2026
@ggazzo
ggazzo added this pull request to the merge queue Jul 30, 2026
Merged via the queue into develop with commit cb7c5c2 Jul 30, 2026
56 checks passed
@ggazzo
ggazzo deleted the test/deflake-bh-agent-created branch July 30, 2026 12:31
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.

2 participants