Skip to content

test(federation): add e2e test for self-join in federated rooms#38669

Open
Aryan-Verma-999 wants to merge 3 commits intoRocketChat:developfrom
Aryan-Verma-999:test/federation-self-join
Open

test(federation): add e2e test for self-join in federated rooms#38669
Aryan-Verma-999 wants to merge 3 commits intoRocketChat:developfrom
Aryan-Verma-999:test/federation-self-join

Conversation

@Aryan-Verma-999
Copy link

@Aryan-Verma-999 Aryan-Verma-999 commented Feb 13, 2026

Proposed Changes

Adds a failing e2e test that demonstrates users who self-join a federated room via channels.join API are not properly registered on the Matrix homeserver, unlike users who are explicitly invited via channels.invite.

Test Suite 1 — Self-join flow:

  • Verifies the room is federated
  • User can self-join via channels.join
  • Subscription is created
  • User appears in room members
  • User can send messages
  • FAILS: User should have federated: true and federation metadata after self-joining

Test Suite 2 — Invited vs self-joined comparison:

  • Both users appear as members
  • Invited user has federation metadata
  • FAILS: Self-joined user should have federation metadata but doesn't

Issue(s)

Closes #38239

Steps to test or reproduce

  1. Enable federation on an EE instance
  2. Create a federated channel as admin
  3. Have a different user call channels.join (self-join, no invite)
  4. Check users.info for that user — federated and federation fields are missing
  5. Compare with a user added via channels.invite — they correctly have federation metadata

Or run the test:

npm run testapi -- --grep "federation - self-join"

Further comments

This test was requested by @ggazzo in #38239 to reproduce the bug before fixing it. The root cause is in apps/meteor/ee/server/hooks/federation/index.ts, the beforeAddUserToRoom callback requires an inviter parameter, which is undefined during self-join, causing the federation registration to be skipped entirely.

Summary by CodeRabbit

Release Notes

  • Tests
    • Added comprehensive end-to-end test coverage for federation self-join scenarios, validating user behavior when joining federated rooms without invitations and ensuring proper member visibility across local and federated contexts.

Adds a failing e2e test demonstrating that users who self-join a federated room via channels.join API are not registered on the Matrix homeserver, unlike users who are explicitly invited
Ref: RocketChat#38239
@Aryan-Verma-999 Aryan-Verma-999 requested a review from a team as a code owner February 13, 2026 19:43
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 13, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Feb 13, 2026

⚠️ No Changeset found

Latest commit: 825c8c2

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
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

Walkthrough

A new end-to-end test suite for federation self-join scenarios. Tests verify local users self-joining federated rooms via the channels.join API, room membership visibility, and federation metadata across federated and local contexts, with conditional execution gated on IS_EE.

Changes

Cohort / File(s) Summary
Federation Self-Join E2E Tests
ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
New test suite covering self-join behavior: local user self-joins federated room without inviter, comparison of invited vs. self-joined users in same room, verification of room membership and federation metadata. Includes test setup with admin config, RC1 user creation, SynapseClient initialization, and cleanup with test user deletion. Several assertions are marked as skipped for future validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

type: chore

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds test coverage for issue #38239 but does not implement the actual fix. The PR only tests the bug without addressing the root cause in the federation callback logic. This PR should either implement the proposed fix for auto-registering self-joined users on the homeserver, or clarify if it's intended as a test-only PR that prepares for a follow-up implementation PR.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding an end-to-end test for self-join functionality in federated rooms, which is the primary purpose of this PR.
Out of Scope Changes check ✅ Passed All changes are focused on adding end-to-end tests for the self-join federation scenario, which is directly aligned with validating issue #38239. No out-of-scope changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

