Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions tests/room_summary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Tests the GET /_matrix/client/v1/room_summary/{roomIdOrAlias} endpoint
// as specified in https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv1room_summaryroomidoralias

package tests

import (
"testing"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

// TestRoomSummaryAllowedRoomIDs checks that the /summary endpoint includes
// allowed_room_ids for rooms with restricted join rules, and omits the field
// for rooms that do not use restricted join rules.
func TestRoomSummaryAllowedRoomIDs(t *testing.T) {
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)

alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})

// Create a space that will be referenced by the restricted room.
space := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "public_chat",
"creation_content": map[string]interface{}{
"type": "m.space",
},
})

// Create a room version 8 room with restricted join rules allowing members
// of the space above.
restrictedRoom := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "public_chat",
"room_version": "8",
"initial_state": []map[string]interface{}{
{
"type": "m.room.join_rules",
"state_key": "",
"content": map[string]interface{}{
"join_rule": "restricted",
"allow": []map[string]interface{}{
{
"type": "m.room_membership",
"room_id": &space,
},
},
},
},
},
})

// Create an invite-only room.
inviteRoom := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "private_chat",
})

t.Run("restricted room includes allowed_room_ids", func(t *testing.T) {
res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v1", "room_summary", restrictedRoom})
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: 200,
JSON: []match.JSON{
match.JSONKeyEqual("room_id", restrictedRoom),
match.JSONKeyEqual("join_rule", "restricted"),
match.JSONKeyEqual("allowed_room_ids", []interface{}{space}),
},
})
})
Comment on lines +59 to +69

@MadLittleMods MadLittleMods Jul 2, 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.

Any tests for /room_summary can be flaky for workerized Synapse deployments because the /room_summary endpoint uses information from the room_stats_state table which is updated out-of-band as replication reaches the worker that handles background tasks. This is a read-after-write consistency issue in Synapse.

I created element-hq/synapse#19905 to track the flakiness for this specific test as we're seeing flaky failures where the join_rule is missing from the /room_summary response (room_stats_state hasn't been updated yet).

I'm commenting as these tests were specifically added to test a change to Synapse (element-hq/synapse#19762). I think this is more a problem with Synapse, not the test though. If we wanted to be extra nice on the test side, we could alice.MustSyncUntil(...) and wait until the room shows up with the expected state. As a note: this isn't bullet-proof either as the worker serving /sync could be different than the worker updating room_stats_state and handling /room_summary. I think it would probably solve the immediate pesky flakes though.


t.Run("non-restricted room omits allowed_room_ids", func(t *testing.T) {
res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v1", "room_summary", inviteRoom})
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: 200,
JSON: []match.JSON{
match.JSONKeyEqual("room_id", inviteRoom),
match.JSONKeyMissing("allowed_room_ids"),
},
})
})
}
Loading