🤖 Fix all issues with AI agents
In `@apps/meteor/tests/end-to-end/api/federation-self-join.ts`:
- Around line 14-23: Remove the top JSDoc block and all inline comments in this
test file so it follows the "avoid code comments" guideline: delete the JSDoc
header and the inline comment lines referenced around the test blocks (near the
federation self-join describe/it blocks and the assertions), leaving the
existing describe/it titles and assertion messages intact as the only
documentation, and then run the linter/formatter to ensure no trailing
whitespace or formatting issues remain; key locations to edit include the file's
Federation self-join test suite (the describe/it blocks and their assertions)
where the inline comments are present.
- Around line 153-172: The two end-to-end tests that assert self-join federation
behavior (the it block titled "should mark the self-joined user as federated in
the user record" and the other failing it at lines covering 257–271) are known
to fail and must be skipped to avoid breaking CI; update those test cases to use
it.skip(...) or it.todo(...) (preserving the test descriptions) and add a short
comment pointing to the related issue/PR so they can be re-enabled when the bug
is fixed.
🧹 Nitpick comments (2)
apps/meteor/tests/end-to-end/api/federation-self-join.ts (2)

54-61: Guard cleanup against undefined references from failed setup.

If the before hook fails partway (e.g., room creation fails but user was created), federatedRoom is undefined and deleteRoom will throw inside Promise.all, potentially masking the real failure and skipping remaining cleanup. A simple guard keeps things robust:

Proposed fix (both after blocks)
         after(async () => {
-            await Promise.all([
-                deleteRoom({ type: 'c', roomId: federatedRoom._id }),
-                deleteUser(testUser),
-                updateSetting('Federation_Service_Enabled', false),
-                updatePermission('access-federation', ['admin']),
-            ]);
+            await Promise.all([
+                federatedRoom && deleteRoom({ type: 'c', roomId: federatedRoom._id }),
+                testUser && deleteUser(testUser),
+                updateSetting('Federation_Service_Enabled', false),
+                updatePermission('access-federation', ['admin']),
+            ]);
         });

Apply the same pattern to the second after block (lines 219–227).

Also applies to: 219-227


76-86: Tests depend on sequential execution order — fragile by design.

The it blocks in lines 76–151 are order-dependent: "self-join" must run before "subscription check," "send message" before "history check." While mocha runs serially by default, this is a common source of confusion. Consider documenting this coupling in the describe title (e.g., describe('sequential: …')) or consolidating tightly coupled assertions into fewer it blocks. This is a minor observation — no action required if this pattern is standard in the repo.

Also applies to: 88-99, 101-114, 116-134, 136-151

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54670a6 and bd5d3e5.

📒 Files selected for processing (1)
  • apps/meteor/tests/end-to-end/api/federation-self-join.ts
🧰 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/federation-self-join.ts
🧠 Learnings (8)
📓 Common learnings
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37377
File: apps/meteor/ee/server/hooks/federation/index.ts:86-88
Timestamp: 2025-11-04T16:49:19.107Z
Learning: In Rocket.Chat's federation system (apps/meteor/ee/server/hooks/federation/), permission checks follow two distinct patterns: (1) User-initiated federation actions (creating rooms, adding users to federated rooms, joining from invites) should throw MeteorError to inform users they lack 'access-federation' permission. (2) Remote server-initiated federation events should silently skip/ignore when users lack permission. The beforeAddUserToRoom hook only executes for local user-initiated actions, so throwing an error there is correct. Remote federation events are handled separately by the federation Matrix package with silent skipping logic.
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.
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.
Learnt from: sampaiodiego
Repo: RocketChat/Rocket.Chat PR: 37532
File: ee/packages/federation-matrix/src/FederationMatrix.ts:920-927
Timestamp: 2025-12-09T20:01:07.355Z
Learning: In Rocket.Chat's federation invite handling (ee/packages/federation-matrix/src/FederationMatrix.ts), when a user rejects an invite via federationSDK.rejectInvite(), the subscription cleanup happens automatically through an event-driven flow: Matrix emits a leave event back, which is processed by handleLeave() in ee/packages/federation-matrix/src/events/member.ts, and that function calls Room.performUserRemoval() to clean up the subscription. No explicit cleanup is needed in the reject branch of handleInvite() because the leave event handler takes care of it.
<!-- </add_learning>
📚 Learning: 2025-11-04T16:49:19.107Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37377
File: apps/meteor/ee/server/hooks/federation/index.ts:86-88
Timestamp: 2025-11-04T16:49:19.107Z
Learning: In Rocket.Chat's federation system (apps/meteor/ee/server/hooks/federation/), permission checks follow two distinct patterns: (1) User-initiated federation actions (creating rooms, adding users to federated rooms, joining from invites) should throw MeteorError to inform users they lack 'access-federation' permission. (2) Remote server-initiated federation events should silently skip/ignore when users lack permission. The beforeAddUserToRoom hook only executes for local user-initiated actions, so throwing an error there is correct. Remote federation events are handled separately by the federation Matrix package with silent skipping logic.

Applied to files:

  • apps/meteor/tests/end-to-end/api/federation-self-join.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
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/federation-self-join.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Group related tests in the same file

Applied to files:

  • apps/meteor/tests/end-to-end/api/federation-self-join.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/end-to-end/api/federation-self-join.ts
📚 Learning: 2025-11-05T21:04:35.787Z
Learnt from: sampaiodiego
Repo: RocketChat/Rocket.Chat PR: 37357
File: ee/packages/federation-matrix/src/setup.ts:103-120
Timestamp: 2025-11-05T21:04:35.787Z
Learning: In Rocket.Chat's federation-matrix setup (ee/packages/federation-matrix/src/setup.ts and apps/meteor/ee/server/startup/federation.ts), configureFederationMatrixSettings does not need to be called before setupFederationMatrix. The SDK's init() establishes infrastructure (database, event handlers, APIs) first, and the configuration can be applied later via settings watchers before actual federation events are processed. The config only matters when events actually occur, at which point all infrastructure is already configured.

Applied to files:

  • apps/meteor/tests/end-to-end/api/federation-self-join.ts
📚 Learning: 2025-12-09T20:01:07.355Z
Learnt from: sampaiodiego
Repo: RocketChat/Rocket.Chat PR: 37532
File: ee/packages/federation-matrix/src/FederationMatrix.ts:920-927
Timestamp: 2025-12-09T20:01:07.355Z
Learning: In Rocket.Chat's federation invite handling (ee/packages/federation-matrix/src/FederationMatrix.ts), when a user rejects an invite via federationSDK.rejectInvite(), the subscription cleanup happens automatically through an event-driven flow: Matrix emits a leave event back, which is processed by handleLeave() in ee/packages/federation-matrix/src/events/member.ts, and that function calls Room.performUserRemoval() to clean up the subscription. No explicit cleanup is needed in the reject branch of handleInvite() because the leave event handler takes care of it.
<!-- </add_learning>

Applied to files:

  • apps/meteor/tests/end-to-end/api/federation-self-join.ts
📚 Learning: 2025-09-19T15:15:04.642Z
Learnt from: rodrigok
Repo: RocketChat/Rocket.Chat PR: 36991
File: apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts:219-221
Timestamp: 2025-09-19T15:15:04.642Z
Learning: The Federation_Matrix_homeserver_domain setting in apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts is part of the old federation system and is being deprecated/removed, so configuration issues with this setting should not be flagged for improvement.

Applied to files:

  • apps/meteor/tests/end-to-end/api/federation-self-join.ts
⏰ 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). (1)
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (2)
apps/meteor/tests/end-to-end/api/federation-self-join.ts (2)

1-12: LGTM — imports are clean and well-scoped.

Correct usage of type-only imports for Credentials, IRoom, IUser, and TestUser. Helper imports are appropriate for the test patterns used.


24-25: LGTM — EE guard and credential setup.

Properly gates the entire suite behind IS_EE and initializes credentials in before.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 1 file

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="apps/meteor/tests/end-to-end/api/federation-self-join.ts">

<violation number="1" location="apps/meteor/tests/end-to-end/api/federation-self-join.ts:170">
P2: The new test contains assertions explicitly documented as "currently FAILS" but is not skipped. This will break CI unless the underlying bug fix is included; consider skipping the test until the behavior is fixed or include the fix in this PR.</violation>

<violation number="2" location="apps/meteor/tests/end-to-end/api/federation-self-join.ts:257">
P1: This test is documented to fail (demonstrating a known bug) and will break CI if merged. Use `it.skip()` or `it.todo()` to mark it as pending until the fix for issue #38239 lands.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.71%. Comparing base (cb3e570) to head (825c8c2).
⚠️ Report is 150 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38669      +/-   ##
===========================================
+ Coverage    70.46%   70.71%   +0.24%     
===========================================
  Files         3175     3195      +20     
  Lines       111091   113106    +2015     
  Branches     20029    20610     +581     
===========================================
+ Hits         78278    79978    +1700     
- Misses       30763    31079     +316     
+ Partials      2050     2049       -1     
Flag Coverage Δ
e2e 60.35% <ø> (-0.07%) ⬇️
e2e-api 47.77% <ø> (+0.06%) ⬆️
unit 71.37% <ø> (-0.09%) ⬇️

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.

Copy link
Member

@ggazzo ggazzo left a comment

Choose a reason for hiding this comment

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

I was expecting those tests under ./ee/packages/federation-matrix make sure lint and ts are ok... then we can work to provide a fix ;)

@Aryan-Verma-999
Copy link
Author

Aryan-Verma-999 commented Feb 28, 2026

Done! Moved the test to ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts :)

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.

🧹 Nitpick comments (2)
ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts (2)

87-88: Consider guarding against undefined config properties.

Non-null assertions on request! and credentials! will throw if getRequestConfig returns an incomplete configuration. A type guard or early validation would provide a clearer error message.

🔧 Optional: Add validation before using config
 it('should allow a local user to self-join the federated room', async () => {
-  const requestInstance = selfJoinUserRequestConfig.request!;
-  const credentialsInstance = selfJoinUserRequestConfig.credentials!;
+  const { request: requestInstance, credentials: credentialsInstance } = selfJoinUserRequestConfig;
+  if (!requestInstance || !credentialsInstance) {
+    throw new Error('Self-join user request config is incomplete');
+  }

   const response = await requestInstance.post('/api/v1/channels.join').set(credentialsInstance).send({ roomId: federatedChannel._id });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts` around
lines 87 - 88, The test currently uses non-null assertions on
selfJoinUserRequestConfig.request and .credentials (assigned to requestInstance
and credentialsInstance) which will throw uninformative errors if
getRequestConfig returns incomplete data; replace the assertions with an
explicit guard/validation: check that selfJoinUserRequestConfig and its request
and credentials properties are defined (or call getRequestConfig and validate
its return), and if not, throw or fail the test with a clear message (e.g.,
"getRequestConfig returned missing request/credentials for self-join") before
using requestInstance/credentialsInstance so later code can assume them safely.

42-42: Consider using a more specific type for federatedChannel.

Using any type loses type safety. Consider importing or defining a type for the room response body.

🔧 Optional: Use IRoom or a partial type
+import type { IRoom } from '@rocket.chat/core-typings';
+
+// In describe blocks:
-let federatedChannel: any;
+let federatedChannel: Pick<IRoom, '_id' | 'federated' | 'name'>;

Also applies to: 125-125

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts` at line 42,
Replace the loose any type for the test variable federatedChannel with a
concrete Room/response type to restore type safety: import or declare the
appropriate interface (e.g., IRoom or a Partial<IRoom> / RoomResponseBody) and
annotate federatedChannel with that type instead of any; update the same
variable usage elsewhere in this file (the other federatedChannel declaration)
to use the same specific type so the test assertions and autocompletion work
correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts`:
- Around line 87-88: The test currently uses non-null assertions on
selfJoinUserRequestConfig.request and .credentials (assigned to requestInstance
and credentialsInstance) which will throw uninformative errors if
getRequestConfig returns incomplete data; replace the assertions with an
explicit guard/validation: check that selfJoinUserRequestConfig and its request
and credentials properties are defined (or call getRequestConfig and validate
its return), and if not, throw or fail the test with a clear message (e.g.,
"getRequestConfig returned missing request/credentials for self-join") before
using requestInstance/credentialsInstance so later code can assume them safely.
- Line 42: Replace the loose any type for the test variable federatedChannel
with a concrete Room/response type to restore type safety: import or declare the
appropriate interface (e.g., IRoom or a Partial<IRoom> / RoomResponseBody) and
annotate federatedChannel with that type instead of any; update the same
variable usage elsewhere in this file (the other federatedChannel declaration)
to use the same specific type so the test assertions and autocompletion work
correctly.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 597f16f and 825c8c2.

📒 Files selected for processing (1)
  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📜 Review details
⏰ 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). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{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:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
**/*.spec.ts

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

**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use .spec.ts extension for test files (e.g., login.spec.ts)

Files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
🧠 Learnings (15)
📓 Common learnings
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37377
File: apps/meteor/ee/server/hooks/federation/index.ts:86-88
Timestamp: 2025-11-04T16:49:19.107Z
Learning: In Rocket.Chat's federation system (apps/meteor/ee/server/hooks/federation/), permission checks follow two distinct patterns: (1) User-initiated federation actions (creating rooms, adding users to federated rooms, joining from invites) should throw MeteorError to inform users they lack 'access-federation' permission. (2) Remote server-initiated federation events should silently skip/ignore when users lack permission. The beforeAddUserToRoom hook only executes for local user-initiated actions, so throwing an error there is correct. Remote federation events are handled separately by the federation Matrix package with silent skipping logic.
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.
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.
Learnt from: sampaiodiego
Repo: RocketChat/Rocket.Chat PR: 37532
File: ee/packages/federation-matrix/src/FederationMatrix.ts:920-927
Timestamp: 2025-12-09T20:01:07.355Z
Learning: In Rocket.Chat's federation invite handling (ee/packages/federation-matrix/src/FederationMatrix.ts), when a user rejects an invite via federationSDK.rejectInvite(), the subscription cleanup happens automatically through an event-driven flow: Matrix emits a leave event back, which is processed by handleLeave() in ee/packages/federation-matrix/src/events/member.ts, and that function calls Room.performUserRemoval() to clean up the subscription. No explicit cleanup is needed in the reject branch of handleInvite() because the leave event handler takes care of it.
<!-- </add_learning>
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Group related tests in the same file

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (`test`, `page`, `expect`) for consistency in test files

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `test.step()` for complex test scenarios to improve organization in Playwright tests

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Maintain test isolation between test cases in Playwright tests

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-12-10T21:00:54.909Z
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:54.909Z
Learning: Rocket.Chat monorepo: Jest testMatch pattern '<rootDir>/src/**/*.spec.(ts|js|mjs)' is valid in this repo and used across multiple packages (e.g., packages/tools, ee/packages/omnichannel-services). Do not flag it as invalid in future reviews.

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : All test files must be created in `apps/meteor/tests/e2e/` directory

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-11-05T21:04:35.787Z
Learnt from: sampaiodiego
Repo: RocketChat/Rocket.Chat PR: 37357
File: ee/packages/federation-matrix/src/setup.ts:103-120
Timestamp: 2025-11-05T21:04:35.787Z
Learning: In Rocket.Chat's federation-matrix setup (ee/packages/federation-matrix/src/setup.ts and apps/meteor/ee/server/startup/federation.ts), configureFederationMatrixSettings does not need to be called before setupFederationMatrix. The SDK's init() establishes infrastructure (database, event handlers, APIs) first, and the configuration can be applied later via settings watchers before actual federation events are processed. The config only matters when events actually occur, at which point all infrastructure is already configured.

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.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:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-11-04T16:49:19.107Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37377
File: apps/meteor/ee/server/hooks/federation/index.ts:86-88
Timestamp: 2025-11-04T16:49:19.107Z
Learning: In Rocket.Chat's federation system (apps/meteor/ee/server/hooks/federation/), permission checks follow two distinct patterns: (1) User-initiated federation actions (creating rooms, adding users to federated rooms, joining from invites) should throw MeteorError to inform users they lack 'access-federation' permission. (2) Remote server-initiated federation events should silently skip/ignore when users lack permission. The beforeAddUserToRoom hook only executes for local user-initiated actions, so throwing an error there is correct. Remote federation events are handled separately by the federation Matrix package with silent skipping logic.

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2025-12-09T20:01:00.324Z
Learnt from: sampaiodiego
Repo: RocketChat/Rocket.Chat PR: 37532
File: ee/packages/federation-matrix/src/FederationMatrix.ts:920-927
Timestamp: 2025-12-09T20:01:00.324Z
Learning: When reviewing federation invite handling in Rocket.Chat (specifically under ee/packages/federation-matrix), understand that rejecting an invite via federationSDK.rejectInvite() triggers an event-driven cleanup: a leave event is emitted and handled by handleLeave() in ee/packages/federation-matrix/src/events/member.ts, which calls Room.performUserRemoval() to remove the subscription. Do not add explicit cleanup in the reject branch of handleInvite(); rely on the existing leave-event flow for cleanup. If making changes, ensure this invariant remains and that any related paths still funnel cleanup through the leave event to avoid duplicate or missing removals.

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.

Applied to files:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.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 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:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.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:

  • ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts
🔇 Additional comments (6)
ee/packages/federation-matrix/tests/end-to-end/self-join.spec.ts (6)

1-7: LGTM!

Imports are well-organized and include all necessary dependencies for the federation self-join test scenarios.


9-38: LGTM!

The conditional execution pattern with IS_EE and the setup/teardown for federation testing infrastructure is appropriate.


96-105: LGTM!

The retry configuration for findRoomMember is appropriate for handling eventual consistency in federation scenarios.


107-120: LGTM!

The skipped tests appropriately document the expected behavior that will pass once the federation self-join bug is fixed (per Issue #38239).


179-215: LGTM!

The comparison tests effectively demonstrate the discrepancy between invited and self-joined users, which aligns with the bug reproduction intent of this PR.


86-94: channels.join is the correct unified endpoint for joining both public and private rooms.

There is no groups.join endpoint in Rocket.Chat's API. The channels.join endpoint is the standard way to join all room types, including private federated rooms. The findChannelByIdOrName function searches rooms by ID or name regardless of type, and the underlying Room.join() method handles both public and private rooms generically. The test design and explicit suite name confirm this is intentional.

Likely an incorrect or invalid review comment.

@Aryan-Verma-999
Copy link
Author

Aryan-Verma-999 commented Mar 2, 2026

CI results confirm the test reproduces the bug correctly
TypeScript and lint both pass, all 171 existing tests pass, and only the 4 new self-join tests fail as expected (demonstrating #38239). Ready for re-review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] [Federation] Allow users to self-join federated rooms with proper homeserver registration

2 participants